Ahan Wu | d860933 | 2020-01-15 20:08:08 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.glwallpaper; |
| 18 | |
| 19 | import static com.android.systemui.glwallpaper.GLWallpaperRenderer.SurfaceProxy; |
| 20 | |
| 21 | import static com.google.common.truth.Truth.assertThat; |
| 22 | |
| 23 | import static org.mockito.Mockito.doReturn; |
| 24 | import static org.mockito.Mockito.spy; |
| 25 | |
| 26 | import android.app.WallpaperManager; |
| 27 | import android.app.WallpaperManager.ColorManagementProxy; |
| 28 | import android.graphics.Bitmap; |
| 29 | import android.graphics.ColorSpace; |
| 30 | import android.testing.AndroidTestingRunner; |
| 31 | import android.testing.TestableLooper; |
| 32 | |
| 33 | import androidx.test.filters.SmallTest; |
| 34 | |
| 35 | import com.android.systemui.SysuiTestCase; |
| 36 | |
| 37 | import org.junit.Before; |
| 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
| 40 | |
| 41 | import java.io.IOException; |
| 42 | import java.util.HashSet; |
| 43 | import java.util.Set; |
| 44 | |
| 45 | @SmallTest |
| 46 | @RunWith(AndroidTestingRunner.class) |
| 47 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 48 | public 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 Wu | 3222d3f | 2020-03-11 20:24:00 +0800 | [diff] [blame] | 95 | rendererP3.reportSurfaceSize(); |
Ahan Wu | d860933 | 2020-01-15 20:08:08 +0800 | [diff] [blame] | 96 | 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 | } |