| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 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 | #include <cstdarg> | 
|  | 18 | #include <cstdint> | 
|  | 19 |  | 
|  | 20 | #include <compositionengine/RenderSurfaceCreationArgs.h> | 
|  | 21 | #include <compositionengine/impl/RenderSurface.h> | 
|  | 22 | #include <compositionengine/mock/CompositionEngine.h> | 
|  | 23 | #include <compositionengine/mock/Display.h> | 
|  | 24 | #include <compositionengine/mock/DisplaySurface.h> | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 25 | #include <compositionengine/mock/OutputLayer.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 26 | #include <gtest/gtest.h> | 
|  | 27 | #include <renderengine/mock/RenderEngine.h> | 
|  | 28 | #include <system/window.h> | 
|  | 29 | #include <ui/ANativeObjectBase.h> | 
|  | 30 |  | 
|  | 31 | #include "MockHWComposer.h" | 
|  | 32 |  | 
|  | 33 | namespace android::compositionengine { | 
|  | 34 | namespace { | 
|  | 35 |  | 
|  | 36 | /* ------------------------------------------------------------------------ | 
|  | 37 | * MockNativeWindow | 
|  | 38 | * | 
|  | 39 | * An intentionally simplified Mock which implements a minimal subset of the full | 
|  | 40 | * ANativeWindow interface. | 
|  | 41 | */ | 
|  | 42 |  | 
|  | 43 | class MockNativeWindow : public ANativeObjectBase<ANativeWindow, MockNativeWindow, RefBase> { | 
|  | 44 | public: | 
|  | 45 | MockNativeWindow() { | 
|  | 46 | ANativeWindow::setSwapInterval = &forwardSetSwapInterval; | 
|  | 47 | ANativeWindow::dequeueBuffer = &forwardDequeueBuffer; | 
|  | 48 | ANativeWindow::cancelBuffer = &forwardCancelBuffer; | 
|  | 49 | ANativeWindow::queueBuffer = &forwardQueueBuffer; | 
|  | 50 | ANativeWindow::query = &forwardQuery; | 
|  | 51 | ANativeWindow::perform = &forwardPerform; | 
|  | 52 |  | 
|  | 53 | ANativeWindow::dequeueBuffer_DEPRECATED = &forwardDequeueBufferDeprecated; | 
|  | 54 | ANativeWindow::cancelBuffer_DEPRECATED = &forwardCancelBufferDeprecated; | 
|  | 55 | ANativeWindow::lockBuffer_DEPRECATED = &forwardLockBufferDeprecated; | 
|  | 56 | ANativeWindow::queueBuffer_DEPRECATED = &forwardQueueBufferDeprecated; | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | MOCK_METHOD1(setSwapInterval, int(int)); | 
|  | 60 | MOCK_METHOD2(dequeueBuffer, int(struct ANativeWindowBuffer**, int*)); | 
|  | 61 | MOCK_METHOD2(cancelBuffer, int(struct ANativeWindowBuffer*, int)); | 
|  | 62 | MOCK_METHOD2(queueBuffer, int(struct ANativeWindowBuffer*, int)); | 
|  | 63 | MOCK_CONST_METHOD2(query, int(int, int*)); | 
|  | 64 | MOCK_METHOD1(connect, int(int)); | 
|  | 65 | MOCK_METHOD1(lockBuffer_DEPRECATED, int(struct ANativeWindowBuffer*)); | 
|  | 66 | MOCK_METHOD1(setBuffersFormat, int(PixelFormat)); | 
|  | 67 | MOCK_METHOD1(setBuffersDataSpace, int(ui::Dataspace)); | 
|  | 68 | MOCK_METHOD1(setUsage, int(uint64_t)); | 
|  | 69 |  | 
|  | 70 | static void unexpectedCall(...) { LOG_ALWAYS_FATAL("Unexpected ANativeWindow API call"); } | 
|  | 71 |  | 
|  | 72 | static int forwardSetSwapInterval(ANativeWindow* window, int interval) { | 
|  | 73 | return getSelf(window)->setSwapInterval(interval); | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | static int forwardDequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, | 
|  | 77 | int* fenceFd) { | 
|  | 78 | return getSelf(window)->dequeueBuffer(buffer, fenceFd); | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | static int forwardCancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, | 
|  | 82 | int fenceFd) { | 
|  | 83 | return getSelf(window)->cancelBuffer(buffer, fenceFd); | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | static int forwardQueueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { | 
|  | 87 | return getSelf(window)->queueBuffer(buffer, fenceFd); | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | static int forwardQuery(const ANativeWindow* window, int what, int* value) { | 
|  | 91 | return getSelf(window)->query(what, value); | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | static int forwardPerform(ANativeWindow* window, int operation, ...) { | 
|  | 95 | va_list args; | 
|  | 96 | va_start(args, operation); | 
|  | 97 | int result = NO_ERROR; | 
|  | 98 | switch (operation) { | 
|  | 99 | case NATIVE_WINDOW_API_CONNECT: { | 
|  | 100 | int api = va_arg(args, int); | 
|  | 101 | result = getSelf(window)->connect(api); | 
|  | 102 | break; | 
|  | 103 | } | 
|  | 104 | case NATIVE_WINDOW_SET_BUFFERS_FORMAT: { | 
|  | 105 | PixelFormat format = va_arg(args, PixelFormat); | 
|  | 106 | result = getSelf(window)->setBuffersFormat(format); | 
|  | 107 | break; | 
|  | 108 | } | 
|  | 109 | case NATIVE_WINDOW_SET_BUFFERS_DATASPACE: { | 
|  | 110 | ui::Dataspace dataspace = static_cast<ui::Dataspace>(va_arg(args, int)); | 
|  | 111 | result = getSelf(window)->setBuffersDataSpace(dataspace); | 
|  | 112 | break; | 
|  | 113 | } | 
|  | 114 | case NATIVE_WINDOW_SET_USAGE: { | 
|  | 115 | // Note: Intentionally widens usage from 32 to 64 bits so we | 
|  | 116 | // just have one implementation. | 
|  | 117 | uint64_t usage = va_arg(args, uint32_t); | 
|  | 118 | result = getSelf(window)->setUsage(usage); | 
|  | 119 | break; | 
|  | 120 | } | 
|  | 121 | case NATIVE_WINDOW_SET_USAGE64: { | 
|  | 122 | uint64_t usage = va_arg(args, uint64_t); | 
|  | 123 | result = getSelf(window)->setUsage(usage); | 
|  | 124 | break; | 
|  | 125 | } | 
|  | 126 | default: | 
|  | 127 | LOG_ALWAYS_FATAL("Unexpected operation %d", operation); | 
|  | 128 | break; | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | va_end(args); | 
|  | 132 | return result; | 
|  | 133 | } | 
|  | 134 |  | 
|  | 135 | static int forwardDequeueBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer** buffer) { | 
|  | 136 | int ignoredFenceFd = -1; | 
|  | 137 | return getSelf(window)->dequeueBuffer(buffer, &ignoredFenceFd); | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | static int forwardCancelBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) { | 
|  | 141 | return getSelf(window)->cancelBuffer(buffer, -1); | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | static int forwardLockBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) { | 
|  | 145 | return getSelf(window)->lockBuffer_DEPRECATED(buffer); | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | static int forwardQueueBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) { | 
|  | 149 | return getSelf(window)->queueBuffer(buffer, -1); | 
|  | 150 | } | 
|  | 151 | }; | 
|  | 152 |  | 
|  | 153 | /* ------------------------------------------------------------------------ | 
|  | 154 | * RenderSurfaceTest | 
|  | 155 | */ | 
|  | 156 |  | 
|  | 157 | constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; | 
|  | 158 | constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; | 
|  | 159 | constexpr std::optional<DisplayId> DEFAULT_DISPLAY_ID = std::make_optional(DisplayId{123u}); | 
|  | 160 | const std::string DEFAULT_DISPLAY_NAME = "Mock Display"; | 
|  | 161 |  | 
|  | 162 | using testing::_; | 
|  | 163 | using testing::ByMove; | 
|  | 164 | using testing::DoAll; | 
|  | 165 | using testing::Ref; | 
|  | 166 | using testing::Return; | 
|  | 167 | using testing::ReturnRef; | 
|  | 168 | using testing::SetArgPointee; | 
|  | 169 | using testing::StrictMock; | 
|  | 170 |  | 
|  | 171 | class RenderSurfaceTest : public testing::Test { | 
|  | 172 | public: | 
|  | 173 | RenderSurfaceTest() { | 
|  | 174 | EXPECT_CALL(mDisplay, getId()).WillRepeatedly(ReturnRef(DEFAULT_DISPLAY_ID)); | 
|  | 175 | EXPECT_CALL(mDisplay, getName()).WillRepeatedly(ReturnRef(DEFAULT_DISPLAY_NAME)); | 
|  | 176 | EXPECT_CALL(mCompositionEngine, getHwComposer).WillRepeatedly(ReturnRef(mHwComposer)); | 
|  | 177 | EXPECT_CALL(mCompositionEngine, getRenderEngine).WillRepeatedly(ReturnRef(mRenderEngine)); | 
|  | 178 | } | 
|  | 179 | ~RenderSurfaceTest() override = default; | 
|  | 180 |  | 
|  | 181 | StrictMock<android::mock::HWComposer> mHwComposer; | 
|  | 182 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; | 
|  | 183 | StrictMock<mock::CompositionEngine> mCompositionEngine; | 
|  | 184 | StrictMock<mock::Display> mDisplay; | 
|  | 185 | sp<MockNativeWindow> mNativeWindow = new StrictMock<MockNativeWindow>(); | 
|  | 186 | sp<mock::DisplaySurface> mDisplaySurface = new StrictMock<mock::DisplaySurface>(); | 
|  | 187 | impl::RenderSurface mSurface{mCompositionEngine, mDisplay, | 
|  | 188 | RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH, | 
|  | 189 | DEFAULT_DISPLAY_HEIGHT, mNativeWindow, | 
|  | 190 | mDisplaySurface}}; | 
|  | 191 | }; | 
|  | 192 |  | 
|  | 193 | /* ------------------------------------------------------------------------ | 
|  | 194 | * Basic construction | 
|  | 195 | */ | 
|  | 196 |  | 
|  | 197 | TEST_F(RenderSurfaceTest, canInstantiate) { | 
|  | 198 | EXPECT_TRUE(mSurface.isValid()); | 
|  | 199 | } | 
|  | 200 |  | 
|  | 201 | /* ------------------------------------------------------------------------ | 
|  | 202 | * RenderSurface::initialize() | 
|  | 203 | */ | 
|  | 204 |  | 
|  | 205 | TEST_F(RenderSurfaceTest, initializeConfiguresNativeWindow) { | 
|  | 206 | EXPECT_CALL(*mNativeWindow, connect(NATIVE_WINDOW_API_EGL)).WillOnce(Return(NO_ERROR)); | 
|  | 207 | EXPECT_CALL(*mNativeWindow, setBuffersFormat(HAL_PIXEL_FORMAT_RGBA_8888)) | 
|  | 208 | .WillOnce(Return(NO_ERROR)); | 
|  | 209 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER)).WillOnce(Return(NO_ERROR)); | 
|  | 210 |  | 
|  | 211 | mSurface.initialize(); | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | /* ------------------------------------------------------------------------ | 
|  | 215 | * RenderSurface::getSize() | 
|  | 216 | */ | 
|  | 217 |  | 
|  | 218 | TEST_F(RenderSurfaceTest, sizeReturnsConstructedSize) { | 
|  | 219 | const ui::Size expected{DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}; | 
|  | 220 |  | 
|  | 221 | EXPECT_EQ(expected, mSurface.getSize()); | 
|  | 222 | } | 
|  | 223 |  | 
|  | 224 | /* ------------------------------------------------------------------------ | 
|  | 225 | * RenderSurface::getClientTargetAcquireFence() | 
|  | 226 | */ | 
|  | 227 |  | 
|  | 228 | TEST_F(RenderSurfaceTest, getClientTargetAcquireFenceForwardsCall) { | 
|  | 229 | sp<Fence> fence = new Fence(); | 
|  | 230 |  | 
|  | 231 | EXPECT_CALL(*mDisplaySurface, getClientTargetAcquireFence()).WillOnce(ReturnRef(fence)); | 
|  | 232 |  | 
|  | 233 | EXPECT_EQ(fence.get(), mSurface.getClientTargetAcquireFence().get()); | 
|  | 234 | } | 
|  | 235 |  | 
|  | 236 | /* ------------------------------------------------------------------------ | 
|  | 237 | * RenderSurface::setDisplaySize() | 
|  | 238 | */ | 
|  | 239 |  | 
|  | 240 | TEST_F(RenderSurfaceTest, setDisplaySizeAppliesChange) { | 
|  | 241 | EXPECT_CALL(*mDisplaySurface, resizeBuffers(640, 480)).Times(1); | 
|  | 242 |  | 
|  | 243 | mSurface.setDisplaySize(ui::Size(640, 480)); | 
|  | 244 | } | 
|  | 245 |  | 
|  | 246 | /* ------------------------------------------------------------------------ | 
|  | 247 | * RenderSurface::setBufferDataspace() | 
|  | 248 | */ | 
|  | 249 |  | 
|  | 250 | TEST_F(RenderSurfaceTest, setBufferDataspaceAppliesChange) { | 
|  | 251 | EXPECT_CALL(*mNativeWindow, setBuffersDataSpace(ui::Dataspace::DISPLAY_P3)) | 
|  | 252 | .WillOnce(Return(NO_ERROR)); | 
|  | 253 |  | 
|  | 254 | mSurface.setBufferDataspace(ui::Dataspace::DISPLAY_P3); | 
|  | 255 | } | 
|  | 256 |  | 
|  | 257 | /* ------------------------------------------------------------------------ | 
|  | 258 | * RenderSurface::setProtected() | 
|  | 259 | */ | 
|  | 260 |  | 
|  | 261 | TEST_F(RenderSurfaceTest, setProtectedTrueEnablesProtection) { | 
|  | 262 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_PROTECTED)) | 
|  | 263 | .WillOnce(Return(NO_ERROR)); | 
|  | 264 |  | 
|  | 265 | mSurface.setProtected(true); | 
|  | 266 | } | 
|  | 267 |  | 
|  | 268 | TEST_F(RenderSurfaceTest, setProtectedFalseDisablesProtection) { | 
|  | 269 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER)).WillOnce(Return(NO_ERROR)); | 
|  | 270 |  | 
|  | 271 | mSurface.setProtected(false); | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 | /* ------------------------------------------------------------------------ | 
|  | 275 | * RenderSurface::beginFrame() | 
|  | 276 | */ | 
|  | 277 |  | 
|  | 278 | TEST_F(RenderSurfaceTest, beginFrameAppliesChange) { | 
|  | 279 | EXPECT_CALL(*mDisplaySurface, beginFrame(true)).WillOnce(Return(NO_ERROR)); | 
|  | 280 |  | 
|  | 281 | EXPECT_EQ(NO_ERROR, mSurface.beginFrame(true)); | 
|  | 282 | } | 
|  | 283 |  | 
|  | 284 | /* ------------------------------------------------------------------------ | 
|  | 285 | * RenderSurface::prepareFrame() | 
|  | 286 | */ | 
|  | 287 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 288 | TEST_F(RenderSurfaceTest, prepareFramePassesOutputLayersToHwc) { | 
|  | 289 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 290 | .WillOnce(Return(INVALID_OPERATION)); | 
|  | 291 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 292 | EXPECT_EQ(INVALID_OPERATION, mSurface.prepareFrame()); | 
|  | 293 | } | 
|  | 294 |  | 
|  | 295 | TEST_F(RenderSurfaceTest, prepareFrameTakesEarlyOutOnHwcError) { | 
|  | 296 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) | 
|  | 297 | .WillOnce(Return(INVALID_OPERATION)); | 
|  | 298 |  | 
|  | 299 | EXPECT_EQ(INVALID_OPERATION, mSurface.prepareFrame()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 300 | } | 
|  | 301 |  | 
|  | 302 | TEST_F(RenderSurfaceTest, prepareFrameHandlesMixedComposition) { | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 303 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) | 
|  | 304 | .WillOnce(Return(NO_ERROR)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 305 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 306 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 307 |  | 
|  | 308 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_MIXED)) | 
|  | 309 | .WillOnce(Return(INVALID_OPERATION)); | 
|  | 310 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 311 | EXPECT_EQ(INVALID_OPERATION, mSurface.prepareFrame()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 312 | } | 
|  | 313 |  | 
|  | 314 | TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyGlesComposition) { | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 315 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) | 
|  | 316 | .WillOnce(Return(NO_ERROR)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 317 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 318 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); | 
|  | 319 |  | 
|  | 320 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_GLES)) | 
|  | 321 | .WillOnce(Return(NO_ERROR)); | 
|  | 322 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 323 | EXPECT_EQ(NO_ERROR, mSurface.prepareFrame()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 324 | } | 
|  | 325 |  | 
|  | 326 | TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyHwcComposition) { | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 327 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) | 
|  | 328 | .WillOnce(Return(NO_ERROR)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 329 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); | 
|  | 330 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 331 |  | 
|  | 332 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC)) | 
|  | 333 | .WillOnce(Return(NO_ERROR)); | 
|  | 334 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 335 | EXPECT_EQ(NO_ERROR, mSurface.prepareFrame()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 336 | } | 
|  | 337 |  | 
|  | 338 | TEST_F(RenderSurfaceTest, prepareFrameHandlesNoComposition) { | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 339 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) | 
|  | 340 | .WillOnce(Return(NO_ERROR)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 341 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); | 
|  | 342 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); | 
|  | 343 |  | 
|  | 344 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC)) | 
|  | 345 | .WillOnce(Return(NO_ERROR)); | 
|  | 346 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 347 | EXPECT_EQ(NO_ERROR, mSurface.prepareFrame()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 348 | } | 
|  | 349 |  | 
|  | 350 | /* ------------------------------------------------------------------------ | 
|  | 351 | * RenderSurface::dequeueBuffer() | 
|  | 352 | */ | 
|  | 353 |  | 
|  | 354 | TEST_F(RenderSurfaceTest, dequeueBufferObtainsABuffer) { | 
|  | 355 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
|  | 356 |  | 
|  | 357 | EXPECT_CALL(*mNativeWindow, dequeueBuffer(_, _)) | 
|  | 358 | .WillOnce( | 
|  | 359 | DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); | 
|  | 360 |  | 
| Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 361 | base::unique_fd fence; | 
|  | 362 | EXPECT_EQ(buffer.get(), mSurface.dequeueBuffer(&fence).get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 363 |  | 
|  | 364 | EXPECT_EQ(buffer.get(), mSurface.mutableGraphicBufferForTest().get()); | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | /* ------------------------------------------------------------------------ | 
|  | 368 | * RenderSurface::queueBuffer() | 
|  | 369 | */ | 
|  | 370 |  | 
|  | 371 | TEST_F(RenderSurfaceTest, queueBufferHandlesNoClientComposition) { | 
|  | 372 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
|  | 373 | mSurface.mutableGraphicBufferForTest() = buffer; | 
|  | 374 |  | 
|  | 375 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); | 
|  | 376 | EXPECT_CALL(mHwComposer, hasFlipClientTargetRequest(DEFAULT_DISPLAY_ID)) | 
|  | 377 | .WillOnce(Return(false)); | 
|  | 378 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
|  | 379 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 380 | mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 381 |  | 
|  | 382 | EXPECT_EQ(buffer.get(), mSurface.mutableGraphicBufferForTest().get()); | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | TEST_F(RenderSurfaceTest, queueBufferHandlesClientComposition) { | 
|  | 386 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
|  | 387 | mSurface.mutableGraphicBufferForTest() = buffer; | 
|  | 388 |  | 
|  | 389 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 390 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) | 
|  | 391 | .WillOnce(Return(NO_ERROR)); | 
|  | 392 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
|  | 393 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 394 | mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 395 |  | 
|  | 396 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); | 
|  | 397 | } | 
|  | 398 |  | 
|  | 399 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequest) { | 
|  | 400 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
|  | 401 | mSurface.mutableGraphicBufferForTest() = buffer; | 
|  | 402 |  | 
|  | 403 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); | 
|  | 404 | EXPECT_CALL(mHwComposer, hasFlipClientTargetRequest(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 405 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) | 
|  | 406 | .WillOnce(Return(NO_ERROR)); | 
|  | 407 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
|  | 408 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 409 | mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 410 |  | 
|  | 411 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); | 
|  | 412 | } | 
|  | 413 |  | 
|  | 414 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequestWithNoBufferYetDequeued) { | 
|  | 415 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
|  | 416 |  | 
|  | 417 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); | 
|  | 418 | EXPECT_CALL(mHwComposer, hasFlipClientTargetRequest(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 419 | EXPECT_CALL(*mNativeWindow, dequeueBuffer(_, _)) | 
|  | 420 | .WillOnce( | 
|  | 421 | DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); | 
|  | 422 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) | 
|  | 423 | .WillOnce(Return(NO_ERROR)); | 
|  | 424 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
|  | 425 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 426 | mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 427 |  | 
|  | 428 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 | TEST_F(RenderSurfaceTest, queueBufferHandlesNativeWindowQueueBufferFailureOnVirtualDisplay) { | 
|  | 432 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
|  | 433 | mSurface.mutableGraphicBufferForTest() = buffer; | 
|  | 434 |  | 
|  | 435 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); | 
|  | 436 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) | 
|  | 437 | .WillOnce(Return(INVALID_OPERATION)); | 
|  | 438 | EXPECT_CALL(mDisplay, isVirtual()).WillOnce(Return(true)); | 
|  | 439 | EXPECT_CALL(*mNativeWindow, cancelBuffer(buffer->getNativeBuffer(), -1)) | 
|  | 440 | .WillOnce(Return(NO_ERROR)); | 
|  | 441 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
|  | 442 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 443 | mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 444 |  | 
|  | 445 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | /* ------------------------------------------------------------------------ | 
|  | 449 | * RenderSurface::onPresentDisplayCompleted() | 
|  | 450 | */ | 
|  | 451 |  | 
|  | 452 | TEST_F(RenderSurfaceTest, onPresentDisplayCompletedForwardsSignal) { | 
|  | 453 | EXPECT_CALL(*mDisplaySurface, onFrameCommitted()).Times(1); | 
|  | 454 |  | 
|  | 455 | mSurface.onPresentDisplayCompleted(); | 
|  | 456 | } | 
|  | 457 |  | 
|  | 458 | /* ------------------------------------------------------------------------ | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 459 | * RenderSurface::setViewportAndProjection() | 
|  | 460 | */ | 
|  | 461 |  | 
|  | 462 | TEST_F(RenderSurfaceTest, setViewportAndProjectionAppliesChang) { | 
|  | 463 | mSurface.setSizeForTest(ui::Size(100, 200)); | 
|  | 464 |  | 
|  | 465 | EXPECT_CALL(mRenderEngine, | 
|  | 466 | setViewportAndProjection(100, 200, Rect(100, 200), ui::Transform::ROT_0)) | 
|  | 467 | .Times(1); | 
|  | 468 |  | 
|  | 469 | mSurface.setViewportAndProjection(); | 
|  | 470 | } | 
|  | 471 |  | 
|  | 472 | /* ------------------------------------------------------------------------ | 
|  | 473 | * RenderSurface::flip() | 
|  | 474 | */ | 
|  | 475 |  | 
|  | 476 | TEST_F(RenderSurfaceTest, flipForwardsSignal) { | 
|  | 477 | mSurface.setPageFlipCountForTest(500); | 
|  | 478 |  | 
|  | 479 | mSurface.flip(); | 
|  | 480 |  | 
|  | 481 | EXPECT_EQ(501, mSurface.getPageFlipCount()); | 
|  | 482 | } | 
|  | 483 |  | 
|  | 484 | } // namespace | 
|  | 485 | } // namespace android::compositionengine |