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