CTS drawing pictures through HWUI for b/21945972
Make sure that a Picture drawn through a hardware Canvas respects
transforms and clips previously applied.
Change-Id: I6e41a069fda8e0791ad136a5ef1365a229966e44
diff --git a/tests/tests/uirendering/src/android/uirendering/cts/testclasses/PictureTest.java b/tests/tests/uirendering/src/android/uirendering/cts/testclasses/PictureTest.java
new file mode 100644
index 0000000..6619b11
--- /dev/null
+++ b/tests/tests/uirendering/src/android/uirendering/cts/testclasses/PictureTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.uirendering.cts.testclasses;
+
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Picture;
+import android.graphics.Rect;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.uirendering.cts.bitmapverifiers.ColorVerifier;
+import android.uirendering.cts.bitmapverifiers.RectVerifier;
+import android.uirendering.cts.testinfrastructure.ActivityTestBase;
+import android.uirendering.cts.testinfrastructure.CanvasClient;
+
+public class PictureTest extends ActivityTestBase {
+
+ private static final Rect sRect = new Rect(0, 0, 40, 40);
+ private static final Rect sOffsetRect = new Rect(40, 0, 80, 40);
+
+ private static final Picture greenSquare() {
+ Paint pt = new Paint();
+ pt.setColor(Color.GREEN);
+ Picture pic = new Picture();
+ Canvas subcanvas = pic.beginRecording(ActivityTestBase.TEST_WIDTH,
+ ActivityTestBase.TEST_HEIGHT);
+ subcanvas.drawRect(sRect, pt);
+ pic.endRecording();
+
+ return pic;
+ }
+
+ public void testPictureRespectsClip() throws Exception {
+ createTest()
+ .addCanvasClient(
+ new CanvasClient() {
+ @Override
+ public void draw(Canvas canvas, int width, int height) {
+ Picture pic = greenSquare();
+ canvas.clipRect(sOffsetRect);
+ pic.draw(canvas); // should be clipped out
+ }
+ }
+ ).runWithVerifier(new ColorVerifier(Color.WHITE));
+ }
+
+ public void testPictureRespectsTranslate() throws Exception {
+ createTest()
+ .addCanvasClient(
+ new CanvasClient() {
+ @Override
+ public void draw(Canvas canvas, int width, int height) {
+ Picture pic = greenSquare();
+ canvas.translate(40, 0);
+ pic.draw(canvas); // should be offset
+ }
+ }
+ ).runWithVerifier(
+ new RectVerifier(Color.WHITE, Color.GREEN, sOffsetRect));
+ }
+}
+