| 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 | 50121d5 | 2021-04-23 13:01:16 -0700 | [diff] [blame] | 29 | #include <renderengine/ExternalTexture.h> | 
| Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 30 | #include <renderengine/impl/ExternalTexture.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 31 | #include <renderengine/mock/RenderEngine.h> | 
| Dominik Laskowski | 50121d5 | 2021-04-23 13:01:16 -0700 | [diff] [blame] | 32 | #include <ui/GraphicBuffer.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 33 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 34 | namespace android::compositionengine { | 
|  | 35 | namespace { | 
|  | 36 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 37 | constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; | 
|  | 38 | constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; | 
| Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 39 | constexpr DisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 40 | const std::string DEFAULT_DISPLAY_NAME = "Mock Display"; | 
|  | 41 |  | 
|  | 42 | using testing::_; | 
|  | 43 | using testing::ByMove; | 
|  | 44 | using testing::DoAll; | 
|  | 45 | using testing::Ref; | 
|  | 46 | using testing::Return; | 
|  | 47 | using testing::ReturnRef; | 
|  | 48 | using testing::SetArgPointee; | 
|  | 49 | using testing::StrictMock; | 
|  | 50 |  | 
|  | 51 | class RenderSurfaceTest : public testing::Test { | 
|  | 52 | public: | 
|  | 53 | RenderSurfaceTest() { | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 54 | EXPECT_CALL(mDisplay, getId()).WillRepeatedly(Return(DEFAULT_DISPLAY_ID)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 55 | EXPECT_CALL(mDisplay, getName()).WillRepeatedly(ReturnRef(DEFAULT_DISPLAY_NAME)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 56 | EXPECT_CALL(mCompositionEngine, getRenderEngine).WillRepeatedly(ReturnRef(mRenderEngine)); | 
| chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 57 | EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)) | 
|  | 58 | .WillRepeatedly(Return(NO_ERROR)); | 
| 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 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 61 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; | 
|  | 62 | StrictMock<mock::CompositionEngine> mCompositionEngine; | 
|  | 63 | StrictMock<mock::Display> mDisplay; | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 64 | sp<mock::NativeWindow> mNativeWindow = sp<StrictMock<mock::NativeWindow>>::make(); | 
|  | 65 | sp<mock::DisplaySurface> mDisplaySurface = sp<StrictMock<mock::DisplaySurface>>::make(); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 66 | impl::RenderSurface mSurface{mCompositionEngine, mDisplay, | 
| Dominik Laskowski | 50121d5 | 2021-04-23 13:01:16 -0700 | [diff] [blame] | 67 | RenderSurfaceCreationArgsBuilder() | 
|  | 68 | .setDisplayWidth(DEFAULT_DISPLAY_WIDTH) | 
|  | 69 | .setDisplayHeight(DEFAULT_DISPLAY_HEIGHT) | 
|  | 70 | .setNativeWindow(mNativeWindow) | 
|  | 71 | .setDisplaySurface(mDisplaySurface) | 
|  | 72 | .build()}; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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) { | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 112 | sp<Fence> fence = sp<Fence>::make(); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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) { | 
| Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 205 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::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) { | 
| Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 212 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::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) { | 
| Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 219 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::Hwc)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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) { | 
| Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 226 | EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::Hwc)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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) { | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 237 | sp<GraphicBuffer> buffer = sp<GraphicBuffer>::make(); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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< | 
| Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 255 | renderengine::impl:: | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 256 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, | 
| Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 257 | renderengine::impl::ExternalTexture::Usage::READABLE | | 
|  | 258 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 259 | mSurface.mutableTextureForTest() = buffer; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 260 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 261 | impl::OutputCompositionState state; | 
|  | 262 | state.usesClientComposition = false; | 
|  | 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(*mDisplaySurface, advanceFrame()).Times(1); | 
|  | 267 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 268 | mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 269 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 270 | EXPECT_EQ(buffer.get(), mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 271 | } | 
|  | 272 |  | 
|  | 273 | TEST_F(RenderSurfaceTest, queueBufferHandlesClientComposition) { | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 274 | const auto buffer = | 
|  | 275 | std::make_shared<renderengine::impl::ExternalTexture>(sp<GraphicBuffer>::make(), | 
|  | 276 | mRenderEngine, false); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 277 | mSurface.mutableTextureForTest() = buffer; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 278 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 279 | impl::OutputCompositionState state; | 
|  | 280 | state.usesClientComposition = true; | 
|  | 281 | state.flipClientTarget = false; | 
|  | 282 |  | 
|  | 283 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 284 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 290 | EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 291 | } | 
|  | 292 |  | 
|  | 293 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequest) { | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 294 | const auto buffer = | 
|  | 295 | std::make_shared<renderengine::impl::ExternalTexture>(sp<GraphicBuffer>::make(), | 
|  | 296 | mRenderEngine, false); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 297 | mSurface.mutableTextureForTest() = buffer; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 298 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 299 | impl::OutputCompositionState state; | 
|  | 300 | state.usesClientComposition = false; | 
|  | 301 | state.flipClientTarget = true; | 
|  | 302 |  | 
|  | 303 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 304 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 310 | EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 311 | } | 
|  | 312 |  | 
|  | 313 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequestWithNoBufferYetDequeued) { | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 314 | sp<GraphicBuffer> buffer = sp<GraphicBuffer>::make(); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 315 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 316 | impl::OutputCompositionState state; | 
|  | 317 | state.usesClientComposition = false; | 
|  | 318 | state.flipClientTarget = 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, dequeueBuffer(_, _)) | 
|  | 322 | .WillOnce( | 
|  | 323 | DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); | 
|  | 324 | EXPECT_CALL(*mNativeWindow, queueBuffer(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 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 330 | EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 331 | } | 
|  | 332 |  | 
|  | 333 | TEST_F(RenderSurfaceTest, queueBufferHandlesNativeWindowQueueBufferFailureOnVirtualDisplay) { | 
| Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 334 | const auto buffer = | 
|  | 335 | std::make_shared<renderengine::impl::ExternalTexture>(sp<GraphicBuffer>::make(), | 
|  | 336 | mRenderEngine, false); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 337 | mSurface.mutableTextureForTest() = buffer; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 338 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 339 | impl::OutputCompositionState state; | 
|  | 340 | state.usesClientComposition = true; | 
|  | 341 |  | 
|  | 342 | EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 343 | EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 344 | .WillOnce(Return(INVALID_OPERATION)); | 
|  | 345 | EXPECT_CALL(mDisplay, isVirtual()).WillOnce(Return(true)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 346 | EXPECT_CALL(*mNativeWindow, cancelBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 347 | .WillOnce(Return(NO_ERROR)); | 
|  | 348 | EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
|  | 349 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 350 | mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 351 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 352 | EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 353 | } | 
|  | 354 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 355 | /* | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 356 | * RenderSurface::onPresentDisplayCompleted() | 
|  | 357 | */ | 
|  | 358 |  | 
|  | 359 | TEST_F(RenderSurfaceTest, onPresentDisplayCompletedForwardsSignal) { | 
|  | 360 | EXPECT_CALL(*mDisplaySurface, onFrameCommitted()).Times(1); | 
|  | 361 |  | 
|  | 362 | mSurface.onPresentDisplayCompleted(); | 
|  | 363 | } | 
|  | 364 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 365 | } // namespace | 
|  | 366 | } // namespace android::compositionengine |