1 /* 2 * Copyright (C) 2015 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 17 package android.uirendering.cts.testclasses; 18 19 import android.graphics.Canvas; 20 import android.graphics.Color; 21 import android.graphics.Paint; 22 import android.graphics.Picture; 23 import android.graphics.Rect; 24 import android.test.suitebuilder.annotation.SmallTest; 25 import android.uirendering.cts.bitmapverifiers.ColorVerifier; 26 import android.uirendering.cts.bitmapverifiers.RectVerifier; 27 import android.uirendering.cts.testinfrastructure.ActivityTestBase; 28 import android.uirendering.cts.testinfrastructure.CanvasClient; 29 30 public class PictureTest extends ActivityTestBase { 31 32 private static final Rect sRect = new Rect(0, 0, 40, 40); 33 private static final Rect sOffsetRect = new Rect(40, 0, 80, 40); 34 greenSquare()35 private static final Picture greenSquare() { 36 Paint pt = new Paint(); 37 pt.setColor(Color.GREEN); 38 Picture pic = new Picture(); 39 Canvas subcanvas = pic.beginRecording(ActivityTestBase.TEST_WIDTH, 40 ActivityTestBase.TEST_HEIGHT); 41 subcanvas.drawRect(sRect, pt); 42 pic.endRecording(); 43 44 return pic; 45 } 46 testPictureRespectsClip()47 public void testPictureRespectsClip() throws Exception { 48 createTest() 49 .addCanvasClient( 50 new CanvasClient() { 51 @Override 52 public void draw(Canvas canvas, int width, int height) { 53 Picture pic = greenSquare(); 54 canvas.clipRect(sOffsetRect); 55 pic.draw(canvas); // should be clipped out 56 } 57 } 58 ).runWithVerifier(new ColorVerifier(Color.WHITE)); 59 } 60 testPictureRespectsTranslate()61 public void testPictureRespectsTranslate() throws Exception { 62 createTest() 63 .addCanvasClient( 64 new CanvasClient() { 65 @Override 66 public void draw(Canvas canvas, int width, int height) { 67 Picture pic = greenSquare(); 68 canvas.translate(40, 0); 69 pic.draw(canvas); // should be offset 70 } 71 } 72 ).runWithVerifier( 73 new RectVerifier(Color.WHITE, Color.GREEN, sOffsetRect)); 74 } 75 } 76 77