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