| 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() { | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 917 | auto blurRadius = 50; | 
|  | 918 | auto center = DEFAULT_DISPLAY_WIDTH / 2; | 
|  | 919 |  | 
|  | 920 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 921 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 922 | settings.physicalDisplay = fullscreenRect(); | 
|  | 923 | settings.clip = fullscreenRect(); | 
|  | 924 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 925 | std::vector<const renderengine::LayerSettings*> layers; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 926 |  | 
|  | 927 | renderengine::LayerSettings backgroundLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 928 | backgroundLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 929 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 930 | SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this); | 
|  | 931 | backgroundLayer.alpha = 1.0f; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 932 | layers.push_back(&backgroundLayer); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 933 |  | 
|  | 934 | renderengine::LayerSettings leftLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 935 | leftLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 936 | leftLayer.geometry.boundaries = | 
|  | 937 | Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect(); | 
|  | 938 | SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this); | 
|  | 939 | leftLayer.alpha = 1.0f; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 940 | layers.push_back(&leftLayer); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 941 |  | 
|  | 942 | renderengine::LayerSettings blurLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 943 | blurLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 944 | blurLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 945 | blurLayer.backgroundBlurRadius = blurRadius; | 
| Derek Sollenberger | ecb2146 | 2021-01-29 16:53:49 -0500 | [diff] [blame] | 946 | SourceVariant::fillColor(blurLayer, 0.0f, 0.0f, 1.0f, this); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 947 | blurLayer.alpha = 0; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 948 | layers.push_back(&blurLayer); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 949 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 950 | invokeDraw(settings, layers); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 951 |  | 
| Derek Sollenberger | ecb2146 | 2021-01-29 16:53:49 -0500 | [diff] [blame] | 952 | // solid color | 
|  | 953 | expectBufferColor(Rect(0, 0, 1, 1), 255, 0, 0, 255, 0 /* tolerance */); | 
|  | 954 |  | 
| Derek Sollenberger | b399837 | 2021-02-16 15:16:56 -0500 | [diff] [blame] | 955 | if (mRE->supportsBackgroundBlur()) { | 
|  | 956 | // blurred color (downsampling should result in the center color being close to 128) | 
|  | 957 | expectBufferColor(Rect(center - 1, center - 5, center + 1, center + 5), 128, 128, 0, 255, | 
|  | 958 | 10 /* tolerance */); | 
|  | 959 | } | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 960 | } | 
|  | 961 |  | 
|  | 962 | template <typename SourceVariant> | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 963 | void RenderEngineTest::overlayCorners() { | 
|  | 964 | renderengine::DisplaySettings settings; | 
|  | 965 | settings.physicalDisplay = fullscreenRect(); | 
|  | 966 | settings.clip = fullscreenRect(); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 967 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 968 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 969 | std::vector<const renderengine::LayerSettings*> layersFirst; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 970 |  | 
|  | 971 | renderengine::LayerSettings layerOne; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 972 | layerOne.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 973 | layerOne.geometry.boundaries = | 
|  | 974 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); | 
|  | 975 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); | 
|  | 976 | layerOne.alpha = 0.2; | 
|  | 977 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 978 | layersFirst.push_back(&layerOne); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 979 | invokeDraw(settings, layersFirst); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 980 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); | 
|  | 981 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, | 
|  | 982 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 983 | 0, 0, 0, 0); | 
|  | 984 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 985 | std::vector<const renderengine::LayerSettings*> layersSecond; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 986 | renderengine::LayerSettings layerTwo; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 987 | layerTwo.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 988 | layerTwo.geometry.boundaries = | 
|  | 989 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, | 
|  | 990 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); | 
|  | 991 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); | 
|  | 992 | layerTwo.alpha = 1.0f; | 
|  | 993 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 994 | layersSecond.push_back(&layerTwo); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 995 | invokeDraw(settings, layersSecond); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 996 |  | 
|  | 997 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); | 
|  | 998 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, | 
|  | 999 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 1000 | 0, 255, 0, 255); | 
|  | 1001 | } | 
|  | 1002 |  | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1003 | void RenderEngineTest::fillRedBufferTextureTransform() { | 
|  | 1004 | renderengine::DisplaySettings settings; | 
|  | 1005 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1006 | settings.clip = Rect(1, 1); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1007 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1008 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1009 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1010 |  | 
|  | 1011 | renderengine::LayerSettings layer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1012 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1013 | // Here will allocate a checker board texture, but transform texture | 
|  | 1014 | // coordinates so that only the upper left is applied. | 
|  | 1015 | sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2); | 
|  | 1016 | uint32_t texName; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1017 | RenderEngineTest::mRE->genTextures(1, &texName); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1018 | this->mTexNames.push_back(texName); | 
|  | 1019 |  | 
|  | 1020 | uint8_t* pixels; | 
|  | 1021 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 1022 | reinterpret_cast<void**>(&pixels)); | 
|  | 1023 | // Red top left, Green top right, Blue bottom left, Black bottom right | 
|  | 1024 | pixels[0] = 255; | 
|  | 1025 | pixels[1] = 0; | 
|  | 1026 | pixels[2] = 0; | 
|  | 1027 | pixels[3] = 255; | 
|  | 1028 | pixels[4] = 0; | 
|  | 1029 | pixels[5] = 255; | 
|  | 1030 | pixels[6] = 0; | 
|  | 1031 | pixels[7] = 255; | 
|  | 1032 | pixels[8] = 0; | 
|  | 1033 | pixels[9] = 0; | 
|  | 1034 | pixels[10] = 255; | 
|  | 1035 | pixels[11] = 255; | 
|  | 1036 | buf->unlock(); | 
|  | 1037 |  | 
|  | 1038 | layer.source.buffer.buffer = buf; | 
|  | 1039 | layer.source.buffer.textureName = texName; | 
|  | 1040 | // Transform coordinates to only be inside the red quadrant. | 
|  | 1041 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1)); | 
|  | 1042 | layer.alpha = 1.0f; | 
|  | 1043 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 1044 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1045 | layers.push_back(&layer); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1046 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1047 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1048 | } | 
|  | 1049 |  | 
|  | 1050 | void RenderEngineTest::fillBufferTextureTransform() { | 
|  | 1051 | fillRedBufferTextureTransform(); | 
|  | 1052 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); | 
|  | 1053 | } | 
|  | 1054 |  | 
|  | 1055 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { | 
|  | 1056 | renderengine::DisplaySettings settings; | 
|  | 1057 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1058 | // Here logical space is 1x1 | 
|  | 1059 | settings.clip = Rect(1, 1); | 
|  | 1060 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1061 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1062 |  | 
|  | 1063 | renderengine::LayerSettings layer; | 
|  | 1064 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); | 
|  | 1065 | uint32_t texName; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1066 | RenderEngineTest::mRE->genTextures(1, &texName); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1067 | this->mTexNames.push_back(texName); | 
|  | 1068 |  | 
|  | 1069 | uint8_t* pixels; | 
|  | 1070 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 1071 | reinterpret_cast<void**>(&pixels)); | 
|  | 1072 | pixels[0] = 255; | 
|  | 1073 | pixels[1] = 0; | 
|  | 1074 | pixels[2] = 0; | 
|  | 1075 | pixels[3] = 255; | 
|  | 1076 | buf->unlock(); | 
|  | 1077 |  | 
|  | 1078 | layer.source.buffer.buffer = buf; | 
|  | 1079 | layer.source.buffer.textureName = texName; | 
|  | 1080 | layer.source.buffer.usePremultipliedAlpha = true; | 
|  | 1081 | layer.alpha = 0.5f; | 
|  | 1082 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 1083 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1084 | layers.push_back(&layer); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1085 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1086 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1087 | } | 
|  | 1088 |  | 
|  | 1089 | void RenderEngineTest::fillBufferWithPremultiplyAlpha() { | 
|  | 1090 | fillRedBufferWithPremultiplyAlpha(); | 
|  | 1091 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); | 
|  | 1092 | } | 
|  | 1093 |  | 
|  | 1094 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { | 
|  | 1095 | renderengine::DisplaySettings settings; | 
|  | 1096 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1097 | // Here logical space is 1x1 | 
|  | 1098 | settings.clip = Rect(1, 1); | 
|  | 1099 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1100 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1101 |  | 
|  | 1102 | renderengine::LayerSettings layer; | 
|  | 1103 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); | 
|  | 1104 | uint32_t texName; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1105 | RenderEngineTest::mRE->genTextures(1, &texName); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1106 | this->mTexNames.push_back(texName); | 
|  | 1107 |  | 
|  | 1108 | uint8_t* pixels; | 
|  | 1109 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 1110 | reinterpret_cast<void**>(&pixels)); | 
|  | 1111 | pixels[0] = 255; | 
|  | 1112 | pixels[1] = 0; | 
|  | 1113 | pixels[2] = 0; | 
|  | 1114 | pixels[3] = 255; | 
|  | 1115 | buf->unlock(); | 
|  | 1116 |  | 
|  | 1117 | layer.source.buffer.buffer = buf; | 
|  | 1118 | layer.source.buffer.textureName = texName; | 
|  | 1119 | layer.source.buffer.usePremultipliedAlpha = false; | 
|  | 1120 | layer.alpha = 0.5f; | 
|  | 1121 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); | 
|  | 1122 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1123 | layers.push_back(&layer); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1124 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1125 | invokeDraw(settings, layers); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1126 | } | 
|  | 1127 |  | 
|  | 1128 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { | 
|  | 1129 | fillRedBufferWithoutPremultiplyAlpha(); | 
| wukui1 | 6f3c0bb | 2020-08-05 20:35:29 +0800 | [diff] [blame] | 1130 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128, 1); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1131 | } | 
|  | 1132 |  | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1133 | void RenderEngineTest::clearLeftRegion() { | 
|  | 1134 | renderengine::DisplaySettings settings; | 
|  | 1135 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1136 | // Here logical space is 4x4 | 
|  | 1137 | settings.clip = Rect(4, 4); | 
| Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 1138 | settings.clearRegion = Region(Rect(2, 4)); | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1139 | std::vector<const renderengine::LayerSettings*> layers; | 
| Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 1140 | // fake layer, without bounds should not render anything | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1141 | renderengine::LayerSettings layer; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1142 | layers.push_back(&layer); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1143 | invokeDraw(settings, layers); | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1144 | } | 
|  | 1145 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1146 | void RenderEngineTest::clearRegion() { | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1147 | // Reuse mBuffer | 
|  | 1148 | clearLeftRegion(); | 
|  | 1149 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255); | 
|  | 1150 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, | 
|  | 1151 | DEFAULT_DISPLAY_HEIGHT), | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1152 | 0, 0, 0, 0); | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1153 | } | 
|  | 1154 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1155 | template <typename SourceVariant> | 
|  | 1156 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, | 
|  | 1157 | const renderengine::ShadowSettings& shadow, | 
|  | 1158 | const ubyte4& casterColor, const ubyte4& backgroundColor) { | 
|  | 1159 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1160 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1161 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1162 | settings.clip = fullscreenRect(); | 
|  | 1163 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1164 | std::vector<const renderengine::LayerSettings*> layers; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1165 |  | 
|  | 1166 | // add background layer | 
|  | 1167 | renderengine::LayerSettings bgLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1168 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1169 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1170 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, | 
|  | 1171 | backgroundColor.b / 255.0f, this); | 
|  | 1172 | bgLayer.alpha = backgroundColor.a / 255.0f; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1173 | layers.push_back(&bgLayer); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1174 |  | 
|  | 1175 | // add shadow layer | 
|  | 1176 | renderengine::LayerSettings shadowLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1177 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1178 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; | 
|  | 1179 | shadowLayer.alpha = castingLayer.alpha; | 
|  | 1180 | shadowLayer.shadow = shadow; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1181 | layers.push_back(&shadowLayer); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1182 |  | 
|  | 1183 | // add layer casting the shadow | 
|  | 1184 | renderengine::LayerSettings layer = castingLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1185 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1186 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, | 
|  | 1187 | casterColor.b / 255.0f, this); | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1188 | layers.push_back(&layer); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1189 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1190 | invokeDraw(settings, layers); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1191 | } | 
|  | 1192 |  | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1193 | void RenderEngineTest::drawShadowWithoutCaster(const FloatRect& castingBounds, | 
|  | 1194 | const renderengine::ShadowSettings& shadow, | 
|  | 1195 | const ubyte4& backgroundColor) { | 
|  | 1196 | renderengine::DisplaySettings settings; | 
|  | 1197 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1198 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1199 | settings.clip = fullscreenRect(); | 
|  | 1200 |  | 
|  | 1201 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1202 |  | 
|  | 1203 | // add background layer | 
|  | 1204 | renderengine::LayerSettings bgLayer; | 
|  | 1205 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1206 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1207 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, | 
|  | 1208 | backgroundColor.b / 255.0f, this); | 
|  | 1209 | bgLayer.alpha = backgroundColor.a / 255.0f; | 
|  | 1210 | layers.push_back(&bgLayer); | 
|  | 1211 |  | 
|  | 1212 | // add shadow layer | 
|  | 1213 | renderengine::LayerSettings shadowLayer; | 
|  | 1214 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1215 | shadowLayer.geometry.boundaries = castingBounds; | 
|  | 1216 | shadowLayer.alpha = 1.0f; | 
|  | 1217 | ColorSourceVariant::fillColor(shadowLayer, 0, 0, 0, this); | 
|  | 1218 | shadowLayer.shadow = shadow; | 
|  | 1219 | layers.push_back(&shadowLayer); | 
|  | 1220 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1221 | invokeDraw(settings, layers); | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1222 | } | 
|  | 1223 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1224 | INSTANTIATE_TEST_SUITE_P(PerRenderEngineType, RenderEngineTest, | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1225 | testing::Values(std::make_shared<GLESRenderEngineFactory>(), | 
| Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 1226 | std::make_shared<GLESCMRenderEngineFactory>(), | 
|  | 1227 | std::make_shared<SkiaGLESRenderEngineFactory>(), | 
|  | 1228 | std::make_shared<SkiaGLESCMRenderEngineFactory>())); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1229 |  | 
|  | 1230 | TEST_P(RenderEngineTest, drawLayers_noLayersToDraw) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1231 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1232 | drawEmptyLayers(); | 
|  | 1233 | } | 
|  | 1234 |  | 
| Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1235 | TEST_P(RenderEngineTest, drawLayers_withoutBuffers_withColorTransform) { | 
|  | 1236 | const auto& renderEngineFactory = GetParam(); | 
|  | 1237 | mRE = renderEngineFactory->createRenderEngine(); | 
|  | 1238 |  | 
|  | 1239 | renderengine::DisplaySettings settings; | 
|  | 1240 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1241 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1242 | settings.clip = fullscreenRect(); | 
|  | 1243 |  | 
|  | 1244 | // 255, 255, 255, 255 is full opaque white. | 
|  | 1245 | const ubyte4 backgroundColor(255.f, 255.f, 255.f, 255.f); | 
|  | 1246 | // Create layer with given color. | 
|  | 1247 | renderengine::LayerSettings bgLayer; | 
|  | 1248 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1249 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1250 | bgLayer.source.solidColor = half3(backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, | 
|  | 1251 | backgroundColor.b / 255.0f); | 
|  | 1252 | bgLayer.alpha = backgroundColor.a / 255.0f; | 
|  | 1253 | // Transform the red color. | 
|  | 1254 | bgLayer.colorTransform = mat4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); | 
|  | 1255 |  | 
|  | 1256 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1257 | layers.push_back(&bgLayer); | 
|  | 1258 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1259 | invokeDraw(settings, layers); | 
| Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1260 |  | 
|  | 1261 | // Expect to see full opaque pixel (with inverted red from the transform). | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1262 | expectBufferColor(Rect(0, 0, 10, 10), 0.f, backgroundColor.g, backgroundColor.b, | 
| Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1263 | backgroundColor.a); | 
|  | 1264 | } | 
|  | 1265 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1266 | TEST_P(RenderEngineTest, drawLayers_nullOutputBuffer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1267 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1268 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1269 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1270 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1271 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1272 | renderengine::LayerSettings layer; | 
|  | 1273 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1274 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1275 | layers.push_back(&layer); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1276 | base::unique_fd fence; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1277 | 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] | 1278 |  | 
|  | 1279 | ASSERT_EQ(BAD_VALUE, status); | 
|  | 1280 | } | 
|  | 1281 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1282 | TEST_P(RenderEngineTest, drawLayers_nullOutputFence) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1283 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1284 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1285 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1286 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1287 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1288 | settings.clip = fullscreenRect(); | 
|  | 1289 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1290 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1291 | renderengine::LayerSettings layer; | 
|  | 1292 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1293 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1294 | layer.alpha = 1.0; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1295 | layers.push_back(&layer); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1296 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1297 | status_t status = mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), nullptr); | 
|  | 1298 | mCurrentBuffer = mBuffer; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1299 | ASSERT_EQ(NO_ERROR, status); | 
|  | 1300 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); | 
|  | 1301 | } | 
|  | 1302 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1303 | TEST_P(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) { | 
|  | 1304 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1305 |  | 
|  | 1306 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1307 | // GLES-specific test | 
|  | 1308 | return; | 
|  | 1309 | } | 
|  | 1310 |  | 
|  | 1311 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1312 |  | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1313 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1314 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1315 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1316 | settings.clip = fullscreenRect(); | 
|  | 1317 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1318 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1319 | renderengine::LayerSettings layer; | 
|  | 1320 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1321 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1322 | layer.alpha = 1.0; | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1323 | layers.push_back(&layer); | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1324 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1325 | status_t status = mRE->drawLayers(settings, layers, mBuffer, false, base::unique_fd(), nullptr); | 
|  | 1326 | mCurrentBuffer = mBuffer; | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1327 | ASSERT_EQ(NO_ERROR, status); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1328 | ASSERT_FALSE(mGLESRE->isFramebufferImageCachedForTesting(mBuffer->getId())); | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1329 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); | 
|  | 1330 | } | 
|  | 1331 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1332 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1333 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1334 | fillRedBuffer<ColorSourceVariant>(); | 
|  | 1335 | } | 
|  | 1336 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1337 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1338 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1339 | fillGreenBuffer<ColorSourceVariant>(); | 
|  | 1340 | } | 
|  | 1341 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1342 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1343 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1344 | fillBlueBuffer<ColorSourceVariant>(); | 
|  | 1345 | } | 
|  | 1346 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1347 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1348 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1349 | fillRedTransparentBuffer<ColorSourceVariant>(); | 
|  | 1350 | } | 
|  | 1351 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1352 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1353 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1354 | fillBufferPhysicalOffset<ColorSourceVariant>(); | 
|  | 1355 | } | 
|  | 1356 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1357 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1358 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1359 | fillBufferCheckersRotate0<ColorSourceVariant>(); | 
|  | 1360 | } | 
|  | 1361 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1362 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1363 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1364 | fillBufferCheckersRotate90<ColorSourceVariant>(); | 
|  | 1365 | } | 
|  | 1366 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1367 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1368 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1369 | fillBufferCheckersRotate180<ColorSourceVariant>(); | 
|  | 1370 | } | 
|  | 1371 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1372 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1373 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1374 | fillBufferCheckersRotate270<ColorSourceVariant>(); | 
|  | 1375 | } | 
|  | 1376 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1377 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1378 | initializeRenderEngine(); | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1379 | fillBufferLayerTransform<ColorSourceVariant>(); | 
|  | 1380 | } | 
|  | 1381 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1382 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1383 | initializeRenderEngine(); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1384 | fillBufferColorTransform<ColorSourceVariant>(); | 
|  | 1385 | } | 
|  | 1386 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1387 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1388 | initializeRenderEngine(); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1389 | fillBufferWithRoundedCorners<ColorSourceVariant>(); | 
|  | 1390 | } | 
|  | 1391 |  | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1392 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1393 | initializeRenderEngine(); | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1394 | fillBufferColorTransformZeroLayerAlpha<ColorSourceVariant>(); | 
|  | 1395 | } | 
|  | 1396 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1397 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1398 | initializeRenderEngine(); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1399 | fillBufferAndBlurBackground<ColorSourceVariant>(); | 
|  | 1400 | } | 
|  | 1401 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1402 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_colorSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1403 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1404 | overlayCorners<ColorSourceVariant>(); | 
|  | 1405 | } | 
|  | 1406 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1407 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1408 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1409 | fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1410 | } | 
|  | 1411 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1412 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1413 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1414 | fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1415 | } | 
|  | 1416 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1417 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1418 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1419 | fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1420 | } | 
|  | 1421 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1422 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1423 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1424 | fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1425 | } | 
|  | 1426 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1427 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1428 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1429 | fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1430 | } | 
|  | 1431 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1432 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1433 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1434 | fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1435 | } | 
|  | 1436 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1437 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1438 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1439 | fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1440 | } | 
|  | 1441 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1442 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1443 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1444 | fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1445 | } | 
|  | 1446 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1447 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1448 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1449 | fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1450 | } | 
|  | 1451 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1452 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1453 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1454 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1455 | } | 
|  | 1456 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1457 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1458 | initializeRenderEngine(); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1459 | fillBufferColorTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1460 | } | 
|  | 1461 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1462 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1463 | initializeRenderEngine(); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1464 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1465 | } | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1466 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1467 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_opaqueBufferSource) { | 
|  | 1468 | initializeRenderEngine(); | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1469 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1470 | } | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1471 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1472 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1473 | initializeRenderEngine(); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1474 | fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1475 | } | 
|  | 1476 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1477 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1478 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1479 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); | 
|  | 1480 | } | 
|  | 1481 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1482 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1483 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1484 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1485 | } | 
|  | 1486 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1487 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1488 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1489 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1490 | } | 
|  | 1491 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1492 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1493 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1494 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1495 | } | 
|  | 1496 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1497 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1498 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1499 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1500 | } | 
|  | 1501 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1502 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1503 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1504 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1505 | } | 
|  | 1506 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1507 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1508 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1509 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1510 | } | 
|  | 1511 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1512 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1513 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1514 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1515 | } | 
|  | 1516 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1517 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1518 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1519 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1520 | } | 
|  | 1521 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1522 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1523 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1524 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1525 | } | 
|  | 1526 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1527 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1528 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1529 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1530 | } | 
|  | 1531 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1532 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1533 | initializeRenderEngine(); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1534 | fillBufferColorTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1535 | } | 
|  | 1536 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1537 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1538 | initializeRenderEngine(); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1539 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1540 | } | 
|  | 1541 |  | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1542 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1543 | initializeRenderEngine(); | 
| KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1544 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1545 | } | 
|  | 1546 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1547 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1548 | initializeRenderEngine(); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1549 | fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1550 | } | 
|  | 1551 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1552 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1553 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1554 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); | 
|  | 1555 | } | 
|  | 1556 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1557 | TEST_P(RenderEngineTest, drawLayers_fillBufferTextureTransform) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1558 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1559 | fillBufferTextureTransform(); | 
|  | 1560 | } | 
|  | 1561 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1562 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1563 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1564 | fillBufferWithPremultiplyAlpha(); | 
|  | 1565 | } | 
|  | 1566 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1567 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1568 | initializeRenderEngine(); | 
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1569 | fillBufferWithoutPremultiplyAlpha(); | 
|  | 1570 | } | 
|  | 1571 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1572 | TEST_P(RenderEngineTest, drawLayers_clearRegion) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1573 | initializeRenderEngine(); | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1574 | clearRegion(); | 
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1575 | } | 
|  | 1576 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1577 | TEST_P(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) { | 
|  | 1578 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1579 |  | 
|  | 1580 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1581 | // GLES-specific test | 
|  | 1582 | return; | 
|  | 1583 | } | 
|  | 1584 |  | 
|  | 1585 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1586 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1587 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1588 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1589 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1590 | settings.clip = fullscreenRect(); | 
|  | 1591 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1592 | std::vector<const renderengine::LayerSettings*> layers; | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1593 |  | 
|  | 1594 | renderengine::LayerSettings layer; | 
|  | 1595 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1596 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1597 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1598 | layers.push_back(&layer); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1599 | invokeDraw(settings, layers); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1600 | uint64_t bufferId = layer.source.buffer.buffer->getId(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1601 | EXPECT_TRUE(mGLESRE->isImageCachedForTesting(bufferId)); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1602 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1603 | mGLESRE->unbindExternalTextureBufferForTesting(bufferId); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1604 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1605 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1606 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1607 | return barrier->isOpen; | 
|  | 1608 | })); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1609 | EXPECT_FALSE(mGLESRE->isImageCachedForTesting(bufferId)); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1610 | EXPECT_EQ(NO_ERROR, barrier->result); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1611 | } | 
|  | 1612 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1613 | TEST_P(RenderEngineTest, cacheExternalBuffer_withNullBuffer) { | 
|  | 1614 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1615 |  | 
|  | 1616 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1617 | // GLES-specific test | 
|  | 1618 | return; | 
|  | 1619 | } | 
|  | 1620 |  | 
|  | 1621 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1622 |  | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1623 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1624 | mGLESRE->cacheExternalTextureBufferForTesting(nullptr); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1625 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1626 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1627 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1628 | return barrier->isOpen; | 
|  | 1629 | })); | 
|  | 1630 | EXPECT_TRUE(barrier->isOpen); | 
|  | 1631 | EXPECT_EQ(BAD_VALUE, barrier->result); | 
| Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1632 | } | 
|  | 1633 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1634 | TEST_P(RenderEngineTest, cacheExternalBuffer_cachesImages) { | 
|  | 1635 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1636 |  | 
|  | 1637 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1638 | // GLES-specific test | 
|  | 1639 | return; | 
|  | 1640 | } | 
|  | 1641 |  | 
|  | 1642 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1643 |  | 
| Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1644 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); | 
|  | 1645 | uint64_t bufferId = buf->getId(); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1646 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1647 | mGLESRE->cacheExternalTextureBufferForTesting(buf); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1648 | { | 
|  | 1649 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1650 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1651 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1652 | return barrier->isOpen; | 
|  | 1653 | })); | 
|  | 1654 | EXPECT_EQ(NO_ERROR, barrier->result); | 
|  | 1655 | } | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1656 | EXPECT_TRUE(mGLESRE->isImageCachedForTesting(bufferId)); | 
|  | 1657 | barrier = mGLESRE->unbindExternalTextureBufferForTesting(bufferId); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1658 | { | 
|  | 1659 | std::lock_guard<std::mutex> lock(barrier->mutex); | 
|  | 1660 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), | 
|  | 1661 | [&]() REQUIRES(barrier->mutex) { | 
|  | 1662 | return barrier->isOpen; | 
|  | 1663 | })); | 
|  | 1664 | EXPECT_EQ(NO_ERROR, barrier->result); | 
|  | 1665 | } | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1666 | EXPECT_FALSE(mGLESRE->isImageCachedForTesting(bufferId)); | 
| Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1667 | } | 
|  | 1668 |  | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1669 | TEST_P(RenderEngineTest, drawLayers_fillShadow_castsWithoutCasterLayer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1670 | initializeRenderEngine(); | 
| Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1671 |  | 
|  | 1672 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1673 | const float shadowLength = 5.0f; | 
|  | 1674 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1675 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1676 | renderengine::ShadowSettings settings = | 
|  | 1677 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1678 | false /* casterIsTranslucent */); | 
|  | 1679 |  | 
|  | 1680 | drawShadowWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); | 
|  | 1681 | expectShadowColorWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); | 
|  | 1682 | } | 
|  | 1683 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1684 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1685 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1686 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1687 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1688 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1689 | const float shadowLength = 5.0f; | 
|  | 1690 | Rect casterBounds(1, 1); | 
|  | 1691 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1692 | renderengine::LayerSettings castingLayer; | 
|  | 1693 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1694 | castingLayer.alpha = 1.0f; | 
|  | 1695 | renderengine::ShadowSettings settings = | 
|  | 1696 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1697 | false /* casterIsTranslucent */); | 
|  | 1698 |  | 
|  | 1699 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1700 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1701 | } | 
|  | 1702 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1703 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1704 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1705 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1706 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1707 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1708 | const float shadowLength = 5.0f; | 
|  | 1709 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1710 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1711 | renderengine::LayerSettings castingLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1712 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1713 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1714 | castingLayer.alpha = 1.0f; | 
|  | 1715 | renderengine::ShadowSettings settings = | 
|  | 1716 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1717 | false /* casterIsTranslucent */); | 
|  | 1718 |  | 
|  | 1719 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1720 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1721 | } | 
|  | 1722 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1723 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1724 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1725 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1726 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1727 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1728 | const float shadowLength = 5.0f; | 
|  | 1729 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1730 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1731 | renderengine::LayerSettings castingLayer; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1732 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1733 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1734 | castingLayer.alpha = 1.0f; | 
|  | 1735 | renderengine::ShadowSettings settings = | 
|  | 1736 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1737 | false /* casterIsTranslucent */); | 
|  | 1738 |  | 
|  | 1739 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, | 
|  | 1740 | backgroundColor); | 
|  | 1741 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1742 | } | 
|  | 1743 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1744 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1745 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1746 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1747 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1748 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1749 | const float shadowLength = 5.0f; | 
|  | 1750 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1751 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1752 | renderengine::LayerSettings castingLayer; | 
|  | 1753 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1754 | castingLayer.geometry.roundedCornersRadius = 3.0f; | 
|  | 1755 | castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect(); | 
|  | 1756 | castingLayer.alpha = 1.0f; | 
|  | 1757 | renderengine::ShadowSettings settings = | 
|  | 1758 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1759 | false /* casterIsTranslucent */); | 
|  | 1760 |  | 
|  | 1761 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, | 
|  | 1762 | backgroundColor); | 
|  | 1763 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); | 
|  | 1764 | } | 
|  | 1765 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1766 | TEST_P(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1767 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1768 |  | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1769 | const ubyte4 casterColor(255, 0, 0, 255); | 
|  | 1770 | const ubyte4 backgroundColor(255, 255, 255, 255); | 
|  | 1771 | const float shadowLength = 5.0f; | 
|  | 1772 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); | 
|  | 1773 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); | 
|  | 1774 | renderengine::LayerSettings castingLayer; | 
|  | 1775 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); | 
|  | 1776 | castingLayer.alpha = 0.5f; | 
|  | 1777 | renderengine::ShadowSettings settings = | 
|  | 1778 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, | 
|  | 1779 | true /* casterIsTranslucent */); | 
|  | 1780 |  | 
|  | 1781 | drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor, | 
|  | 1782 | backgroundColor); | 
|  | 1783 |  | 
|  | 1784 | // verify only the background since the shadow will draw behind the caster | 
|  | 1785 | const float shadowInset = settings.length * -1.0f; | 
|  | 1786 | const Rect casterWithShadow = | 
|  | 1787 | Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset); | 
|  | 1788 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); | 
|  | 1789 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, | 
|  | 1790 | backgroundColor.a); | 
|  | 1791 | } | 
|  | 1792 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1793 | TEST_P(RenderEngineTest, cleanupPostRender_cleansUpOnce) { | 
|  | 1794 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1795 |  | 
|  | 1796 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1797 | // GLES-specific test | 
|  | 1798 | return; | 
|  | 1799 | } | 
|  | 1800 |  | 
|  | 1801 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1802 |  | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1803 | renderengine::DisplaySettings settings; | 
|  | 1804 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1805 | settings.clip = fullscreenRect(); | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1806 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1807 |  | 
|  | 1808 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1809 | renderengine::LayerSettings layer; | 
|  | 1810 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1811 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1812 | layer.alpha = 1.0; | 
|  | 1813 | layers.push_back(&layer); | 
|  | 1814 |  | 
|  | 1815 | base::unique_fd fenceOne; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1816 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), &fenceOne); | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1817 | base::unique_fd fenceTwo; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1818 | mRE->drawLayers(settings, layers, mBuffer, true, std::move(fenceOne), &fenceTwo); | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1819 |  | 
|  | 1820 | const int fd = fenceTwo.get(); | 
|  | 1821 | if (fd >= 0) { | 
|  | 1822 | sync_wait(fd, -1); | 
|  | 1823 | } | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1824 | // Only cleanup the first time. | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1825 | EXPECT_TRUE(mRE->cleanupPostRender( | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1826 | renderengine::RenderEngine::CleanupMode::CLEAN_OUTPUT_RESOURCES)); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1827 | EXPECT_FALSE(mRE->cleanupPostRender( | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1828 | renderengine::RenderEngine::CleanupMode::CLEAN_OUTPUT_RESOURCES)); | 
|  | 1829 | } | 
|  | 1830 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1831 | TEST_P(RenderEngineTest, cleanupPostRender_whenCleaningAll_replacesTextureMemory) { | 
|  | 1832 | const auto& renderEngineFactory = GetParam(); | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1833 |  | 
|  | 1834 | if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { | 
|  | 1835 | // GLES-specific test | 
|  | 1836 | return; | 
|  | 1837 | } | 
|  | 1838 |  | 
|  | 1839 | initializeRenderEngine(); | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1840 |  | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1841 | renderengine::DisplaySettings settings; | 
| Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1842 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1843 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1844 | settings.clip = fullscreenRect(); | 
|  | 1845 |  | 
|  | 1846 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1847 | renderengine::LayerSettings layer; | 
|  | 1848 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1849 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); | 
|  | 1850 | layer.alpha = 1.0; | 
|  | 1851 | layers.push_back(&layer); | 
|  | 1852 |  | 
|  | 1853 | base::unique_fd fence; | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1854 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), &fence); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1855 |  | 
|  | 1856 | const int fd = fence.get(); | 
|  | 1857 | if (fd >= 0) { | 
|  | 1858 | sync_wait(fd, -1); | 
|  | 1859 | } | 
|  | 1860 |  | 
|  | 1861 | uint64_t bufferId = layer.source.buffer.buffer->getId(); | 
|  | 1862 | uint32_t texName = layer.source.buffer.textureName; | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1863 | EXPECT_TRUE(mGLESRE->isImageCachedForTesting(bufferId)); | 
|  | 1864 | EXPECT_EQ(bufferId, mGLESRE->getBufferIdForTextureNameForTesting(texName)); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1865 |  | 
| Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1866 | EXPECT_TRUE(mRE->cleanupPostRender(renderengine::RenderEngine::CleanupMode::CLEAN_ALL)); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1867 |  | 
|  | 1868 | // Now check that our view of memory is good. | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1869 | EXPECT_FALSE(mGLESRE->isImageCachedForTesting(bufferId)); | 
|  | 1870 | EXPECT_EQ(std::nullopt, mGLESRE->getBufferIdForTextureNameForTesting(bufferId)); | 
|  | 1871 | EXPECT_TRUE(mGLESRE->isTextureNameKnownForTesting(texName)); | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 1872 | } | 
|  | 1873 |  | 
| Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 1874 | TEST_P(RenderEngineTest, testRoundedCornersCrop) { | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1875 | initializeRenderEngine(); | 
| Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 1876 |  | 
|  | 1877 | renderengine::DisplaySettings settings; | 
|  | 1878 | settings.physicalDisplay = fullscreenRect(); | 
|  | 1879 | settings.clip = fullscreenRect(); | 
|  | 1880 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1881 |  | 
|  | 1882 | std::vector<const renderengine::LayerSettings*> layers; | 
|  | 1883 |  | 
|  | 1884 | renderengine::LayerSettings redLayer; | 
|  | 1885 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1886 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1887 | redLayer.geometry.roundedCornersRadius = 5.0f; | 
|  | 1888 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); | 
|  | 1889 | // Red background. | 
|  | 1890 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); | 
|  | 1891 | redLayer.alpha = 1.0f; | 
|  | 1892 |  | 
|  | 1893 | layers.push_back(&redLayer); | 
|  | 1894 |  | 
|  | 1895 | // Green layer with 1/3 size. | 
|  | 1896 | renderengine::LayerSettings greenLayer; | 
|  | 1897 | greenLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; | 
|  | 1898 | greenLayer.geometry.boundaries = fullscreenRect().toFloatRect(); | 
|  | 1899 | greenLayer.geometry.roundedCornersRadius = 5.0f; | 
|  | 1900 | // Bottom right corner is not going to be rounded. | 
|  | 1901 | greenLayer.geometry.roundedCornersCrop = | 
|  | 1902 | Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3, DEFAULT_DISPLAY_HEIGHT, | 
|  | 1903 | DEFAULT_DISPLAY_HEIGHT) | 
|  | 1904 | .toFloatRect(); | 
|  | 1905 | greenLayer.source.solidColor = half3(0.0f, 1.0f, 0.0f); | 
|  | 1906 | greenLayer.alpha = 1.0f; | 
|  | 1907 |  | 
|  | 1908 | layers.push_back(&greenLayer); | 
|  | 1909 |  | 
| Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1910 | invokeDraw(settings, layers); | 
| Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 1911 |  | 
|  | 1912 | // Corners should be ignored... | 
|  | 1913 | // Screen size: width is 128, height is 256. | 
|  | 1914 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); | 
|  | 1915 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); | 
|  | 1916 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); | 
|  | 1917 | // Bottom right corner is kept out of the clipping, and it's green. | 
|  | 1918 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, | 
|  | 1919 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), | 
|  | 1920 | 0, 255, 0, 255); | 
|  | 1921 | } | 
|  | 1922 |  | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1923 | } // namespace android | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1924 |  | 
|  | 1925 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
| Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 1926 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |