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