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> |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 25 | #include <compositionengine/mock/NativeWindow.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 26 | #include <compositionengine/mock/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 27 | #include <gtest/gtest.h> |
| 28 | #include <renderengine/mock/RenderEngine.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 29 | |
| 30 | #include "MockHWComposer.h" |
| 31 | |
| 32 | namespace android::compositionengine { |
| 33 | namespace { |
| 34 | |
| 35 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 36 | * RenderSurfaceTest |
| 37 | */ |
| 38 | |
| 39 | constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; |
| 40 | constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; |
| 41 | constexpr std::optional<DisplayId> DEFAULT_DISPLAY_ID = std::make_optional(DisplayId{123u}); |
| 42 | const std::string DEFAULT_DISPLAY_NAME = "Mock Display"; |
| 43 | |
| 44 | using testing::_; |
| 45 | using testing::ByMove; |
| 46 | using testing::DoAll; |
| 47 | using testing::Ref; |
| 48 | using testing::Return; |
| 49 | using testing::ReturnRef; |
| 50 | using testing::SetArgPointee; |
| 51 | using testing::StrictMock; |
| 52 | |
| 53 | class RenderSurfaceTest : public testing::Test { |
| 54 | public: |
| 55 | RenderSurfaceTest() { |
| 56 | EXPECT_CALL(mDisplay, getId()).WillRepeatedly(ReturnRef(DEFAULT_DISPLAY_ID)); |
| 57 | EXPECT_CALL(mDisplay, getName()).WillRepeatedly(ReturnRef(DEFAULT_DISPLAY_NAME)); |
| 58 | EXPECT_CALL(mCompositionEngine, getHwComposer).WillRepeatedly(ReturnRef(mHwComposer)); |
| 59 | EXPECT_CALL(mCompositionEngine, getRenderEngine).WillRepeatedly(ReturnRef(mRenderEngine)); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 60 | EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)) |
| 61 | .WillRepeatedly(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 62 | } |
| 63 | ~RenderSurfaceTest() override = default; |
| 64 | |
| 65 | StrictMock<android::mock::HWComposer> mHwComposer; |
| 66 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
| 67 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 68 | StrictMock<mock::Display> mDisplay; |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 69 | sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 70 | sp<mock::DisplaySurface> mDisplaySurface = new StrictMock<mock::DisplaySurface>(); |
| 71 | impl::RenderSurface mSurface{mCompositionEngine, mDisplay, |
| 72 | RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH, |
| 73 | DEFAULT_DISPLAY_HEIGHT, mNativeWindow, |
| 74 | mDisplaySurface}}; |
| 75 | }; |
| 76 | |
| 77 | /* ------------------------------------------------------------------------ |
| 78 | * Basic construction |
| 79 | */ |
| 80 | |
| 81 | TEST_F(RenderSurfaceTest, canInstantiate) { |
| 82 | EXPECT_TRUE(mSurface.isValid()); |
| 83 | } |
| 84 | |
| 85 | /* ------------------------------------------------------------------------ |
| 86 | * RenderSurface::initialize() |
| 87 | */ |
| 88 | |
| 89 | TEST_F(RenderSurfaceTest, initializeConfiguresNativeWindow) { |
| 90 | EXPECT_CALL(*mNativeWindow, connect(NATIVE_WINDOW_API_EGL)).WillOnce(Return(NO_ERROR)); |
| 91 | EXPECT_CALL(*mNativeWindow, setBuffersFormat(HAL_PIXEL_FORMAT_RGBA_8888)) |
| 92 | .WillOnce(Return(NO_ERROR)); |
| 93 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER)).WillOnce(Return(NO_ERROR)); |
| 94 | |
| 95 | mSurface.initialize(); |
| 96 | } |
| 97 | |
| 98 | /* ------------------------------------------------------------------------ |
| 99 | * RenderSurface::getSize() |
| 100 | */ |
| 101 | |
| 102 | TEST_F(RenderSurfaceTest, sizeReturnsConstructedSize) { |
| 103 | const ui::Size expected{DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}; |
| 104 | |
| 105 | EXPECT_EQ(expected, mSurface.getSize()); |
| 106 | } |
| 107 | |
| 108 | /* ------------------------------------------------------------------------ |
| 109 | * RenderSurface::getClientTargetAcquireFence() |
| 110 | */ |
| 111 | |
| 112 | TEST_F(RenderSurfaceTest, getClientTargetAcquireFenceForwardsCall) { |
| 113 | sp<Fence> fence = new Fence(); |
| 114 | |
| 115 | EXPECT_CALL(*mDisplaySurface, getClientTargetAcquireFence()).WillOnce(ReturnRef(fence)); |
| 116 | |
| 117 | EXPECT_EQ(fence.get(), mSurface.getClientTargetAcquireFence().get()); |
| 118 | } |
| 119 | |
| 120 | /* ------------------------------------------------------------------------ |
| 121 | * RenderSurface::setDisplaySize() |
| 122 | */ |
| 123 | |
| 124 | TEST_F(RenderSurfaceTest, setDisplaySizeAppliesChange) { |
| 125 | EXPECT_CALL(*mDisplaySurface, resizeBuffers(640, 480)).Times(1); |
| 126 | |
| 127 | mSurface.setDisplaySize(ui::Size(640, 480)); |
| 128 | } |
| 129 | |
| 130 | /* ------------------------------------------------------------------------ |
| 131 | * RenderSurface::setBufferDataspace() |
| 132 | */ |
| 133 | |
| 134 | TEST_F(RenderSurfaceTest, setBufferDataspaceAppliesChange) { |
| 135 | EXPECT_CALL(*mNativeWindow, setBuffersDataSpace(ui::Dataspace::DISPLAY_P3)) |
| 136 | .WillOnce(Return(NO_ERROR)); |
| 137 | |
| 138 | mSurface.setBufferDataspace(ui::Dataspace::DISPLAY_P3); |
| 139 | } |
| 140 | |
| 141 | /* ------------------------------------------------------------------------ |
| 142 | * RenderSurface::setProtected() |
| 143 | */ |
| 144 | |
| 145 | TEST_F(RenderSurfaceTest, setProtectedTrueEnablesProtection) { |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 146 | EXPECT_FALSE(mSurface.isProtected()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 147 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_PROTECTED)) |
| 148 | .WillOnce(Return(NO_ERROR)); |
| 149 | |
| 150 | mSurface.setProtected(true); |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 151 | EXPECT_TRUE(mSurface.isProtected()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | TEST_F(RenderSurfaceTest, setProtectedFalseDisablesProtection) { |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 155 | EXPECT_FALSE(mSurface.isProtected()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 156 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER)).WillOnce(Return(NO_ERROR)); |
| 157 | |
| 158 | mSurface.setProtected(false); |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 159 | EXPECT_FALSE(mSurface.isProtected()); |
| 160 | } |
| 161 | |
| 162 | TEST_F(RenderSurfaceTest, setProtectedEnableAndDisable) { |
| 163 | EXPECT_FALSE(mSurface.isProtected()); |
| 164 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_PROTECTED)) |
| 165 | .WillOnce(Return(NO_ERROR)); |
| 166 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER)).WillOnce(Return(NO_ERROR)); |
| 167 | |
| 168 | mSurface.setProtected(true); |
| 169 | EXPECT_TRUE(mSurface.isProtected()); |
| 170 | mSurface.setProtected(false); |
| 171 | EXPECT_FALSE(mSurface.isProtected()); |
| 172 | } |
| 173 | |
| 174 | TEST_F(RenderSurfaceTest, setProtectedEnableWithError) { |
| 175 | EXPECT_FALSE(mSurface.isProtected()); |
| 176 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_PROTECTED)) |
| 177 | .WillOnce(Return(INVALID_OPERATION)); |
| 178 | mSurface.setProtected(true); |
| 179 | EXPECT_FALSE(mSurface.isProtected()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* ------------------------------------------------------------------------ |
| 183 | * RenderSurface::beginFrame() |
| 184 | */ |
| 185 | |
| 186 | TEST_F(RenderSurfaceTest, beginFrameAppliesChange) { |
| 187 | EXPECT_CALL(*mDisplaySurface, beginFrame(true)).WillOnce(Return(NO_ERROR)); |
| 188 | |
| 189 | EXPECT_EQ(NO_ERROR, mSurface.beginFrame(true)); |
| 190 | } |
| 191 | |
| 192 | /* ------------------------------------------------------------------------ |
| 193 | * RenderSurface::prepareFrame() |
| 194 | */ |
| 195 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 196 | TEST_F(RenderSurfaceTest, prepareFramePassesOutputLayersToHwc) { |
| 197 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 198 | .WillOnce(Return(INVALID_OPERATION)); |
| 199 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 200 | EXPECT_EQ(INVALID_OPERATION, mSurface.prepareFrame()); |
| 201 | } |
| 202 | |
| 203 | TEST_F(RenderSurfaceTest, prepareFrameTakesEarlyOutOnHwcError) { |
| 204 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) |
| 205 | .WillOnce(Return(INVALID_OPERATION)); |
| 206 | |
| 207 | EXPECT_EQ(INVALID_OPERATION, mSurface.prepareFrame()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | TEST_F(RenderSurfaceTest, prepareFrameHandlesMixedComposition) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 211 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) |
| 212 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 213 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 214 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 215 | |
| 216 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_MIXED)) |
| 217 | .WillOnce(Return(INVALID_OPERATION)); |
| 218 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 219 | EXPECT_EQ(INVALID_OPERATION, mSurface.prepareFrame()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyGlesComposition) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 223 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) |
| 224 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 225 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 226 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); |
| 227 | |
| 228 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_GLES)) |
| 229 | .WillOnce(Return(NO_ERROR)); |
| 230 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 231 | EXPECT_EQ(NO_ERROR, mSurface.prepareFrame()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyHwcComposition) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 235 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) |
| 236 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 237 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); |
| 238 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 239 | |
| 240 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC)) |
| 241 | .WillOnce(Return(NO_ERROR)); |
| 242 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 243 | EXPECT_EQ(NO_ERROR, mSurface.prepareFrame()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | TEST_F(RenderSurfaceTest, prepareFrameHandlesNoComposition) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 247 | EXPECT_CALL(mHwComposer, prepare(*DEFAULT_DISPLAY_ID, Ref(mDisplay))) |
| 248 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 249 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); |
| 250 | EXPECT_CALL(mHwComposer, hasDeviceComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); |
| 251 | |
| 252 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC)) |
| 253 | .WillOnce(Return(NO_ERROR)); |
| 254 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 255 | EXPECT_EQ(NO_ERROR, mSurface.prepareFrame()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /* ------------------------------------------------------------------------ |
| 259 | * RenderSurface::dequeueBuffer() |
| 260 | */ |
| 261 | |
| 262 | TEST_F(RenderSurfaceTest, dequeueBufferObtainsABuffer) { |
| 263 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 264 | |
| 265 | EXPECT_CALL(*mNativeWindow, dequeueBuffer(_, _)) |
| 266 | .WillOnce( |
| 267 | DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); |
| 268 | |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 269 | base::unique_fd fence; |
| 270 | EXPECT_EQ(buffer.get(), mSurface.dequeueBuffer(&fence).get()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 271 | |
| 272 | EXPECT_EQ(buffer.get(), mSurface.mutableGraphicBufferForTest().get()); |
| 273 | } |
| 274 | |
| 275 | /* ------------------------------------------------------------------------ |
| 276 | * RenderSurface::queueBuffer() |
| 277 | */ |
| 278 | |
| 279 | TEST_F(RenderSurfaceTest, queueBufferHandlesNoClientComposition) { |
| 280 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 281 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 282 | |
| 283 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); |
| 284 | EXPECT_CALL(mHwComposer, hasFlipClientTargetRequest(DEFAULT_DISPLAY_ID)) |
| 285 | .WillOnce(Return(false)); |
| 286 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 287 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 288 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 289 | |
| 290 | EXPECT_EQ(buffer.get(), mSurface.mutableGraphicBufferForTest().get()); |
| 291 | } |
| 292 | |
| 293 | TEST_F(RenderSurfaceTest, queueBufferHandlesClientComposition) { |
| 294 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 295 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 296 | |
| 297 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 298 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 299 | .WillOnce(Return(NO_ERROR)); |
| 300 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 301 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 302 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 303 | |
| 304 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 305 | } |
| 306 | |
| 307 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequest) { |
| 308 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 309 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 310 | |
| 311 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); |
| 312 | EXPECT_CALL(mHwComposer, hasFlipClientTargetRequest(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 313 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 314 | .WillOnce(Return(NO_ERROR)); |
| 315 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 316 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 317 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 318 | |
| 319 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 320 | } |
| 321 | |
| 322 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequestWithNoBufferYetDequeued) { |
| 323 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 324 | |
| 325 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(false)); |
| 326 | EXPECT_CALL(mHwComposer, hasFlipClientTargetRequest(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 327 | EXPECT_CALL(*mNativeWindow, dequeueBuffer(_, _)) |
| 328 | .WillOnce( |
| 329 | DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); |
| 330 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 331 | .WillOnce(Return(NO_ERROR)); |
| 332 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 333 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 334 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 335 | |
| 336 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 337 | } |
| 338 | |
| 339 | TEST_F(RenderSurfaceTest, queueBufferHandlesNativeWindowQueueBufferFailureOnVirtualDisplay) { |
| 340 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 341 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 342 | |
| 343 | EXPECT_CALL(mHwComposer, hasClientComposition(DEFAULT_DISPLAY_ID)).WillOnce(Return(true)); |
| 344 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 345 | .WillOnce(Return(INVALID_OPERATION)); |
| 346 | EXPECT_CALL(mDisplay, isVirtual()).WillOnce(Return(true)); |
| 347 | EXPECT_CALL(*mNativeWindow, cancelBuffer(buffer->getNativeBuffer(), -1)) |
| 348 | .WillOnce(Return(NO_ERROR)); |
| 349 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 350 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 351 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 352 | |
| 353 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 354 | } |
| 355 | |
| 356 | /* ------------------------------------------------------------------------ |
| 357 | * RenderSurface::onPresentDisplayCompleted() |
| 358 | */ |
| 359 | |
| 360 | TEST_F(RenderSurfaceTest, onPresentDisplayCompletedForwardsSignal) { |
| 361 | EXPECT_CALL(*mDisplaySurface, onFrameCommitted()).Times(1); |
| 362 | |
| 363 | mSurface.onPresentDisplayCompleted(); |
| 364 | } |
| 365 | |
| 366 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 367 | * RenderSurface::setViewportAndProjection() |
| 368 | */ |
| 369 | |
| 370 | TEST_F(RenderSurfaceTest, setViewportAndProjectionAppliesChang) { |
| 371 | mSurface.setSizeForTest(ui::Size(100, 200)); |
| 372 | |
| 373 | EXPECT_CALL(mRenderEngine, |
| 374 | setViewportAndProjection(100, 200, Rect(100, 200), ui::Transform::ROT_0)) |
| 375 | .Times(1); |
| 376 | |
| 377 | mSurface.setViewportAndProjection(); |
| 378 | } |
| 379 | |
| 380 | /* ------------------------------------------------------------------------ |
| 381 | * RenderSurface::flip() |
| 382 | */ |
| 383 | |
| 384 | TEST_F(RenderSurfaceTest, flipForwardsSignal) { |
| 385 | mSurface.setPageFlipCountForTest(500); |
| 386 | |
| 387 | mSurface.flip(); |
| 388 | |
| 389 | EXPECT_EQ(501, mSurface.getPageFlipCount()); |
| 390 | } |
| 391 | |
| 392 | } // namespace |
| 393 | } // namespace android::compositionengine |