| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2018 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 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 17 | #undef LOG_TAG | 
|  | 18 | #define LOG_TAG "RenderEngineTest" | 
|  | 19 |  | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 20 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 21 | #pragma clang diagnostic push | 
|  | 22 | #pragma clang diagnostic ignored "-Wconversion" | 
| Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 23 | #pragma clang diagnostic ignored "-Wextra" | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 24 |  | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 25 | #include <cutils/properties.h> | 
| Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 26 | #include <gtest/gtest.h> | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 27 | #include <renderengine/RenderEngine.h> | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 28 | #include <sync/sync.h> | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 29 | #include <ui/PixelFormat.h> | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 30 |  | 
|  | 31 | #include <chrono> | 
|  | 32 | #include <condition_variable> | 
|  | 33 | #include <fstream> | 
|  | 34 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 35 | #include "../gl/GLESRenderEngine.h" | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 36 | #include "../skia/SkiaGLRenderEngine.h" | 
| Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 37 | #include "../threaded/RenderEngineThreaded.h" | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 38 |  | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 39 | constexpr int DEFAULT_DISPLAY_WIDTH = 128; | 
|  | 40 | constexpr int DEFAULT_DISPLAY_HEIGHT = 256; | 
|  | 41 | constexpr int DEFAULT_DISPLAY_OFFSET = 64; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 42 | constexpr bool WRITE_BUFFER_TO_FILE_ON_FAILURE = false; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 43 |  | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 44 | namespace android { | 
|  | 45 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 46 | class RenderEngineFactory { | 
|  | 47 | public: | 
|  | 48 | virtual ~RenderEngineFactory() = default; | 
|  | 49 |  | 
|  | 50 | virtual std::string name() = 0; | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 51 | virtual renderengine::RenderEngine::RenderEngineType type() = 0; | 
|  | 52 | virtual std::unique_ptr<renderengine::RenderEngine> createRenderEngine() = 0; | 
|  | 53 | virtual std::unique_ptr<renderengine::gl::GLESRenderEngine> createGLESRenderEngine() { | 
|  | 54 | return nullptr; | 
|  | 55 | } | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 56 | }; | 
|  | 57 |  | 
|  | 58 | class GLESRenderEngineFactory : public RenderEngineFactory { | 
|  | 59 | public: | 
|  | 60 | std::string name() override { return "GLESRenderEngineFactory"; } | 
|  | 61 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 62 | renderengine::RenderEngine::RenderEngineType type() { | 
|  | 63 | return renderengine::RenderEngine::RenderEngineType::GLES; | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { | 
|  | 67 | return createGLESRenderEngine(); | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | std::unique_ptr<renderengine::gl::GLESRenderEngine> createGLESRenderEngine() { | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 71 | renderengine::RenderEngineCreationArgs reCreationArgs = | 
| Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 72 | renderengine::RenderEngineCreationArgs::Builder() | 
| Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 73 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) | 
|  | 74 | .setImageCacheSize(1) | 
|  | 75 | .setUseColorManagerment(false) | 
|  | 76 | .setEnableProtectedContext(false) | 
|  | 77 | .setPrecacheToneMapperShaderOnly(false) | 
|  | 78 | .setSupportsBackgroundBlur(true) | 
|  | 79 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 80 | .setRenderEngineType(type()) | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 81 | .build(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 82 | return renderengine::gl::GLESRenderEngine::create(reCreationArgs); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 83 | } | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 84 | }; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 85 |  | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 86 | class GLESCMRenderEngineFactory : public RenderEngineFactory { | 
|  | 87 | public: | 
|  | 88 | std::string name() override { return "GLESCMRenderEngineFactory"; } | 
|  | 89 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 90 | renderengine::RenderEngine::RenderEngineType type() { | 
|  | 91 | return renderengine::RenderEngine::RenderEngineType::GLES; | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { | 
|  | 95 | return createGLESRenderEngine(); | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | std::unique_ptr<renderengine::gl::GLESRenderEngine> createGLESRenderEngine() override { | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 99 | renderengine::RenderEngineCreationArgs reCreationArgs = | 
|  | 100 | renderengine::RenderEngineCreationArgs::Builder() | 
|  | 101 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) | 
|  | 102 | .setImageCacheSize(1) | 
|  | 103 | .setEnableProtectedContext(false) | 
|  | 104 | .setPrecacheToneMapperShaderOnly(false) | 
|  | 105 | .setSupportsBackgroundBlur(true) | 
|  | 106 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 107 | .setRenderEngineType(type()) | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 108 | .setUseColorManagerment(true) | 
|  | 109 | .build(); | 
|  | 110 | return renderengine::gl::GLESRenderEngine::create(reCreationArgs); | 
|  | 111 | } | 
|  | 112 | }; | 
|  | 113 |  | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 114 | class SkiaGLESRenderEngineFactory : public RenderEngineFactory { | 
|  | 115 | public: | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 116 | std::string name() override { return "SkiaGLRenderEngineFactory"; } | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 117 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 118 | renderengine::RenderEngine::RenderEngineType type() { | 
|  | 119 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 123 | renderengine::RenderEngineCreationArgs reCreationArgs = | 
|  | 124 | renderengine::RenderEngineCreationArgs::Builder() | 
|  | 125 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) | 
|  | 126 | .setImageCacheSize(1) | 
|  | 127 | .setEnableProtectedContext(false) | 
|  | 128 | .setPrecacheToneMapperShaderOnly(false) | 
|  | 129 | .setSupportsBackgroundBlur(true) | 
|  | 130 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 131 | .setRenderEngineType(type()) | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 132 | .build(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 133 | return renderengine::skia::SkiaGLRenderEngine::create(reCreationArgs); | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 134 | } | 
|  | 135 | }; | 
|  | 136 |  | 
|  | 137 | class SkiaGLESCMRenderEngineFactory : public RenderEngineFactory { | 
|  | 138 | public: | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 139 | std::string name() override { return "SkiaGLCMRenderEngineFactory"; } | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 140 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 141 | renderengine::RenderEngine::RenderEngineType type() { | 
|  | 142 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; | 
|  | 143 | } | 
|  | 144 |  | 
|  | 145 | std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 146 | renderengine::RenderEngineCreationArgs reCreationArgs = | 
|  | 147 | renderengine::RenderEngineCreationArgs::Builder() | 
|  | 148 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) | 
|  | 149 | .setImageCacheSize(1) | 
|  | 150 | .setEnableProtectedContext(false) | 
|  | 151 | .setPrecacheToneMapperShaderOnly(false) | 
|  | 152 | .setSupportsBackgroundBlur(true) | 
|  | 153 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 154 | .setRenderEngineType(type()) | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 155 | .setUseColorManagerment(true) | 
|  | 156 | .build(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 157 | return renderengine::skia::SkiaGLRenderEngine::create(reCreationArgs); | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 158 | } | 
|  | 159 | }; | 
|  | 160 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 161 | class RenderEngineTest : public ::testing::TestWithParam<std::shared_ptr<RenderEngineFactory>> { | 
|  | 162 | public: | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 163 | static sp<GraphicBuffer> allocateDefaultBuffer() { | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 164 | return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT, | 
|  | 165 | HAL_PIXEL_FORMAT_RGBA_8888, 1, | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 166 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 167 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE, | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 168 | "output"); | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 169 | } | 
|  | 170 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 171 | // Allocates a 1x1 buffer to fill with a solid color | 
|  | 172 | static sp<GraphicBuffer> allocateSourceBuffer(uint32_t width, uint32_t height) { | 
|  | 173 | return new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 174 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | | 
|  | 175 | GRALLOC_USAGE_HW_TEXTURE, | 
|  | 176 | "input"); | 
|  | 177 | } | 
|  | 178 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 179 | RenderEngineTest() { | 
|  | 180 | const ::testing::TestInfo* const test_info = | 
|  | 181 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 182 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 183 | mBuffer = allocateDefaultBuffer(); | 
|  | 184 | } | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 185 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 186 | ~RenderEngineTest() { | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 187 | if (WRITE_BUFFER_TO_FILE_ON_FAILURE && ::testing::Test::HasFailure()) { | 
|  | 188 | writeBufferToFile("/data/texture_out_"); | 
|  | 189 | } | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 190 | for (uint32_t texName : mTexNames) { | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 191 | mRE->deleteTextures(1, &texName); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 192 | if (mGLESRE != nullptr) { | 
|  | 193 | EXPECT_FALSE(mGLESRE->isTextureNameKnownForTesting(texName)); | 
|  | 194 | } | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 195 | } | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 196 | const ::testing::TestInfo* const test_info = | 
|  | 197 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 198 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 201 | void writeBufferToFile(const char* basename) { | 
|  | 202 | std::string filename(basename); | 
|  | 203 | filename.append(::testing::UnitTest::GetInstance()->current_test_info()->name()); | 
|  | 204 | filename.append(".ppm"); | 
|  | 205 | std::ofstream file(filename.c_str(), std::ios::binary); | 
|  | 206 | if (!file.is_open()) { | 
|  | 207 | ALOGE("Unable to open file: %s", filename.c_str()); | 
|  | 208 | ALOGE("You may need to do: \"adb shell setenforce 0\" to enable " | 
|  | 209 | "surfaceflinger to write debug images"); | 
|  | 210 | return; | 
|  | 211 | } | 
|  | 212 |  | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 213 | uint8_t* pixels; | 
|  | 214 | mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 215 | reinterpret_cast<void**>(&pixels)); | 
|  | 216 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 217 | file << "P6\n"; | 
|  | 218 | file << mBuffer->getWidth() << "\n"; | 
|  | 219 | file << mBuffer->getHeight() << "\n"; | 
|  | 220 | file << 255 << "\n"; | 
|  | 221 |  | 
|  | 222 | std::vector<uint8_t> outBuffer(mBuffer->getWidth() * mBuffer->getHeight() * 3); | 
|  | 223 | auto outPtr = reinterpret_cast<uint8_t*>(outBuffer.data()); | 
|  | 224 |  | 
|  | 225 | for (int32_t j = 0; j < mBuffer->getHeight(); j++) { | 
|  | 226 | const uint8_t* src = pixels + (mBuffer->getStride() * j) * 4; | 
|  | 227 | for (int32_t i = 0; i < mBuffer->getWidth(); i++) { | 
|  | 228 | // Only copy R, G and B components | 
|  | 229 | outPtr[0] = src[0]; | 
|  | 230 | outPtr[1] = src[1]; | 
|  | 231 | outPtr[2] = src[2]; | 
|  | 232 | outPtr += 3; | 
|  | 233 |  | 
|  | 234 | src += 4; | 
|  | 235 | } | 
|  | 236 | } | 
|  | 237 | file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size()); | 
|  | 238 | mBuffer->unlock(); | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | void expectBufferColor(const Region& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { | 
|  | 242 | size_t c; | 
|  | 243 | Rect const* rect = region.getArray(&c); | 
|  | 244 | for (size_t i = 0; i < c; i++, rect++) { | 
|  | 245 | expectBufferColor(*rect, r, g, b, a); | 
|  | 246 | } | 
|  | 247 | } | 
|  | 248 |  | 
|  | 249 | void expectBufferColor(const Rect& rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a, | 
|  | 250 | uint8_t tolerance = 0) { | 
|  | 251 | auto colorCompare = [tolerance](const uint8_t* colorA, const uint8_t* colorB) { | 
|  | 252 | auto colorBitCompare = [tolerance](uint8_t a, uint8_t b) { | 
|  | 253 | uint8_t tmp = a >= b ? a - b : b - a; | 
|  | 254 | return tmp <= tolerance; | 
|  | 255 | }; | 
|  | 256 | return std::equal(colorA, colorA + 4, colorB, colorBitCompare); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 257 | }; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 258 |  | 
|  | 259 | expectBufferColor(rect, r, g, b, a, colorCompare); | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | void expectBufferColor(const Rect& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a, | 
|  | 263 | std::function<bool(const uint8_t* a, const uint8_t* b)> colorCompare) { | 
|  | 264 | uint8_t* pixels; | 
|  | 265 | mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 266 | reinterpret_cast<void**>(&pixels)); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 267 | int32_t maxFails = 10; | 
|  | 268 | int32_t fails = 0; | 
|  | 269 | for (int32_t j = 0; j < region.getHeight(); j++) { | 
|  | 270 | const uint8_t* src = | 
|  | 271 | pixels + (mBuffer->getStride() * (region.top + j) + region.left) * 4; | 
|  | 272 | for (int32_t i = 0; i < region.getWidth(); i++) { | 
|  | 273 | const uint8_t expected[4] = {r, g, b, a}; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 274 | bool equal = colorCompare(src, expected); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 275 | EXPECT_TRUE(equal) | 
|  | 276 | << "pixel @ (" << region.left + i << ", " << region.top + j << "): " | 
|  | 277 | << "expected (" << static_cast<uint32_t>(r) << ", " | 
|  | 278 | << static_cast<uint32_t>(g) << ", " << static_cast<uint32_t>(b) << ", " | 
|  | 279 | << static_cast<uint32_t>(a) << "), " | 
|  | 280 | << "got (" << static_cast<uint32_t>(src[0]) << ", " | 
|  | 281 | << static_cast<uint32_t>(src[1]) << ", " << static_cast<uint32_t>(src[2]) | 
|  | 282 | << ", " << static_cast<uint32_t>(src[3]) << ")"; | 
|  | 283 | src += 4; | 
|  | 284 | if (!equal && ++fails >= maxFails) { | 
|  | 285 | break; | 
|  | 286 | } | 
|  | 287 | } | 
|  | 288 | if (fails >= maxFails) { | 
|  | 289 | break; | 
|  | 290 | } | 
|  | 291 | } | 
|  | 292 | mBuffer->unlock(); | 
|  | 293 | } | 
|  | 294 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 295 | void expectAlpha(const Rect& rect, uint8_t a) { | 
|  | 296 | auto colorCompare = [](const uint8_t* colorA, const uint8_t* colorB) { | 
|  | 297 | return colorA[3] == colorB[3]; | 
|  | 298 | }; | 
|  | 299 | expectBufferColor(rect, 0.0f /* r */, 0.0f /*g */, 0.0f /* b */, a, colorCompare); | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | void expectShadowColor(const renderengine::LayerSettings& castingLayer, | 
|  | 303 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, | 
|  | 304 | const ubyte4& backgroundColor) { | 
|  | 305 | const Rect casterRect(castingLayer.geometry.boundaries); | 
|  | 306 | Region casterRegion = Region(casterRect); | 
|  | 307 | const float casterCornerRadius = castingLayer.geometry.roundedCornersRadius; | 
|  | 308 | if (casterCornerRadius > 0.0f) { | 
|  | 309 | // ignore the corners if a corner radius is set | 
|  | 310 | Rect cornerRect(casterCornerRadius, casterCornerRadius); | 
|  | 311 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.left, casterRect.top)); | 
|  | 312 | casterRegion.subtractSelf( | 
|  | 313 | cornerRect.offsetTo(casterRect.right - casterCornerRadius, casterRect.top)); | 
|  | 314 | casterRegion.subtractSelf( | 
|  | 315 | cornerRect.offsetTo(casterRect.left, casterRect.bottom - casterCornerRadius)); | 
|  | 316 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.right - casterCornerRadius, | 
|  | 317 | casterRect.bottom - casterCornerRadius)); | 
|  | 318 | } | 
|  | 319 |  | 
|  | 320 | const float shadowInset = shadow.length * -1.0f; | 
|  | 321 | const Rect casterWithShadow = | 
|  | 322 | Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset); | 
|  | 323 | const Region shadowRegion = Region(casterWithShadow).subtractSelf(casterRect); | 
|  | 324 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); | 
|  | 325 |  | 
|  | 326 | // verify casting layer | 
|  | 327 | expectBufferColor(casterRegion, casterColor.r, casterColor.g, casterColor.b, casterColor.a); | 
|  | 328 |  | 
|  | 329 | // verify shadows by testing just the alpha since its difficult to validate the shadow color | 
|  | 330 | size_t c; | 
|  | 331 | Rect const* r = shadowRegion.getArray(&c); | 
|  | 332 | for (size_t i = 0; i < c; i++, r++) { | 
|  | 333 | expectAlpha(*r, 255); | 
|  | 334 | } | 
|  | 335 |  | 
|  | 336 | // verify background | 
|  | 337 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, | 
|  | 338 | backgroundColor.a); | 
|  | 339 | } | 
|  | 340 |  | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 341 | void expectShadowColorWithoutCaster(const FloatRect& casterBounds, | 
|  | 342 | const renderengine::ShadowSettings& shadow, | 
|  | 343 | const ubyte4& backgroundColor) { | 
|  | 344 | const float shadowInset = shadow.length * -1.0f; | 
|  | 345 | const Rect casterRect(casterBounds); | 
|  | 346 | const Rect shadowRect = | 
|  | 347 | Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset); | 
|  | 348 |  | 
|  | 349 | const Region backgroundRegion = | 
|  | 350 | Region(fullscreenRect()).subtractSelf(casterRect).subtractSelf(shadowRect); | 
|  | 351 |  | 
|  | 352 | expectAlpha(shadowRect, 255); | 
|  | 353 | // (0, 0, 0) fill on the bounds of the layer should be ignored. | 
|  | 354 | expectBufferColor(casterRect, 255, 255, 255, 255, 254); | 
|  | 355 |  | 
|  | 356 | // verify background | 
|  | 357 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, | 
|  | 358 | backgroundColor.a); | 
|  | 359 | } | 
|  | 360 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 361 | static renderengine::ShadowSettings getShadowSettings(const vec2& casterPos, float shadowLength, | 
|  | 362 | bool casterIsTranslucent) { | 
|  | 363 | renderengine::ShadowSettings shadow; | 
|  | 364 | shadow.ambientColor = {0.0f, 0.0f, 0.0f, 0.039f}; | 
|  | 365 | shadow.spotColor = {0.0f, 0.0f, 0.0f, 0.19f}; | 
|  | 366 | shadow.lightPos = vec3(casterPos.x, casterPos.y, 0); | 
|  | 367 | shadow.lightRadius = 0.0f; | 
|  | 368 | shadow.length = shadowLength; | 
|  | 369 | shadow.casterIsTranslucent = casterIsTranslucent; | 
|  | 370 | return shadow; | 
|  | 371 | } | 
|  | 372 |  | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 373 | static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); } | 
|  | 374 |  | 
|  | 375 | static Rect offsetRect() { | 
|  | 376 | return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, | 
|  | 377 | DEFAULT_DISPLAY_HEIGHT); | 
|  | 378 | } | 
|  | 379 |  | 
|  | 380 | static Rect offsetRectAtZero() { | 
|  | 381 | return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET, | 
|  | 382 | DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET); | 
|  | 383 | } | 
|  | 384 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 385 | void invokeDraw(renderengine::DisplaySettings settings, | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 386 | std::vector<const renderengine::LayerSettings*> layers) { | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 387 | base::unique_fd fence; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 388 | status_t status = | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 389 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), &fence); | 
|  | 390 | mCurrentBuffer = mBuffer; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 391 |  | 
|  | 392 | int fd = fence.release(); | 
|  | 393 | if (fd >= 0) { | 
|  | 394 | sync_wait(fd, -1); | 
|  | 395 | close(fd); | 
|  | 396 | } | 
|  | 397 |  | 
|  | 398 | ASSERT_EQ(NO_ERROR, status); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 399 | if (layers.size() > 0 && mGLESRE != nullptr) { | 
|  | 400 | ASSERT_TRUE(mGLESRE->isFramebufferImageCachedForTesting(mBuffer->getId())); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 401 | } | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 402 | } | 
|  | 403 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 404 | void drawEmptyLayers() { | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 405 | renderengine::DisplaySettings settings; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 406 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 407 | invokeDraw(settings, layers); | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 408 | } | 
|  | 409 |  | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 410 | template <typename SourceVariant> | 
|  | 411 | void fillBuffer(half r, half g, half b, half a); | 
|  | 412 |  | 
|  | 413 | template <typename SourceVariant> | 
|  | 414 | void fillRedBuffer(); | 
|  | 415 |  | 
|  | 416 | template <typename SourceVariant> | 
|  | 417 | void fillGreenBuffer(); | 
|  | 418 |  | 
|  | 419 | template <typename SourceVariant> | 
|  | 420 | void fillBlueBuffer(); | 
|  | 421 |  | 
|  | 422 | template <typename SourceVariant> | 
|  | 423 | void fillRedTransparentBuffer(); | 
|  | 424 |  | 
|  | 425 | template <typename SourceVariant> | 
|  | 426 | void fillRedOffsetBuffer(); | 
|  | 427 |  | 
|  | 428 | template <typename SourceVariant> | 
|  | 429 | void fillBufferPhysicalOffset(); | 
|  | 430 |  | 
|  | 431 | template <typename SourceVariant> | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 432 | void fillBufferCheckers(uint32_t rotation); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 433 |  | 
|  | 434 | template <typename SourceVariant> | 
|  | 435 | void fillBufferCheckersRotate0(); | 
|  | 436 |  | 
|  | 437 | template <typename SourceVariant> | 
|  | 438 | void fillBufferCheckersRotate90(); | 
|  | 439 |  | 
|  | 440 | template <typename SourceVariant> | 
|  | 441 | void fillBufferCheckersRotate180(); | 
|  | 442 |  | 
|  | 443 | template <typename SourceVariant> | 
|  | 444 | void fillBufferCheckersRotate270(); | 
|  | 445 |  | 
|  | 446 | template <typename SourceVariant> | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 447 | void fillBufferWithLayerTransform(); | 
|  | 448 |  | 
|  | 449 | template <typename SourceVariant> | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 450 | void fillBufferLayerTransform(); | 
|  | 451 |  | 
|  | 452 | template <typename SourceVariant> | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 453 | void fillBufferWithColorTransform(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 454 |  | 
|  | 455 | template <typename SourceVariant> | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 456 | void fillBufferColorTransform(); | 
|  | 457 |  | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 458 | template <typename SourceVariant> | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 459 | void fillBufferWithColorTransformZeroLayerAlpha(); | 
|  | 460 |  | 
|  | 461 | template <typename SourceVariant> | 
|  | 462 | void fillBufferColorTransformZeroLayerAlpha(); | 
|  | 463 |  | 
|  | 464 | template <typename SourceVariant> | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 465 | void fillRedBufferWithRoundedCorners(); | 
|  | 466 |  | 
|  | 467 | template <typename SourceVariant> | 
|  | 468 | void fillBufferWithRoundedCorners(); | 
|  | 469 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 470 | template <typename SourceVariant> | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 471 | void fillBufferAndBlurBackground(); | 
|  | 472 |  | 
|  | 473 | template <typename SourceVariant> | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 474 | void overlayCorners(); | 
|  | 475 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 476 | void fillRedBufferTextureTransform(); | 
|  | 477 |  | 
|  | 478 | void fillBufferTextureTransform(); | 
|  | 479 |  | 
|  | 480 | void fillRedBufferWithPremultiplyAlpha(); | 
|  | 481 |  | 
|  | 482 | void fillBufferWithPremultiplyAlpha(); | 
|  | 483 |  | 
|  | 484 | void fillRedBufferWithoutPremultiplyAlpha(); | 
|  | 485 |  | 
|  | 486 | void fillBufferWithoutPremultiplyAlpha(); | 
|  | 487 |  | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 488 | void fillGreenColorBufferThenClearRegion(); | 
|  | 489 |  | 
|  | 490 | void clearLeftRegion(); | 
|  | 491 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 492 | void clearRegion(); | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 493 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 494 | template <typename SourceVariant> | 
|  | 495 | void drawShadow(const renderengine::LayerSettings& castingLayer, | 
|  | 496 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, | 
|  | 497 | const ubyte4& backgroundColor); | 
|  | 498 |  | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 499 | void drawShadowWithoutCaster(const FloatRect& castingBounds, | 
|  | 500 | const renderengine::ShadowSettings& shadow, | 
|  | 501 | const ubyte4& backgroundColor); | 
|  | 502 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 503 | void initializeRenderEngine(); | 
|  | 504 |  | 
|  | 505 | std::unique_ptr<renderengine::RenderEngine> mRE; | 
|  | 506 | // GLESRenderEngine for testing GLES-specific behavior. | 
|  | 507 | // Owened by mRE, but this is downcasted. | 
|  | 508 | renderengine::gl::GLESRenderEngine* mGLESRE = nullptr; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 509 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 510 | // Dumb hack to avoid NPE in the EGL driver: the GraphicBuffer needs to | 
|  | 511 | // be freed *after* RenderEngine is destroyed, so that the EGL image is | 
|  | 512 | // destroyed first. | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 513 | sp<GraphicBuffer> mCurrentBuffer; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 514 |  | 
|  | 515 | sp<GraphicBuffer> mBuffer; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 516 |  | 
|  | 517 | std::vector<uint32_t> mTexNames; | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 518 | }; | 
|  | 519 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 520 | void RenderEngineTest::initializeRenderEngine() { | 
|  | 521 | const auto& renderEngineFactory = GetParam(); | 
|  | 522 | if (renderEngineFactory->type() == renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 523 | // Only GLESRenderEngine exposes test-only methods. Provide a pointer to the | 
|  | 524 | // GLESRenderEngine if we're using it so that we don't need to dynamic_cast | 
|  | 525 | // every time. | 
|  | 526 | std::unique_ptr<renderengine::gl::GLESRenderEngine> renderEngine = | 
|  | 527 | renderEngineFactory->createGLESRenderEngine(); | 
|  | 528 | mGLESRE = renderEngine.get(); | 
|  | 529 | mRE = std::move(renderEngine); | 
|  | 530 | } else { | 
|  | 531 | mRE = renderEngineFactory->createRenderEngine(); | 
|  | 532 | } | 
|  | 533 | } | 
|  | 534 |  | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 535 | struct ColorSourceVariant { | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 536 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 537 | RenderEngineTest* /*fixture*/) { | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 538 | layer.source.solidColor = half3(r, g, b); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 539 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 540 | } | 
|  | 541 | }; | 
|  | 542 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 543 | struct RelaxOpaqueBufferVariant { | 
|  | 544 | static void setOpaqueBit(renderengine::LayerSettings& layer) { | 
|  | 545 | layer.source.buffer.isOpaque = false; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 546 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 547 | } | 
|  | 548 |  | 
|  | 549 | static uint8_t getAlphaChannel() { return 255; } | 
|  | 550 | }; | 
|  | 551 |  | 
|  | 552 | struct ForceOpaqueBufferVariant { | 
|  | 553 | static void setOpaqueBit(renderengine::LayerSettings& layer) { | 
|  | 554 | layer.source.buffer.isOpaque = true; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 555 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 556 | } | 
|  | 557 |  | 
|  | 558 | static uint8_t getAlphaChannel() { | 
|  | 559 | // The isOpaque bit will override the alpha channel, so this should be | 
|  | 560 | // arbitrary. | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 561 | return 50; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 562 | } | 
|  | 563 | }; | 
|  | 564 |  | 
|  | 565 | template <typename OpaquenessVariant> | 
|  | 566 | struct BufferSourceVariant { | 
|  | 567 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 568 | RenderEngineTest* fixture) { | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 569 | sp<GraphicBuffer> buf = RenderEngineTest::allocateSourceBuffer(1, 1); | 
|  | 570 | uint32_t texName; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 571 | fixture->mRE->genTextures(1, &texName); | 
|  | 572 | fixture->mTexNames.push_back(texName); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 573 |  | 
|  | 574 | uint8_t* pixels; | 
|  | 575 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 576 | reinterpret_cast<void**>(&pixels)); | 
|  | 577 |  | 
|  | 578 | for (int32_t j = 0; j < buf->getHeight(); j++) { | 
|  | 579 | uint8_t* iter = pixels + (buf->getStride() * j) * 4; | 
|  | 580 | for (int32_t i = 0; i < buf->getWidth(); i++) { | 
|  | 581 | iter[0] = uint8_t(r * 255); | 
|  | 582 | iter[1] = uint8_t(g * 255); | 
|  | 583 | iter[2] = uint8_t(b * 255); | 
|  | 584 | iter[3] = OpaquenessVariant::getAlphaChannel(); | 
|  | 585 | iter += 4; | 
|  | 586 | } | 
|  | 587 | } | 
|  | 588 |  | 
|  | 589 | buf->unlock(); | 
|  | 590 |  | 
|  | 591 | layer.source.buffer.buffer = buf; | 
|  | 592 | layer.source.buffer.textureName = texName; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 593 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 594 | OpaquenessVariant::setOpaqueBit(layer); | 
|  | 595 | } | 
|  | 596 | }; | 
|  | 597 |  | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 598 | template <typename SourceVariant> | 
|  | 599 | void RenderEngineTest::fillBuffer(half r, half g, half b, half a) { | 
|  | 600 | renderengine::DisplaySettings settings; | 
|  | 601 | settings.physicalDisplay = fullscreenRect(); | 
|  | 602 | settings.clip = fullscreenRect(); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 603 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 604 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 605 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 606 |  | 
|  | 607 | renderengine::LayerSettings layer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 608 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 609 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 610 | SourceVariant::fillColor(layer, r, g, b, this); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 611 | layer.alpha = a; | 
|  | 612 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 613 | layers.push_back(&layer); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 614 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 615 | invokeDraw(settings, layers); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 616 | } | 
|  | 617 |  | 
|  | 618 | template <typename SourceVariant> | 
|  | 619 | void RenderEngineTest::fillRedBuffer() { | 
|  | 620 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f); | 
|  | 621 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); | 
|  | 622 | } | 
|  | 623 |  | 
|  | 624 | template <typename SourceVariant> | 
|  | 625 | void RenderEngineTest::fillGreenBuffer() { | 
|  | 626 | fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f); | 
|  | 627 | expectBufferColor(fullscreenRect(), 0, 255, 0, 255); | 
|  | 628 | } | 
|  | 629 |  | 
|  | 630 | template <typename SourceVariant> | 
|  | 631 | void RenderEngineTest::fillBlueBuffer() { | 
|  | 632 | fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f); | 
|  | 633 | expectBufferColor(fullscreenRect(), 0, 0, 255, 255); | 
|  | 634 | } | 
|  | 635 |  | 
|  | 636 | template <typename SourceVariant> | 
|  | 637 | void RenderEngineTest::fillRedTransparentBuffer() { | 
|  | 638 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f); | 
|  | 639 | expectBufferColor(fullscreenRect(), 51, 0, 0, 51); | 
|  | 640 | } | 
|  | 641 |  | 
|  | 642 | template <typename SourceVariant> | 
|  | 643 | void RenderEngineTest::fillRedOffsetBuffer() { | 
|  | 644 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 645 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 646 | settings.physicalDisplay = offsetRect(); | 
|  | 647 | settings.clip = offsetRectAtZero(); | 
|  | 648 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 649 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 650 |  | 
|  | 651 | renderengine::LayerSettings layer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 652 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 653 | layer.geometry.boundaries = offsetRectAtZero().toFloatRect(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 654 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 655 | layer.alpha = 1.0f; | 
|  | 656 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 657 | layers.push_back(&layer); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 658 | invokeDraw(settings, layers); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 659 | } | 
|  | 660 |  | 
|  | 661 | template <typename SourceVariant> | 
|  | 662 | void RenderEngineTest::fillBufferPhysicalOffset() { | 
|  | 663 | fillRedOffsetBuffer<SourceVariant>(); | 
|  | 664 |  | 
|  | 665 | expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, | 
|  | 666 | DEFAULT_DISPLAY_HEIGHT), | 
|  | 667 | 255, 0, 0, 255); | 
|  | 668 | Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT); | 
|  | 669 | Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET); | 
|  | 670 |  | 
|  | 671 | expectBufferColor(offsetRegionLeft, 0, 0, 0, 0); | 
|  | 672 | expectBufferColor(offsetRegionTop, 0, 0, 0, 0); | 
|  | 673 | } | 
|  | 674 |  | 
|  | 675 | template <typename SourceVariant> | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 676 | void RenderEngineTest::fillBufferCheckers(uint32_t orientationFlag) { | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 677 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 678 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 679 | settings.physicalDisplay = fullscreenRect(); | 
|  | 680 | // Here logical space is 2x2 | 
|  | 681 | settings.clip = Rect(2, 2); | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 682 | settings.orientation = orientationFlag; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 683 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 684 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 685 |  | 
|  | 686 | renderengine::LayerSettings layerOne; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 687 | layerOne.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 688 | Rect rectOne(0, 0, 1, 1); | 
|  | 689 | layerOne.geometry.boundaries = rectOne.toFloatRect(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 690 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 691 | layerOne.alpha = 1.0f; | 
|  | 692 |  | 
|  | 693 | renderengine::LayerSettings layerTwo; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 694 | layerTwo.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 695 | Rect rectTwo(0, 1, 1, 2); | 
|  | 696 | layerTwo.geometry.boundaries = rectTwo.toFloatRect(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 697 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 698 | layerTwo.alpha = 1.0f; | 
|  | 699 |  | 
|  | 700 | renderengine::LayerSettings layerThree; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 701 | layerThree.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 702 | Rect rectThree(1, 0, 2, 1); | 
|  | 703 | layerThree.geometry.boundaries = rectThree.toFloatRect(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 704 | SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 705 | layerThree.alpha = 1.0f; | 
|  | 706 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 707 | layers.push_back(&layerOne); | 
|  | 708 | layers.push_back(&layerTwo); | 
|  | 709 | layers.push_back(&layerThree); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 710 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 711 | invokeDraw(settings, layers); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 712 | } | 
|  | 713 |  | 
|  | 714 | template <typename SourceVariant> | 
|  | 715 | void RenderEngineTest::fillBufferCheckersRotate0() { | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 716 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_0); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 717 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, | 
|  | 718 | 255); | 
|  | 719 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, | 
|  | 720 | DEFAULT_DISPLAY_HEIGHT / 2), | 
|  | 721 | 0, 0, 255, 255); | 
|  | 722 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, | 
|  | 723 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 724 | 0, 0, 0, 0); | 
|  | 725 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, | 
|  | 726 | DEFAULT_DISPLAY_HEIGHT), | 
|  | 727 | 0, 255, 0, 255); | 
|  | 728 | } | 
|  | 729 |  | 
|  | 730 | template <typename SourceVariant> | 
|  | 731 | void RenderEngineTest::fillBufferCheckersRotate90() { | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 732 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_90); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 733 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0, | 
|  | 734 | 255); | 
|  | 735 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, | 
|  | 736 | DEFAULT_DISPLAY_HEIGHT / 2), | 
|  | 737 | 255, 0, 0, 255); | 
|  | 738 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, | 
|  | 739 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 740 | 0, 0, 255, 255); | 
|  | 741 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, | 
|  | 742 | DEFAULT_DISPLAY_HEIGHT), | 
|  | 743 | 0, 0, 0, 0); | 
|  | 744 | } | 
|  | 745 |  | 
|  | 746 | template <typename SourceVariant> | 
|  | 747 | void RenderEngineTest::fillBufferCheckersRotate180() { | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 748 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_180); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 749 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, | 
|  | 750 | 0); | 
|  | 751 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, | 
|  | 752 | DEFAULT_DISPLAY_HEIGHT / 2), | 
|  | 753 | 0, 255, 0, 255); | 
|  | 754 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, | 
|  | 755 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 756 | 255, 0, 0, 255); | 
|  | 757 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, | 
|  | 758 | DEFAULT_DISPLAY_HEIGHT), | 
|  | 759 | 0, 0, 255, 255); | 
|  | 760 | } | 
|  | 761 |  | 
|  | 762 | template <typename SourceVariant> | 
|  | 763 | void RenderEngineTest::fillBufferCheckersRotate270() { | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 764 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_270); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 765 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255, | 
|  | 766 | 255); | 
|  | 767 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, | 
|  | 768 | DEFAULT_DISPLAY_HEIGHT / 2), | 
|  | 769 | 0, 0, 0, 0); | 
|  | 770 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, | 
|  | 771 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 772 | 0, 255, 0, 255); | 
|  | 773 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, | 
|  | 774 | DEFAULT_DISPLAY_HEIGHT), | 
|  | 775 | 255, 0, 0, 255); | 
|  | 776 | } | 
|  | 777 |  | 
|  | 778 | template <typename SourceVariant> | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 779 | void RenderEngineTest::fillBufferWithLayerTransform() { | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 780 | renderengine::DisplaySettings settings; | 
|  | 781 | settings.physicalDisplay = fullscreenRect(); | 
|  | 782 | // Here logical space is 2x2 | 
|  | 783 | settings.clip = Rect(2, 2); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 784 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 785 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 786 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 787 |  | 
|  | 788 | renderengine::LayerSettings layer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 789 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 790 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 791 | // Translate one pixel diagonally | 
|  | 792 | layer.geometry.positionTransform = mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 793 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 794 | layer.source.solidColor = half3(1.0f, 0.0f, 0.0f); | 
|  | 795 | layer.alpha = 1.0f; | 
|  | 796 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 797 | layers.push_back(&layer); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 798 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 799 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 800 | } | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 801 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 802 | template <typename SourceVariant> | 
|  | 803 | void RenderEngineTest::fillBufferLayerTransform() { | 
|  | 804 | fillBufferWithLayerTransform<SourceVariant>(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 805 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0); | 
|  | 806 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); | 
|  | 807 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, | 
|  | 808 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 809 | 255, 0, 0, 255); | 
|  | 810 | } | 
|  | 811 |  | 
|  | 812 | template <typename SourceVariant> | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 813 | void RenderEngineTest::fillBufferWithColorTransform() { | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 814 | renderengine::DisplaySettings settings; | 
|  | 815 | settings.physicalDisplay = fullscreenRect(); | 
|  | 816 | settings.clip = Rect(1, 1); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 817 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 818 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 819 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 820 |  | 
|  | 821 | renderengine::LayerSettings layer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 822 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 823 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 824 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 825 | layer.alpha = 1.0f; | 
|  | 826 |  | 
|  | 827 | // construct a fake color matrix | 
|  | 828 | // annihilate green and blue channels | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 829 | settings.colorTransform = mat4::scale(vec4(0.9f, 0, 0, 1)); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 830 | // set red channel to red + green | 
|  | 831 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); | 
|  | 832 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 833 | layer.alpha = 1.0f; | 
|  | 834 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 835 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 836 | layers.push_back(&layer); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 837 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 838 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 839 | } | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 840 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 841 | template <typename SourceVariant> | 
|  | 842 | void RenderEngineTest::fillBufferColorTransform() { | 
|  | 843 | fillBufferWithColorTransform<SourceVariant>(); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 844 | expectBufferColor(fullscreenRect(), 172, 0, 0, 255, 1); | 
|  | 845 | } | 
|  | 846 |  | 
|  | 847 | template <typename SourceVariant> | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 848 | void RenderEngineTest::fillBufferWithColorTransformZeroLayerAlpha() { | 
|  | 849 | renderengine::DisplaySettings settings; | 
|  | 850 | settings.physicalDisplay = fullscreenRect(); | 
|  | 851 | settings.clip = Rect(1, 1); | 
|  | 852 |  | 
|  | 853 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 854 |  | 
|  | 855 | renderengine::LayerSettings layer; | 
|  | 856 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 857 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); | 
|  | 858 | layer.alpha = 0; | 
|  | 859 |  | 
|  | 860 | // construct a fake color matrix | 
|  | 861 | // simple inverse color | 
|  | 862 | settings.colorTransform = mat4(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 1, 1, 1, 1); | 
|  | 863 |  | 
|  | 864 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 865 |  | 
|  | 866 | layers.push_back(&layer); | 
|  | 867 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 868 | invokeDraw(settings, layers); | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 869 | } | 
|  | 870 |  | 
|  | 871 | template <typename SourceVariant> | 
|  | 872 | void RenderEngineTest::fillBufferColorTransformZeroLayerAlpha() { | 
|  | 873 | fillBufferWithColorTransformZeroLayerAlpha<SourceVariant>(); | 
|  | 874 | expectBufferColor(fullscreenRect(), 0, 0, 0, 0); | 
|  | 875 | } | 
|  | 876 |  | 
|  | 877 | template <typename SourceVariant> | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 878 | void RenderEngineTest::fillRedBufferWithRoundedCorners() { | 
|  | 879 | renderengine::DisplaySettings settings; | 
|  | 880 | settings.physicalDisplay = fullscreenRect(); | 
|  | 881 | settings.clip = fullscreenRect(); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 882 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 883 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 884 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 885 |  | 
|  | 886 | renderengine::LayerSettings layer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 887 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 888 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 889 | layer.geometry.roundedCornersRadius = 5.0f; | 
|  | 890 | layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); | 
|  | 891 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 892 | layer.alpha = 1.0f; | 
|  | 893 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 894 | layers.push_back(&layer); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 895 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 896 | invokeDraw(settings, layers); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 897 | } | 
|  | 898 |  | 
|  | 899 | template <typename SourceVariant> | 
|  | 900 | void RenderEngineTest::fillBufferWithRoundedCorners() { | 
|  | 901 | fillRedBufferWithRoundedCorners<SourceVariant>(); | 
|  | 902 | // Corners should be ignored... | 
|  | 903 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); | 
|  | 904 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); | 
|  | 905 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); | 
|  | 906 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, | 
|  | 907 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 908 | 0, 0, 0, 0); | 
|  | 909 | // ...And the non-rounded portion should be red. | 
|  | 910 | // Other pixels may be anti-aliased, so let's not check those. | 
|  | 911 | expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0, | 
|  | 912 | 255); | 
|  | 913 | } | 
|  | 914 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 915 | template <typename SourceVariant> | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 916 | void RenderEngineTest::fillBufferAndBlurBackground() { | 
|  | 917 | char value[PROPERTY_VALUE_MAX]; | 
|  | 918 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); | 
|  | 919 | if (!atoi(value)) { | 
|  | 920 | // This device doesn't support blurs, no-op. | 
|  | 921 | return; | 
|  | 922 | } | 
|  | 923 |  | 
|  | 924 | auto blurRadius = 50; | 
|  | 925 | auto center = DEFAULT_DISPLAY_WIDTH / 2; | 
|  | 926 |  | 
|  | 927 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 928 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 929 | settings.physicalDisplay = fullscreenRect(); | 
|  | 930 | settings.clip = fullscreenRect(); | 
|  | 931 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 932 | std::vector<const renderengine::LayerSettings*> layers; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 933 |  | 
|  | 934 | renderengine::LayerSettings backgroundLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 935 | backgroundLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 936 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 937 | SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this); | 
|  | 938 | backgroundLayer.alpha = 1.0f; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 939 | layers.push_back(&backgroundLayer); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 940 |  | 
|  | 941 | renderengine::LayerSettings leftLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 942 | leftLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 943 | leftLayer.geometry.boundaries = | 
|  | 944 | Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect(); | 
|  | 945 | SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this); | 
|  | 946 | leftLayer.alpha = 1.0f; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 947 | layers.push_back(&leftLayer); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 948 |  | 
|  | 949 | renderengine::LayerSettings blurLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 950 | blurLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 951 | blurLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 952 | blurLayer.backgroundBlurRadius = blurRadius; | 
|  | 953 | blurLayer.alpha = 0; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 954 | layers.push_back(&blurLayer); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 955 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 956 | invokeDraw(settings, layers); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 957 |  | 
|  | 958 | expectBufferColor(Rect(center - 1, center - 5, center, center + 5), 150, 150, 0, 255, | 
|  | 959 | 50 /* tolerance */); | 
|  | 960 | expectBufferColor(Rect(center, center - 5, center + 1, center + 5), 150, 150, 0, 255, | 
|  | 961 | 50 /* tolerance */); | 
|  | 962 | } | 
|  | 963 |  | 
|  | 964 | template <typename SourceVariant> | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 965 | void RenderEngineTest::overlayCorners() { | 
|  | 966 | renderengine::DisplaySettings settings; | 
|  | 967 | settings.physicalDisplay = fullscreenRect(); | 
|  | 968 | settings.clip = fullscreenRect(); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 969 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 970 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 971 | std::vector<const renderengine::LayerSettings*> layersFirst; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 972 |  | 
|  | 973 | renderengine::LayerSettings layerOne; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 974 | layerOne.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 975 | layerOne.geometry.boundaries = | 
|  | 976 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); | 
|  | 977 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); | 
|  | 978 | layerOne.alpha = 0.2; | 
|  | 979 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 980 | layersFirst.push_back(&layerOne); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 981 | invokeDraw(settings, layersFirst); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 982 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); | 
|  | 983 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, | 
|  | 984 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 985 | 0, 0, 0, 0); | 
|  | 986 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 987 | std::vector<const renderengine::LayerSettings*> layersSecond; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 988 | renderengine::LayerSettings layerTwo; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 989 | layerTwo.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 990 | layerTwo.geometry.boundaries = | 
|  | 991 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, | 
|  | 992 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); | 
|  | 993 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); | 
|  | 994 | layerTwo.alpha = 1.0f; | 
|  | 995 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 996 | layersSecond.push_back(&layerTwo); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 997 | invokeDraw(settings, layersSecond); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 998 |  | 
|  | 999 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); | 
|  | 1000 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, | 
|  | 1001 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 1002 | 0, 255, 0, 255); | 
|  | 1003 | } | 
|  | 1004 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1005 | void RenderEngineTest::fillRedBufferTextureTransform() { | 
|  | 1006 | renderengine::DisplaySettings settings; | 
|  | 1007 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1008 | settings.clip = Rect(1, 1); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1009 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1010 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1011 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1012 |  | 
|  | 1013 | renderengine::LayerSettings layer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1014 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1015 | // Here will allocate a checker board texture, but transform texture | 
|  | 1016 | // coordinates so that only the upper left is applied. | 
|  | 1017 | sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2); | 
|  | 1018 | uint32_t texName; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1019 | RenderEngineTest::mRE->genTextures(1, &texName); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1020 | this->mTexNames.push_back(texName); | 
|  | 1021 |  | 
|  | 1022 | uint8_t* pixels; | 
|  | 1023 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 1024 | reinterpret_cast<void**>(&pixels)); | 
|  | 1025 | // Red top left, Green top right, Blue bottom left, Black bottom right | 
|  | 1026 | pixels[0] = 255; | 
|  | 1027 | pixels[1] = 0; | 
|  | 1028 | pixels[2] = 0; | 
|  | 1029 | pixels[3] = 255; | 
|  | 1030 | pixels[4] = 0; | 
|  | 1031 | pixels[5] = 255; | 
|  | 1032 | pixels[6] = 0; | 
|  | 1033 | pixels[7] = 255; | 
|  | 1034 | pixels[8] = 0; | 
|  | 1035 | pixels[9] = 0; | 
|  | 1036 | pixels[10] = 255; | 
|  | 1037 | pixels[11] = 255; | 
|  | 1038 | buf->unlock(); | 
|  | 1039 |  | 
|  | 1040 | layer.source.buffer.buffer = buf; | 
|  | 1041 | layer.source.buffer.textureName = texName; | 
|  | 1042 | // Transform coordinates to only be inside the red quadrant. | 
|  | 1043 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1)); | 
|  | 1044 | layer.alpha = 1.0f; | 
|  | 1045 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 1046 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1047 | layers.push_back(&layer); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1048 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1049 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1050 | } | 
|  | 1051 |  | 
|  | 1052 | void RenderEngineTest::fillBufferTextureTransform() { | 
|  | 1053 | fillRedBufferTextureTransform(); | 
|  | 1054 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); | 
|  | 1055 | } | 
|  | 1056 |  | 
|  | 1057 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { | 
|  | 1058 | renderengine::DisplaySettings settings; | 
|  | 1059 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1060 | // Here logical space is 1x1 | 
|  | 1061 | settings.clip = Rect(1, 1); | 
|  | 1062 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1063 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1064 |  | 
|  | 1065 | renderengine::LayerSettings layer; | 
|  | 1066 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); | 
|  | 1067 | uint32_t texName; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1068 | RenderEngineTest::mRE->genTextures(1, &texName); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1069 | this->mTexNames.push_back(texName); | 
|  | 1070 |  | 
|  | 1071 | uint8_t* pixels; | 
|  | 1072 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 1073 | reinterpret_cast<void**>(&pixels)); | 
|  | 1074 | pixels[0] = 255; | 
|  | 1075 | pixels[1] = 0; | 
|  | 1076 | pixels[2] = 0; | 
|  | 1077 | pixels[3] = 255; | 
|  | 1078 | buf->unlock(); | 
|  | 1079 |  | 
|  | 1080 | layer.source.buffer.buffer = buf; | 
|  | 1081 | layer.source.buffer.textureName = texName; | 
|  | 1082 | layer.source.buffer.usePremultipliedAlpha = true; | 
|  | 1083 | layer.alpha = 0.5f; | 
|  | 1084 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 1085 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1086 | layers.push_back(&layer); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1087 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1088 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1089 | } | 
|  | 1090 |  | 
|  | 1091 | void RenderEngineTest::fillBufferWithPremultiplyAlpha() { | 
|  | 1092 | fillRedBufferWithPremultiplyAlpha(); | 
|  | 1093 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); | 
|  | 1094 | } | 
|  | 1095 |  | 
|  | 1096 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { | 
|  | 1097 | renderengine::DisplaySettings settings; | 
|  | 1098 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1099 | // Here logical space is 1x1 | 
|  | 1100 | settings.clip = Rect(1, 1); | 
|  | 1101 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1102 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1103 |  | 
|  | 1104 | renderengine::LayerSettings layer; | 
|  | 1105 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); | 
|  | 1106 | uint32_t texName; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1107 | RenderEngineTest::mRE->genTextures(1, &texName); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1108 | this->mTexNames.push_back(texName); | 
|  | 1109 |  | 
|  | 1110 | uint8_t* pixels; | 
|  | 1111 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 1112 | reinterpret_cast<void**>(&pixels)); | 
|  | 1113 | pixels[0] = 255; | 
|  | 1114 | pixels[1] = 0; | 
|  | 1115 | pixels[2] = 0; | 
|  | 1116 | pixels[3] = 255; | 
|  | 1117 | buf->unlock(); | 
|  | 1118 |  | 
|  | 1119 | layer.source.buffer.buffer = buf; | 
|  | 1120 | layer.source.buffer.textureName = texName; | 
|  | 1121 | layer.source.buffer.usePremultipliedAlpha = false; | 
|  | 1122 | layer.alpha = 0.5f; | 
|  | 1123 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 1124 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1125 | layers.push_back(&layer); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1126 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1127 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1128 | } | 
|  | 1129 |  | 
|  | 1130 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { | 
|  | 1131 | fillRedBufferWithoutPremultiplyAlpha(); | 
| wukui1 | 6f3c0bb | 2020-08-05 20:35:29 +0800 | [diff] [blame] | 1132 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128, 1); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1133 | } | 
|  | 1134 |  | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1135 | void RenderEngineTest::clearLeftRegion() { | 
|  | 1136 | renderengine::DisplaySettings settings; | 
|  | 1137 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1138 | // Here logical space is 4x4 | 
|  | 1139 | settings.clip = Rect(4, 4); | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 1140 | settings.clearRegion = Region(Rect(2, 4)); | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1141 | std::vector<const renderengine::LayerSettings*> layers; | 
| Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 1142 | // fake layer, without bounds should not render anything | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1143 | renderengine::LayerSettings layer; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1144 | layers.push_back(&layer); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1145 | invokeDraw(settings, layers); | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1146 | } | 
|  | 1147 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1148 | void RenderEngineTest::clearRegion() { | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1149 | // Reuse mBuffer | 
|  | 1150 | clearLeftRegion(); | 
|  | 1151 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255); | 
|  | 1152 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, | 
|  | 1153 | DEFAULT_DISPLAY_HEIGHT), | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1154 | 0, 0, 0, 0); | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1155 | } | 
|  | 1156 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1157 | template <typename SourceVariant> | 
|  | 1158 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, | 
|  | 1159 | const renderengine::ShadowSettings& shadow, | 
|  | 1160 | const ubyte4& casterColor, const ubyte4& backgroundColor) { | 
|  | 1161 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1162 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1163 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1164 | settings.clip = fullscreenRect(); | 
|  | 1165 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1166 | std::vector<const renderengine::LayerSettings*> layers; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1167 |  | 
|  | 1168 | // add background layer | 
|  | 1169 | renderengine::LayerSettings bgLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1170 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1171 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1172 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, | 
|  | 1173 | backgroundColor.b / 255.0f, this); | 
|  | 1174 | bgLayer.alpha = backgroundColor.a / 255.0f; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1175 | layers.push_back(&bgLayer); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1176 |  | 
|  | 1177 | // add shadow layer | 
|  | 1178 | renderengine::LayerSettings shadowLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1179 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1180 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; | 
|  | 1181 | shadowLayer.alpha = castingLayer.alpha; | 
|  | 1182 | shadowLayer.shadow = shadow; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1183 | layers.push_back(&shadowLayer); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1184 |  | 
|  | 1185 | // add layer casting the shadow | 
|  | 1186 | renderengine::LayerSettings layer = castingLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1187 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1188 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, | 
|  | 1189 | casterColor.b / 255.0f, this); | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1190 | layers.push_back(&layer); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1191 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1192 | invokeDraw(settings, layers); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1193 | } | 
|  | 1194 |  | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1195 | void RenderEngineTest::drawShadowWithoutCaster(const FloatRect& castingBounds, | 
|  | 1196 | const renderengine::ShadowSettings& shadow, | 
|  | 1197 | const ubyte4& backgroundColor) { | 
|  | 1198 | renderengine::DisplaySettings settings; | 
|  | 1199 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1200 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1201 | settings.clip = fullscreenRect(); | 
|  | 1202 |  | 
|  | 1203 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1204 |  | 
|  | 1205 | // add background layer | 
|  | 1206 | renderengine::LayerSettings bgLayer; | 
|  | 1207 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1208 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1209 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, | 
|  | 1210 | backgroundColor.b / 255.0f, this); | 
|  | 1211 | bgLayer.alpha = backgroundColor.a / 255.0f; | 
|  | 1212 | layers.push_back(&bgLayer); | 
|  | 1213 |  | 
|  | 1214 | // add shadow layer | 
|  | 1215 | renderengine::LayerSettings shadowLayer; | 
|  | 1216 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1217 | shadowLayer.geometry.boundaries = castingBounds; | 
|  | 1218 | shadowLayer.alpha = 1.0f; | 
|  | 1219 | ColorSourceVariant::fillColor(shadowLayer, 0, 0, 0, this); | 
|  | 1220 | shadowLayer.shadow = shadow; | 
|  | 1221 | layers.push_back(&shadowLayer); | 
|  | 1222 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1223 | invokeDraw(settings, layers); | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1224 | } | 
|  | 1225 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1226 | INSTANTIATE_TEST_SUITE_P(PerRenderEngineType, RenderEngineTest, | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1227 | testing::Values(std::make_shared<GLESRenderEngineFactory>(), | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 1228 | std::make_shared<GLESCMRenderEngineFactory>(), | 
|  | 1229 | std::make_shared<SkiaGLESRenderEngineFactory>(), | 
|  | 1230 | std::make_shared<SkiaGLESCMRenderEngineFactory>())); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1231 |  | 
|  | 1232 | TEST_P(RenderEngineTest, drawLayers_noLayersToDraw) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1233 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1234 | drawEmptyLayers(); | 
|  | 1235 | } | 
|  | 1236 |  | 
| Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1237 | TEST_P(RenderEngineTest, drawLayers_withoutBuffers_withColorTransform) { | 
|  | 1238 | const auto& renderEngineFactory = GetParam(); | 
|  | 1239 | mRE = renderEngineFactory->createRenderEngine(); | 
|  | 1240 |  | 
|  | 1241 | renderengine::DisplaySettings settings; | 
|  | 1242 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1243 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1244 | settings.clip = fullscreenRect(); | 
|  | 1245 |  | 
|  | 1246 | // 255, 255, 255, 255 is full opaque white. | 
|  | 1247 | const ubyte4 backgroundColor(255.f, 255.f, 255.f, 255.f); | 
|  | 1248 | // Create layer with given color. | 
|  | 1249 | renderengine::LayerSettings bgLayer; | 
|  | 1250 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1251 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1252 | bgLayer.source.solidColor = half3(backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, | 
|  | 1253 | backgroundColor.b / 255.0f); | 
|  | 1254 | bgLayer.alpha = backgroundColor.a / 255.0f; | 
|  | 1255 | // Transform the red color. | 
|  | 1256 | bgLayer.colorTransform = mat4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); | 
|  | 1257 |  | 
|  | 1258 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1259 | layers.push_back(&bgLayer); | 
|  | 1260 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1261 | invokeDraw(settings, layers); | 
| Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1262 |  | 
|  | 1263 | // Expect to see full opaque pixel (with inverted red from the transform). | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1264 | expectBufferColor(Rect(0, 0, 10, 10), 0.f, backgroundColor.g, backgroundColor.b, | 
| Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1265 | backgroundColor.a); | 
|  | 1266 | } | 
|  | 1267 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1268 | TEST_P(RenderEngineTest, drawLayers_nullOutputBuffer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1269 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1270 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1271 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1272 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1273 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1274 | renderengine::LayerSettings layer; | 
|  | 1275 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1276 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1277 | layers.push_back(&layer); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1278 | base::unique_fd fence; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1279 | status_t status = mRE->drawLayers(settings, layers, nullptr, true, base::unique_fd(), &fence); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1280 |  | 
|  | 1281 | ASSERT_EQ(BAD_VALUE, status); | 
|  | 1282 | } | 
|  | 1283 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1284 | TEST_P(RenderEngineTest, drawLayers_nullOutputFence) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1285 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1286 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1287 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1288 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1289 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1290 | settings.clip = fullscreenRect(); | 
|  | 1291 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1292 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1293 | renderengine::LayerSettings layer; | 
|  | 1294 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1295 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1296 | layer.alpha = 1.0; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1297 | layers.push_back(&layer); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1298 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1299 | status_t status = mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), nullptr); | 
|  | 1300 | mCurrentBuffer = mBuffer; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1301 | ASSERT_EQ(NO_ERROR, status); | 
|  | 1302 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); | 
|  | 1303 | } | 
|  | 1304 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1305 | TEST_P(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) { | 
|  | 1306 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1307 |  | 
|  | 1308 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1309 | // GLES-specific test | 
|  | 1310 | return; | 
|  | 1311 | } | 
|  | 1312 |  | 
|  | 1313 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1314 |  | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1315 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1316 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1317 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1318 | settings.clip = fullscreenRect(); | 
|  | 1319 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1320 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1321 | renderengine::LayerSettings layer; | 
|  | 1322 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1323 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1324 | layer.alpha = 1.0; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1325 | layers.push_back(&layer); | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1326 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1327 | status_t status = mRE->drawLayers(settings, layers, mBuffer, false, base::unique_fd(), nullptr); | 
|  | 1328 | mCurrentBuffer = mBuffer; | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1329 | ASSERT_EQ(NO_ERROR, status); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1330 | ASSERT_FALSE(mGLESRE->isFramebufferImageCachedForTesting(mBuffer->getId())); | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1331 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); | 
|  | 1332 | } | 
|  | 1333 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1334 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1335 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1336 | fillRedBuffer<ColorSourceVariant>(); | 
|  | 1337 | } | 
|  | 1338 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1339 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1340 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1341 | fillGreenBuffer<ColorSourceVariant>(); | 
|  | 1342 | } | 
|  | 1343 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1344 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1345 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1346 | fillBlueBuffer<ColorSourceVariant>(); | 
|  | 1347 | } | 
|  | 1348 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1349 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1350 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1351 | fillRedTransparentBuffer<ColorSourceVariant>(); | 
|  | 1352 | } | 
|  | 1353 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1354 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1355 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1356 | fillBufferPhysicalOffset<ColorSourceVariant>(); | 
|  | 1357 | } | 
|  | 1358 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1359 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1360 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1361 | fillBufferCheckersRotate0<ColorSourceVariant>(); | 
|  | 1362 | } | 
|  | 1363 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1364 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1365 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1366 | fillBufferCheckersRotate90<ColorSourceVariant>(); | 
|  | 1367 | } | 
|  | 1368 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1369 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1370 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1371 | fillBufferCheckersRotate180<ColorSourceVariant>(); | 
|  | 1372 | } | 
|  | 1373 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1374 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1375 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1376 | fillBufferCheckersRotate270<ColorSourceVariant>(); | 
|  | 1377 | } | 
|  | 1378 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1379 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1380 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1381 | fillBufferLayerTransform<ColorSourceVariant>(); | 
|  | 1382 | } | 
|  | 1383 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1384 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1385 | initializeRenderEngine(); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1386 | fillBufferColorTransform<ColorSourceVariant>(); | 
|  | 1387 | } | 
|  | 1388 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1389 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1390 | initializeRenderEngine(); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1391 | fillBufferWithRoundedCorners<ColorSourceVariant>(); | 
|  | 1392 | } | 
|  | 1393 |  | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1394 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1395 | initializeRenderEngine(); | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1396 | fillBufferColorTransformZeroLayerAlpha<ColorSourceVariant>(); | 
|  | 1397 | } | 
|  | 1398 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1399 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1400 | initializeRenderEngine(); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1401 | fillBufferAndBlurBackground<ColorSourceVariant>(); | 
|  | 1402 | } | 
|  | 1403 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1404 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1405 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1406 | overlayCorners<ColorSourceVariant>(); | 
|  | 1407 | } | 
|  | 1408 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1409 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1410 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1411 | fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1412 | } | 
|  | 1413 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1414 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1415 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1416 | fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1417 | } | 
|  | 1418 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1419 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1420 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1421 | fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1422 | } | 
|  | 1423 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1424 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1425 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1426 | fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1427 | } | 
|  | 1428 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1429 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1430 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1431 | fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1432 | } | 
|  | 1433 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1434 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1435 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1436 | fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1437 | } | 
|  | 1438 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1439 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1440 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1441 | fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1442 | } | 
|  | 1443 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1444 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1445 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1446 | fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1447 | } | 
|  | 1448 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1449 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1450 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1451 | fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1452 | } | 
|  | 1453 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1454 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1455 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1456 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1457 | } | 
|  | 1458 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1459 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1460 | initializeRenderEngine(); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1461 | fillBufferColorTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1462 | } | 
|  | 1463 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1464 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1465 | initializeRenderEngine(); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1466 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1467 | } | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1468 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1469 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_opaqueBufferSource) { | 
|  | 1470 | initializeRenderEngine(); | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1471 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1472 | } | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1473 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1474 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1475 | initializeRenderEngine(); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1476 | fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1477 | } | 
|  | 1478 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1479 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1480 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1481 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1482 | } | 
|  | 1483 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1484 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1485 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1486 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1487 | } | 
|  | 1488 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1489 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1490 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1491 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1492 | } | 
|  | 1493 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1494 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1495 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1496 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1497 | } | 
|  | 1498 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1499 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1500 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1501 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1502 | } | 
|  | 1503 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1504 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1505 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1506 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1507 | } | 
|  | 1508 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1509 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1510 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1511 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1512 | } | 
|  | 1513 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1514 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1515 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1516 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1517 | } | 
|  | 1518 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1519 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1520 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1521 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1522 | } | 
|  | 1523 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1524 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1525 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1526 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1527 | } | 
|  | 1528 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1529 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1530 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1531 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1532 | } | 
|  | 1533 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1534 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1535 | initializeRenderEngine(); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1536 | fillBufferColorTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1537 | } | 
|  | 1538 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1539 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1540 | initializeRenderEngine(); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1541 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1542 | } | 
|  | 1543 |  | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1544 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1545 | initializeRenderEngine(); | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1546 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1547 | } | 
|  | 1548 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1549 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1550 | initializeRenderEngine(); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1551 | fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1552 | } | 
|  | 1553 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1554 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1555 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1556 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1557 | } | 
|  | 1558 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1559 | TEST_P(RenderEngineTest, drawLayers_fillBufferTextureTransform) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1560 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1561 | fillBufferTextureTransform(); | 
|  | 1562 | } | 
|  | 1563 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1564 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1565 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1566 | fillBufferWithPremultiplyAlpha(); | 
|  | 1567 | } | 
|  | 1568 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1569 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1570 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1571 | fillBufferWithoutPremultiplyAlpha(); | 
|  | 1572 | } | 
|  | 1573 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1574 | TEST_P(RenderEngineTest, drawLayers_clearRegion) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1575 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1576 | clearRegion(); | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1577 | } | 
|  | 1578 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1579 | TEST_P(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) { | 
|  | 1580 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1581 |  | 
|  | 1582 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1583 | // GLES-specific test | 
|  | 1584 | return; | 
|  | 1585 | } | 
|  | 1586 |  | 
|  | 1587 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1588 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1589 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1590 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1591 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1592 | settings.clip = fullscreenRect(); | 
|  | 1593 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1594 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1595 |  | 
|  | 1596 | renderengine::LayerSettings layer; | 
|  | 1597 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1598 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1599 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1600 | layers.push_back(&layer); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1601 | invokeDraw(settings, layers); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1602 | uint64_t bufferId = layer.source.buffer.buffer->getId(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1603 | EXPECT_TRUE(mGLESRE->isImageCachedForTesting(bufferId)); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1604 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1605 | mGLESRE->unbindExternalTextureBufferForTesting(bufferId); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1606 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1607 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1608 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1609 | return barrier->isOpen; | 
|  | 1610 | })); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1611 | EXPECT_FALSE(mGLESRE->isImageCachedForTesting(bufferId)); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1612 | EXPECT_EQ(NO_ERROR, barrier->result); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1613 | } | 
|  | 1614 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1615 | TEST_P(RenderEngineTest, cacheExternalBuffer_withNullBuffer) { | 
|  | 1616 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1617 |  | 
|  | 1618 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1619 | // GLES-specific test | 
|  | 1620 | return; | 
|  | 1621 | } | 
|  | 1622 |  | 
|  | 1623 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1624 |  | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1625 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1626 | mGLESRE->cacheExternalTextureBufferForTesting(nullptr); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1627 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1628 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1629 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1630 | return barrier->isOpen; | 
|  | 1631 | })); | 
|  | 1632 | EXPECT_TRUE(barrier->isOpen); | 
|  | 1633 | EXPECT_EQ(BAD_VALUE, barrier->result); | 
| Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1634 | } | 
|  | 1635 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1636 | TEST_P(RenderEngineTest, cacheExternalBuffer_cachesImages) { | 
|  | 1637 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1638 |  | 
|  | 1639 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1640 | // GLES-specific test | 
|  | 1641 | return; | 
|  | 1642 | } | 
|  | 1643 |  | 
|  | 1644 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1645 |  | 
| Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1646 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); | 
|  | 1647 | uint64_t bufferId = buf->getId(); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1648 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1649 | mGLESRE->cacheExternalTextureBufferForTesting(buf); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1650 | { | 
|  | 1651 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1652 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1653 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1654 | return barrier->isOpen; | 
|  | 1655 | })); | 
|  | 1656 | EXPECT_EQ(NO_ERROR, barrier->result); | 
|  | 1657 | } | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1658 | EXPECT_TRUE(mGLESRE->isImageCachedForTesting(bufferId)); | 
|  | 1659 | barrier = mGLESRE->unbindExternalTextureBufferForTesting(bufferId); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1660 | { | 
|  | 1661 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1662 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1663 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1664 | return barrier->isOpen; | 
|  | 1665 | })); | 
|  | 1666 | EXPECT_EQ(NO_ERROR, barrier->result); | 
|  | 1667 | } | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1668 | EXPECT_FALSE(mGLESRE->isImageCachedForTesting(bufferId)); | 
| Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1669 | } | 
|  | 1670 |  | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1671 | TEST_P(RenderEngineTest, drawLayers_fillShadow_castsWithoutCasterLayer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1672 | initializeRenderEngine(); | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1673 |  | 
|  | 1674 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1675 | const float shadowLength = 5.0f; | 
|  | 1676 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1677 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1678 | renderengine::ShadowSettings settings = | 
|  | 1679 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1680 | false /* casterIsTranslucent */); | 
|  | 1681 |  | 
|  | 1682 | drawShadowWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); | 
|  | 1683 | expectShadowColorWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); | 
|  | 1684 | } | 
|  | 1685 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1686 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1687 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1688 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1689 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1690 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1691 | const float shadowLength = 5.0f; | 
|  | 1692 | Rect casterBounds(1, 1); | 
|  | 1693 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1694 | renderengine::LayerSettings castingLayer; | 
|  | 1695 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1696 | castingLayer.alpha = 1.0f; | 
|  | 1697 | renderengine::ShadowSettings settings = | 
|  | 1698 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1699 | false /* casterIsTranslucent */); | 
|  | 1700 |  | 
|  | 1701 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1702 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1703 | } | 
|  | 1704 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1705 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1706 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1707 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1708 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1709 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1710 | const float shadowLength = 5.0f; | 
|  | 1711 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1712 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1713 | renderengine::LayerSettings castingLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1714 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1715 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1716 | castingLayer.alpha = 1.0f; | 
|  | 1717 | renderengine::ShadowSettings settings = | 
|  | 1718 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1719 | false /* casterIsTranslucent */); | 
|  | 1720 |  | 
|  | 1721 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1722 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1723 | } | 
|  | 1724 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1725 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1726 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1727 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1728 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1729 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1730 | const float shadowLength = 5.0f; | 
|  | 1731 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1732 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1733 | renderengine::LayerSettings castingLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1734 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1735 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1736 | castingLayer.alpha = 1.0f; | 
|  | 1737 | renderengine::ShadowSettings settings = | 
|  | 1738 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1739 | false /* casterIsTranslucent */); | 
|  | 1740 |  | 
|  | 1741 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, | 
|  | 1742 | backgroundColor); | 
|  | 1743 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1744 | } | 
|  | 1745 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1746 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1747 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1748 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1749 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1750 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1751 | const float shadowLength = 5.0f; | 
|  | 1752 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1753 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1754 | renderengine::LayerSettings castingLayer; | 
|  | 1755 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1756 | castingLayer.geometry.roundedCornersRadius = 3.0f; | 
|  | 1757 | castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect(); | 
|  | 1758 | castingLayer.alpha = 1.0f; | 
|  | 1759 | renderengine::ShadowSettings settings = | 
|  | 1760 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1761 | false /* casterIsTranslucent */); | 
|  | 1762 |  | 
|  | 1763 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, | 
|  | 1764 | backgroundColor); | 
|  | 1765 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1766 | } | 
|  | 1767 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1768 | TEST_P(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1769 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1770 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1771 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1772 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1773 | const float shadowLength = 5.0f; | 
|  | 1774 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1775 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1776 | renderengine::LayerSettings castingLayer; | 
|  | 1777 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1778 | castingLayer.alpha = 0.5f; | 
|  | 1779 | renderengine::ShadowSettings settings = | 
|  | 1780 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1781 | true /* casterIsTranslucent */); | 
|  | 1782 |  | 
|  | 1783 | drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor, | 
|  | 1784 | backgroundColor); | 
|  | 1785 |  | 
|  | 1786 | // verify only the background since the shadow will draw behind the caster | 
|  | 1787 | const float shadowInset = settings.length * -1.0f; | 
|  | 1788 | const Rect casterWithShadow = | 
|  | 1789 | Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset); | 
|  | 1790 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); | 
|  | 1791 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, | 
|  | 1792 | backgroundColor.a); | 
|  | 1793 | } | 
|  | 1794 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1795 | TEST_P(RenderEngineTest, cleanupPostRender_cleansUpOnce) { | 
|  | 1796 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1797 |  | 
|  | 1798 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1799 | // GLES-specific test | 
|  | 1800 | return; | 
|  | 1801 | } | 
|  | 1802 |  | 
|  | 1803 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1804 |  | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1805 | renderengine::DisplaySettings settings; | 
|  | 1806 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1807 | settings.clip = fullscreenRect(); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1808 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1809 |  | 
|  | 1810 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1811 | renderengine::LayerSettings layer; | 
|  | 1812 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1813 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1814 | layer.alpha = 1.0; | 
|  | 1815 | layers.push_back(&layer); | 
|  | 1816 |  | 
|  | 1817 | base::unique_fd fenceOne; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1818 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), &fenceOne); | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1819 | base::unique_fd fenceTwo; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1820 | mRE->drawLayers(settings, layers, mBuffer, true, std::move(fenceOne), &fenceTwo); | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1821 |  | 
|  | 1822 | const int fd = fenceTwo.get(); | 
|  | 1823 | if (fd >= 0) { | 
|  | 1824 | sync_wait(fd, -1); | 
|  | 1825 | } | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1826 | // Only cleanup the first time. | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1827 | EXPECT_TRUE(mRE->cleanupPostRender( | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1828 | renderengine::RenderEngine::CleanupMode::CLEAN_OUTPUT_RESOURCES)); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1829 | EXPECT_FALSE(mRE->cleanupPostRender( | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1830 | renderengine::RenderEngine::CleanupMode::CLEAN_OUTPUT_RESOURCES)); | 
|  | 1831 | } | 
|  | 1832 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1833 | TEST_P(RenderEngineTest, cleanupPostRender_whenCleaningAll_replacesTextureMemory) { | 
|  | 1834 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1835 |  | 
|  | 1836 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1837 | // GLES-specific test | 
|  | 1838 | return; | 
|  | 1839 | } | 
|  | 1840 |  | 
|  | 1841 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1842 |  | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1843 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1844 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1845 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1846 | settings.clip = fullscreenRect(); | 
|  | 1847 |  | 
|  | 1848 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1849 | renderengine::LayerSettings layer; | 
|  | 1850 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1851 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1852 | layer.alpha = 1.0; | 
|  | 1853 | layers.push_back(&layer); | 
|  | 1854 |  | 
|  | 1855 | base::unique_fd fence; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1856 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), &fence); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1857 |  | 
|  | 1858 | const int fd = fence.get(); | 
|  | 1859 | if (fd >= 0) { | 
|  | 1860 | sync_wait(fd, -1); | 
|  | 1861 | } | 
|  | 1862 |  | 
|  | 1863 | uint64_t bufferId = layer.source.buffer.buffer->getId(); | 
|  | 1864 | uint32_t texName = layer.source.buffer.textureName; | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1865 | EXPECT_TRUE(mGLESRE->isImageCachedForTesting(bufferId)); | 
|  | 1866 | EXPECT_EQ(bufferId, mGLESRE->getBufferIdForTextureNameForTesting(texName)); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1867 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1868 | EXPECT_TRUE(mRE->cleanupPostRender(renderengine::RenderEngine::CleanupMode::CLEAN_ALL)); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1869 |  | 
|  | 1870 | // Now check that our view of memory is good. | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1871 | EXPECT_FALSE(mGLESRE->isImageCachedForTesting(bufferId)); | 
|  | 1872 | EXPECT_EQ(std::nullopt, mGLESRE->getBufferIdForTextureNameForTesting(bufferId)); | 
|  | 1873 | EXPECT_TRUE(mGLESRE->isTextureNameKnownForTesting(texName)); | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1874 | } | 
|  | 1875 |  | 
| Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 1876 | TEST_P(RenderEngineTest, testRoundedCornersCrop) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1877 | initializeRenderEngine(); | 
| Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 1878 |  | 
|  | 1879 | renderengine::DisplaySettings settings; | 
|  | 1880 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1881 | settings.clip = fullscreenRect(); | 
|  | 1882 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1883 |  | 
|  | 1884 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1885 |  | 
|  | 1886 | renderengine::LayerSettings redLayer; | 
|  | 1887 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1888 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1889 | redLayer.geometry.roundedCornersRadius = 5.0f; | 
|  | 1890 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); | 
|  | 1891 | // Red background. | 
|  | 1892 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); | 
|  | 1893 | redLayer.alpha = 1.0f; | 
|  | 1894 |  | 
|  | 1895 | layers.push_back(&redLayer); | 
|  | 1896 |  | 
|  | 1897 | // Green layer with 1/3 size. | 
|  | 1898 | renderengine::LayerSettings greenLayer; | 
|  | 1899 | greenLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1900 | greenLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1901 | greenLayer.geometry.roundedCornersRadius = 5.0f; | 
|  | 1902 | // Bottom right corner is not going to be rounded. | 
|  | 1903 | greenLayer.geometry.roundedCornersCrop = | 
|  | 1904 | Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3, DEFAULT_DISPLAY_HEIGHT, | 
|  | 1905 | DEFAULT_DISPLAY_HEIGHT) | 
|  | 1906 | .toFloatRect(); | 
|  | 1907 | greenLayer.source.solidColor = half3(0.0f, 1.0f, 0.0f); | 
|  | 1908 | greenLayer.alpha = 1.0f; | 
|  | 1909 |  | 
|  | 1910 | layers.push_back(&greenLayer); | 
|  | 1911 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1912 | invokeDraw(settings, layers); | 
| Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 1913 |  | 
|  | 1914 | // Corners should be ignored... | 
|  | 1915 | // Screen size: width is 128, height is 256. | 
|  | 1916 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); | 
|  | 1917 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); | 
|  | 1918 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); | 
|  | 1919 | // Bottom right corner is kept out of the clipping, and it's green. | 
|  | 1920 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, | 
|  | 1921 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 1922 | 0, 255, 0, 255); | 
|  | 1923 | } | 
|  | 1924 |  | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1925 | } // namespace android | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1926 |  | 
|  | 1927 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
| Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 1928 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |