blob: 71579892644b8ae3e9979c621394ee344e11bae2 [file] [log] [blame]
Robert Phillips0c6daf02019-05-16 12:43:11 -04001/*
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 Phillipse19babf2020-04-06 13:57:30 -04008#include "include/core/SkCanvas.h"
Mike Kleinfe0aeb32019-05-20 10:55:11 -05009#include "include/core/SkSurface.h"
Robert Phillips02dc0302019-07-02 17:58:27 -040010#include "include/core/SkSurfaceCharacterization.h"
Robert Phillips6d344c32020-07-06 10:56:46 -040011#include "include/gpu/GrDirectContext.h"
Robert Phillips459b2952019-05-23 09:38:27 -040012#include "src/core/SkAutoPixmapStorage.h"
Adlai Hollera0693042020-10-14 11:23:11 -040013#include "src/gpu/GrDirectContextPriv.h"
Brian Salomon04e3e502020-12-16 15:55:25 -050014#include "src/gpu/GrProxyProvider.h"
15#include "src/gpu/GrSurfaceFillContext.h"
16#include "src/gpu/effects/GrBlendFragmentProcessor.h"
17#include "src/gpu/effects/generated/GrConstColorProcessor.h"
Robert Phillipsefb9f142019-05-17 14:19:44 -040018#include "src/image/SkImage_Base.h"
Robert Phillips0c6daf02019-05-16 12:43:11 -040019#include "tests/Test.h"
Robert Phillipse3b6fe42019-09-11 11:26:46 -040020#include "tests/TestUtils.h"
21#include "tools/ToolUtils.h"
Brian Salomon20f1b342020-12-15 20:23:03 -050022#include "tools/gpu/ManagedBackendTexture.h"
Brian Salomone6662542021-02-23 10:45:39 -050023#include "tools/gpu/ProxyUtils.h"
Robert Phillips0c6daf02019-05-16 12:43:11 -040024
Robert Phillips27eb5252019-06-03 12:59:40 -040025#ifdef SK_GL
Robert Phillipsee946932019-12-18 11:16:17 -050026#include "src/gpu/gl/GrGLCaps.h"
27#include "src/gpu/gl/GrGLDefines.h"
Robert Phillips27eb5252019-06-03 12:59:40 -040028#include "src/gpu/gl/GrGLGpu.h"
29#include "src/gpu/gl/GrGLUtil.h"
30#endif
31
Robert Phillips7f367982019-09-26 14:01:36 -040032#ifdef SK_METAL
33#include "include/gpu/mtl/GrMtlTypes.h"
34#include "src/gpu/mtl/GrMtlCppUtil.h"
35#endif
36
Brian Salomon20f1b342020-12-15 20:23:03 -050037using sk_gpu_test::ManagedBackendTexture;
Greg Danielb2365d82020-05-13 15:32:04 -040038
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -040039// Test wrapping of GrBackendObjects in SkSurfaces and SkImages (non-static since used in Mtl test)
Robert Phillipsfe4b4812020-07-17 14:15:51 -040040void test_wrapping(GrDirectContext* dContext,
41 skiatest::Reporter* reporter,
Brian Salomon20f1b342020-12-15 20:23:03 -050042 std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
43 GrMipmapped,
44 GrRenderable)> create,
Robert Phillipsfe4b4812020-07-17 14:15:51 -040045 GrColorType grColorType,
Brian Salomon7e67dca2020-07-21 09:27:25 -040046 GrMipmapped mipMapped,
Brian Salomon20f1b342020-12-15 20:23:03 -050047 GrRenderable renderable) {
Robert Phillipsfe4b4812020-07-17 14:15:51 -040048 GrResourceCache* cache = dContext->priv().getResourceCache();
Robert Phillips0c6daf02019-05-16 12:43:11 -040049
50 const int initialCount = cache->getResourceCount();
51
Brian Salomon20f1b342020-12-15 20:23:03 -050052 sk_sp<ManagedBackendTexture> mbet = create(dContext, mipMapped, renderable);
53 if (!mbet) {
Robert Phillipsb7f95d12019-07-26 11:13:19 -040054 ERRORF(reporter, "Couldn't create backendTexture for grColorType %d renderable %s\n",
55 grColorType,
Robert Phillips0c6daf02019-05-16 12:43:11 -040056 GrRenderable::kYes == renderable ? "yes" : "no");
57 return;
58 }
Robert Phillipsb04b6942019-05-21 17:24:31 -040059
Robert Phillips0c6daf02019-05-16 12:43:11 -040060 // Skia proper should know nothing about the new backend object
61 REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
62
Robert Phillipsb7f95d12019-07-26 11:13:19 -040063 SkColorType skColorType = GrColorTypeToSkColorType(grColorType);
64
Brian Salomon04e3e502020-12-16 15:55:25 -050065 // Wrapping a backendTexture in an SkImage/SkSurface requires an SkColorType
66 if (skColorType == kUnknown_SkColorType) {
Robert Phillipsb04b6942019-05-21 17:24:31 -040067 return;
68 }
69
Robert Phillipsfe4b4812020-07-17 14:15:51 -040070 if (GrRenderable::kYes == renderable && dContext->colorTypeSupportedAsSurface(skColorType)) {
71 sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(dContext,
Brian Salomon20f1b342020-12-15 20:23:03 -050072 mbet->texture(),
Robert Phillips459b2952019-05-23 09:38:27 -040073 kTopLeft_GrSurfaceOrigin,
74 0,
Robert Phillipsb7f95d12019-07-26 11:13:19 -040075 skColorType,
Robert Phillips459b2952019-05-23 09:38:27 -040076 nullptr, nullptr);
Robert Phillipsb04b6942019-05-21 17:24:31 -040077 if (!surf) {
Brian Salomon04e3e502020-12-16 15:55:25 -050078 ERRORF(reporter, "Couldn't make SkSurface from backendTexture for %s\n",
Robert Phillips9a30ee02020-04-29 08:58:39 -040079 ToolUtils::colortype_name(skColorType));
Robert Phillipsb04b6942019-05-21 17:24:31 -040080 } else {
Greg Daniel3dc6c192021-03-05 10:01:53 -050081 // As we transition to using attachments instead of GrTextures and GrRenderTargets
82 // individual proxy instansiations may add multiple things to the cache. There would be
83 // an entry for the GrTexture/GrRenderTarget and entries for one or more attachments.
84 int cacheEntriesPerProxy = 1;
85 // We currently only have attachments on the vulkan backend
86 if (dContext->backend() == GrBackend::kVulkan) {
87 // If we ever make a rt with multisamples this would have an additional
88 // attachment as well.
89 cacheEntriesPerProxy++;
90 }
91 REPORTER_ASSERT(reporter,
92 initialCount + cacheEntriesPerProxy == cache->getResourceCount());
Robert Phillips0c6daf02019-05-16 12:43:11 -040093 }
Robert Phillipsb04b6942019-05-21 17:24:31 -040094 }
Robert Phillips0c6daf02019-05-16 12:43:11 -040095
Robert Phillipsb04b6942019-05-21 17:24:31 -040096 {
Robert Phillipsfe4b4812020-07-17 14:15:51 -040097 sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext,
Brian Salomon20f1b342020-12-15 20:23:03 -050098 mbet->texture(),
Robert Phillips459b2952019-05-23 09:38:27 -040099 kTopLeft_GrSurfaceOrigin,
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400100 skColorType,
Brian Salomon04e3e502020-12-16 15:55:25 -0500101 kUnpremul_SkAlphaType,
Robert Phillips459b2952019-05-23 09:38:27 -0400102 nullptr);
Robert Phillipsb04b6942019-05-21 17:24:31 -0400103 if (!img) {
Brian Salomon04e3e502020-12-16 15:55:25 -0500104 ERRORF(reporter, "Couldn't make SkImage from backendTexture for %s\n",
Robert Phillips9a30ee02020-04-29 08:58:39 -0400105 ToolUtils::colortype_name(skColorType));
Robert Phillipsb04b6942019-05-21 17:24:31 -0400106 } else {
Brian Salomone6662542021-02-23 10:45:39 -0500107 GrTextureProxy* proxy = sk_gpu_test::GetTextureImageProxy(img.get(), dContext);
Robert Phillipsb04b6942019-05-21 17:24:31 -0400108 REPORTER_ASSERT(reporter, proxy);
Robert Phillipsefb9f142019-05-17 14:19:44 -0400109
Brian Salomon8c82a872020-07-21 12:09:58 -0400110 REPORTER_ASSERT(reporter, mipMapped == proxy->proxyMipmapped());
Robert Phillipsb04b6942019-05-21 17:24:31 -0400111 REPORTER_ASSERT(reporter, proxy->isInstantiated());
Brian Salomon8c82a872020-07-21 12:09:58 -0400112 REPORTER_ASSERT(reporter, mipMapped == proxy->mipmapped());
Robert Phillipsefb9f142019-05-17 14:19:44 -0400113
Robert Phillipsb04b6942019-05-21 17:24:31 -0400114 REPORTER_ASSERT(reporter, initialCount+1 == cache->getResourceCount());
Robert Phillips0c6daf02019-05-16 12:43:11 -0400115 }
116 }
117
118 REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
Robert Phillips0c6daf02019-05-16 12:43:11 -0400119}
120
Robert Phillips9a30ee02020-04-29 08:58:39 -0400121static bool isBGRA8(const GrBackendFormat& format) {
Robert Phillips7f367982019-09-26 14:01:36 -0400122 switch (format.backend()) {
Robert Phillips7f367982019-09-26 14:01:36 -0400123 case GrBackendApi::kOpenGL:
124#ifdef SK_GL
125 return format.asGLFormat() == GrGLFormat::kBGRA8;
126#else
127 return false;
128#endif
129 case GrBackendApi::kVulkan: {
130#ifdef SK_VULKAN
131 VkFormat vkFormat;
132 format.asVkFormat(&vkFormat);
133 return vkFormat == VK_FORMAT_B8G8R8A8_UNORM;
134#else
135 return false;
136#endif
137 }
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500138 case GrBackendApi::kMetal:
139#ifdef SK_METAL
Robert Phillips9a30ee02020-04-29 08:58:39 -0400140 return GrMtlFormatIsBGRA8(format.asMtlFormat());
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500141#else
142 return false;
143#endif
144 case GrBackendApi::kDirect3D:
145#ifdef SK_DIRECT3D
146 return false; // TODO
147#else
148 return false;
149#endif
150 case GrBackendApi::kDawn:
Stephen White36248742020-06-10 22:24:57 -0400151#ifdef SK_DAWN
152 wgpu::TextureFormat dawnFormat;
153 format.asDawnFormat(&dawnFormat);
154 return dawnFormat == wgpu::TextureFormat::BGRA8Unorm;
155#else
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500156 return false;
Stephen White36248742020-06-10 22:24:57 -0400157#endif
Robert Phillipsa27d6252019-12-10 14:48:36 -0500158 case GrBackendApi::kMock: {
159 SkImage::CompressionType compression = format.asMockCompressionType();
160 if (compression != SkImage::CompressionType::kNone) {
161 return false; // No compressed formats are BGRA
162 }
163
Robert Phillips7f367982019-09-26 14:01:36 -0400164 return format.asMockColorType() == GrColorType::kBGRA_8888;
Robert Phillipsa27d6252019-12-10 14:48:36 -0500165 }
Robert Phillips7f367982019-09-26 14:01:36 -0400166 }
167 SkUNREACHABLE;
168}
169
170static bool isRGB(const GrBackendFormat& format) {
171 switch (format.backend()) {
Robert Phillips7f367982019-09-26 14:01:36 -0400172 case GrBackendApi::kOpenGL:
173#ifdef SK_GL
174 return format.asGLFormat() == GrGLFormat::kRGB8;
175#else
176 return false;
177#endif
178 case GrBackendApi::kVulkan: {
179#ifdef SK_VULKAN
180 VkFormat vkFormat;
181 format.asVkFormat(&vkFormat);
182 return vkFormat == VK_FORMAT_R8G8B8_UNORM;
183#else
184 return false;
185#endif
186 }
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500187 case GrBackendApi::kMetal:
188 return false; // Metal doesn't even pretend to support this
189 case GrBackendApi::kDirect3D:
190 return false; // Not supported in Direct3D 12
191 case GrBackendApi::kDawn:
192 return false;
Robert Phillips7f367982019-09-26 14:01:36 -0400193 case GrBackendApi::kMock:
194 return false; // No GrColorType::kRGB_888
195 }
196 SkUNREACHABLE;
197}
198
Robert Phillipse3b6fe42019-09-11 11:26:46 -0400199static void check_solid_pixmap(skiatest::Reporter* reporter,
Brian Salomon04e3e502020-12-16 15:55:25 -0500200 const SkColor4f& expected,
201 const SkPixmap& actual,
202 GrColorType ct,
203 const char* label1,
204 const char* label2) {
Robert Phillipse3b6fe42019-09-11 11:26:46 -0400205 // we need 0.001f across the board just for noise
206 // we need 0.01f across the board for 1010102
Robert Phillips7f367982019-09-26 14:01:36 -0400207 const float tols[4] = { 0.01f, 0.01f, 0.01f, 0.01f };
Robert Phillips27eb5252019-06-03 12:59:40 -0400208
Robert Phillipse3b6fe42019-09-11 11:26:46 -0400209 auto error = std::function<ComparePixmapsErrorReporter>(
Robert Phillips7f367982019-09-26 14:01:36 -0400210 [reporter, ct, label1, label2](int x, int y, const float diffs[4]) {
Robert Phillipse3b6fe42019-09-11 11:26:46 -0400211 SkASSERT(x >= 0 && y >= 0);
Brian Salomon04e3e502020-12-16 15:55:25 -0500212 ERRORF(reporter, "%s %s %s - mismatch at %d, %d (%f, %f, %f %f)", GrColorTypeToStr(ct),
213 label1, label2, x, y, diffs[0], diffs[1], diffs[2], diffs[3]);
Robert Phillipse3b6fe42019-09-11 11:26:46 -0400214 });
215
Brian Salomon28a8f282019-10-24 20:07:39 -0400216 CheckSolidPixels(expected, actual, tols, error);
Robert Phillips27eb5252019-06-03 12:59:40 -0400217}
218
Brian Salomon04e3e502020-12-16 15:55:25 -0500219// Determine what color we expect if we store 'orig' in 'ct' converted back to SkColor4f.
220static SkColor4f get_expected_color(SkColor4f orig, GrColorType ct) {
221 GrImageInfo ii(ct, kUnpremul_SkAlphaType, nullptr, {1, 1});
222 std::unique_ptr<char[]> data(new char[ii.minRowBytes()]);
223 GrClearImage(ii, data.get(), ii.minRowBytes(), orig);
Robert Phillipse3b6fe42019-09-11 11:26:46 -0400224
Brian Salomon04e3e502020-12-16 15:55:25 -0500225 // Read back to SkColor4f.
226 SkColor4f result;
227 GrImageInfo resultII(GrColorType::kRGBA_F32, kUnpremul_SkAlphaType, nullptr, {1, 1});
228 GrConvertPixels(resultII, &result.fR, sizeof(result), ii, data.get(), ii.minRowBytes());
229 return result;
Robert Phillips459b2952019-05-23 09:38:27 -0400230}
231
Brian Salomon04e3e502020-12-16 15:55:25 -0500232static void check_mipmaps(GrDirectContext*,
233 const GrBackendTexture&,
234 GrColorType,
235 const SkColor4f expectedColors[6],
236 skiatest::Reporter*,
237 const char* label);
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400238
Brian Salomon04e3e502020-12-16 15:55:25 -0500239static void check_base_readbacks(GrDirectContext* dContext,
240 const GrBackendTexture& backendTex,
241 GrColorType colorType,
242 GrRenderable renderableTexture,
243 const SkColor4f& color,
244 skiatest::Reporter* reporter,
Robert Phillips7f367982019-09-26 14:01:36 -0400245 const char* label) {
246 if (isRGB(backendTex.getBackendFormat())) {
247 // readPixels is busted for the RGB backend format (skbug.com/8862)
248 // TODO: add a GrColorType::kRGB_888 to fix the situation
249 return;
250 }
Robert Phillips0ee10342019-09-25 09:55:16 -0400251
Brian Salomon04e3e502020-12-16 15:55:25 -0500252 SkColor4f expectedColor = get_expected_color(color, colorType);
Robert Phillips0ee10342019-09-25 09:55:16 -0400253
254 SkAutoPixmapStorage actual;
255
256 {
Brian Salomon04e3e502020-12-16 15:55:25 -0500257 SkImageInfo readBackII = SkImageInfo::Make(32, 32,
258 kRGBA_8888_SkColorType,
Robert Phillips7f367982019-09-26 14:01:36 -0400259 kUnpremul_SkAlphaType);
Robert Phillips0ee10342019-09-25 09:55:16 -0400260
261 SkAssertResult(actual.tryAlloc(readBackII));
262 }
Brian Salomon04e3e502020-12-16 15:55:25 -0500263 for (GrRenderable renderableCtx : {GrRenderable::kNo, GrRenderable::kYes}) {
264 if (renderableCtx == GrRenderable::kYes && renderableTexture == GrRenderable::kNo) {
265 continue;
Brian Salomon0263bff2020-12-16 08:41:39 -0500266 }
Brian Salomon04e3e502020-12-16 15:55:25 -0500267 sk_sp<GrSurfaceProxy> proxy;
268 if (renderableCtx == GrRenderable::kYes) {
269 proxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture(
270 backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, nullptr);
271 } else {
272 proxy = dContext->priv().proxyProvider()->wrapBackendTexture(
273 backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
274 }
275 if (!proxy) {
276 ERRORF(reporter, "Could not make proxy from backend texture");
277 return;
278 }
279 auto swizzle = dContext->priv().caps()->getReadSwizzle(backendTex.getBackendFormat(),
280 colorType);
281 GrSurfaceProxyView readView(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
282 GrColorInfo info(colorType, kUnpremul_SkAlphaType, nullptr);
283 auto surfaceContext = GrSurfaceContext::Make(dContext, readView, info);
284 if (!surfaceContext) {
285 ERRORF(reporter, "Could not create surface context for colorType: %d\n", colorType);
286 }
Brian Salomon0263bff2020-12-16 08:41:39 -0500287
Brian Salomondd4087d2020-12-23 20:36:44 -0500288 if (!surfaceContext->readPixels(dContext, actual, {0, 0})) {
Brian Salomon04e3e502020-12-16 15:55:25 -0500289 // TODO: we need a better way to tell a priori if readPixels will work for an
290 // arbitrary colorType
291#if 0
292 ERRORF(reporter, "Couldn't readback from GrSurfaceContext for colorType: %d\n",
293 colorType);
294#endif
295 } else {
296 auto name = SkStringPrintf("%s::readPixels",
297 (renderableCtx == GrRenderable::kYes ? "GrSurfaceFillContext"
298 : "GrSurfaceContext"));
299 check_solid_pixmap(reporter, expectedColor, actual, colorType, label, name.c_str());
Robert Phillips7f367982019-09-26 14:01:36 -0400300 }
301 }
Robert Phillips0ee10342019-09-25 09:55:16 -0400302}
303
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400304// Test initialization of GrBackendObjects to a specific color (non-static since used in Mtl test)
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400305void test_color_init(GrDirectContext* dContext,
306 skiatest::Reporter* reporter,
Brian Salomon20f1b342020-12-15 20:23:03 -0500307 std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
308 const SkColor4f&,
309 GrMipmapped,
310 GrRenderable)> create,
Brian Salomon04e3e502020-12-16 15:55:25 -0500311 GrColorType colorType,
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400312 const SkColor4f& color,
Brian Salomon01ff5382020-12-15 16:06:26 -0500313 GrMipmapped mipmapped,
Brian Salomon20f1b342020-12-15 20:23:03 -0500314 GrRenderable renderable) {
Brian Salomon01ff5382020-12-15 16:06:26 -0500315 sk_sp<ManagedBackendTexture> mbet = create(dContext, color, mipmapped, renderable);
Brian Salomon20f1b342020-12-15 20:23:03 -0500316 if (!mbet) {
Robert Phillips459b2952019-05-23 09:38:27 -0400317 // errors here should be reported by the test_wrapping test
318 return;
319 }
320
Greg Danielb2365d82020-05-13 15:32:04 -0400321 auto checkBackendTexture = [&](const SkColor4f& testColor) {
Brian Salomon01ff5382020-12-15 16:06:26 -0500322 if (mipmapped == GrMipmapped::kYes) {
Brian Salomon04e3e502020-12-16 15:55:25 -0500323 SkColor4f expectedColor = get_expected_color(testColor, colorType);
Greg Danielb2365d82020-05-13 15:32:04 -0400324 SkColor4f expectedColors[6] = {expectedColor, expectedColor, expectedColor,
325 expectedColor, expectedColor, expectedColor};
Brian Salomon20f1b342020-12-15 20:23:03 -0500326 check_mipmaps(dContext, mbet->texture(), colorType, expectedColors, reporter,
327 "colorinit");
Greg Danielb2365d82020-05-13 15:32:04 -0400328 }
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400329
Greg Danielb2365d82020-05-13 15:32:04 -0400330 // The last step in this test will dirty the mipmaps so do it last
Brian Salomon20f1b342020-12-15 20:23:03 -0500331 check_base_readbacks(dContext, mbet->texture(), colorType, renderable, testColor, reporter,
Brian Salomon04e3e502020-12-16 15:55:25 -0500332 "colorinit");
Greg Danielb2365d82020-05-13 15:32:04 -0400333 };
334
335 checkBackendTexture(color);
336
Greg Danielb2365d82020-05-13 15:32:04 -0400337 SkColor4f newColor = {color.fB , color.fR, color.fG, color.fA };
338
Brian Salomon04e3e502020-12-16 15:55:25 -0500339 SkColorType skColorType = GrColorTypeToSkColorType(colorType);
Brian Salomon04e3e502020-12-16 15:55:25 -0500340 // Our update method only works with SkColorTypes.
341 if (skColorType != kUnknown_SkColorType) {
Brian Salomon20f1b342020-12-15 20:23:03 -0500342 dContext->updateBackendTexture(mbet->texture(),
343 skColorType,
344 newColor,
345 ManagedBackendTexture::ReleaseProc,
346 mbet->releaseContext());
Brian Salomon04e3e502020-12-16 15:55:25 -0500347 checkBackendTexture(newColor);
348 }
Robert Phillips459b2952019-05-23 09:38:27 -0400349}
350
Brian Salomon04e3e502020-12-16 15:55:25 -0500351// Draw the backend texture into an RGBA surface fill context, attempting to access all the mipMap
352// levels.
353static void check_mipmaps(GrDirectContext* dContext,
354 const GrBackendTexture& backendTex,
355 GrColorType colorType,
356 const SkColor4f expectedColors[6],
357 skiatest::Reporter* reporter,
358 const char* label) {
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400359#ifdef SK_GL
360 // skbug.com/9141 (RGBA_F32 mipmaps appear to be broken on some Mali devices)
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400361 if (GrBackendApi::kOpenGL == dContext->backend()) {
362 GrGLGpu* glGPU = static_cast<GrGLGpu*>(dContext->priv().getGpu());
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400363
Brian Salomon04e3e502020-12-16 15:55:25 -0500364 if (colorType == GrColorType::kRGBA_F32 &&
365 glGPU->ctxInfo().standard() == kGLES_GrGLStandard) {
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400366 return;
367 }
368 }
369#endif
370
Robert Phillips7f367982019-09-26 14:01:36 -0400371 if (isRGB(backendTex.getBackendFormat())) {
372 // readPixels is busted for the RGB backend format (skbug.com/8862)
373 // TODO: add a GrColorType::kRGB_888 to fix the situation
374 return;
375 }
376
Brian Salomon04e3e502020-12-16 15:55:25 -0500377 GrImageInfo info(GrColorType::kRGBA_8888, kUnpremul_SkAlphaType, nullptr, {32, 32});
378 auto dstFillContext = GrSurfaceFillContext::Make(dContext, info);
379 if (!dstFillContext) {
380 ERRORF(reporter, "Could not make dst fill context.");
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400381 return;
382 }
383
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400384 int numMipLevels = 6;
385
Brian Salomon04e3e502020-12-16 15:55:25 -0500386 auto proxy = dContext->priv().proxyProvider()->wrapBackendTexture(backendTex,
387 kBorrow_GrWrapOwnership,
388 GrWrapCacheable::kNo,
389 kRW_GrIOType);
390 if (!proxy) {
391 ERRORF(reporter, "Could not make proxy from backend texture");
392 return;
393 }
394 auto swizzle = dContext->priv().caps()->getReadSwizzle(backendTex.getBackendFormat(),
395 colorType);
396 GrSurfaceProxyView readView(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
397
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400398 for (int i = 0, rectSize = 32; i < numMipLevels; ++i, rectSize /= 2) {
399 SkASSERT(rectSize >= 1);
Brian Salomon04e3e502020-12-16 15:55:25 -0500400 dstFillContext->clear(SK_PMColor4fTRANSPARENT);
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400401
Brian Salomon04e3e502020-12-16 15:55:25 -0500402 SkMatrix texMatrix;
403 texMatrix.setScale(1 << i, 1 << i);
404 static constexpr GrSamplerState kNearestNearest(GrSamplerState::Filter::kNearest,
405 GrSamplerState::MipmapMode::kNearest);
406 auto fp = GrTextureEffect::Make(readView,
407 kUnpremul_SkAlphaType,
408 texMatrix,
409 kNearestNearest,
410 *dstFillContext->caps());
411 // Our swizzles for alpha color types currently produce (a, a, a, a) in the shader. Remove
412 // this once they are correctly (0, 0, 0, a).
413 if (GrColorTypeIsAlphaOnly(colorType)) {
414 auto black = GrConstColorProcessor::Make(SK_PMColor4fBLACK);
415 fp = GrBlendFragmentProcessor::Make(std::move(fp),
416 std::move(black),
417 SkBlendMode::kModulate);
418 }
419 dstFillContext->fillRectWithFP(SkIRect::MakeWH(rectSize, rectSize), std::move(fp));
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400420
421 SkImageInfo readbackII = SkImageInfo::Make(rectSize, rectSize,
422 kRGBA_8888_SkColorType,
Robert Phillips7f367982019-09-26 14:01:36 -0400423 kUnpremul_SkAlphaType);
Brian Salomon04e3e502020-12-16 15:55:25 -0500424 SkAutoPixmapStorage actual;
425 SkAssertResult(actual.tryAlloc(readbackII));
426 actual.erase(SkColors::kTransparent);
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400427
Brian Salomondd4087d2020-12-23 20:36:44 -0500428 bool result = dstFillContext->readPixels(dContext, actual, {0, 0});
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400429 REPORTER_ASSERT(reporter, result);
430
Robert Phillipsee946932019-12-18 11:16:17 -0500431 SkString str;
432 str.appendf("mip-level %d", i);
433
Brian Salomon04e3e502020-12-16 15:55:25 -0500434 check_solid_pixmap(reporter, expectedColors[i], actual, colorType, label, str.c_str());
Robert Phillipsc1dbb4b2019-09-24 16:32:35 -0400435 }
436}
437
Brian Salomon759217e2021-01-31 13:16:39 -0500438static int make_pixmaps(SkColorType skColorType,
439 GrMipmapped mipmapped,
440 const SkColor4f colors[6],
441 SkPixmap pixmaps[6],
442 std::unique_ptr<char[]>* mem) {
Robert Phillips7f367982019-09-26 14:01:36 -0400443 int levelSize = 32;
Brian Salomon759217e2021-01-31 13:16:39 -0500444 int numMipLevels = mipmapped == GrMipmapped::kYes ? 6 : 1;
445 size_t size = 0;
446 SkImageInfo ii[6];
447 size_t rowBytes[6];
Robert Phillips7f367982019-09-26 14:01:36 -0400448 for (int level = 0; level < numMipLevels; ++level) {
Brian Salomon759217e2021-01-31 13:16:39 -0500449 ii[level] = SkImageInfo::Make(levelSize, levelSize, skColorType, kUnpremul_SkAlphaType);
450 rowBytes[level] = ii[level].minRowBytes();
451 // Make sure we test row bytes that aren't tight.
452 if (!(level % 2)) {
453 rowBytes[level] += (level + 1)*SkColorTypeBytesPerPixel(ii[level].colorType());
454 }
455 size += rowBytes[level]*ii[level].height();
456 levelSize /= 2;
457 }
458 mem->reset(new char[size]);
459 char* addr = mem->get();
460 for (int level = 0; level < numMipLevels; ++level) {
461 pixmaps[level].reset(ii[level], addr, rowBytes[level]);
462 addr += rowBytes[level]*ii[level].height();
Robert Phillips7f367982019-09-26 14:01:36 -0400463 pixmaps[level].erase(colors[level]);
464 levelSize /= 2;
465 }
466 return numMipLevels;
467}
468
469// Test initialization of GrBackendObjects using SkPixmaps
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400470static void test_pixmap_init(GrDirectContext* dContext,
471 skiatest::Reporter* reporter,
Brian Salomon20f1b342020-12-15 20:23:03 -0500472 std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
473 const SkPixmap srcData[],
474 int numLevels,
475 GrSurfaceOrigin,
476 GrRenderable)> create,
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400477 SkColorType skColorType,
Brian Salomonb5f880a2020-12-07 11:30:16 -0500478 GrSurfaceOrigin origin,
Brian Salomon759217e2021-01-31 13:16:39 -0500479 GrMipmapped mipmapped,
Brian Salomon20f1b342020-12-15 20:23:03 -0500480 GrRenderable renderable) {
Brian Salomon759217e2021-01-31 13:16:39 -0500481 SkPixmap pixmaps[6];
482 std::unique_ptr<char[]> memForPixmaps;
Robert Phillips7f367982019-09-26 14:01:36 -0400483 SkColor4f colors[6] = {
484 { 1.0f, 0.0f, 0.0f, 1.0f }, // R
485 { 0.0f, 1.0f, 0.0f, 0.9f }, // G
486 { 0.0f, 0.0f, 1.0f, 0.7f }, // B
487 { 0.0f, 1.0f, 1.0f, 0.5f }, // C
488 { 1.0f, 0.0f, 1.0f, 0.3f }, // M
489 { 1.0f, 1.0f, 0.0f, 0.2f }, // Y
490 };
491
Brian Salomon759217e2021-01-31 13:16:39 -0500492 int numMipLevels = make_pixmaps(skColorType, mipmapped, colors, pixmaps, &memForPixmaps);
Robert Phillips7f367982019-09-26 14:01:36 -0400493 SkASSERT(numMipLevels);
494
Brian Salomon20f1b342020-12-15 20:23:03 -0500495 sk_sp<ManagedBackendTexture> mbet = create(dContext, pixmaps, numMipLevels, origin, renderable);
496 if (!mbet) {
Robert Phillips7f367982019-09-26 14:01:36 -0400497 // errors here should be reported by the test_wrapping test
498 return;
499 }
500
Brian Salomon20f1b342020-12-15 20:23:03 -0500501 if (skColorType == kBGRA_8888_SkColorType && !isBGRA8(mbet->texture().getBackendFormat())) {
Robert Phillips7f367982019-09-26 14:01:36 -0400502 // When kBGRA is backed by an RGBA something goes wrong in the swizzling
503 return;
504 }
505
Greg Danielb2365d82020-05-13 15:32:04 -0400506 auto checkBackendTexture = [&](SkColor4f colors[6]) {
Brian Salomon04e3e502020-12-16 15:55:25 -0500507 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
Brian Salomon759217e2021-01-31 13:16:39 -0500508 if (mipmapped == GrMipmapped::kYes) {
Greg Danielb2365d82020-05-13 15:32:04 -0400509 SkColor4f expectedColors[6] = {
Brian Salomon04e3e502020-12-16 15:55:25 -0500510 get_expected_color(colors[0], grColorType),
511 get_expected_color(colors[1], grColorType),
512 get_expected_color(colors[2], grColorType),
513 get_expected_color(colors[3], grColorType),
514 get_expected_color(colors[4], grColorType),
515 get_expected_color(colors[5], grColorType),
Greg Danielb2365d82020-05-13 15:32:04 -0400516 };
Robert Phillips7f367982019-09-26 14:01:36 -0400517
Brian Salomon20f1b342020-12-15 20:23:03 -0500518 check_mipmaps(dContext, mbet->texture(), grColorType, expectedColors, reporter,
519 "pixmap");
Greg Danielb2365d82020-05-13 15:32:04 -0400520 }
521
522 // The last step in this test will dirty the mipmaps so do it last
Brian Salomon20f1b342020-12-15 20:23:03 -0500523 check_base_readbacks(dContext, mbet->texture(), grColorType, renderable, colors[0],
524 reporter, "pixmap");
Greg Danielb2365d82020-05-13 15:32:04 -0400525 };
526
527 checkBackendTexture(colors);
528
Greg Danielb2365d82020-05-13 15:32:04 -0400529 SkColor4f colorsNew[6] = {
530 {1.0f, 1.0f, 0.0f, 0.2f}, // Y
531 {1.0f, 0.0f, 0.0f, 1.0f}, // R
532 {0.0f, 1.0f, 0.0f, 0.9f}, // G
533 {0.0f, 0.0f, 1.0f, 0.7f}, // B
534 {0.0f, 1.0f, 1.0f, 0.5f}, // C
535 {1.0f, 0.0f, 1.0f, 0.3f}, // M
536 };
Brian Salomon759217e2021-01-31 13:16:39 -0500537 make_pixmaps(skColorType, mipmapped, colorsNew, pixmaps, &memForPixmaps);
Robert Phillips7f367982019-09-26 14:01:36 -0400538
Greg Danielb2365d82020-05-13 15:32:04 -0400539 // Upload new data and make sure everything still works
Brian Salomon20f1b342020-12-15 20:23:03 -0500540 dContext->updateBackendTexture(mbet->texture(),
541 pixmaps,
542 numMipLevels,
543 origin,
544 ManagedBackendTexture::ReleaseProc,
545 mbet->releaseContext());
Greg Danielb2365d82020-05-13 15:32:04 -0400546
547 checkBackendTexture(colorsNew);
Robert Phillips7f367982019-09-26 14:01:36 -0400548}
549
Robert Phillips02dc0302019-07-02 17:58:27 -0400550enum class VkLayout {
551 kUndefined,
552 kReadOnlyOptimal,
Robert Phillips02dc0302019-07-02 17:58:27 -0400553};
554
555void check_vk_layout(const GrBackendTexture& backendTex, VkLayout layout) {
556#if defined(SK_VULKAN) && defined(SK_DEBUG)
557 VkImageLayout expected;
558
559 switch (layout) {
560 case VkLayout::kUndefined:
561 expected = VK_IMAGE_LAYOUT_UNDEFINED;
562 break;
563 case VkLayout::kReadOnlyOptimal:
564 expected = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
565 break;
Robert Phillips02dc0302019-07-02 17:58:27 -0400566 default:
567 SkUNREACHABLE;
568 }
569
570 GrVkImageInfo vkII;
571
572 if (backendTex.getVkImageInfo(&vkII)) {
573 SkASSERT(expected == vkII.fImageLayout);
574 SkASSERT(VK_IMAGE_TILING_OPTIMAL == vkII.fImageTiling);
575 }
576#endif
577}
578
579///////////////////////////////////////////////////////////////////////////////
Brian Salomon759217e2021-01-31 13:16:39 -0500580void color_type_backend_allocation_test(const sk_gpu_test::ContextInfo& ctxInfo,
581 skiatest::Reporter* reporter) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400582 auto context = ctxInfo.directContext();
Robert Phillips0c6daf02019-05-16 12:43:11 -0400583 const GrCaps* caps = context->priv().caps();
584
Robert Phillips459b2952019-05-23 09:38:27 -0400585 constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
Robert Phillipsbd1ef682019-05-31 12:48:49 -0400586 constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f };
Robert Phillips459b2952019-05-23 09:38:27 -0400587
Robert Phillips0c6daf02019-05-16 12:43:11 -0400588 struct {
589 SkColorType fColorType;
Robert Phillips459b2952019-05-23 09:38:27 -0400590 SkColor4f fColor;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400591 } combinations[] = {
Robert Phillipsea1b30b2019-09-19 16:05:48 -0400592 { kAlpha_8_SkColorType, kTransCol },
593 { kRGB_565_SkColorType, SkColors::kRed },
594 { kARGB_4444_SkColorType, SkColors::kGreen },
595 { kRGBA_8888_SkColorType, SkColors::kBlue },
596 { kRGB_888x_SkColorType, SkColors::kCyan },
Robert Phillips459b2952019-05-23 09:38:27 -0400597 // TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
Robert Phillipsea1b30b2019-09-19 16:05:48 -0400598 { kBGRA_8888_SkColorType, { 1, 0, 0, 1.0f } },
Robert Phillips9a30ee02020-04-29 08:58:39 -0400599 // TODO: readback is busted for *10A2 when alpha = 0.5f (perhaps premul vs. unpremul)
600 { kRGBA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
601 { kBGRA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
602 // RGB/BGR 101010x have no Ganesh correlate
Robert Phillipsea1b30b2019-09-19 16:05:48 -0400603 { kRGB_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
Mike Kleinf7eb0542020-02-11 12:19:08 -0600604 { kBGR_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
Robert Phillipsea1b30b2019-09-19 16:05:48 -0400605 { kGray_8_SkColorType, kGrayCol },
606 { kRGBA_F16Norm_SkColorType, SkColors::kLtGray },
607 { kRGBA_F16_SkColorType, SkColors::kYellow },
608 { kRGBA_F32_SkColorType, SkColors::kGray },
Robert Phillips7f367982019-09-26 14:01:36 -0400609 { kR8G8_unorm_SkColorType, { .25f, .75f, 0, 1 } },
Robert Phillipsea1b30b2019-09-19 16:05:48 -0400610 { kR16G16_unorm_SkColorType, SkColors::kGreen },
611 { kA16_unorm_SkColorType, kTransCol },
612 { kA16_float_SkColorType, kTransCol },
Robert Phillips7f367982019-09-26 14:01:36 -0400613 { kR16G16_float_SkColorType, { .25f, .75f, 0, 1 } },
Robert Phillipsea1b30b2019-09-19 16:05:48 -0400614 { kR16G16B16A16_unorm_SkColorType,{ .25f, .5f, .75f, 1 } },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400615 };
616
Brian Salomon4dea72a2019-12-18 10:43:10 -0500617 static_assert(kLastEnum_SkColorType == SK_ARRAY_COUNT(combinations));
Robert Phillips0c6daf02019-05-16 12:43:11 -0400618
619 for (auto combo : combinations) {
620 SkColorType colorType = combo.fColorType;
621
Robert Phillips0c6daf02019-05-16 12:43:11 -0400622 if (GrBackendApi::kMetal == context->backend()) {
623 // skbug.com/9086 (Metal caps may not be handling RGBA32 correctly)
624 if (kRGBA_F32_SkColorType == combo.fColorType) {
625 continue;
626 }
627 }
628
Brian Salomon04e3e502020-12-16 15:55:25 -0500629 for (auto mipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
630 if (GrMipmapped::kYes == mipmapped && !caps->mipmapSupport()) {
Robert Phillipsefb9f142019-05-17 14:19:44 -0400631 continue;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400632 }
633
Robert Phillipsefb9f142019-05-17 14:19:44 -0400634 for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
Greg Daniel7bfc9132019-08-14 14:23:53 -0400635 if (!caps->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType),
636 renderable).isValid()) {
637 continue;
638 }
Robert Phillips7f367982019-09-26 14:01:36 -0400639
Robert Phillipsefb9f142019-05-17 14:19:44 -0400640 if (GrRenderable::kYes == renderable) {
641 if (kRGB_888x_SkColorType == combo.fColorType) {
642 // Ganesh can't perform the blends correctly when rendering this format
643 continue;
644 }
Robert Phillipsefb9f142019-05-17 14:19:44 -0400645 }
Robert Phillips0c6daf02019-05-16 12:43:11 -0400646
Robert Phillipsb04b6942019-05-21 17:24:31 -0400647 {
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400648 auto uninitCreateMtd = [colorType](GrDirectContext* dContext,
Brian Salomon04e3e502020-12-16 15:55:25 -0500649 GrMipmapped mipmapped,
Robert Phillipsb04b6942019-05-21 17:24:31 -0400650 GrRenderable renderable) {
Brian Salomon20f1b342020-12-15 20:23:03 -0500651 auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
652 32, 32,
653 colorType,
654 mipmapped,
655 renderable,
656 GrProtected::kNo);
657 check_vk_layout(mbet->texture(), VkLayout::kUndefined);
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400658#ifdef SK_DEBUG
659 {
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400660 GrBackendFormat format = dContext->defaultBackendFormat(colorType,
661 renderable);
Brian Salomon20f1b342020-12-15 20:23:03 -0500662 SkASSERT(format == mbet->texture().getBackendFormat());
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400663 }
664#endif
665
Brian Salomon20f1b342020-12-15 20:23:03 -0500666 return mbet;
Robert Phillipsb04b6942019-05-21 17:24:31 -0400667 };
Robert Phillipsefb9f142019-05-17 14:19:44 -0400668
Robert Phillipsb04b6942019-05-21 17:24:31 -0400669 test_wrapping(context, reporter, uninitCreateMtd,
Brian Salomon20f1b342020-12-15 20:23:03 -0500670 SkColorTypeToGrColorType(colorType), mipmapped, renderable);
Robert Phillipsb04b6942019-05-21 17:24:31 -0400671 }
Robert Phillips459b2952019-05-23 09:38:27 -0400672
673 {
Brian Salomon20f1b342020-12-15 20:23:03 -0500674 auto createWithColorMtd = [colorType](GrDirectContext* dContext,
675 const SkColor4f& color,
676 GrMipmapped mipmapped,
677 GrRenderable renderable) {
678 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
679 32, 32,
680 colorType,
681 color,
682 mipmapped,
683 renderable,
684 GrProtected::kNo);
685 check_vk_layout(mbet->texture(), VkLayout::kReadOnlyOptimal);
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400686
687#ifdef SK_DEBUG
688 {
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400689 GrBackendFormat format = dContext->defaultBackendFormat(colorType,
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400690 renderable);
Brian Salomon20f1b342020-12-15 20:23:03 -0500691 SkASSERT(format == mbet->texture().getBackendFormat());
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400692 }
693#endif
694
Brian Salomon20f1b342020-12-15 20:23:03 -0500695 return mbet;
Robert Phillips459b2952019-05-23 09:38:27 -0400696 };
Robert Phillips459b2952019-05-23 09:38:27 -0400697 test_color_init(context, reporter, createWithColorMtd,
Brian Salomon04e3e502020-12-16 15:55:25 -0500698 SkColorTypeToGrColorType(colorType), combo.fColor, mipmapped,
Brian Salomon20f1b342020-12-15 20:23:03 -0500699 renderable);
Robert Phillips459b2952019-05-23 09:38:27 -0400700 }
Robert Phillips7f367982019-09-26 14:01:36 -0400701
Brian Salomonb5f880a2020-12-07 11:30:16 -0500702 for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
Brian Salomon20f1b342020-12-15 20:23:03 -0500703 auto createWithSrcDataMtd = [](GrDirectContext* dContext,
704 const SkPixmap srcData[],
705 int numLevels,
706 GrSurfaceOrigin origin,
707 GrRenderable renderable) {
Robert Phillips9a30ee02020-04-29 08:58:39 -0400708 SkASSERT(srcData && numLevels);
Brian Salomon20f1b342020-12-15 20:23:03 -0500709 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
710 srcData,
711 numLevels,
712 origin,
713 renderable,
714 GrProtected::kNo);
715 check_vk_layout(mbet->texture(), VkLayout::kReadOnlyOptimal);
Robert Phillips7f367982019-09-26 14:01:36 -0400716#ifdef SK_DEBUG
Robert Phillips9a30ee02020-04-29 08:58:39 -0400717 {
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400718 auto format = dContext->defaultBackendFormat(srcData[0].colorType(),
719 renderable);
Brian Salomon20f1b342020-12-15 20:23:03 -0500720 SkASSERT(format == mbet->texture().getBackendFormat());
Robert Phillips9a30ee02020-04-29 08:58:39 -0400721 }
Robert Phillips7f367982019-09-26 14:01:36 -0400722#endif
Brian Salomon20f1b342020-12-15 20:23:03 -0500723 return mbet;
Robert Phillips9a30ee02020-04-29 08:58:39 -0400724 };
Robert Phillips7f367982019-09-26 14:01:36 -0400725
Brian Salomonb5f880a2020-12-07 11:30:16 -0500726 test_pixmap_init(context,
727 reporter,
728 createWithSrcDataMtd,
729 colorType,
730 origin,
Brian Salomon04e3e502020-12-16 15:55:25 -0500731 mipmapped,
Brian Salomon20f1b342020-12-15 20:23:03 -0500732 renderable);
Robert Phillips9a30ee02020-04-29 08:58:39 -0400733 }
Robert Phillipsefb9f142019-05-17 14:19:44 -0400734 }
Robert Phillips0c6daf02019-05-16 12:43:11 -0400735 }
736 }
Robert Phillips0c6daf02019-05-16 12:43:11 -0400737}
738
Brian Salomon759217e2021-01-31 13:16:39 -0500739DEF_GPUTEST(ColorTypeBackendAllocationTest, reporter, options) {
740 for (int t = 0; t < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++t) {
741 auto type = static_cast<sk_gpu_test::GrContextFactory::ContextType>(t);
742 if (!sk_gpu_test::GrContextFactory::IsRenderingContext(type)) {
743 continue;
744 }
745 sk_gpu_test::GrContextFactory factory(options);
746 sk_gpu_test::ContextInfo info = factory.getContextInfo(type);
747 if (!info.directContext()) {
748 continue;
749 }
750 color_type_backend_allocation_test(info, reporter);
751 // The GL backend must support contexts that don't allow GL_UNPACK_ROW_LENGTH. Other
752 // backends are not required to work with this cap disabled.
753 if (info.directContext()->priv().caps()->writePixelsRowBytesSupport() &&
754 info.directContext()->backend() == GrBackendApi::kOpenGL) {
755 GrContextOptions overrideOptions = options;
756 overrideOptions.fDisallowWritePixelRowBytes = true;
757 sk_gpu_test::GrContextFactory overrideFactory(overrideOptions);
758 info = overrideFactory.getContextInfo(type);
759 color_type_backend_allocation_test(info, reporter);
760 }
761 }
762}
763
Robert Phillipsefb9f142019-05-17 14:19:44 -0400764///////////////////////////////////////////////////////////////////////////////
765#ifdef SK_GL
766
Robert Phillips0c6daf02019-05-16 12:43:11 -0400767DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) {
768 sk_gpu_test::GLTestContext* glCtx = ctxInfo.glContext();
769 GrGLStandard standard = glCtx->gl()->fStandard;
Robert Phillips6d344c32020-07-06 10:56:46 -0400770 auto context = ctxInfo.directContext();
Robert Phillipsefb9f142019-05-17 14:19:44 -0400771 const GrGLCaps* glCaps = static_cast<const GrGLCaps*>(context->priv().caps());
Robert Phillips0c6daf02019-05-16 12:43:11 -0400772
Brian Salomon01ff5382020-12-15 16:06:26 -0500773 constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
774 constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 1.f };
775 constexpr SkColor4f kTransGrayCol { 0.5f, 0.5f, 0.5f, .8f };
Robert Phillips459b2952019-05-23 09:38:27 -0400776
Robert Phillips0c6daf02019-05-16 12:43:11 -0400777 struct {
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400778 GrColorType fColorType;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400779 GrGLenum fFormat;
Robert Phillips459b2952019-05-23 09:38:27 -0400780 SkColor4f fColor;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400781 } combinations[] = {
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400782 { GrColorType::kRGBA_8888, GR_GL_RGBA8, SkColors::kRed },
783 { GrColorType::kRGBA_8888_SRGB, GR_GL_SRGB8_ALPHA8, SkColors::kRed },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400784
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400785 { GrColorType::kRGB_888x, GR_GL_RGBA8, SkColors::kYellow },
786 { GrColorType::kRGB_888x, GR_GL_RGB8, SkColors::kCyan },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400787
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400788 { GrColorType::kBGRA_8888, GR_GL_RGBA8, SkColors::kBlue },
789 { GrColorType::kBGRA_8888, GR_GL_BGRA8, SkColors::kBlue },
790 // TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
Robert Phillips9a30ee02020-04-29 08:58:39 -0400791 { GrColorType::kRGBA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }},
792 { GrColorType::kBGRA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }},
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400793 { GrColorType::kBGR_565, GR_GL_RGB565, SkColors::kRed },
794 { GrColorType::kABGR_4444, GR_GL_RGBA4, SkColors::kGreen },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400795
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400796 { GrColorType::kAlpha_8, GR_GL_ALPHA8, kTransCol },
797 { GrColorType::kAlpha_8, GR_GL_R8, kTransCol },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400798
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400799 { GrColorType::kGray_8, GR_GL_LUMINANCE8, kGrayCol },
800 { GrColorType::kGray_8, GR_GL_R8, kGrayCol },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400801
Brian Salomon01ff5382020-12-15 16:06:26 -0500802 { GrColorType::kGrayAlpha_88, GR_GL_LUMINANCE8_ALPHA8, kTransGrayCol },
803
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400804 { GrColorType::kRGBA_F32, GR_GL_RGBA32F, SkColors::kRed },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400805
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400806 { GrColorType::kRGBA_F16_Clamped, GR_GL_RGBA16F, SkColors::kLtGray },
807 { GrColorType::kRGBA_F16, GR_GL_RGBA16F, SkColors::kYellow },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400808
Robert Phillipsd470e1b2019-09-04 15:05:35 -0400809 { GrColorType::kRG_88, GR_GL_RG8, { 1, 0.5f, 0, 1 } },
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400810 { GrColorType::kAlpha_F16, GR_GL_R16F, { 1.0f, 0, 0, 0.5f } },
811 { GrColorType::kAlpha_F16, GR_GL_LUMINANCE16F, kGrayCol },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400812
Robert Phillips429f0d32019-09-11 17:03:28 -0400813 { GrColorType::kAlpha_16, GR_GL_R16, kTransCol },
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400814 { GrColorType::kRG_1616, GR_GL_RG16, SkColors::kYellow },
Robert Phillips66a46032019-06-18 08:00:42 -0400815
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400816 { GrColorType::kRGBA_16161616, GR_GL_RGBA16, SkColors::kLtGray },
817 { GrColorType::kRG_F16, GR_GL_RG16F, SkColors::kYellow },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400818 };
819
820 for (auto combo : combinations) {
Brian Salomon0f396992020-06-19 19:51:21 -0400821 for (GrGLenum target : {GR_GL_TEXTURE_2D, GR_GL_TEXTURE_RECTANGLE}) {
822 GrBackendFormat format = GrBackendFormat::MakeGL(combo.fFormat, target);
Robert Phillips0c6daf02019-05-16 12:43:11 -0400823
Brian Salomon0f396992020-06-19 19:51:21 -0400824 if (!glCaps->isFormatTexturable(format)) {
Robert Phillipsefb9f142019-05-17 14:19:44 -0400825 continue;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400826 }
827
Brian Salomon0f396992020-06-19 19:51:21 -0400828 if (GrColorType::kBGRA_8888 == combo.fColorType ||
829 GrColorType::kBGRA_1010102 == combo.fColorType) {
830 // We allow using a GL_RGBA8 or GR_GL_RGB10_A2 texture as BGRA on desktop GL but not
831 // ES
832 if (kGL_GrGLStandard != standard &&
833 (GR_GL_RGBA8 == combo.fFormat || GR_GL_RGB10_A2 == combo.fFormat)) {
834 continue;
835 }
836 }
Robert Phillips0c6daf02019-05-16 12:43:11 -0400837
Brian Salomon7e67dca2020-07-21 09:27:25 -0400838 for (auto mipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
839 if (GrMipmapped::kYes == mipMapped &&
Brian Salomon69100f02020-07-21 10:49:25 -0400840 (!glCaps->mipmapSupport() || target == GR_GL_TEXTURE_RECTANGLE)) {
Brian Salomon0f396992020-06-19 19:51:21 -0400841 continue;
Robert Phillipsefb9f142019-05-17 14:19:44 -0400842 }
843
Brian Salomon0f396992020-06-19 19:51:21 -0400844 for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
845 if (GrRenderable::kYes == renderable) {
846 if (!glCaps->isFormatAsColorTypeRenderable(combo.fColorType, format)) {
847 continue;
848 }
Robert Phillips459b2952019-05-23 09:38:27 -0400849 }
850
Brian Salomon0f396992020-06-19 19:51:21 -0400851 {
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400852 auto uninitCreateMtd = [format](GrDirectContext* dContext,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400853 GrMipmapped mipMapped,
Brian Salomon0f396992020-06-19 19:51:21 -0400854 GrRenderable renderable) {
Brian Salomon20f1b342020-12-15 20:23:03 -0500855 return ManagedBackendTexture::MakeWithoutData(dContext,
856 32, 32,
857 format,
858 mipMapped,
859 renderable,
860 GrProtected::kNo);
Brian Salomon0f396992020-06-19 19:51:21 -0400861 };
Greg Danielc1ad77c2020-05-06 11:40:03 -0400862
Brian Salomon0f396992020-06-19 19:51:21 -0400863 test_wrapping(context, reporter, uninitCreateMtd, combo.fColorType,
Brian Salomon20f1b342020-12-15 20:23:03 -0500864 mipMapped, renderable);
Brian Salomon85c3d682019-11-04 15:04:54 -0500865 }
Robert Phillips459b2952019-05-23 09:38:27 -0400866
Brian Salomon0f396992020-06-19 19:51:21 -0400867 {
868 // We're creating backend textures without specifying a color type "view" of
869 // them at the public API level. Therefore, Ganesh will not apply any
870 // swizzles before writing the color to the texture. However, our validation
871 // code does rely on interpreting the texture contents via a SkColorType and
872 // therefore swizzles may be applied during the read step. Ideally we'd
873 // update our validation code to use a "raw" read that doesn't impose a
874 // color type but for now we just munge the data we upload to match the
875 // expectation.
876 GrSwizzle swizzle;
877 switch (combo.fColorType) {
878 case GrColorType::kAlpha_8:
879 swizzle = GrSwizzle("aaaa");
880 break;
881 case GrColorType::kAlpha_16:
882 swizzle = GrSwizzle("aaaa");
883 break;
884 case GrColorType::kAlpha_F16:
885 swizzle = GrSwizzle("aaaa");
886 break;
887 default:
888 break;
889 }
Brian Salomon20f1b342020-12-15 20:23:03 -0500890 auto createWithColorMtd = [format, swizzle](GrDirectContext* dContext,
891 const SkColor4f& color,
892 GrMipmapped mipmapped,
893 GrRenderable renderable) {
Brian Salomon0f396992020-06-19 19:51:21 -0400894 auto swizzledColor = swizzle.applyTo(color);
Brian Salomon20f1b342020-12-15 20:23:03 -0500895 return ManagedBackendTexture::MakeWithData(dContext,
896 32, 32,
897 format,
898 swizzledColor,
899 mipmapped,
900 renderable,
901 GrProtected::kNo);
Brian Salomon0f396992020-06-19 19:51:21 -0400902 };
Brian Salomon0f396992020-06-19 19:51:21 -0400903 test_color_init(context, reporter, createWithColorMtd, combo.fColorType,
Brian Salomon20f1b342020-12-15 20:23:03 -0500904 combo.fColor, mipMapped, renderable);
Brian Salomon0f396992020-06-19 19:51:21 -0400905 }
Robert Phillips459b2952019-05-23 09:38:27 -0400906 }
Robert Phillipsefb9f142019-05-17 14:19:44 -0400907 }
Robert Phillips0c6daf02019-05-16 12:43:11 -0400908 }
909 }
910}
911
Robert Phillipsefb9f142019-05-17 14:19:44 -0400912#endif
913
914///////////////////////////////////////////////////////////////////////////////
Robert Phillips0c6daf02019-05-16 12:43:11 -0400915
916#ifdef SK_VULKAN
917
918#include "src/gpu/vk/GrVkCaps.h"
919
920DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendAllocationTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400921 auto context = ctxInfo.directContext();
Robert Phillips0c6daf02019-05-16 12:43:11 -0400922 const GrVkCaps* vkCaps = static_cast<const GrVkCaps*>(context->priv().caps());
923
Robert Phillips459b2952019-05-23 09:38:27 -0400924 constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
Robert Phillips7f367982019-09-26 14:01:36 -0400925 constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 1 };
Robert Phillips459b2952019-05-23 09:38:27 -0400926
Robert Phillips0c6daf02019-05-16 12:43:11 -0400927 struct {
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400928 GrColorType fColorType;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400929 VkFormat fFormat;
Robert Phillips459b2952019-05-23 09:38:27 -0400930 SkColor4f fColor;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400931 } combinations[] = {
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400932 { GrColorType::kRGBA_8888, VK_FORMAT_R8G8B8A8_UNORM, SkColors::kRed },
933 { GrColorType::kRGBA_8888_SRGB, VK_FORMAT_R8G8B8A8_SRGB, SkColors::kRed },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400934
Robert Phillipsbd1ef682019-05-31 12:48:49 -0400935 // In this configuration (i.e., an RGB_888x colortype with an RGBA8 backing format),
936 // there is nothing to tell Skia to make the provided color opaque. Clients will need
937 // to provide an opaque initialization color in this case.
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400938 { GrColorType::kRGB_888x, VK_FORMAT_R8G8B8A8_UNORM, SkColors::kYellow },
939 { GrColorType::kRGB_888x, VK_FORMAT_R8G8B8_UNORM, SkColors::kCyan },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400940
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400941 { GrColorType::kBGRA_8888, VK_FORMAT_B8G8R8A8_UNORM, SkColors::kBlue },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400942
Robert Phillips9a30ee02020-04-29 08:58:39 -0400943 { GrColorType::kRGBA_1010102, VK_FORMAT_A2B10G10R10_UNORM_PACK32,
944 { 0.25f, 0.5f, 0.75f, 1.0f }},
945 { GrColorType::kBGRA_1010102, VK_FORMAT_A2R10G10B10_UNORM_PACK32,
946 { 0.25f, 0.5f, 0.75f, 1.0f }},
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400947 { GrColorType::kBGR_565, VK_FORMAT_R5G6B5_UNORM_PACK16, SkColors::kRed },
Robert Phillipsefb9f142019-05-17 14:19:44 -0400948
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400949 { GrColorType::kABGR_4444, VK_FORMAT_R4G4B4A4_UNORM_PACK16, SkColors::kCyan },
950 { GrColorType::kABGR_4444, VK_FORMAT_B4G4R4A4_UNORM_PACK16, SkColors::kYellow },
Robert Phillipsefb9f142019-05-17 14:19:44 -0400951
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400952 { GrColorType::kAlpha_8, VK_FORMAT_R8_UNORM, kTransCol },
Robert Phillipsbd1ef682019-05-31 12:48:49 -0400953 // In this config (i.e., a Gray8 color type with an R8 backing format), there is nothing
954 // to tell Skia this isn't an Alpha8 color type (so it will initialize the texture with
955 // the alpha channel of the color). Clients should, in general, fill all the channels
956 // of the provided color with the same value in such cases.
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400957 { GrColorType::kGray_8, VK_FORMAT_R8_UNORM, kGrayCol },
Robert Phillipsbd1ef682019-05-31 12:48:49 -0400958
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400959 { GrColorType::kRGBA_F16_Clamped, VK_FORMAT_R16G16B16A16_SFLOAT, SkColors::kLtGray },
960 { GrColorType::kRGBA_F16, VK_FORMAT_R16G16B16A16_SFLOAT, SkColors::kYellow },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400961
Robert Phillipsd470e1b2019-09-04 15:05:35 -0400962 { GrColorType::kRG_88, VK_FORMAT_R8G8_UNORM, { 1, 0.5f, 0, 1 } },
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400963 { GrColorType::kAlpha_F16, VK_FORMAT_R16_SFLOAT, { 1.0f, 0, 0, 0.5f }},
964
Robert Phillips429f0d32019-09-11 17:03:28 -0400965 { GrColorType::kAlpha_16, VK_FORMAT_R16_UNORM, kTransCol },
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400966 { GrColorType::kRG_1616, VK_FORMAT_R16G16_UNORM, SkColors::kYellow },
Robert Phillipsb7f95d12019-07-26 11:13:19 -0400967 { GrColorType::kRGBA_16161616, VK_FORMAT_R16G16B16A16_UNORM, SkColors::kLtGray },
968 { GrColorType::kRG_F16, VK_FORMAT_R16G16_SFLOAT, SkColors::kYellow },
Robert Phillips0c6daf02019-05-16 12:43:11 -0400969 };
970
971 for (auto combo : combinations) {
Greg Daniel2f2caea2019-07-08 14:24:47 -0400972 if (!vkCaps->isVkFormatTexturable(combo.fFormat)) {
Robert Phillips0c6daf02019-05-16 12:43:11 -0400973 continue;
974 }
975
976 GrBackendFormat format = GrBackendFormat::MakeVk(combo.fFormat);
977
Brian Salomon7e67dca2020-07-21 09:27:25 -0400978 for (auto mipMapped : { GrMipmapped::kNo, GrMipmapped::kYes }) {
Brian Salomon69100f02020-07-21 10:49:25 -0400979 if (GrMipmapped::kYes == mipMapped && !vkCaps->mipmapSupport()) {
Robert Phillipsefb9f142019-05-17 14:19:44 -0400980 continue;
Robert Phillips0c6daf02019-05-16 12:43:11 -0400981 }
982
Robert Phillipsefb9f142019-05-17 14:19:44 -0400983 for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
Robert Phillips0c6daf02019-05-16 12:43:11 -0400984
Robert Phillipsefb9f142019-05-17 14:19:44 -0400985 if (GrRenderable::kYes == renderable) {
Brian Salomon4eb38b72019-08-05 12:58:39 -0400986 // We must also check whether we allow rendering to the format using the
987 // color type.
Greg Daniel900583a2019-08-06 12:05:31 -0400988 if (!vkCaps->isFormatAsColorTypeRenderable(
989 combo.fColorType, GrBackendFormat::MakeVk(combo.fFormat), 1)) {
Brian Salomon4eb38b72019-08-05 12:58:39 -0400990 continue;
991 }
Robert Phillipsefb9f142019-05-17 14:19:44 -0400992 }
993
Robert Phillipsd34691b2019-09-24 13:38:43 -0400994 {
Robert Phillipsfe4b4812020-07-17 14:15:51 -0400995 auto uninitCreateMtd = [format](GrDirectContext* dContext,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400996 GrMipmapped mipMapped,
Robert Phillips459b2952019-05-23 09:38:27 -0400997 GrRenderable renderable) {
Brian Salomon20f1b342020-12-15 20:23:03 -0500998 auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
999 32, 32,
1000 format,
1001 mipMapped,
1002 renderable,
1003 GrProtected::kNo);
1004 check_vk_layout(mbet->texture(), VkLayout::kUndefined);
1005 return mbet;
Robert Phillipsb04b6942019-05-21 17:24:31 -04001006 };
Robert Phillipsefb9f142019-05-17 14:19:44 -04001007
Brian Salomon20f1b342020-12-15 20:23:03 -05001008 test_wrapping(context, reporter, uninitCreateMtd, combo.fColorType, mipMapped,
1009 renderable);
Robert Phillipsb04b6942019-05-21 17:24:31 -04001010 }
Robert Phillips459b2952019-05-23 09:38:27 -04001011
Robert Phillips459b2952019-05-23 09:38:27 -04001012 {
Brian Salomonb450f3b2019-07-09 09:36:51 -04001013 // We're creating backend textures without specifying a color type "view" of
1014 // them at the public API level. Therefore, Ganesh will not apply any swizzles
1015 // before writing the color to the texture. However, our validation code does
1016 // rely on interpreting the texture contents via a SkColorType and therefore
1017 // swizzles may be applied during the read step.
1018 // Ideally we'd update our validation code to use a "raw" read that doesn't
1019 // impose a color type but for now we just munge the data we upload to match the
1020 // expectation.
1021 GrSwizzle swizzle;
1022 switch (combo.fColorType) {
Robert Phillipsb7f95d12019-07-26 11:13:19 -04001023 case GrColorType::kAlpha_8:
Brian Salomonb450f3b2019-07-09 09:36:51 -04001024 SkASSERT(combo.fFormat == VK_FORMAT_R8_UNORM);
1025 swizzle = GrSwizzle("aaaa");
1026 break;
Robert Phillips429f0d32019-09-11 17:03:28 -04001027 case GrColorType::kAlpha_16:
1028 SkASSERT(combo.fFormat == VK_FORMAT_R16_UNORM);
1029 swizzle = GrSwizzle("aaaa");
1030 break;
Robert Phillips17a3a0b2019-09-18 13:56:54 -04001031 case GrColorType::kAlpha_F16:
1032 SkASSERT(combo.fFormat == VK_FORMAT_R16_SFLOAT);
1033 swizzle = GrSwizzle("aaaa");
1034 break;
Robert Phillipsb7f95d12019-07-26 11:13:19 -04001035 case GrColorType::kABGR_4444:
Brian Salomonb450f3b2019-07-09 09:36:51 -04001036 if (combo.fFormat == VK_FORMAT_B4G4R4A4_UNORM_PACK16) {
1037 swizzle = GrSwizzle("bgra");
1038 }
1039 break;
1040 default:
1041 swizzle = GrSwizzle("rgba");
1042 break;
1043 }
Greg Danielc1ad77c2020-05-06 11:40:03 -04001044
Brian Salomon20f1b342020-12-15 20:23:03 -05001045 auto createWithColorMtd = [format, swizzle](GrDirectContext* dContext,
1046 const SkColor4f& color,
1047 GrMipmapped mipMapped,
1048 GrRenderable renderable) {
Brian Salomonb450f3b2019-07-09 09:36:51 -04001049 auto swizzledColor = swizzle.applyTo(color);
Brian Salomon20f1b342020-12-15 20:23:03 -05001050 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
1051 32, 32,
1052 format,
1053 swizzledColor,
1054 mipMapped,
1055 renderable,
1056 GrProtected::kNo);
1057 check_vk_layout(mbet->texture(), VkLayout::kReadOnlyOptimal);
1058 return mbet;
Robert Phillips459b2952019-05-23 09:38:27 -04001059 };
Brian Salomon20f1b342020-12-15 20:23:03 -05001060 test_color_init(context, reporter, createWithColorMtd, combo.fColorType,
1061 combo.fColor, mipMapped, renderable);
Robert Phillips459b2952019-05-23 09:38:27 -04001062 }
Robert Phillipsefb9f142019-05-17 14:19:44 -04001063 }
Robert Phillips0c6daf02019-05-16 12:43:11 -04001064 }
1065 }
1066}
1067
1068#endif