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