Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" |
Mike Klein | fe0aeb3 | 2019-05-20 10:55:11 -0500 | [diff] [blame] | 9 | #include "include/core/SkSurface.h" |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 10 | #include "include/core/SkSurfaceCharacterization.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 11 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 12 | #include "src/core/SkAutoPixmapStorage.h" |
Mike Klein | 4b432fa | 2019-06-06 11:44:05 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrContextPriv.h" |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 14 | #include "src/image/SkImage_Base.h" |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 15 | #include "tests/Test.h" |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 16 | #include "tests/TestUtils.h" |
| 17 | #include "tools/ToolUtils.h" |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 18 | |
Robert Phillips | 27eb525 | 2019-06-03 12:59:40 -0400 | [diff] [blame] | 19 | #ifdef SK_GL |
Robert Phillips | ee94693 | 2019-12-18 11:16:17 -0500 | [diff] [blame] | 20 | #include "src/gpu/gl/GrGLCaps.h" |
| 21 | #include "src/gpu/gl/GrGLDefines.h" |
Robert Phillips | 27eb525 | 2019-06-03 12:59:40 -0400 | [diff] [blame] | 22 | #include "src/gpu/gl/GrGLGpu.h" |
| 23 | #include "src/gpu/gl/GrGLUtil.h" |
| 24 | #endif |
| 25 | |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 26 | #ifdef SK_METAL |
| 27 | #include "include/gpu/mtl/GrMtlTypes.h" |
| 28 | #include "src/gpu/mtl/GrMtlCppUtil.h" |
| 29 | #endif |
| 30 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 31 | static void wait_on_backend_work_to_finish(GrDirectContext* dContext, bool* finishedCreate) { |
| 32 | dContext->submit(); |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 33 | while (finishedCreate && !(*finishedCreate)) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 34 | dContext->checkAsyncWorkCompletion(); |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 35 | } |
| 36 | if (finishedCreate) { |
| 37 | // The same boolean (pointed to by finishedCreate) is often used multiply and sequentially |
| 38 | // throughout our tests to create different backend textures. |
| 39 | // Reset it here so that it can be use to signal a future backend texture's creation |
| 40 | *finishedCreate = false; |
| 41 | } |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 44 | static void delete_backend_texture(GrDirectContext* dContext, |
| 45 | const GrBackendTexture& backendTexture, |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 46 | bool* finishedCreate) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 47 | wait_on_backend_work_to_finish(dContext, finishedCreate); |
| 48 | dContext->deleteBackendTexture(backendTexture); |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 51 | static void mark_signaled(void* context) { |
| 52 | *(bool*)context = true; |
| 53 | } |
| 54 | |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 55 | // Test wrapping of GrBackendObjects in SkSurfaces and SkImages (non-static since used in Mtl test) |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 56 | void test_wrapping(GrDirectContext* dContext, |
| 57 | skiatest::Reporter* reporter, |
| 58 | std::function<GrBackendTexture (GrDirectContext*, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 59 | GrMipmapped, |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 60 | GrRenderable)> create, |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 61 | GrColorType grColorType, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 62 | GrMipmapped mipMapped, |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 63 | GrRenderable renderable, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 64 | bool* finishedBECreate) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 65 | GrResourceCache* cache = dContext->priv().getResourceCache(); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 66 | |
| 67 | const int initialCount = cache->getResourceCount(); |
| 68 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 69 | GrBackendTexture backendTex = create(dContext, mipMapped, renderable); |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 70 | if (!backendTex.isValid()) { |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 71 | ERRORF(reporter, "Couldn't create backendTexture for grColorType %d renderable %s\n", |
| 72 | grColorType, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 73 | GrRenderable::kYes == renderable ? "yes" : "no"); |
| 74 | return; |
| 75 | } |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 76 | |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 77 | // Skia proper should know nothing about the new backend object |
| 78 | REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount()); |
| 79 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 80 | SkColorType skColorType = GrColorTypeToSkColorType(grColorType); |
| 81 | |
| 82 | // Wrapping a backendTexture in an image requires an SkColorType |
| 83 | if (kUnknown_SkColorType == skColorType) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 84 | delete_backend_texture(dContext, backendTex, finishedBECreate); |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 85 | return; |
| 86 | } |
| 87 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 88 | if (GrRenderable::kYes == renderable && dContext->colorTypeSupportedAsSurface(skColorType)) { |
| 89 | sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(dContext, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 90 | backendTex, |
| 91 | kTopLeft_GrSurfaceOrigin, |
| 92 | 0, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 93 | skColorType, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 94 | nullptr, nullptr); |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 95 | if (!surf) { |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 96 | ERRORF(reporter, "Couldn't make surface from backendTexture for %s\n", |
| 97 | ToolUtils::colortype_name(skColorType)); |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 98 | } else { |
| 99 | REPORTER_ASSERT(reporter, initialCount+1 == cache->getResourceCount()); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 100 | } |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 101 | } |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 102 | |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 103 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 104 | sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 105 | backendTex, |
| 106 | kTopLeft_GrSurfaceOrigin, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 107 | skColorType, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 108 | kPremul_SkAlphaType, |
| 109 | nullptr); |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 110 | if (!img) { |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 111 | ERRORF(reporter, "Couldn't make image from backendTexture for %s\n", |
| 112 | ToolUtils::colortype_name(skColorType)); |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 113 | } else { |
| 114 | SkImage_Base* ib = as_IB(img); |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 115 | |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 116 | GrTextureProxy* proxy = ib->peekProxy(); |
| 117 | REPORTER_ASSERT(reporter, proxy); |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 118 | |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 119 | REPORTER_ASSERT(reporter, mipMapped == proxy->proxyMipMapped()); |
| 120 | REPORTER_ASSERT(reporter, proxy->isInstantiated()); |
| 121 | REPORTER_ASSERT(reporter, mipMapped == proxy->mipMapped()); |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 122 | |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, initialCount+1 == cache->getResourceCount()); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount()); |
| 128 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 129 | delete_backend_texture(dContext, backendTex, finishedBECreate); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 130 | } |
| 131 | |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 132 | static bool isBGRA8(const GrBackendFormat& format) { |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 133 | switch (format.backend()) { |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 134 | case GrBackendApi::kOpenGL: |
| 135 | #ifdef SK_GL |
| 136 | return format.asGLFormat() == GrGLFormat::kBGRA8; |
| 137 | #else |
| 138 | return false; |
| 139 | #endif |
| 140 | case GrBackendApi::kVulkan: { |
| 141 | #ifdef SK_VULKAN |
| 142 | VkFormat vkFormat; |
| 143 | format.asVkFormat(&vkFormat); |
| 144 | return vkFormat == VK_FORMAT_B8G8R8A8_UNORM; |
| 145 | #else |
| 146 | return false; |
| 147 | #endif |
| 148 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 149 | case GrBackendApi::kMetal: |
| 150 | #ifdef SK_METAL |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 151 | return GrMtlFormatIsBGRA8(format.asMtlFormat()); |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 152 | #else |
| 153 | return false; |
| 154 | #endif |
| 155 | case GrBackendApi::kDirect3D: |
| 156 | #ifdef SK_DIRECT3D |
| 157 | return false; // TODO |
| 158 | #else |
| 159 | return false; |
| 160 | #endif |
| 161 | case GrBackendApi::kDawn: |
Stephen White | 3624874 | 2020-06-10 22:24:57 -0400 | [diff] [blame] | 162 | #ifdef SK_DAWN |
| 163 | wgpu::TextureFormat dawnFormat; |
| 164 | format.asDawnFormat(&dawnFormat); |
| 165 | return dawnFormat == wgpu::TextureFormat::BGRA8Unorm; |
| 166 | #else |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 167 | return false; |
Stephen White | 3624874 | 2020-06-10 22:24:57 -0400 | [diff] [blame] | 168 | #endif |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 169 | case GrBackendApi::kMock: { |
| 170 | SkImage::CompressionType compression = format.asMockCompressionType(); |
| 171 | if (compression != SkImage::CompressionType::kNone) { |
| 172 | return false; // No compressed formats are BGRA |
| 173 | } |
| 174 | |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 175 | return format.asMockColorType() == GrColorType::kBGRA_8888; |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 176 | } |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 177 | } |
| 178 | SkUNREACHABLE; |
| 179 | } |
| 180 | |
| 181 | static bool isRGB(const GrBackendFormat& format) { |
| 182 | switch (format.backend()) { |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 183 | case GrBackendApi::kOpenGL: |
| 184 | #ifdef SK_GL |
| 185 | return format.asGLFormat() == GrGLFormat::kRGB8; |
| 186 | #else |
| 187 | return false; |
| 188 | #endif |
| 189 | case GrBackendApi::kVulkan: { |
| 190 | #ifdef SK_VULKAN |
| 191 | VkFormat vkFormat; |
| 192 | format.asVkFormat(&vkFormat); |
| 193 | return vkFormat == VK_FORMAT_R8G8B8_UNORM; |
| 194 | #else |
| 195 | return false; |
| 196 | #endif |
| 197 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 198 | case GrBackendApi::kMetal: |
| 199 | return false; // Metal doesn't even pretend to support this |
| 200 | case GrBackendApi::kDirect3D: |
| 201 | return false; // Not supported in Direct3D 12 |
| 202 | case GrBackendApi::kDawn: |
| 203 | return false; |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 204 | case GrBackendApi::kMock: |
| 205 | return false; // No GrColorType::kRGB_888 |
| 206 | } |
| 207 | SkUNREACHABLE; |
| 208 | } |
| 209 | |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 210 | static void check_solid_pixmap(skiatest::Reporter* reporter, |
| 211 | const SkColor4f& expected, const SkPixmap& actual, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 212 | SkColorType ct, const char* label1, const char* label2) { |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 213 | // we need 0.001f across the board just for noise |
| 214 | // we need 0.01f across the board for 1010102 |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 215 | const float tols[4] = { 0.01f, 0.01f, 0.01f, 0.01f }; |
Robert Phillips | 27eb525 | 2019-06-03 12:59:40 -0400 | [diff] [blame] | 216 | |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 217 | auto error = std::function<ComparePixmapsErrorReporter>( |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 218 | [reporter, ct, label1, label2](int x, int y, const float diffs[4]) { |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 219 | SkASSERT(x >= 0 && y >= 0); |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 220 | ERRORF(reporter, "%s %s %s - mismatch at %d, %d (%f, %f, %f %f)", |
| 221 | ToolUtils::colortype_name(ct), label1, label2, x, y, |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 222 | diffs[0], diffs[1], diffs[2], diffs[3]); |
| 223 | }); |
| 224 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 225 | CheckSolidPixels(expected, actual, tols, error); |
Robert Phillips | 27eb525 | 2019-06-03 12:59:40 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 228 | // What would raster do? |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 229 | static SkColor4f get_expected_color(SkColor4f orig, SkColorType ct) { |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 230 | SkAlphaType at = SkColorTypeIsAlwaysOpaque(ct) ? kOpaque_SkAlphaType |
| 231 | : kPremul_SkAlphaType; |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 232 | |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 233 | SkImageInfo ii = SkImageInfo::Make(2, 2, ct, at); |
| 234 | SkAutoPixmapStorage pm; |
| 235 | pm.alloc(ii); |
| 236 | pm.erase(orig); |
| 237 | SkColor tmp = pm.getColor(0, 0); |
| 238 | return SkColor4f::FromColor(tmp); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 239 | } |
| 240 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 241 | static void check_mipmaps(GrDirectContext*, const GrBackendTexture&, |
| 242 | SkColorType, const SkColor4f expectedColors[6], |
| 243 | skiatest::Reporter*, const char* label); |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 244 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 245 | static void check_base_readbacks(GrDirectContext* dContext, const GrBackendTexture& backendTex, |
Robert Phillips | 0ee1034 | 2019-09-25 09:55:16 -0400 | [diff] [blame] | 246 | SkColorType skColorType, GrRenderable renderable, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 247 | const SkColor4f& color, skiatest::Reporter* reporter, |
| 248 | const char* label) { |
| 249 | if (isRGB(backendTex.getBackendFormat())) { |
| 250 | // readPixels is busted for the RGB backend format (skbug.com/8862) |
| 251 | // TODO: add a GrColorType::kRGB_888 to fix the situation |
| 252 | return; |
| 253 | } |
Robert Phillips | 0ee1034 | 2019-09-25 09:55:16 -0400 | [diff] [blame] | 254 | |
| 255 | SkAlphaType at = SkColorTypeIsAlwaysOpaque(skColorType) ? kOpaque_SkAlphaType |
| 256 | : kPremul_SkAlphaType; |
| 257 | |
| 258 | SkColor4f expectedColor = get_expected_color(color, skColorType); |
| 259 | |
| 260 | SkAutoPixmapStorage actual; |
| 261 | |
| 262 | { |
| 263 | SkImageInfo readBackII = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 264 | kUnpremul_SkAlphaType); |
Robert Phillips | 0ee1034 | 2019-09-25 09:55:16 -0400 | [diff] [blame] | 265 | |
| 266 | SkAssertResult(actual.tryAlloc(readBackII)); |
| 267 | } |
| 268 | |
Robert Phillips | 0ee1034 | 2019-09-25 09:55:16 -0400 | [diff] [blame] | 269 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 270 | sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext, |
Robert Phillips | 0ee1034 | 2019-09-25 09:55:16 -0400 | [diff] [blame] | 271 | backendTex, |
| 272 | kTopLeft_GrSurfaceOrigin, |
| 273 | skColorType, |
| 274 | at, |
| 275 | nullptr); |
| 276 | if (img) { |
| 277 | actual.erase(SkColors::kTransparent); |
| 278 | bool result = img->readPixels(actual, 0, 0); |
| 279 | if (!result) { |
| 280 | // TODO: we need a better way to tell a priori if readPixels will work for an |
| 281 | // arbitrary colorType |
| 282 | #if 0 |
| 283 | ERRORF(reporter, "Couldn't readback from SkImage for colorType: %d\n", colorType); |
| 284 | #endif |
| 285 | } else { |
| 286 | check_solid_pixmap(reporter, expectedColor, actual, skColorType, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 287 | label, "SkImage::readPixels"); |
Robert Phillips | 0ee1034 | 2019-09-25 09:55:16 -0400 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | } |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 291 | |
| 292 | // This will mark any mipmaps as dirty (bc that is what we do when we wrap a renderable |
| 293 | // backend texture) so it must be done last! |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 294 | if (GrRenderable::kYes == renderable && dContext->colorTypeSupportedAsSurface(skColorType)) { |
| 295 | sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(dContext, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 296 | backendTex, |
| 297 | kTopLeft_GrSurfaceOrigin, |
| 298 | 0, |
| 299 | skColorType, |
| 300 | nullptr, nullptr); |
| 301 | if (surf) { |
| 302 | actual.erase(SkColors::kTransparent); |
| 303 | bool result = surf->readPixels(actual, 0, 0); |
| 304 | REPORTER_ASSERT(reporter, result); |
| 305 | |
| 306 | check_solid_pixmap(reporter, expectedColor, actual, skColorType, |
| 307 | label, "SkSurface::readPixels"); |
| 308 | } |
| 309 | } |
Robert Phillips | 0ee1034 | 2019-09-25 09:55:16 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 312 | // Test initialization of GrBackendObjects to a specific color (non-static since used in Mtl test) |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 313 | void test_color_init(GrDirectContext* dContext, |
| 314 | skiatest::Reporter* reporter, |
| 315 | std::function<GrBackendTexture (GrDirectContext*, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 316 | const SkColor4f&, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 317 | GrMipmapped, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 318 | GrRenderable)> create, |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 319 | GrColorType grColorType, |
| 320 | const SkColor4f& color, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 321 | GrMipmapped mipMapped, |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 322 | GrRenderable renderable, |
| 323 | bool* finishedBECreate) { |
| 324 | GrBackendTexture backendTex = create(dContext, color, mipMapped, renderable); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 325 | if (!backendTex.isValid()) { |
| 326 | // errors here should be reported by the test_wrapping test |
| 327 | return; |
| 328 | } |
| 329 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 330 | SkColorType skColorType = GrColorTypeToSkColorType(grColorType); |
| 331 | |
| 332 | // Can't wrap backend textures in images and surfaces w/o an SkColorType |
| 333 | if (kUnknown_SkColorType == skColorType) { |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 334 | // TODO: burrow in and scrappily check that data was uploaded! |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 335 | delete_backend_texture(dContext, backendTex, finishedBECreate); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 339 | auto checkBackendTexture = [&](const SkColor4f& testColor) { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 340 | if (mipMapped == GrMipmapped::kYes) { |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 341 | SkColor4f expectedColor = get_expected_color(testColor, skColorType); |
| 342 | SkColor4f expectedColors[6] = {expectedColor, expectedColor, expectedColor, |
| 343 | expectedColor, expectedColor, expectedColor}; |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 344 | check_mipmaps(dContext, backendTex, skColorType, expectedColors, |
| 345 | reporter, "colorinit"); |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 346 | } |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 347 | |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 348 | // The last step in this test will dirty the mipmaps so do it last |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 349 | check_base_readbacks(dContext, backendTex, skColorType, renderable, testColor, |
| 350 | reporter, "colorinit"); |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | checkBackendTexture(color); |
| 354 | |
| 355 | // Make sure the initial create work has finished so we can test the update independently. |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 356 | wait_on_backend_work_to_finish(dContext, finishedBECreate); |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 357 | |
| 358 | SkColor4f newColor = {color.fB , color.fR, color.fG, color.fA }; |
| 359 | |
| 360 | // Reupload the new data and make sure everything still works. We test with an SkColorType so |
| 361 | // we may actually swizzle the input during the create path. The update does not do any swizzle |
| 362 | // of the passed in color. So we manually do it here so we get the same expected results. |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 363 | SkColor4f swizzledColor = dContext->priv().caps()->getWriteSwizzle( |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 364 | backendTex.getBackendFormat(), grColorType).applyTo(newColor); |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 365 | dContext->updateBackendTexture(backendTex, swizzledColor, mark_signaled, finishedBECreate); |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 366 | |
| 367 | checkBackendTexture(newColor); |
| 368 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 369 | delete_backend_texture(dContext, backendTex, finishedBECreate); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 370 | } |
| 371 | |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 372 | // Draw the backend texture (wrapped in an SkImage) into an RGBA surface, attempting to access |
| 373 | // all the mipMap levels. |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 374 | static void check_mipmaps(GrDirectContext* dContext, const GrBackendTexture& backendTex, |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 375 | SkColorType skColorType, const SkColor4f expectedColors[6], |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 376 | skiatest::Reporter* reporter, const char* label) { |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 377 | |
| 378 | #ifdef SK_GL |
| 379 | // skbug.com/9141 (RGBA_F32 mipmaps appear to be broken on some Mali devices) |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 380 | if (GrBackendApi::kOpenGL == dContext->backend()) { |
| 381 | GrGLGpu* glGPU = static_cast<GrGLGpu*>(dContext->priv().getGpu()); |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 382 | |
| 383 | if (kRGBA_F32_SkColorType == skColorType && |
| 384 | kGLES_GrGLStandard == glGPU->ctxInfo().standard()) { |
| 385 | return; |
| 386 | } |
| 387 | } |
| 388 | #endif |
| 389 | |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 390 | if (isRGB(backendTex.getBackendFormat())) { |
| 391 | // readPixels is busted for the RGB backend format (skbug.com/8862) |
| 392 | // TODO: add a GrColorType::kRGB_888 to fix the situation |
| 393 | return; |
| 394 | } |
| 395 | |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 396 | SkAlphaType at = SkColorTypeIsAlwaysOpaque(skColorType) ? kOpaque_SkAlphaType |
| 397 | : kPremul_SkAlphaType; |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 398 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 399 | sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext, |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 400 | backendTex, |
| 401 | kTopLeft_GrSurfaceOrigin, |
| 402 | skColorType, |
| 403 | at, |
| 404 | nullptr); |
| 405 | if (!img) { |
| 406 | return; |
| 407 | } |
| 408 | |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 409 | SkImageInfo readbackSurfaceII = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType, |
| 410 | kPremul_SkAlphaType); |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 411 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 412 | sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(dContext, |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 413 | SkBudgeted::kNo, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 414 | readbackSurfaceII, 1, |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 415 | kTopLeft_GrSurfaceOrigin, |
| 416 | nullptr); |
| 417 | if (!surf) { |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | SkCanvas* canvas = surf->getCanvas(); |
| 422 | |
| 423 | SkPaint p; |
| 424 | p.setFilterQuality(kHigh_SkFilterQuality); |
| 425 | |
| 426 | int numMipLevels = 6; |
| 427 | |
| 428 | for (int i = 0, rectSize = 32; i < numMipLevels; ++i, rectSize /= 2) { |
| 429 | SkASSERT(rectSize >= 1); |
| 430 | |
| 431 | SkRect r = SkRect::MakeWH(rectSize, rectSize); |
| 432 | canvas->clear(SK_ColorTRANSPARENT); |
| 433 | canvas->drawImageRect(img, r, &p); |
| 434 | |
| 435 | SkImageInfo readbackII = SkImageInfo::Make(rectSize, rectSize, |
| 436 | kRGBA_8888_SkColorType, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 437 | kUnpremul_SkAlphaType); |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 438 | SkAutoPixmapStorage actual2; |
| 439 | SkAssertResult(actual2.tryAlloc(readbackII)); |
| 440 | actual2.erase(SkColors::kTransparent); |
| 441 | |
| 442 | bool result = surf->readPixels(actual2, 0, 0); |
| 443 | REPORTER_ASSERT(reporter, result); |
| 444 | |
Robert Phillips | ee94693 | 2019-12-18 11:16:17 -0500 | [diff] [blame] | 445 | SkString str; |
| 446 | str.appendf("mip-level %d", i); |
| 447 | |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 448 | check_solid_pixmap(reporter, expectedColors[i], actual2, skColorType, |
Robert Phillips | ee94693 | 2019-12-18 11:16:17 -0500 | [diff] [blame] | 449 | label, str.c_str()); |
Robert Phillips | c1dbb4b | 2019-09-24 16:32:35 -0400 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 453 | static int make_pixmaps(SkColorType skColorType, GrMipmapped mipMapped, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 454 | const SkColor4f colors[6], SkAutoPixmapStorage pixmaps[6]) { |
| 455 | int levelSize = 32; |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 456 | int numMipLevels = mipMapped == GrMipmapped::kYes ? 6 : 1; |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 457 | SkAlphaType at = SkColorTypeIsAlwaysOpaque(skColorType) ? kOpaque_SkAlphaType |
| 458 | : kPremul_SkAlphaType; |
| 459 | for (int level = 0; level < numMipLevels; ++level) { |
| 460 | SkImageInfo ii = SkImageInfo::Make(levelSize, levelSize, skColorType, at); |
| 461 | pixmaps[level].alloc(ii); |
| 462 | pixmaps[level].erase(colors[level]); |
| 463 | levelSize /= 2; |
| 464 | } |
| 465 | return numMipLevels; |
| 466 | } |
| 467 | |
| 468 | // Test initialization of GrBackendObjects using SkPixmaps |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 469 | static void test_pixmap_init(GrDirectContext* dContext, |
| 470 | skiatest::Reporter* reporter, |
| 471 | std::function<GrBackendTexture (GrDirectContext*, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 472 | const SkPixmap srcData[], |
| 473 | int numLevels, |
| 474 | GrRenderable)> create, |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 475 | SkColorType skColorType, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 476 | GrMipmapped mipMapped, |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 477 | GrRenderable renderable, |
| 478 | bool* finishedBECreate) { |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 479 | SkAutoPixmapStorage pixmapMem[6]; |
| 480 | SkColor4f colors[6] = { |
| 481 | { 1.0f, 0.0f, 0.0f, 1.0f }, // R |
| 482 | { 0.0f, 1.0f, 0.0f, 0.9f }, // G |
| 483 | { 0.0f, 0.0f, 1.0f, 0.7f }, // B |
| 484 | { 0.0f, 1.0f, 1.0f, 0.5f }, // C |
| 485 | { 1.0f, 0.0f, 1.0f, 0.3f }, // M |
| 486 | { 1.0f, 1.0f, 0.0f, 0.2f }, // Y |
| 487 | }; |
| 488 | |
| 489 | int numMipLevels = make_pixmaps(skColorType, mipMapped, colors, pixmapMem); |
| 490 | SkASSERT(numMipLevels); |
| 491 | |
| 492 | // TODO: this is tedious. Should we pass in an array of SkBitmaps instead? |
| 493 | SkPixmap pixmaps[6]; |
| 494 | for (int i = 0; i < numMipLevels; ++i) { |
| 495 | pixmaps[i].reset(pixmapMem[i].info(), pixmapMem[i].addr(), pixmapMem[i].rowBytes()); |
| 496 | } |
| 497 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 498 | GrBackendTexture backendTex = create(dContext, pixmaps, numMipLevels, renderable); |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 499 | if (!backendTex.isValid()) { |
| 500 | // errors here should be reported by the test_wrapping test |
| 501 | return; |
| 502 | } |
| 503 | |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 504 | if (skColorType == kBGRA_8888_SkColorType && !isBGRA8(backendTex.getBackendFormat())) { |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 505 | // When kBGRA is backed by an RGBA something goes wrong in the swizzling |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 506 | delete_backend_texture(dContext, backendTex, finishedBECreate); |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 507 | return; |
| 508 | } |
| 509 | |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 510 | auto checkBackendTexture = [&](SkColor4f colors[6]) { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 511 | if (mipMapped == GrMipmapped::kYes) { |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 512 | SkColor4f expectedColors[6] = { |
| 513 | get_expected_color(colors[0], skColorType), |
| 514 | get_expected_color(colors[1], skColorType), |
| 515 | get_expected_color(colors[2], skColorType), |
| 516 | get_expected_color(colors[3], skColorType), |
| 517 | get_expected_color(colors[4], skColorType), |
| 518 | get_expected_color(colors[5], skColorType), |
| 519 | }; |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 520 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 521 | check_mipmaps(dContext, backendTex, skColorType, expectedColors, reporter, "pixmap"); |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | // The last step in this test will dirty the mipmaps so do it last |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 525 | check_base_readbacks(dContext, backendTex, skColorType, renderable, colors[0], reporter, |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 526 | "pixmap"); |
| 527 | }; |
| 528 | |
| 529 | checkBackendTexture(colors); |
| 530 | |
| 531 | // Make sure the initial create work has finished so we can test the update independently. |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 532 | wait_on_backend_work_to_finish(dContext, finishedBECreate); |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 533 | |
| 534 | SkColor4f colorsNew[6] = { |
| 535 | {1.0f, 1.0f, 0.0f, 0.2f}, // Y |
| 536 | {1.0f, 0.0f, 0.0f, 1.0f}, // R |
| 537 | {0.0f, 1.0f, 0.0f, 0.9f}, // G |
| 538 | {0.0f, 0.0f, 1.0f, 0.7f}, // B |
| 539 | {0.0f, 1.0f, 1.0f, 0.5f}, // C |
| 540 | {1.0f, 0.0f, 1.0f, 0.3f}, // M |
| 541 | }; |
| 542 | make_pixmaps(skColorType, mipMapped, colorsNew, pixmapMem); |
| 543 | for (int i = 0; i < numMipLevels; ++i) { |
| 544 | pixmaps[i].reset(pixmapMem[i].info(), pixmapMem[i].addr(), pixmapMem[i].rowBytes()); |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 545 | } |
| 546 | |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 547 | // Upload new data and make sure everything still works |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 548 | dContext->updateBackendTexture(backendTex, pixmaps, numMipLevels, mark_signaled, |
| 549 | finishedBECreate); |
Greg Daniel | b2365d8 | 2020-05-13 15:32:04 -0400 | [diff] [blame] | 550 | |
| 551 | checkBackendTexture(colorsNew); |
| 552 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 553 | delete_backend_texture(dContext, backendTex, finishedBECreate); |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 556 | enum class VkLayout { |
| 557 | kUndefined, |
| 558 | kReadOnlyOptimal, |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 559 | }; |
| 560 | |
| 561 | void check_vk_layout(const GrBackendTexture& backendTex, VkLayout layout) { |
| 562 | #if defined(SK_VULKAN) && defined(SK_DEBUG) |
| 563 | VkImageLayout expected; |
| 564 | |
| 565 | switch (layout) { |
| 566 | case VkLayout::kUndefined: |
| 567 | expected = VK_IMAGE_LAYOUT_UNDEFINED; |
| 568 | break; |
| 569 | case VkLayout::kReadOnlyOptimal: |
| 570 | expected = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 571 | break; |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 572 | default: |
| 573 | SkUNREACHABLE; |
| 574 | } |
| 575 | |
| 576 | GrVkImageInfo vkII; |
| 577 | |
| 578 | if (backendTex.getVkImageInfo(&vkII)) { |
| 579 | SkASSERT(expected == vkII.fImageLayout); |
| 580 | SkASSERT(VK_IMAGE_TILING_OPTIMAL == vkII.fImageTiling); |
| 581 | } |
| 582 | #endif |
| 583 | } |
| 584 | |
| 585 | /////////////////////////////////////////////////////////////////////////////// |
| 586 | // This test is a bit different from the others in this file. It is mainly checking that, for any |
| 587 | // SkSurface we can create in Ganesh, we can also create a backend texture that is compatible with |
| 588 | // its characterization and then create a new surface that wraps that backend texture. |
| 589 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CharacterizationBackendAllocationTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 590 | auto context = ctxInfo.directContext(); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 591 | |
| 592 | for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { |
| 593 | SkColorType colorType = static_cast<SkColorType>(ct); |
| 594 | |
| 595 | SkImageInfo ii = SkImageInfo::Make(32, 32, colorType, kPremul_SkAlphaType); |
| 596 | |
| 597 | for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) { |
| 598 | for (bool mipMaps : { true, false } ) { |
| 599 | for (int sampleCount : {1, 2}) { |
| 600 | SkSurfaceCharacterization c; |
| 601 | |
| 602 | // Get a characterization, if possible |
| 603 | { |
| 604 | sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, |
| 605 | ii, sampleCount, |
| 606 | origin, nullptr, mipMaps); |
| 607 | if (!s) { |
| 608 | continue; |
| 609 | } |
| 610 | |
| 611 | if (!s->characterize(&c)) { |
| 612 | continue; |
| 613 | } |
| 614 | |
| 615 | REPORTER_ASSERT(reporter, s->isCompatible(c)); |
| 616 | } |
| 617 | |
| 618 | // Test out uninitialized path |
| 619 | { |
| 620 | GrBackendTexture backendTex = context->createBackendTexture(c); |
| 621 | check_vk_layout(backendTex, VkLayout::kUndefined); |
| 622 | REPORTER_ASSERT(reporter, backendTex.isValid()); |
| 623 | REPORTER_ASSERT(reporter, c.isCompatible(backendTex)); |
| 624 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 625 | { |
| 626 | GrBackendFormat format = context->defaultBackendFormat( |
| 627 | c.imageInfo().colorType(), |
| 628 | GrRenderable::kYes); |
| 629 | REPORTER_ASSERT(reporter, format == backendTex.getBackendFormat()); |
| 630 | } |
| 631 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 632 | sk_sp<SkSurface> s2 = SkSurface::MakeFromBackendTexture(context, c, |
| 633 | backendTex); |
| 634 | REPORTER_ASSERT(reporter, s2); |
| 635 | REPORTER_ASSERT(reporter, s2->isCompatible(c)); |
| 636 | |
| 637 | s2 = nullptr; |
| 638 | context->deleteBackendTexture(backendTex); |
| 639 | } |
| 640 | |
| 641 | // Test out color-initialized path |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 642 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 643 | { |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 644 | |
| 645 | bool finished = false; |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 646 | GrBackendTexture backendTex = context->createBackendTexture(c, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 647 | SkColors::kRed, |
| 648 | mark_signaled, |
| 649 | &finished); |
Greg Daniel | dddf709 | 2020-05-06 11:52:37 -0400 | [diff] [blame] | 650 | check_vk_layout(backendTex, VkLayout::kReadOnlyOptimal); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 651 | REPORTER_ASSERT(reporter, backendTex.isValid()); |
| 652 | REPORTER_ASSERT(reporter, c.isCompatible(backendTex)); |
| 653 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 654 | { |
| 655 | GrBackendFormat format = context->defaultBackendFormat( |
| 656 | c.imageInfo().colorType(), |
| 657 | GrRenderable::kYes); |
| 658 | REPORTER_ASSERT(reporter, format == backendTex.getBackendFormat()); |
| 659 | } |
| 660 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 661 | sk_sp<SkSurface> s2 = SkSurface::MakeFromBackendTexture(context, c, |
| 662 | backendTex); |
| 663 | REPORTER_ASSERT(reporter, s2); |
| 664 | REPORTER_ASSERT(reporter, s2->isCompatible(c)); |
| 665 | |
| 666 | s2 = nullptr; |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 667 | delete_backend_texture(context, backendTex, &finished); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 675 | /////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 676 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 677 | auto context = ctxInfo.directContext(); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 678 | const GrCaps* caps = context->priv().caps(); |
| 679 | |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 680 | constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f }; |
Robert Phillips | bd1ef68 | 2019-05-31 12:48:49 -0400 | [diff] [blame] | 681 | constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f }; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 682 | |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 683 | struct { |
| 684 | SkColorType fColorType; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 685 | SkColor4f fColor; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 686 | } combinations[] = { |
Robert Phillips | ea1b30b | 2019-09-19 16:05:48 -0400 | [diff] [blame] | 687 | { kAlpha_8_SkColorType, kTransCol }, |
| 688 | { kRGB_565_SkColorType, SkColors::kRed }, |
| 689 | { kARGB_4444_SkColorType, SkColors::kGreen }, |
| 690 | { kRGBA_8888_SkColorType, SkColors::kBlue }, |
| 691 | { kRGB_888x_SkColorType, SkColors::kCyan }, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 692 | // TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul) |
Robert Phillips | ea1b30b | 2019-09-19 16:05:48 -0400 | [diff] [blame] | 693 | { kBGRA_8888_SkColorType, { 1, 0, 0, 1.0f } }, |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 694 | // TODO: readback is busted for *10A2 when alpha = 0.5f (perhaps premul vs. unpremul) |
| 695 | { kRGBA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }}, |
| 696 | { kBGRA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }}, |
| 697 | // RGB/BGR 101010x have no Ganesh correlate |
Robert Phillips | ea1b30b | 2019-09-19 16:05:48 -0400 | [diff] [blame] | 698 | { kRGB_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } }, |
Mike Klein | f7eb054 | 2020-02-11 12:19:08 -0600 | [diff] [blame] | 699 | { kBGR_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } }, |
Robert Phillips | ea1b30b | 2019-09-19 16:05:48 -0400 | [diff] [blame] | 700 | { kGray_8_SkColorType, kGrayCol }, |
| 701 | { kRGBA_F16Norm_SkColorType, SkColors::kLtGray }, |
| 702 | { kRGBA_F16_SkColorType, SkColors::kYellow }, |
| 703 | { kRGBA_F32_SkColorType, SkColors::kGray }, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 704 | { kR8G8_unorm_SkColorType, { .25f, .75f, 0, 1 } }, |
Robert Phillips | ea1b30b | 2019-09-19 16:05:48 -0400 | [diff] [blame] | 705 | { kR16G16_unorm_SkColorType, SkColors::kGreen }, |
| 706 | { kA16_unorm_SkColorType, kTransCol }, |
| 707 | { kA16_float_SkColorType, kTransCol }, |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 708 | { kR16G16_float_SkColorType, { .25f, .75f, 0, 1 } }, |
Robert Phillips | ea1b30b | 2019-09-19 16:05:48 -0400 | [diff] [blame] | 709 | { kR16G16B16A16_unorm_SkColorType,{ .25f, .5f, .75f, 1 } }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 710 | }; |
| 711 | |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 712 | static_assert(kLastEnum_SkColorType == SK_ARRAY_COUNT(combinations)); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 713 | |
| 714 | for (auto combo : combinations) { |
| 715 | SkColorType colorType = combo.fColorType; |
| 716 | |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 717 | if (GrBackendApi::kMetal == context->backend()) { |
| 718 | // skbug.com/9086 (Metal caps may not be handling RGBA32 correctly) |
| 719 | if (kRGBA_F32_SkColorType == combo.fColorType) { |
| 720 | continue; |
| 721 | } |
| 722 | } |
| 723 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 724 | for (auto mipMapped : { GrMipmapped::kNo, GrMipmapped::kYes }) { |
| 725 | if (GrMipmapped::kYes == mipMapped && !caps->mipMapSupport()) { |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 726 | continue; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 727 | } |
| 728 | |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 729 | for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 730 | if (!caps->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType), |
| 731 | renderable).isValid()) { |
| 732 | continue; |
| 733 | } |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 734 | |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 735 | if (GrRenderable::kYes == renderable) { |
| 736 | if (kRGB_888x_SkColorType == combo.fColorType) { |
| 737 | // Ganesh can't perform the blends correctly when rendering this format |
| 738 | continue; |
| 739 | } |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 740 | } |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 741 | |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 742 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 743 | auto uninitCreateMtd = [colorType](GrDirectContext* dContext, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 744 | GrMipmapped mipMapped, |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 745 | GrRenderable renderable) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 746 | auto result = dContext->createBackendTexture(32, 32, colorType, |
| 747 | mipMapped, renderable, |
| 748 | GrProtected::kNo); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 749 | check_vk_layout(result, VkLayout::kUndefined); |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 750 | |
| 751 | #ifdef SK_DEBUG |
| 752 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 753 | GrBackendFormat format = dContext->defaultBackendFormat(colorType, |
| 754 | renderable); |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 755 | SkASSERT(format == result.getBackendFormat()); |
| 756 | } |
| 757 | #endif |
| 758 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 759 | return result; |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 760 | }; |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 761 | |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 762 | test_wrapping(context, reporter, uninitCreateMtd, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 763 | SkColorTypeToGrColorType(colorType), mipMapped, renderable, |
| 764 | nullptr); |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 765 | } |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 766 | |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 767 | bool finishedBackendCreation = false; |
| 768 | bool* finishedPtr = &finishedBackendCreation; |
| 769 | |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 770 | { |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 771 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 772 | auto createWithColorMtd = [colorType, finishedPtr](GrDirectContext* dContext, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 773 | const SkColor4f& color, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 774 | GrMipmapped mipMapped, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 775 | GrRenderable renderable) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 776 | auto result = dContext->createBackendTexture(32, 32, colorType, color, |
| 777 | mipMapped, renderable, |
| 778 | GrProtected::kNo, |
| 779 | mark_signaled, finishedPtr); |
Greg Daniel | dddf709 | 2020-05-06 11:52:37 -0400 | [diff] [blame] | 780 | check_vk_layout(result, VkLayout::kReadOnlyOptimal); |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 781 | |
| 782 | #ifdef SK_DEBUG |
| 783 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 784 | GrBackendFormat format = dContext->defaultBackendFormat(colorType, |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 785 | renderable); |
| 786 | SkASSERT(format == result.getBackendFormat()); |
| 787 | } |
| 788 | #endif |
| 789 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 790 | return result; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 791 | }; |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 792 | // We make our comparison color using SkPixmap::erase(color) on a pixmap of |
| 793 | // combo.fColorType and then calling SkPixmap::readPixels(). erase() will premul |
| 794 | // the color passed to it. However, createBackendTexture() that takes a |
| 795 | // SkColor4f is color type / alpha type unaware and will simply compute |
| 796 | // luminance from the r, g, b, channels. |
| 797 | SkColor4f color = combo.fColor; |
| 798 | if (colorType == kGray_8_SkColorType) { |
| 799 | color = {color.fR * color.fA, |
| 800 | color.fG * color.fA, |
| 801 | color.fB * color.fA, |
| 802 | 1.f}; |
| 803 | } |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 804 | test_color_init(context, reporter, createWithColorMtd, |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 805 | SkColorTypeToGrColorType(colorType), color, mipMapped, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 806 | renderable, finishedPtr); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 807 | } |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 808 | |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 809 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 810 | auto createWithSrcDataMtd = [finishedPtr](GrDirectContext* dContext, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 811 | const SkPixmap srcData[], |
| 812 | int numLevels, |
| 813 | GrRenderable renderable) { |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 814 | SkASSERT(srcData && numLevels); |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 815 | auto result = dContext->createBackendTexture(srcData, numLevels, renderable, |
| 816 | GrProtected::kNo, mark_signaled, |
| 817 | finishedPtr); |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 818 | check_vk_layout(result, VkLayout::kReadOnlyOptimal); |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 819 | #ifdef SK_DEBUG |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 820 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 821 | auto format = dContext->defaultBackendFormat(srcData[0].colorType(), |
| 822 | renderable); |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 823 | SkASSERT(format == result.getBackendFormat()); |
| 824 | } |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 825 | #endif |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 826 | return result; |
| 827 | }; |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 828 | |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 829 | test_pixmap_init(context, reporter, createWithSrcDataMtd, colorType, mipMapped, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 830 | renderable, finishedPtr); |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 831 | } |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 832 | } |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 833 | } |
| 834 | } |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 835 | } |
| 836 | |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 837 | /////////////////////////////////////////////////////////////////////////////// |
| 838 | #ifdef SK_GL |
| 839 | |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 840 | DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) { |
| 841 | sk_gpu_test::GLTestContext* glCtx = ctxInfo.glContext(); |
| 842 | GrGLStandard standard = glCtx->gl()->fStandard; |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 843 | auto context = ctxInfo.directContext(); |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 844 | const GrGLCaps* glCaps = static_cast<const GrGLCaps*>(context->priv().caps()); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 845 | |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 846 | constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f }; |
Robert Phillips | bd1ef68 | 2019-05-31 12:48:49 -0400 | [diff] [blame] | 847 | constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f }; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 848 | |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 849 | struct { |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 850 | GrColorType fColorType; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 851 | GrGLenum fFormat; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 852 | SkColor4f fColor; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 853 | } combinations[] = { |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 854 | { GrColorType::kRGBA_8888, GR_GL_RGBA8, SkColors::kRed }, |
| 855 | { GrColorType::kRGBA_8888_SRGB, GR_GL_SRGB8_ALPHA8, SkColors::kRed }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 856 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 857 | { GrColorType::kRGB_888x, GR_GL_RGBA8, SkColors::kYellow }, |
| 858 | { GrColorType::kRGB_888x, GR_GL_RGB8, SkColors::kCyan }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 859 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 860 | { GrColorType::kBGRA_8888, GR_GL_RGBA8, SkColors::kBlue }, |
| 861 | { GrColorType::kBGRA_8888, GR_GL_BGRA8, SkColors::kBlue }, |
| 862 | // TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul) |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 863 | { GrColorType::kRGBA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }}, |
| 864 | { GrColorType::kBGRA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }}, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 865 | { GrColorType::kBGR_565, GR_GL_RGB565, SkColors::kRed }, |
| 866 | { GrColorType::kABGR_4444, GR_GL_RGBA4, SkColors::kGreen }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 867 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 868 | { GrColorType::kAlpha_8, GR_GL_ALPHA8, kTransCol }, |
| 869 | { GrColorType::kAlpha_8, GR_GL_R8, kTransCol }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 870 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 871 | { GrColorType::kGray_8, GR_GL_LUMINANCE8, kGrayCol }, |
| 872 | { GrColorType::kGray_8, GR_GL_R8, kGrayCol }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 873 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 874 | { GrColorType::kRGBA_F32, GR_GL_RGBA32F, SkColors::kRed }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 875 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 876 | { GrColorType::kRGBA_F16_Clamped, GR_GL_RGBA16F, SkColors::kLtGray }, |
| 877 | { GrColorType::kRGBA_F16, GR_GL_RGBA16F, SkColors::kYellow }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 878 | |
Robert Phillips | d470e1b | 2019-09-04 15:05:35 -0400 | [diff] [blame] | 879 | { GrColorType::kRG_88, GR_GL_RG8, { 1, 0.5f, 0, 1 } }, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 880 | { GrColorType::kAlpha_F16, GR_GL_R16F, { 1.0f, 0, 0, 0.5f } }, |
| 881 | { GrColorType::kAlpha_F16, GR_GL_LUMINANCE16F, kGrayCol }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 882 | |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 883 | { GrColorType::kAlpha_16, GR_GL_R16, kTransCol }, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 884 | { GrColorType::kRG_1616, GR_GL_RG16, SkColors::kYellow }, |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 885 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 886 | { GrColorType::kRGBA_16161616, GR_GL_RGBA16, SkColors::kLtGray }, |
| 887 | { GrColorType::kRG_F16, GR_GL_RG16F, SkColors::kYellow }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 888 | }; |
| 889 | |
| 890 | for (auto combo : combinations) { |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 891 | for (GrGLenum target : {GR_GL_TEXTURE_2D, GR_GL_TEXTURE_RECTANGLE}) { |
| 892 | GrBackendFormat format = GrBackendFormat::MakeGL(combo.fFormat, target); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 893 | |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 894 | if (!glCaps->isFormatTexturable(format)) { |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 895 | continue; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 896 | } |
| 897 | |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 898 | if (GrColorType::kBGRA_8888 == combo.fColorType || |
| 899 | GrColorType::kBGRA_1010102 == combo.fColorType) { |
| 900 | // We allow using a GL_RGBA8 or GR_GL_RGB10_A2 texture as BGRA on desktop GL but not |
| 901 | // ES |
| 902 | if (kGL_GrGLStandard != standard && |
| 903 | (GR_GL_RGBA8 == combo.fFormat || GR_GL_RGB10_A2 == combo.fFormat)) { |
| 904 | continue; |
| 905 | } |
| 906 | } |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 907 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 908 | for (auto mipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { |
| 909 | if (GrMipmapped::kYes == mipMapped && |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 910 | (!glCaps->mipMapSupport() || target == GR_GL_TEXTURE_RECTANGLE)) { |
| 911 | continue; |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 912 | } |
| 913 | |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 914 | for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) { |
| 915 | if (GrRenderable::kYes == renderable) { |
| 916 | if (!glCaps->isFormatAsColorTypeRenderable(combo.fColorType, format)) { |
| 917 | continue; |
| 918 | } |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 919 | } |
| 920 | |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 921 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 922 | auto uninitCreateMtd = [format](GrDirectContext* dContext, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 923 | GrMipmapped mipMapped, |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 924 | GrRenderable renderable) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 925 | return dContext->createBackendTexture(32, 32, format, mipMapped, |
| 926 | renderable, GrProtected::kNo); |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 927 | }; |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 928 | |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 929 | test_wrapping(context, reporter, uninitCreateMtd, combo.fColorType, |
| 930 | mipMapped, renderable, nullptr); |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 931 | } |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 932 | |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 933 | { |
| 934 | // We're creating backend textures without specifying a color type "view" of |
| 935 | // them at the public API level. Therefore, Ganesh will not apply any |
| 936 | // swizzles before writing the color to the texture. However, our validation |
| 937 | // code does rely on interpreting the texture contents via a SkColorType and |
| 938 | // therefore swizzles may be applied during the read step. Ideally we'd |
| 939 | // update our validation code to use a "raw" read that doesn't impose a |
| 940 | // color type but for now we just munge the data we upload to match the |
| 941 | // expectation. |
| 942 | GrSwizzle swizzle; |
| 943 | switch (combo.fColorType) { |
| 944 | case GrColorType::kAlpha_8: |
| 945 | swizzle = GrSwizzle("aaaa"); |
| 946 | break; |
| 947 | case GrColorType::kAlpha_16: |
| 948 | swizzle = GrSwizzle("aaaa"); |
| 949 | break; |
| 950 | case GrColorType::kAlpha_F16: |
| 951 | swizzle = GrSwizzle("aaaa"); |
| 952 | break; |
| 953 | default: |
| 954 | break; |
| 955 | } |
| 956 | |
| 957 | bool finishedBackendCreation = false; |
| 958 | bool* finishedPtr = &finishedBackendCreation; |
| 959 | |
| 960 | auto createWithColorMtd = [format, swizzle, finishedPtr]( |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 961 | GrDirectContext* dContext, |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 962 | const SkColor4f& color, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 963 | GrMipmapped mipMapped, |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 964 | GrRenderable renderable) { |
| 965 | auto swizzledColor = swizzle.applyTo(color); |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 966 | return dContext->createBackendTexture( |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 967 | 32, 32, format, swizzledColor, mipMapped, renderable, |
| 968 | GrProtected::kNo, mark_signaled, finishedPtr); |
| 969 | }; |
| 970 | // We make our comparison color using SkPixmap::erase(color) on a pixmap of |
| 971 | // combo.fColorType and then calling SkPixmap::readPixels(). erase() will |
| 972 | // premul the color passed to it. However, createBackendTexture() that takes |
| 973 | // a SkColor4f is color type/alpha type unaware and will simply compute |
| 974 | // luminance from the r, g, b, channels. |
| 975 | SkColor4f color = combo.fColor; |
| 976 | if (combo.fColorType == GrColorType::kGray_8) { |
| 977 | color = {color.fR * color.fA, |
| 978 | color.fG * color.fA, |
| 979 | color.fB * color.fA, |
| 980 | 1.f}; |
| 981 | } |
| 982 | |
| 983 | test_color_init(context, reporter, createWithColorMtd, combo.fColorType, |
| 984 | color, mipMapped, renderable, finishedPtr); |
| 985 | } |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 986 | } |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 987 | } |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | } |
| 991 | |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 992 | #endif |
| 993 | |
| 994 | /////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 995 | |
| 996 | #ifdef SK_VULKAN |
| 997 | |
| 998 | #include "src/gpu/vk/GrVkCaps.h" |
| 999 | |
| 1000 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendAllocationTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 1001 | auto context = ctxInfo.directContext(); |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1002 | const GrVkCaps* vkCaps = static_cast<const GrVkCaps*>(context->priv().caps()); |
| 1003 | |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1004 | constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f }; |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame] | 1005 | constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 1 }; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1006 | |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1007 | struct { |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1008 | GrColorType fColorType; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1009 | VkFormat fFormat; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1010 | SkColor4f fColor; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1011 | } combinations[] = { |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1012 | { GrColorType::kRGBA_8888, VK_FORMAT_R8G8B8A8_UNORM, SkColors::kRed }, |
| 1013 | { GrColorType::kRGBA_8888_SRGB, VK_FORMAT_R8G8B8A8_SRGB, SkColors::kRed }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1014 | |
Robert Phillips | bd1ef68 | 2019-05-31 12:48:49 -0400 | [diff] [blame] | 1015 | // In this configuration (i.e., an RGB_888x colortype with an RGBA8 backing format), |
| 1016 | // there is nothing to tell Skia to make the provided color opaque. Clients will need |
| 1017 | // to provide an opaque initialization color in this case. |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1018 | { GrColorType::kRGB_888x, VK_FORMAT_R8G8B8A8_UNORM, SkColors::kYellow }, |
| 1019 | { GrColorType::kRGB_888x, VK_FORMAT_R8G8B8_UNORM, SkColors::kCyan }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1020 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1021 | { GrColorType::kBGRA_8888, VK_FORMAT_B8G8R8A8_UNORM, SkColors::kBlue }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1022 | |
Robert Phillips | 9a30ee0 | 2020-04-29 08:58:39 -0400 | [diff] [blame] | 1023 | { GrColorType::kRGBA_1010102, VK_FORMAT_A2B10G10R10_UNORM_PACK32, |
| 1024 | { 0.25f, 0.5f, 0.75f, 1.0f }}, |
| 1025 | { GrColorType::kBGRA_1010102, VK_FORMAT_A2R10G10B10_UNORM_PACK32, |
| 1026 | { 0.25f, 0.5f, 0.75f, 1.0f }}, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1027 | { GrColorType::kBGR_565, VK_FORMAT_R5G6B5_UNORM_PACK16, SkColors::kRed }, |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1028 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1029 | { GrColorType::kABGR_4444, VK_FORMAT_R4G4B4A4_UNORM_PACK16, SkColors::kCyan }, |
| 1030 | { GrColorType::kABGR_4444, VK_FORMAT_B4G4R4A4_UNORM_PACK16, SkColors::kYellow }, |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1031 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1032 | { GrColorType::kAlpha_8, VK_FORMAT_R8_UNORM, kTransCol }, |
Robert Phillips | bd1ef68 | 2019-05-31 12:48:49 -0400 | [diff] [blame] | 1033 | // In this config (i.e., a Gray8 color type with an R8 backing format), there is nothing |
| 1034 | // to tell Skia this isn't an Alpha8 color type (so it will initialize the texture with |
| 1035 | // the alpha channel of the color). Clients should, in general, fill all the channels |
| 1036 | // of the provided color with the same value in such cases. |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1037 | { GrColorType::kGray_8, VK_FORMAT_R8_UNORM, kGrayCol }, |
Robert Phillips | bd1ef68 | 2019-05-31 12:48:49 -0400 | [diff] [blame] | 1038 | |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1039 | { GrColorType::kRGBA_F16_Clamped, VK_FORMAT_R16G16B16A16_SFLOAT, SkColors::kLtGray }, |
| 1040 | { GrColorType::kRGBA_F16, VK_FORMAT_R16G16B16A16_SFLOAT, SkColors::kYellow }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1041 | |
Robert Phillips | d470e1b | 2019-09-04 15:05:35 -0400 | [diff] [blame] | 1042 | { GrColorType::kRG_88, VK_FORMAT_R8G8_UNORM, { 1, 0.5f, 0, 1 } }, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1043 | { GrColorType::kAlpha_F16, VK_FORMAT_R16_SFLOAT, { 1.0f, 0, 0, 0.5f }}, |
| 1044 | |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1045 | { GrColorType::kAlpha_16, VK_FORMAT_R16_UNORM, kTransCol }, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1046 | { GrColorType::kRG_1616, VK_FORMAT_R16G16_UNORM, SkColors::kYellow }, |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1047 | { GrColorType::kRGBA_16161616, VK_FORMAT_R16G16B16A16_UNORM, SkColors::kLtGray }, |
| 1048 | { GrColorType::kRG_F16, VK_FORMAT_R16G16_SFLOAT, SkColors::kYellow }, |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1049 | }; |
| 1050 | |
| 1051 | for (auto combo : combinations) { |
Greg Daniel | 2f2caea | 2019-07-08 14:24:47 -0400 | [diff] [blame] | 1052 | if (!vkCaps->isVkFormatTexturable(combo.fFormat)) { |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1053 | continue; |
| 1054 | } |
| 1055 | |
| 1056 | GrBackendFormat format = GrBackendFormat::MakeVk(combo.fFormat); |
| 1057 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 1058 | for (auto mipMapped : { GrMipmapped::kNo, GrMipmapped::kYes }) { |
| 1059 | if (GrMipmapped::kYes == mipMapped && !vkCaps->mipMapSupport()) { |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1060 | continue; |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1061 | } |
| 1062 | |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1063 | for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) { |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1064 | |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1065 | if (GrRenderable::kYes == renderable) { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 1066 | // We must also check whether we allow rendering to the format using the |
| 1067 | // color type. |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 1068 | if (!vkCaps->isFormatAsColorTypeRenderable( |
| 1069 | combo.fColorType, GrBackendFormat::MakeVk(combo.fFormat), 1)) { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 1070 | continue; |
| 1071 | } |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1072 | } |
| 1073 | |
Robert Phillips | d34691b | 2019-09-24 13:38:43 -0400 | [diff] [blame] | 1074 | { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 1075 | auto uninitCreateMtd = [format](GrDirectContext* dContext, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 1076 | GrMipmapped mipMapped, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1077 | GrRenderable renderable) { |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 1078 | GrBackendTexture beTex = dContext->createBackendTexture(32, 32, format, |
| 1079 | mipMapped, |
| 1080 | renderable, |
| 1081 | GrProtected::kNo); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 1082 | check_vk_layout(beTex, VkLayout::kUndefined); |
Robert Phillips | d1d869d | 2019-06-07 14:21:31 -0400 | [diff] [blame] | 1083 | return beTex; |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 1084 | }; |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1085 | |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 1086 | test_wrapping(context, reporter, uninitCreateMtd, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 1087 | combo.fColorType, mipMapped, renderable, nullptr); |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 1088 | } |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1089 | |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1090 | { |
Brian Salomon | b450f3b | 2019-07-09 09:36:51 -0400 | [diff] [blame] | 1091 | // We're creating backend textures without specifying a color type "view" of |
| 1092 | // them at the public API level. Therefore, Ganesh will not apply any swizzles |
| 1093 | // before writing the color to the texture. However, our validation code does |
| 1094 | // rely on interpreting the texture contents via a SkColorType and therefore |
| 1095 | // swizzles may be applied during the read step. |
| 1096 | // Ideally we'd update our validation code to use a "raw" read that doesn't |
| 1097 | // impose a color type but for now we just munge the data we upload to match the |
| 1098 | // expectation. |
| 1099 | GrSwizzle swizzle; |
| 1100 | switch (combo.fColorType) { |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1101 | case GrColorType::kAlpha_8: |
Brian Salomon | b450f3b | 2019-07-09 09:36:51 -0400 | [diff] [blame] | 1102 | SkASSERT(combo.fFormat == VK_FORMAT_R8_UNORM); |
| 1103 | swizzle = GrSwizzle("aaaa"); |
| 1104 | break; |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 1105 | case GrColorType::kAlpha_16: |
| 1106 | SkASSERT(combo.fFormat == VK_FORMAT_R16_UNORM); |
| 1107 | swizzle = GrSwizzle("aaaa"); |
| 1108 | break; |
Robert Phillips | 17a3a0b | 2019-09-18 13:56:54 -0400 | [diff] [blame] | 1109 | case GrColorType::kAlpha_F16: |
| 1110 | SkASSERT(combo.fFormat == VK_FORMAT_R16_SFLOAT); |
| 1111 | swizzle = GrSwizzle("aaaa"); |
| 1112 | break; |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 1113 | case GrColorType::kABGR_4444: |
Brian Salomon | b450f3b | 2019-07-09 09:36:51 -0400 | [diff] [blame] | 1114 | if (combo.fFormat == VK_FORMAT_B4G4R4A4_UNORM_PACK16) { |
| 1115 | swizzle = GrSwizzle("bgra"); |
| 1116 | } |
| 1117 | break; |
| 1118 | default: |
| 1119 | swizzle = GrSwizzle("rgba"); |
| 1120 | break; |
| 1121 | } |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 1122 | |
| 1123 | bool finishedBackendCreation = false; |
| 1124 | bool* finishedPtr = &finishedBackendCreation; |
| 1125 | |
| 1126 | auto createWithColorMtd = [format, swizzle, finishedPtr]( |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 1127 | GrDirectContext* dContext, |
| 1128 | const SkColor4f& color, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame^] | 1129 | GrMipmapped mipMapped, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 1130 | GrRenderable renderable) { |
Brian Salomon | b450f3b | 2019-07-09 09:36:51 -0400 | [diff] [blame] | 1131 | auto swizzledColor = swizzle.applyTo(color); |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 1132 | GrBackendTexture beTex = dContext->createBackendTexture(32, 32, format, |
| 1133 | swizzledColor, |
| 1134 | mipMapped, |
| 1135 | renderable, |
| 1136 | GrProtected::kNo, |
| 1137 | mark_signaled, |
| 1138 | finishedPtr); |
Greg Daniel | dddf709 | 2020-05-06 11:52:37 -0400 | [diff] [blame] | 1139 | check_vk_layout(beTex, VkLayout::kReadOnlyOptimal); |
Robert Phillips | d1d869d | 2019-06-07 14:21:31 -0400 | [diff] [blame] | 1140 | return beTex; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1141 | }; |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1142 | test_color_init(context, reporter, createWithColorMtd, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 1143 | combo.fColorType, combo.fColor, mipMapped, renderable, |
| 1144 | finishedPtr); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 1145 | } |
Robert Phillips | efb9f14 | 2019-05-17 14:19:44 -0400 | [diff] [blame] | 1146 | } |
Robert Phillips | 0c6daf0 | 2019-05-16 12:43:11 -0400 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | #endif |