1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.uirendering.cts.testinfrastructure; 17 18 import android.content.Context; 19 import android.graphics.Canvas; 20 import android.graphics.Color; 21 import android.graphics.Paint; 22 import android.util.AttributeSet; 23 import android.view.View; 24 25 /** 26 * A simple View that uses a CanvasClient to draw its contents 27 */ 28 public class CanvasClientView extends View { 29 private CanvasClient mCanvasClient; 30 CanvasClientView(Context context)31 public CanvasClientView(Context context) { 32 super(context); 33 } 34 CanvasClientView(Context context, AttributeSet attrs)35 public CanvasClientView(Context context, AttributeSet attrs) { 36 super(context, attrs); 37 } 38 CanvasClientView(Context context, AttributeSet attrs, int defStyleAttr)39 public CanvasClientView(Context context, AttributeSet attrs, int defStyleAttr) { 40 super(context, attrs, defStyleAttr); 41 } 42 setCanvasClient(CanvasClient canvasClient)43 public void setCanvasClient(CanvasClient canvasClient) { 44 mCanvasClient = canvasClient; 45 } 46 47 @Override onDraw(Canvas canvas)48 public void onDraw(Canvas canvas) { 49 if (ActivityTestBase.DEBUG) { 50 String s = canvas.isHardwareAccelerated() ? "HARDWARE" : "SOFTWARE"; 51 Paint paint = new Paint(); 52 paint.setColor(Color.BLACK); 53 paint.setTextSize(20); 54 canvas.drawText(s, 200, 200, paint); 55 } 56 if (mCanvasClient == null) throw new IllegalStateException("Canvas client missing"); 57 58 canvas.save(); 59 canvas.clipRect(0, 0, ActivityTestBase.TEST_WIDTH, ActivityTestBase.TEST_HEIGHT); 60 mCanvasClient.draw(canvas, ActivityTestBase.TEST_WIDTH, ActivityTestBase.TEST_HEIGHT); 61 canvas.restore(); 62 } 63 } 64