| 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; | 
| chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 64 |     sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 65 |     sp<mock::DisplaySurface> mDisplaySurface = new StrictMock<mock::DisplaySurface>(); | 
 | 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) { | 
 | 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) { | 
| 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) { | 
 | 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< | 
| Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 255 |             renderengine::impl:: | 
 | 256 |                     ExternalTexture>(new GraphicBuffer(), mRenderEngine, | 
 | 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) { | 
| Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 274 |     const auto buffer = std::make_shared<renderengine::impl::ExternalTexture>(new GraphicBuffer(), | 
 | 275 |                                                                               mRenderEngine, false); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 276 |     mSurface.mutableTextureForTest() = buffer; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 277 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 278 |     impl::OutputCompositionState state; | 
 | 279 |     state.usesClientComposition = true; | 
 | 280 |     state.flipClientTarget = false; | 
 | 281 |  | 
 | 282 |     EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 283 |     EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 284 |             .WillOnce(Return(NO_ERROR)); | 
 | 285 |     EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
 | 286 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 287 |     mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 288 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 289 |     EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 290 | } | 
 | 291 |  | 
 | 292 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequest) { | 
| Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 293 |     const auto buffer = std::make_shared<renderengine::impl::ExternalTexture>(new GraphicBuffer(), | 
 | 294 |                                                                               mRenderEngine, false); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 295 |     mSurface.mutableTextureForTest() = buffer; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 296 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 297 |     impl::OutputCompositionState state; | 
 | 298 |     state.usesClientComposition = false; | 
 | 299 |     state.flipClientTarget = true; | 
 | 300 |  | 
 | 301 |     EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 302 |     EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 303 |             .WillOnce(Return(NO_ERROR)); | 
 | 304 |     EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
 | 305 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 306 |     mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 307 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 308 |     EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 309 | } | 
 | 310 |  | 
 | 311 | TEST_F(RenderSurfaceTest, queueBufferHandlesFlipClientTargetRequestWithNoBufferYetDequeued) { | 
 | 312 |     sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
 | 313 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 314 |     impl::OutputCompositionState state; | 
 | 315 |     state.usesClientComposition = false; | 
 | 316 |     state.flipClientTarget = true; | 
 | 317 |  | 
 | 318 |     EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 319 |     EXPECT_CALL(*mNativeWindow, dequeueBuffer(_, _)) | 
 | 320 |             .WillOnce( | 
 | 321 |                     DoAll(SetArgPointee<0>(buffer.get()), SetArgPointee<1>(-1), Return(NO_ERROR))); | 
 | 322 |     EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getNativeBuffer(), -1)) | 
 | 323 |             .WillOnce(Return(NO_ERROR)); | 
 | 324 |     EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
 | 325 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 326 |     mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 327 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 328 |     EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 329 | } | 
 | 330 |  | 
 | 331 | TEST_F(RenderSurfaceTest, queueBufferHandlesNativeWindowQueueBufferFailureOnVirtualDisplay) { | 
| Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 332 |     const auto buffer = std::make_shared<renderengine::impl::ExternalTexture>(new GraphicBuffer(), | 
 | 333 |                                                                               mRenderEngine, false); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 334 |     mSurface.mutableTextureForTest() = buffer; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 335 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 336 |     impl::OutputCompositionState state; | 
 | 337 |     state.usesClientComposition = true; | 
 | 338 |  | 
 | 339 |     EXPECT_CALL(mDisplay, getState()).WillOnce(ReturnRef(state)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 340 |     EXPECT_CALL(*mNativeWindow, queueBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 341 |             .WillOnce(Return(INVALID_OPERATION)); | 
 | 342 |     EXPECT_CALL(mDisplay, isVirtual()).WillOnce(Return(true)); | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 343 |     EXPECT_CALL(*mNativeWindow, cancelBuffer(buffer->getBuffer()->getNativeBuffer(), -1)) | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 344 |             .WillOnce(Return(NO_ERROR)); | 
 | 345 |     EXPECT_CALL(*mDisplaySurface, advanceFrame()).Times(1); | 
 | 346 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 347 |     mSurface.queueBuffer(base::unique_fd()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 348 |  | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 349 |     EXPECT_EQ(nullptr, mSurface.mutableTextureForTest().get()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 350 | } | 
 | 351 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 352 | /* | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 353 |  * RenderSurface::onPresentDisplayCompleted() | 
 | 354 |  */ | 
 | 355 |  | 
 | 356 | TEST_F(RenderSurfaceTest, onPresentDisplayCompletedForwardsSignal) { | 
 | 357 |     EXPECT_CALL(*mDisplaySurface, onFrameCommitted()).Times(1); | 
 | 358 |  | 
 | 359 |     mSurface.onPresentDisplayCompleted(); | 
 | 360 | } | 
 | 361 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 362 | /* | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 363 |  * RenderSurface::flip() | 
 | 364 |  */ | 
 | 365 |  | 
 | 366 | TEST_F(RenderSurfaceTest, flipForwardsSignal) { | 
 | 367 |     mSurface.setPageFlipCountForTest(500); | 
 | 368 |  | 
 | 369 |     mSurface.flip(); | 
 | 370 |  | 
| Dominik Laskowski | 50121d5 | 2021-04-23 13:01:16 -0700 | [diff] [blame] | 371 |     EXPECT_EQ(501u, mSurface.getPageFlipCount()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 372 | } | 
 | 373 |  | 
 | 374 | } // namespace | 
 | 375 | } // namespace android::compositionengine |