1 /* 2 * Copyright (C) 2019 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.Color; 20 import android.graphics.Point; 21 import android.graphics.PorterDuff; 22 import android.uirendering.cts.bitmapverifiers.SamplePointVerifier; 23 import android.uirendering.cts.blendmode.BitmapBlendModeCanvasClient; 24 import android.uirendering.cts.testinfrastructure.ActivityTestBase; 25 26 import androidx.test.filters.SmallTest; 27 import androidx.test.runner.AndroidJUnit4; 28 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 @SmallTest 33 @RunWith(AndroidJUnit4.class) 34 public class BitmapBlendModeTest extends ActivityTestBase { 35 36 private static final Point[] SAMPLE_POINTS = { 37 new Point(0, 0), 38 new Point(TEST_WIDTH - 1, 0), 39 new Point(0, TEST_HEIGHT - 1), 40 new Point(TEST_WIDTH - 1, TEST_HEIGHT - 1), 41 new Point (TEST_WIDTH / 2, TEST_HEIGHT / 2) 42 }; 43 44 @Test testClearBlendMode()45 public void testClearBlendMode() { 46 // Verify that using CLEAR for rendering a bitmap has the same behavior as 47 // DST_OUT. This is to verify the backward compatible behavior of using clear ends up 48 // utilizing dst_out while rendering a bitmap on API levels 27 and below 49 // The output image here should be a red circle with a white background even though 50 // the original mask bitmap is drawn with a blue circle 51 int[] colors = {Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.RED}; 52 BitmapBlendModeCanvasClient client = new BitmapBlendModeCanvasClient( 53 PorterDuff.Mode.CLEAR, PorterDuff.Mode.DST_OVER, 54 Color.BLUE, Color.RED); 55 createTest().addCanvasClientWithoutUsingPicture(client, true) 56 .runWithVerifier(new SamplePointVerifier(SAMPLE_POINTS, colors)); 57 } 58 59 @Test testDstOutBlendMode()60 public void testDstOutBlendMode() { 61 // Verify that using DST_OUT for rendering a bitmap only clears the overlapping 62 // pixels of the bitmap from the destination. 63 // The output image here should be a red circle with a white background even though 64 // the original mask bitmap is drawn with a blue circle 65 int[] colors = {Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.RED}; 66 BitmapBlendModeCanvasClient client = new BitmapBlendModeCanvasClient( 67 PorterDuff.Mode.DST_OUT, PorterDuff.Mode.DST_OVER, 68 Color.BLUE, Color.RED); 69 createTest().addCanvasClientWithoutUsingPicture(client, true) 70 .runWithVerifier(new SamplePointVerifier(SAMPLE_POINTS, colors)); 71 } 72 } 73