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 | |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wextra" |
| 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; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 40 | constexpr DisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId(123u); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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() { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 55 | EXPECT_CALL(mDisplay, getId()).WillRepeatedly(Return(DEFAULT_DISPLAY_ID)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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)); |
John Reck | 44418f5 | 2020-09-15 18:02:17 -0700 | [diff] [blame] | 89 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE)) |
| 90 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 91 | |
| 92 | mSurface.initialize(); |
| 93 | } |
| 94 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 95 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 96 | * RenderSurface::getSize() |
| 97 | */ |
| 98 | |
| 99 | TEST_F(RenderSurfaceTest, sizeReturnsConstructedSize) { |
| 100 | const ui::Size expected{DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}; |
| 101 | |
| 102 | EXPECT_EQ(expected, mSurface.getSize()); |
| 103 | } |
| 104 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 105 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 106 | * RenderSurface::getClientTargetAcquireFence() |
| 107 | */ |
| 108 | |
| 109 | TEST_F(RenderSurfaceTest, getClientTargetAcquireFenceForwardsCall) { |
| 110 | sp<Fence> fence = new Fence(); |
| 111 | |
| 112 | EXPECT_CALL(*mDisplaySurface, getClientTargetAcquireFence()).WillOnce(ReturnRef(fence)); |
| 113 | |
| 114 | EXPECT_EQ(fence.get(), mSurface.getClientTargetAcquireFence().get()); |
| 115 | } |
| 116 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 117 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 118 | * RenderSurface::setDisplaySize() |
| 119 | */ |
| 120 | |
| 121 | TEST_F(RenderSurfaceTest, setDisplaySizeAppliesChange) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame^] | 122 | const ui::Size size(640, 480); |
| 123 | EXPECT_CALL(*mDisplaySurface, resizeBuffers(size)).Times(1); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 124 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame^] | 125 | mSurface.setDisplaySize(size); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 128 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 129 | * RenderSurface::setBufferDataspace() |
| 130 | */ |
| 131 | |
| 132 | TEST_F(RenderSurfaceTest, setBufferDataspaceAppliesChange) { |
| 133 | EXPECT_CALL(*mNativeWindow, setBuffersDataSpace(ui::Dataspace::DISPLAY_P3)) |
| 134 | .WillOnce(Return(NO_ERROR)); |
| 135 | |
| 136 | mSurface.setBufferDataspace(ui::Dataspace::DISPLAY_P3); |
| 137 | } |
| 138 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 139 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 140 | * RenderSurface::setProtected() |
| 141 | */ |
| 142 | |
| 143 | TEST_F(RenderSurfaceTest, setProtectedTrueEnablesProtection) { |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 144 | EXPECT_FALSE(mSurface.isProtected()); |
John Reck | 44418f5 | 2020-09-15 18:02:17 -0700 | [diff] [blame] | 145 | EXPECT_CALL(*mNativeWindow, |
| 146 | setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE | |
| 147 | GRALLOC_USAGE_PROTECTED)) |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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()); |
John Reck | 44418f5 | 2020-09-15 18:02:17 -0700 | [diff] [blame] | 156 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE)) |
| 157 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 158 | |
| 159 | mSurface.setProtected(false); |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 160 | EXPECT_FALSE(mSurface.isProtected()); |
| 161 | } |
| 162 | |
| 163 | TEST_F(RenderSurfaceTest, setProtectedEnableAndDisable) { |
| 164 | EXPECT_FALSE(mSurface.isProtected()); |
John Reck | 44418f5 | 2020-09-15 18:02:17 -0700 | [diff] [blame] | 165 | EXPECT_CALL(*mNativeWindow, |
| 166 | setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE | |
| 167 | GRALLOC_USAGE_PROTECTED)) |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 168 | .WillOnce(Return(NO_ERROR)); |
John Reck | 44418f5 | 2020-09-15 18:02:17 -0700 | [diff] [blame] | 169 | EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE)) |
| 170 | .WillOnce(Return(NO_ERROR)); |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 171 | |
| 172 | mSurface.setProtected(true); |
| 173 | EXPECT_TRUE(mSurface.isProtected()); |
| 174 | mSurface.setProtected(false); |
| 175 | EXPECT_FALSE(mSurface.isProtected()); |
| 176 | } |
| 177 | |
| 178 | TEST_F(RenderSurfaceTest, setProtectedEnableWithError) { |
| 179 | EXPECT_FALSE(mSurface.isProtected()); |
John Reck | 44418f5 | 2020-09-15 18:02:17 -0700 | [diff] [blame] | 180 | EXPECT_CALL(*mNativeWindow, |
| 181 | setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE | |
| 182 | GRALLOC_USAGE_PROTECTED)) |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 183 | .WillOnce(Return(INVALID_OPERATION)); |
| 184 | mSurface.setProtected(true); |
| 185 | EXPECT_FALSE(mSurface.isProtected()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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::beginFrame() |
| 190 | */ |
| 191 | |
| 192 | TEST_F(RenderSurfaceTest, beginFrameAppliesChange) { |
| 193 | EXPECT_CALL(*mDisplaySurface, beginFrame(true)).WillOnce(Return(NO_ERROR)); |
| 194 | |
| 195 | EXPECT_EQ(NO_ERROR, mSurface.beginFrame(true)); |
| 196 | } |
| 197 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 198 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 199 | * RenderSurface::prepareFrame() |
| 200 | */ |
| 201 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 202 | TEST_F(RenderSurfaceTest, prepareFrameHandlesMixedComposition) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 203 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_MIXED)) |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 204 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 205 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 206 | mSurface.prepareFrame(true, true); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 209 | TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyGpuComposition) { |
| 210 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_GPU)) |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 211 | .WillOnce(Return(NO_ERROR)); |
| 212 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 213 | mSurface.prepareFrame(true, false); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyHwcComposition) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 217 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC)) |
| 218 | .WillOnce(Return(NO_ERROR)); |
| 219 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 220 | mSurface.prepareFrame(false, true); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | TEST_F(RenderSurfaceTest, prepareFrameHandlesNoComposition) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 224 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC)) |
| 225 | .WillOnce(Return(NO_ERROR)); |
| 226 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 227 | mSurface.prepareFrame(false, false); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 230 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 231 | * RenderSurface::dequeueBuffer() |
| 232 | */ |
| 233 | |
| 234 | TEST_F(RenderSurfaceTest, dequeueBufferObtainsABuffer) { |
| 235 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 236 | |
| 237 | EXPECT_CALL(*mNativeWindow, dequeueBuffer(_, _)) |
| 238 | .WillOnce( |
| 239 | DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); |
| 240 | |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 241 | base::unique_fd fence; |
| 242 | EXPECT_EQ(buffer.get(), mSurface.dequeueBuffer(&fence).get()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 243 | |
| 244 | EXPECT_EQ(buffer.get(), mSurface.mutableGraphicBufferForTest().get()); |
| 245 | } |
| 246 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 247 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 248 | * RenderSurface::queueBuffer() |
| 249 | */ |
| 250 | |
| 251 | TEST_F(RenderSurfaceTest, queueBufferHandlesNoClientComposition) { |
| 252 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 253 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 254 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 255 | impl::OutputCompositionState state; |
| 256 | state.usesClientComposition = false; |
| 257 | state.flipClientTarget = false; |
| 258 | |
| 259 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 260 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 261 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 262 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 263 | |
| 264 | EXPECT_EQ(buffer.get(), mSurface.mutableGraphicBufferForTest().get()); |
| 265 | } |
| 266 | |
| 267 | TEST_F(RenderSurfaceTest, queueBufferHandlesClientComposition) { |
| 268 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 269 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 270 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 271 | impl::OutputCompositionState state; |
| 272 | state.usesClientComposition = true; |
| 273 | state.flipClientTarget = false; |
| 274 | |
| 275 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 276 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 277 | .WillOnce(Return(NO_ERROR)); |
| 278 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 279 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 280 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 281 | |
| 282 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 283 | } |
| 284 | |
| 285 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequest) { |
| 286 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 287 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 288 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 289 | impl::OutputCompositionState state; |
| 290 | state.usesClientComposition = false; |
| 291 | state.flipClientTarget = true; |
| 292 | |
| 293 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 294 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 295 | .WillOnce(Return(NO_ERROR)); |
| 296 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 297 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 298 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 299 | |
| 300 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 301 | } |
| 302 | |
| 303 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequestWithNoBufferYetDequeued) { |
| 304 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 305 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 306 | impl::OutputCompositionState state; |
| 307 | state.usesClientComposition = false; |
| 308 | state.flipClientTarget = true; |
| 309 | |
| 310 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 311 | EXPECT_CALL(*mNativeWindow, dequeueBuffer(_, _)) |
| 312 | .WillOnce( |
| 313 | DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); |
| 314 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 315 | .WillOnce(Return(NO_ERROR)); |
| 316 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 317 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 318 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 319 | |
| 320 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 321 | } |
| 322 | |
| 323 | TEST_F(RenderSurfaceTest, queueBufferHandlesNativeWindowQueueBufferFailureOnVirtualDisplay) { |
| 324 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 325 | mSurface.mutableGraphicBufferForTest() = buffer; |
| 326 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 327 | impl::OutputCompositionState state; |
| 328 | state.usesClientComposition = true; |
| 329 | |
| 330 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 331 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) |
| 332 | .WillOnce(Return(INVALID_OPERATION)); |
| 333 | EXPECT_CALL(mDisplay, isVirtual()).WillOnce(Return(true)); |
| 334 | EXPECT_CALL(*mNativeWindow, cancelBuffer(buffer->getNativeBuffer(), -1)) |
| 335 | .WillOnce(Return(NO_ERROR)); |
| 336 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); |
| 337 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 338 | mSurface.queueBuffer(base::unique_fd()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 339 | |
| 340 | EXPECT_EQ(nullptr, mSurface.mutableGraphicBufferForTest().get()); |
| 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::onPresentDisplayCompleted() |
| 345 | */ |
| 346 | |
| 347 | TEST_F(RenderSurfaceTest, onPresentDisplayCompletedForwardsSignal) { |
| 348 | EXPECT_CALL(*mDisplaySurface, onFrameCommitted()).Times(1); |
| 349 | |
| 350 | mSurface.onPresentDisplayCompleted(); |
| 351 | } |
| 352 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 353 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 354 | * RenderSurface::flip() |
| 355 | */ |
| 356 | |
| 357 | TEST_F(RenderSurfaceTest, flipForwardsSignal) { |
| 358 | mSurface.setPageFlipCountForTest(500); |
| 359 | |
| 360 | mSurface.flip(); |
| 361 | |
| 362 | EXPECT_EQ(501, mSurface.getPageFlipCount()); |
| 363 | } |
| 364 | |
| 365 | } // namespace |
| 366 | } // namespace android::compositionengine |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 367 | |
| 368 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 369 | #pragma clang diagnostic pop // ignored "-Wextra" |