| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2011 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 | #include <gtest/gtest.h> | 
|  | 18 |  | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 19 | #include <android/native_window.h> | 
|  | 20 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 21 | #include <binder/IMemory.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 22 |  | 
|  | 23 | #include <gui/ISurfaceComposer.h> | 
|  | 24 | #include <gui/Surface.h> | 
|  | 25 | #include <gui/SurfaceComposerClient.h> | 
|  | 26 | #include <private/gui/ComposerService.h> | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 27 | #include <private/gui/LayerState.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 28 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 29 | #include <utils/String8.h> | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 30 | #include <ui/DisplayInfo.h> | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 31 |  | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 32 | #include <math.h> | 
|  | 33 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 34 | namespace android { | 
|  | 35 |  | 
|  | 36 | // Fill an RGBA_8888 formatted surface with a single color. | 
|  | 37 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, | 
|  | 38 | uint8_t r, uint8_t g, uint8_t b) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 39 | ANativeWindow_Buffer outBuffer; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 40 | sp<Surface> s = sc->getSurface(); | 
|  | 41 | ASSERT_TRUE(s != NULL); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 42 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, NULL)); | 
|  | 43 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 44 | for (int y = 0; y < outBuffer.height; y++) { | 
|  | 45 | for (int x = 0; x < outBuffer.width; x++) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 46 | uint8_t* pixel = img + (4 * (y*outBuffer.stride + x)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 47 | pixel[0] = r; | 
|  | 48 | pixel[1] = g; | 
|  | 49 | pixel[2] = b; | 
|  | 50 | pixel[3] = 255; | 
|  | 51 | } | 
|  | 52 | } | 
|  | 53 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check | 
|  | 57 | // individual pixel values for testing purposes. | 
|  | 58 | class ScreenCapture : public RefBase { | 
|  | 59 | public: | 
|  | 60 | static void captureScreen(sp<ScreenCapture>* sc) { | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 61 | sp<IGraphicBufferProducer> producer; | 
|  | 62 | sp<IGraphicBufferConsumer> consumer; | 
|  | 63 | BufferQueue::createBufferQueue(&producer, &consumer); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 64 | sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 65 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 66 | sp<IBinder> display(sf->getBuiltInDisplay( | 
|  | 67 | ISurfaceComposer::eDisplayIdMain)); | 
| Pablo Ceballos | 15311bd | 2016-06-01 18:53:40 -0700 | [diff] [blame] | 68 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 69 | SurfaceComposerClient::closeGlobalTransaction(true); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 70 | ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0, | 
|  | 71 | 0, INT_MAX, false)); | 
|  | 72 | *sc = new ScreenCapture(cpuConsumer); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
|  | 75 | void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) { | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 76 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format); | 
|  | 77 | const uint8_t* img = static_cast<const uint8_t*>(mBuf.data); | 
|  | 78 | const uint8_t* pixel = img + (4 * (y * mBuf.stride + x)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 79 | if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { | 
|  | 80 | String8 err(String8::format("pixel @ (%3d, %3d): " | 
|  | 81 | "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", | 
|  | 82 | x, y, r, g, b, pixel[0], pixel[1], pixel[2])); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 83 | EXPECT_EQ(String8(), err) << err.string(); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 84 | } | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | private: | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 88 | ScreenCapture(const sp<CpuConsumer>& cc) : | 
|  | 89 | mCC(cc) { | 
|  | 90 | EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf)); | 
|  | 91 | } | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 92 |  | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 93 | ~ScreenCapture() { | 
|  | 94 | mCC->unlockBuffer(mBuf); | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | sp<CpuConsumer> mCC; | 
|  | 98 | CpuConsumer::LockedBuffer mBuf; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 99 | }; | 
|  | 100 |  | 
|  | 101 | class LayerUpdateTest : public ::testing::Test { | 
|  | 102 | protected: | 
|  | 103 | virtual void SetUp() { | 
|  | 104 | mComposerClient = new SurfaceComposerClient; | 
|  | 105 | ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); | 
|  | 106 |  | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 107 | sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay( | 
|  | 108 | ISurfaceComposer::eDisplayIdMain)); | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 109 | DisplayInfo info; | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 110 | SurfaceComposerClient::getDisplayInfo(display, &info); | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 111 |  | 
|  | 112 | ssize_t displayWidth = info.w; | 
|  | 113 | ssize_t displayHeight = info.h; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 114 |  | 
|  | 115 | // Background surface | 
|  | 116 | mBGSurfaceControl = mComposerClient->createSurface( | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 117 | String8("BG Test Surface"), displayWidth, displayHeight, | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 118 | PIXEL_FORMAT_RGBA_8888, 0); | 
|  | 119 | ASSERT_TRUE(mBGSurfaceControl != NULL); | 
|  | 120 | ASSERT_TRUE(mBGSurfaceControl->isValid()); | 
|  | 121 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); | 
|  | 122 |  | 
|  | 123 | // Foreground surface | 
|  | 124 | mFGSurfaceControl = mComposerClient->createSurface( | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 125 | String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 126 | ASSERT_TRUE(mFGSurfaceControl != NULL); | 
|  | 127 | ASSERT_TRUE(mFGSurfaceControl->isValid()); | 
|  | 128 |  | 
|  | 129 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 130 |  | 
|  | 131 | // Synchronization surface | 
|  | 132 | mSyncSurfaceControl = mComposerClient->createSurface( | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 133 | String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 134 | ASSERT_TRUE(mSyncSurfaceControl != NULL); | 
|  | 135 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); | 
|  | 136 |  | 
|  | 137 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 138 |  | 
|  | 139 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 140 |  | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 141 | mComposerClient->setDisplayLayerStack(display, 0); | 
|  | 142 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 143 | ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT_MAX-2)); | 
|  | 144 | ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show()); | 
|  | 145 |  | 
|  | 146 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX-1)); | 
|  | 147 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64)); | 
|  | 148 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show()); | 
|  | 149 |  | 
|  | 150 | ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setLayer(INT_MAX-1)); | 
|  | 151 | ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setPosition(displayWidth-2, | 
|  | 152 | displayHeight-2)); | 
|  | 153 | ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->show()); | 
|  | 154 |  | 
|  | 155 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | virtual void TearDown() { | 
|  | 159 | mComposerClient->dispose(); | 
|  | 160 | mBGSurfaceControl = 0; | 
|  | 161 | mFGSurfaceControl = 0; | 
|  | 162 | mSyncSurfaceControl = 0; | 
|  | 163 | mComposerClient = 0; | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | void waitForPostedBuffers() { | 
|  | 167 | // Since the sync surface is in synchronous mode (i.e. double buffered) | 
|  | 168 | // posting three buffers to it should ensure that at least two | 
|  | 169 | // SurfaceFlinger::handlePageFlip calls have been made, which should | 
|  | 170 | // guaranteed that a buffer posted to another Surface has been retired. | 
|  | 171 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 172 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 173 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 174 | } | 
|  | 175 |  | 
|  | 176 | sp<SurfaceComposerClient> mComposerClient; | 
|  | 177 | sp<SurfaceControl> mBGSurfaceControl; | 
|  | 178 | sp<SurfaceControl> mFGSurfaceControl; | 
|  | 179 |  | 
|  | 180 | // This surface is used to ensure that the buffers posted to | 
|  | 181 | // mFGSurfaceControl have been picked up by SurfaceFlinger. | 
|  | 182 | sp<SurfaceControl> mSyncSurfaceControl; | 
|  | 183 | }; | 
|  | 184 |  | 
|  | 185 | TEST_F(LayerUpdateTest, LayerMoveWorks) { | 
|  | 186 | sp<ScreenCapture> sc; | 
|  | 187 | { | 
|  | 188 | SCOPED_TRACE("before move"); | 
|  | 189 | ScreenCapture::captureScreen(&sc); | 
|  | 190 | sc->checkPixel(  0,  12,  63,  63, 195); | 
|  | 191 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 192 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 196 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128)); | 
|  | 197 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 198 | { | 
|  | 199 | // This should reflect the new position, but not the new color. | 
|  | 200 | SCOPED_TRACE("after move, before redraw"); | 
|  | 201 | ScreenCapture::captureScreen(&sc); | 
|  | 202 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 203 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 204 | sc->checkPixel(145, 145, 195,  63,  63); | 
|  | 205 | } | 
|  | 206 |  | 
|  | 207 | fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63); | 
|  | 208 | waitForPostedBuffers(); | 
|  | 209 | { | 
|  | 210 | // This should reflect the new position and the new color. | 
|  | 211 | SCOPED_TRACE("after redraw"); | 
|  | 212 | ScreenCapture::captureScreen(&sc); | 
|  | 213 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 214 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 215 | sc->checkPixel(145, 145,  63, 195,  63); | 
|  | 216 | } | 
|  | 217 | } | 
|  | 218 |  | 
|  | 219 | TEST_F(LayerUpdateTest, LayerResizeWorks) { | 
|  | 220 | sp<ScreenCapture> sc; | 
|  | 221 | { | 
|  | 222 | SCOPED_TRACE("before resize"); | 
|  | 223 | ScreenCapture::captureScreen(&sc); | 
|  | 224 | sc->checkPixel(  0,  12,  63,  63, 195); | 
|  | 225 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 226 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 227 | } | 
|  | 228 |  | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 229 | ALOGD("resizing"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 230 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 231 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128)); | 
|  | 232 | SurfaceComposerClient::closeGlobalTransaction(true); | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 233 | ALOGD("resized"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 234 | { | 
|  | 235 | // This should not reflect the new size or color because SurfaceFlinger | 
|  | 236 | // has not yet received a buffer of the correct size. | 
|  | 237 | SCOPED_TRACE("after resize, before redraw"); | 
|  | 238 | ScreenCapture::captureScreen(&sc); | 
|  | 239 | sc->checkPixel(  0,  12,  63,  63, 195); | 
|  | 240 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 241 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 242 | } | 
|  | 243 |  | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 244 | ALOGD("drawing"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 245 | fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63); | 
|  | 246 | waitForPostedBuffers(); | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 247 | ALOGD("drawn"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 248 | { | 
|  | 249 | // This should reflect the new size and the new color. | 
|  | 250 | SCOPED_TRACE("after redraw"); | 
|  | 251 | ScreenCapture::captureScreen(&sc); | 
|  | 252 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 253 | sc->checkPixel( 75,  75,  63, 195,  63); | 
|  | 254 | sc->checkPixel(145, 145,  63, 195,  63); | 
|  | 255 | } | 
|  | 256 | } | 
|  | 257 |  | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 258 | TEST_F(LayerUpdateTest, LayerCropWorks) { | 
|  | 259 | sp<ScreenCapture> sc; | 
|  | 260 | { | 
|  | 261 | SCOPED_TRACE("before crop"); | 
|  | 262 | ScreenCapture::captureScreen(&sc); | 
|  | 263 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 264 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 265 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 266 | } | 
|  | 267 |  | 
|  | 268 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 269 | Rect cropRect(16, 16, 32, 32); | 
|  | 270 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setCrop(cropRect)); | 
|  | 271 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 272 | { | 
|  | 273 | // This should crop the foreground surface. | 
|  | 274 | SCOPED_TRACE("after crop"); | 
|  | 275 | ScreenCapture::captureScreen(&sc); | 
|  | 276 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 277 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 278 | sc->checkPixel( 95,  80, 195,  63,  63); | 
|  | 279 | sc->checkPixel( 80,  95, 195,  63,  63); | 
|  | 280 | sc->checkPixel( 96,  96,  63,  63, 195); | 
|  | 281 | } | 
|  | 282 | } | 
|  | 283 |  | 
| Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 284 | TEST_F(LayerUpdateTest, LayerFinalCropWorks) { | 
|  | 285 | sp<ScreenCapture> sc; | 
|  | 286 | { | 
|  | 287 | SCOPED_TRACE("before crop"); | 
|  | 288 | ScreenCapture::captureScreen(&sc); | 
|  | 289 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 290 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 291 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 292 | } | 
|  | 293 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 294 | Rect cropRect(16, 16, 32, 32); | 
|  | 295 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect)); | 
|  | 296 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 297 | { | 
|  | 298 | // This should crop the foreground surface. | 
|  | 299 | SCOPED_TRACE("after crop"); | 
|  | 300 | ScreenCapture::captureScreen(&sc); | 
|  | 301 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 302 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 303 | sc->checkPixel( 95,  80,  63,  63, 195); | 
|  | 304 | sc->checkPixel( 80,  95,  63,  63, 195); | 
|  | 305 | sc->checkPixel( 96,  96,  63,  63, 195); | 
|  | 306 | } | 
|  | 307 | } | 
|  | 308 |  | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 309 | TEST_F(LayerUpdateTest, LayerSetLayerWorks) { | 
|  | 310 | sp<ScreenCapture> sc; | 
|  | 311 | { | 
|  | 312 | SCOPED_TRACE("before setLayer"); | 
|  | 313 | ScreenCapture::captureScreen(&sc); | 
|  | 314 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 315 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 316 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 317 | } | 
|  | 318 |  | 
|  | 319 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 320 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3)); | 
|  | 321 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 322 | { | 
|  | 323 | // This should hide the foreground surface beneath the background. | 
|  | 324 | SCOPED_TRACE("after setLayer"); | 
|  | 325 | ScreenCapture::captureScreen(&sc); | 
|  | 326 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 327 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 328 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 329 | } | 
|  | 330 | } | 
|  | 331 |  | 
|  | 332 | TEST_F(LayerUpdateTest, LayerShowHideWorks) { | 
|  | 333 | sp<ScreenCapture> sc; | 
|  | 334 | { | 
|  | 335 | SCOPED_TRACE("before hide"); | 
|  | 336 | ScreenCapture::captureScreen(&sc); | 
|  | 337 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 338 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 339 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 340 | } | 
|  | 341 |  | 
|  | 342 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 343 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide()); | 
|  | 344 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 345 | { | 
|  | 346 | // This should hide the foreground surface. | 
|  | 347 | SCOPED_TRACE("after hide, before show"); | 
|  | 348 | ScreenCapture::captureScreen(&sc); | 
|  | 349 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 350 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 351 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 355 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show()); | 
|  | 356 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 357 | { | 
|  | 358 | // This should show the foreground surface. | 
|  | 359 | SCOPED_TRACE("after show"); | 
|  | 360 | ScreenCapture::captureScreen(&sc); | 
|  | 361 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 362 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 363 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 364 | } | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | TEST_F(LayerUpdateTest, LayerSetAlphaWorks) { | 
|  | 368 | sp<ScreenCapture> sc; | 
|  | 369 | { | 
|  | 370 | SCOPED_TRACE("before setAlpha"); | 
|  | 371 | ScreenCapture::captureScreen(&sc); | 
|  | 372 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 373 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 374 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 375 | } | 
|  | 376 |  | 
|  | 377 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 378 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75f)); | 
|  | 379 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 380 | { | 
|  | 381 | // This should set foreground to be 75% opaque. | 
|  | 382 | SCOPED_TRACE("after setAlpha"); | 
|  | 383 | ScreenCapture::captureScreen(&sc); | 
|  | 384 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 385 | sc->checkPixel( 75,  75, 162,  63,  96); | 
|  | 386 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 387 | } | 
|  | 388 | } | 
|  | 389 |  | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 390 | TEST_F(LayerUpdateTest, LayerSetLayerStackWorks) { | 
|  | 391 | sp<ScreenCapture> sc; | 
|  | 392 | { | 
|  | 393 | SCOPED_TRACE("before setLayerStack"); | 
|  | 394 | ScreenCapture::captureScreen(&sc); | 
|  | 395 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 396 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 397 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 401 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayerStack(1)); | 
|  | 402 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 403 | { | 
|  | 404 | // This should hide the foreground surface since it goes to a different | 
|  | 405 | // layer stack. | 
|  | 406 | SCOPED_TRACE("after setLayerStack"); | 
|  | 407 | ScreenCapture::captureScreen(&sc); | 
|  | 408 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 409 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 410 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 411 | } | 
|  | 412 | } | 
|  | 413 |  | 
|  | 414 | TEST_F(LayerUpdateTest, LayerSetFlagsWorks) { | 
|  | 415 | sp<ScreenCapture> sc; | 
|  | 416 | { | 
|  | 417 | SCOPED_TRACE("before setFlags"); | 
|  | 418 | ScreenCapture::captureScreen(&sc); | 
|  | 419 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 420 | sc->checkPixel( 75,  75, 195,  63,  63); | 
|  | 421 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 425 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFlags( | 
|  | 426 | layer_state_t::eLayerHidden, layer_state_t::eLayerHidden)); | 
|  | 427 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 428 | { | 
|  | 429 | // This should hide the foreground surface | 
|  | 430 | SCOPED_TRACE("after setFlags"); | 
|  | 431 | ScreenCapture::captureScreen(&sc); | 
|  | 432 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 433 | sc->checkPixel( 75,  75,  63,  63, 195); | 
|  | 434 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 435 | } | 
|  | 436 | } | 
|  | 437 |  | 
|  | 438 | TEST_F(LayerUpdateTest, LayerSetMatrixWorks) { | 
|  | 439 | sp<ScreenCapture> sc; | 
|  | 440 | { | 
|  | 441 | SCOPED_TRACE("before setMatrix"); | 
|  | 442 | ScreenCapture::captureScreen(&sc); | 
|  | 443 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 444 | sc->checkPixel( 91,  96, 195,  63,  63); | 
|  | 445 | sc->checkPixel( 96, 101, 195,  63,  63); | 
|  | 446 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 447 | } | 
|  | 448 |  | 
|  | 449 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 450 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setMatrix(M_SQRT1_2, M_SQRT1_2, | 
|  | 451 | -M_SQRT1_2, M_SQRT1_2)); | 
|  | 452 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 453 | { | 
|  | 454 | SCOPED_TRACE("after setMatrix"); | 
|  | 455 | ScreenCapture::captureScreen(&sc); | 
|  | 456 | sc->checkPixel( 24,  24,  63,  63, 195); | 
|  | 457 | sc->checkPixel( 91,  96, 195,  63,  63); | 
|  | 458 | sc->checkPixel( 96,  91,  63,  63, 195); | 
|  | 459 | sc->checkPixel(145, 145,  63,  63, 195); | 
|  | 460 | } | 
|  | 461 | } | 
|  | 462 |  | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 463 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { | 
|  | 464 | sp<ScreenCapture> sc; | 
|  | 465 | { | 
|  | 466 | SCOPED_TRACE("before anything"); | 
|  | 467 | ScreenCapture::captureScreen(&sc); | 
|  | 468 | sc->checkPixel( 32,  32,  63,  63, 195); | 
|  | 469 | sc->checkPixel( 96,  96, 195,  63,  63); | 
|  | 470 | sc->checkPixel(160, 160,  63,  63, 195); | 
|  | 471 | } | 
|  | 472 |  | 
|  | 473 | // set up two deferred transactions on different frames | 
|  | 474 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 475 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75)); | 
|  | 476 | mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), | 
|  | 477 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); | 
|  | 478 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 479 |  | 
|  | 480 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 481 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128)); | 
|  | 482 | mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), | 
|  | 483 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); | 
|  | 484 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 485 |  | 
|  | 486 | { | 
|  | 487 | SCOPED_TRACE("before any trigger"); | 
|  | 488 | ScreenCapture::captureScreen(&sc); | 
|  | 489 | sc->checkPixel( 32,  32,  63,  63, 195); | 
|  | 490 | sc->checkPixel( 96,  96, 195,  63,  63); | 
|  | 491 | sc->checkPixel(160, 160,  63,  63, 195); | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 | // should trigger the first deferred transaction, but not the second one | 
|  | 495 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 496 | { | 
|  | 497 | SCOPED_TRACE("after first trigger"); | 
|  | 498 | ScreenCapture::captureScreen(&sc); | 
|  | 499 | sc->checkPixel( 32,  32,  63,  63, 195); | 
|  | 500 | sc->checkPixel( 96,  96, 162,  63,  96); | 
|  | 501 | sc->checkPixel(160, 160,  63,  63, 195); | 
|  | 502 | } | 
|  | 503 |  | 
|  | 504 | // should show up immediately since it's not deferred | 
|  | 505 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 506 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0)); | 
|  | 507 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 508 |  | 
|  | 509 | // trigger the second deferred transaction | 
|  | 510 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 511 | { | 
|  | 512 | SCOPED_TRACE("after second trigger"); | 
|  | 513 | ScreenCapture::captureScreen(&sc); | 
|  | 514 | sc->checkPixel( 32,  32,  63,  63, 195); | 
|  | 515 | sc->checkPixel( 96,  96,  63,  63, 195); | 
|  | 516 | sc->checkPixel(160, 160, 195,  63,  63); | 
|  | 517 | } | 
|  | 518 | } | 
|  | 519 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 520 | } |