blob: d61be37692c4baa149782bd0834b274693fb4133 [file] [log] [blame]
Ahan Wud8609332020-01-15 20:08:08 +08001/*
2 * Copyright (C) 2020 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
17package com.android.systemui.glwallpaper;
18
19import static com.android.systemui.glwallpaper.GLWallpaperRenderer.SurfaceProxy;
20
21import static com.google.common.truth.Truth.assertThat;
22
23import static org.mockito.Mockito.doReturn;
24import static org.mockito.Mockito.spy;
25
26import android.app.WallpaperManager;
27import android.app.WallpaperManager.ColorManagementProxy;
28import android.graphics.Bitmap;
29import android.graphics.ColorSpace;
30import android.testing.AndroidTestingRunner;
31import android.testing.TestableLooper;
32
33import androidx.test.filters.SmallTest;
34
35import com.android.systemui.SysuiTestCase;
36
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40
41import java.io.IOException;
42import java.util.HashSet;
43import java.util.Set;
44
45@SmallTest
46@RunWith(AndroidTestingRunner.class)
47@TestableLooper.RunWithLooper(setAsMainLooper = true)
48public class ImageWallpaperRendererTest extends SysuiTestCase {
49
50 private WallpaperManager mWpmSpy;
51 private SurfaceProxy mSurfaceProxy;
52
53 @Before
54 public void setUp() throws Exception {
55 final WallpaperManager wpm = mContext.getSystemService(WallpaperManager.class);
56 mWpmSpy = spy(wpm);
57 mContext.addMockSystemService(WallpaperManager.class, mWpmSpy);
58
59 mSurfaceProxy = new SurfaceProxy() {
60 @Override
61 public void requestRender() {
62 // NO-op
63 }
64
65 @Override
66 public void preRender() {
67 // No-op
68 }
69
70 @Override
71 public void postRender() {
72 // No-op
73 }
74 };
75 }
76
77 @Test
78 public void testWcgContent() throws IOException {
79 final Bitmap srgbBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
80 final Bitmap p3Bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888,
81 false /* hasAlpha */, ColorSpace.get(ColorSpace.Named.DISPLAY_P3));
82
83 final ColorManagementProxy proxy = new ColorManagementProxy(mContext);
84 final ColorManagementProxy cmProxySpy = spy(proxy);
85 final Set<ColorSpace> supportedWideGamuts = new HashSet<>();
86 supportedWideGamuts.add(ColorSpace.get(ColorSpace.Named.DISPLAY_P3));
87
88 try {
89 doReturn(true).when(mWpmSpy).shouldEnableWideColorGamut();
90 doReturn(cmProxySpy).when(mWpmSpy).getColorManagementProxy();
91 doReturn(supportedWideGamuts).when(cmProxySpy).getSupportedColorSpaces();
92
93 mWpmSpy.setBitmap(p3Bitmap);
94 ImageWallpaperRenderer rendererP3 = new ImageWallpaperRenderer(mContext, mSurfaceProxy);
Ahan Wu3222d3f2020-03-11 20:24:00 +080095 rendererP3.reportSurfaceSize();
Ahan Wud8609332020-01-15 20:08:08 +080096 assertThat(rendererP3.isWcgContent()).isTrue();
97
98 mWpmSpy.setBitmap(srgbBitmap);
99 ImageWallpaperRenderer renderer = new ImageWallpaperRenderer(mContext, mSurfaceProxy);
100 assertThat(renderer.isWcgContent()).isFalse();
101 } finally {
102 srgbBitmap.recycle();
103 p3Bitmap.recycle();
104 }
105 }
106
107}