xref: /aosp_15_r20/external/skia/tests/TransferPixelsTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2017 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 
8 // This is a GPU-backend specific test. It relies on static initializers to work
9 
10 #include "include/core/SkAlphaType.h"
11 #include "include/core/SkColorSpace.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkSize.h"
15 #include "include/core/SkTypes.h"
16 #include "include/gpu/GpuTypes.h"
17 #include "include/gpu/ganesh/GrBackendSurface.h"
18 #include "include/gpu/ganesh/GrDirectContext.h"
19 #include "include/gpu/ganesh/GrTypes.h"
20 #include "include/private/base/SkAlign.h"
21 #include "include/private/gpu/ganesh/GrTypesPriv.h"
22 #include "src/gpu/ganesh/GrCaps.h"
23 #include "src/gpu/ganesh/GrColor.h"
24 #include "src/gpu/ganesh/GrDataUtils.h"
25 #include "src/gpu/ganesh/GrDirectContextPriv.h"
26 #include "src/gpu/ganesh/GrGpu.h"
27 #include "src/gpu/ganesh/GrGpuBuffer.h"
28 #include "src/gpu/ganesh/GrImageInfo.h"
29 #include "src/gpu/ganesh/GrPixmap.h"
30 #include "src/gpu/ganesh/GrResourceProvider.h"
31 #include "src/gpu/ganesh/GrTexture.h"
32 #include "src/gpu/ganesh/GrUtil.h"
33 #include "tests/CtsEnforcement.h"
34 #include "tests/Test.h"
35 #include "tests/TestUtils.h"
36 
37 #include <algorithm>
38 #include <cstdint>
39 #include <cstring>
40 #include <functional>
41 #include <initializer_list>
42 #include <memory>
43 
44 struct GrContextOptions;
45 
46 using sk_gpu_test::GrContextFactory;
47 
fill_transfer_data(int left,int top,int width,int height,int rowBytes,GrColorType dstType,char * dst)48 void fill_transfer_data(int left, int top, int width, int height, int rowBytes,
49                         GrColorType dstType, char* dst) {
50     size_t dstBpp = GrColorTypeBytesPerPixel(dstType);
51     auto dstLocation = [dst, dstBpp, rowBytes](int x, int y) {
52         return dst + y * rowBytes + x * dstBpp;
53     };
54     // build red-green gradient
55     for (int j = top; j < top + height; ++j) {
56         for (int i = left; i < left + width; ++i) {
57             auto r = (unsigned int)(256.f*((i - left) / (float)width));
58             auto g = (unsigned int)(256.f*((j - top) / (float)height));
59             r -= (r >> 8);
60             g -= (g >> 8);
61             // set b and a channels to be inverse of r and g just to have interesting values to
62             // test.
63             uint32_t srcPixel = GrColorPackRGBA(r, g, 0xff - r, 0xff - g);
64             GrImageInfo srcInfo(GrColorType::kRGBA_8888, kUnpremul_SkAlphaType, nullptr, 1, 1);
65             GrImageInfo dstInfo(dstType, kUnpremul_SkAlphaType, nullptr, 1, 1);
66             GrConvertPixels(GrPixmap(dstInfo, dstLocation(i, j), dstBpp),
67                             GrPixmap(srcInfo,         &srcPixel,      4));
68         }
69     }
70 }
71 
determine_tolerances(GrColorType a,GrColorType b,float tolerances[4])72 void determine_tolerances(GrColorType a, GrColorType b, float tolerances[4]) {
73     std::fill_n(tolerances, 4, 0);
74 
75     auto descA = GrGetColorTypeDesc(a);
76     auto descB = GrGetColorTypeDesc(b);
77     // For each channel x set the tolerance to 1 / (2^min(bits_in_a, bits_in_b) - 1) unless
78     // one color type is missing the channel. In that case leave it at 0. If the other color
79     // has the channel then it better be exactly 1 for alpha or 0 for rgb.
80     for (int i = 0; i < 4; ++i) {
81         if (descA[i] != descB[i]) {
82             auto m = std::min(descA[i], descB[i]);
83             if (m) {
84                 tolerances[i] = 1.f / (m - 1);
85             }
86         }
87     }
88 }
89 
read_pixels_from_texture(GrTexture * texture,GrColorType colorType,char * dst,float tolerances[4])90 bool read_pixels_from_texture(GrTexture* texture, GrColorType colorType, char* dst,
91                               float tolerances[4]) {
92     auto* context = texture->getContext();
93     auto* gpu = context->priv().getGpu();
94     auto* caps = context->priv().caps();
95 
96     int w = texture->width();
97     int h = texture->height();
98     size_t rowBytes = GrColorTypeBytesPerPixel(colorType) * w;
99 
100     GrCaps::SupportedRead supportedRead =
101             caps->supportedReadPixelsColorType(colorType, texture->backendFormat(), colorType);
102     std::fill_n(tolerances, 4, 0);
103     if (supportedRead.fColorType != colorType) {
104         size_t tmpRowBytes = GrColorTypeBytesPerPixel(supportedRead.fColorType) * w;
105         std::unique_ptr<char[]> tmpPixels(new char[tmpRowBytes * h]);
106         if (!gpu->readPixels(texture,
107                              SkIRect::MakeWH(w, h),
108                              colorType,
109                              supportedRead.fColorType,
110                              tmpPixels.get(),
111                              tmpRowBytes)) {
112             return false;
113         }
114         GrImageInfo tmpInfo(supportedRead.fColorType, kUnpremul_SkAlphaType, nullptr, w, h);
115         GrImageInfo dstInfo(colorType,                kUnpremul_SkAlphaType, nullptr, w, h);
116         determine_tolerances(tmpInfo.colorType(), dstInfo.colorType(), tolerances);
117         return GrConvertPixels(GrPixmap(dstInfo,             dst,    rowBytes),
118                                GrPixmap(tmpInfo, tmpPixels.get(), tmpRowBytes));
119     }
120     return gpu->readPixels(texture,
121                            SkIRect::MakeWH(w, h),
122                            colorType,
123                            supportedRead.fColorType,
124                            dst,
125                            rowBytes);
126 }
127 
basic_transfer_to_test(skiatest::Reporter * reporter,GrDirectContext * dContext,GrColorType colorType,GrRenderable renderable)128 void basic_transfer_to_test(skiatest::Reporter* reporter,
129                             GrDirectContext* dContext,
130                             GrColorType colorType,
131                             GrRenderable renderable) {
132     if (GrCaps::kNone_MapFlags == dContext->priv().caps()->mapBufferFlags()) {
133         return;
134     }
135 
136     auto* caps = dContext->priv().caps();
137 
138     auto backendFormat = caps->getDefaultBackendFormat(colorType, renderable);
139     if (!backendFormat.isValid()) {
140         return;
141     }
142 
143     auto resourceProvider = dContext->priv().resourceProvider();
144     GrGpu* gpu = dContext->priv().getGpu();
145 
146     static constexpr SkISize kTexDims = {16, 16};
147     int srcBufferWidth = caps->transferPixelsToRowBytesSupport() ? 20 : 16;
148     const int kBufferHeight = 16;
149 
150     sk_sp<GrTexture> tex = resourceProvider->createTexture(kTexDims,
151                                                            backendFormat,
152                                                            GrTextureType::k2D,
153                                                            renderable,
154                                                            1,
155                                                            skgpu::Mipmapped::kNo,
156                                                            skgpu::Budgeted::kNo,
157                                                            GrProtected::kNo,
158                                                            /*label=*/{});
159     if (!tex) {
160         ERRORF(reporter, "Could not create texture");
161         return;
162     }
163 
164     // We validate the results using GrGpu::readPixels, so exit if this is not supported.
165     // TODO: Do this through SurfaceContext once it works for all color types or support
166     // kCopyToTexture2D here.
167     if (GrCaps::SurfaceReadPixelsSupport::kSupported !=
168         caps->surfaceSupportsReadPixels(tex.get())) {
169         return;
170     }
171     // GL requires a texture to be framebuffer bindable to call glReadPixels. However, we have not
172     // incorporated that test into surfaceSupportsReadPixels(). TODO: Remove this once we handle
173     // drawing to a bindable format.
174     if (!caps->isFormatAsColorTypeRenderable(colorType, tex->backendFormat())) {
175         return;
176     }
177 
178     // The caps tell us what color type we are allowed to upload and read back from this texture,
179     // either of which may differ from 'colorType'.
180     GrCaps::SupportedWrite allowedSrc =
181             caps->supportedWritePixelsColorType(colorType, tex->backendFormat(), colorType);
182     if (!allowedSrc.fOffsetAlignmentForTransferBuffer) {
183         return;
184     }
185     size_t srcRowBytes = SkAlignTo(GrColorTypeBytesPerPixel(allowedSrc.fColorType) * srcBufferWidth,
186                                    caps->transferBufferRowBytesAlignment());
187 
188     std::unique_ptr<char[]> srcData(new char[kTexDims.fHeight * srcRowBytes]);
189 
190     fill_transfer_data(0, 0, kTexDims.fWidth, kTexDims.fHeight, srcRowBytes,
191                        allowedSrc.fColorType, srcData.get());
192 
193     // create and fill transfer buffer
194     size_t size = srcRowBytes * kBufferHeight;
195     sk_sp<GrGpuBuffer> buffer = resourceProvider->createBuffer(size,
196                                                                GrGpuBufferType::kXferCpuToGpu,
197                                                                kDynamic_GrAccessPattern,
198                                                                GrResourceProvider::ZeroInit::kNo);
199     if (!buffer) {
200         return;
201     }
202     void* data = buffer->map();
203     if (!buffer) {
204         ERRORF(reporter, "Could not map buffer");
205         return;
206     }
207     memcpy(data, srcData.get(), size);
208     buffer->unmap();
209 
210     //////////////////////////
211     // transfer full data
212 
213     bool result;
214     result = gpu->transferPixelsTo(tex.get(),
215                                    SkIRect::MakeSize(kTexDims),
216                                    colorType,
217                                    allowedSrc.fColorType,
218                                    buffer,
219                                    0,
220                                    srcRowBytes);
221     REPORTER_ASSERT(reporter, result);
222 
223     size_t dstRowBytes = GrColorTypeBytesPerPixel(colorType) * kTexDims.fWidth;
224     std::unique_ptr<char[]> dstBuffer(new char[dstRowBytes * kTexDims.fHeight]());
225 
226     float compareTolerances[4] = {};
227     result = read_pixels_from_texture(tex.get(), colorType, dstBuffer.get(), compareTolerances);
228     if (!result) {
229         ERRORF(reporter, "Could not read pixels from texture, color type: %d",
230                static_cast<int>(colorType));
231         return;
232     }
233 
234     auto error = std::function<ComparePixmapsErrorReporter>(
235             [reporter, colorType](int x, int y, const float diffs[4]) {
236                 ERRORF(reporter,
237                        "Error at (%d %d) in transfer, color type: %s, diffs: (%f, %f, %f, %f)",
238                        x, y, GrColorTypeToStr(colorType),
239                        diffs[0], diffs[1], diffs[2], diffs[3]);
240             });
241     GrImageInfo srcInfo(allowedSrc.fColorType, kUnpremul_SkAlphaType, nullptr, tex->dimensions());
242     GrImageInfo dstInfo(            colorType, kUnpremul_SkAlphaType, nullptr, tex->dimensions());
243     ComparePixels(GrCPixmap(srcInfo,   srcData.get(), srcRowBytes),
244                   GrCPixmap(dstInfo, dstBuffer.get(), dstRowBytes),
245                   compareTolerances,
246                   error);
247 
248     //////////////////////////
249     // transfer partial data
250 
251     // We're relying on this cap to write partial texture data
252     if (!caps->transferPixelsToRowBytesSupport()) {
253         return;
254     }
255     // We keep a 1 to 1 correspondence between pixels in the buffer and the entire texture. We
256     // update the contents of a sub-rect of the buffer and push that rect to the texture. We start
257     // with a left sub-rect inset of 2 but may adjust that so we can fulfill the transfer buffer
258     // offset alignment requirement.
259     int left = 2;
260     int top = 10;
261     const int width = 10;
262     const int height = 2;
263     size_t offset = top * srcRowBytes + left * GrColorTypeBytesPerPixel(allowedSrc.fColorType);
264     while (offset % allowedSrc.fOffsetAlignmentForTransferBuffer) {
265         offset += GrColorTypeBytesPerPixel(allowedSrc.fColorType);
266         ++left;
267         // In most cases we assume that the required alignment is 1 or a small multiple of the bpp,
268         // which it is for color types across all current backends except Direct3D. To correct for
269         // Direct3D's large alignment requirement we may adjust the top location as well.
270         if (left + width > tex->width()) {
271             left = 0;
272             ++top;
273             offset = top * srcRowBytes;
274         }
275         SkASSERT(left + width <= tex->width());
276         SkASSERT(top + height <= tex->height());
277     }
278 
279     // change color of subrectangle
280     fill_transfer_data(left, top, width, height, srcRowBytes, allowedSrc.fColorType,
281                        srcData.get());
282     data = buffer->map();
283     memcpy(data, srcData.get(), size);
284     buffer->unmap();
285 
286     result = gpu->transferPixelsTo(tex.get(),
287                                    SkIRect::MakeXYWH(left, top, width, height),
288                                    colorType,
289                                    allowedSrc.fColorType,
290                                    buffer,
291                                    offset,
292                                    srcRowBytes);
293     if (!result) {
294         ERRORF(reporter, "Could not transfer pixels to texture, color type: %d",
295                static_cast<int>(colorType));
296         return;
297     }
298 
299     result = read_pixels_from_texture(tex.get(), colorType, dstBuffer.get(), compareTolerances);
300     if (!result) {
301         ERRORF(reporter, "Could not read pixels from texture, color type: %d",
302                static_cast<int>(colorType));
303         return;
304     }
305     ComparePixels(GrCPixmap(srcInfo,   srcData.get(), srcRowBytes),
306                   GrCPixmap(dstInfo, dstBuffer.get(), dstRowBytes),
307                   compareTolerances,
308                   error);
309 }
310 
basic_transfer_from_test(skiatest::Reporter * reporter,const sk_gpu_test::ContextInfo & ctxInfo,GrColorType colorType,GrRenderable renderable)311 void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& ctxInfo,
312                               GrColorType colorType, GrRenderable renderable) {
313     auto context = ctxInfo.directContext();
314     auto caps = context->priv().caps();
315     if (GrCaps::kNone_MapFlags == caps->mapBufferFlags()) {
316         return;
317     }
318 
319     auto resourceProvider = context->priv().resourceProvider();
320     GrGpu* gpu = context->priv().getGpu();
321 
322     static constexpr SkISize kTexDims = {16, 16};
323 
324     // We'll do a full texture read into the buffer followed by a partial read. These values
325     // describe the partial read subrect.
326     const int kPartialLeft = 2;
327     const int kPartialTop = 10;
328     const int kPartialWidth = 10;
329     const int kPartialHeight = 2;
330 
331     // create texture
332     auto format = context->priv().caps()->getDefaultBackendFormat(colorType, renderable);
333     if (!format.isValid()) {
334         return;
335     }
336 
337     size_t textureDataBpp = GrColorTypeBytesPerPixel(colorType);
338     size_t textureDataRowBytes = kTexDims.fWidth * textureDataBpp;
339     std::unique_ptr<char[]> textureData(new char[kTexDims.fHeight * textureDataRowBytes]);
340     fill_transfer_data(0, 0, kTexDims.fWidth, kTexDims.fHeight, textureDataRowBytes, colorType,
341                        textureData.get());
342     GrMipLevel data;
343     data.fPixels = textureData.get();
344     data.fRowBytes = textureDataRowBytes;
345     sk_sp<GrTexture> tex = resourceProvider->createTexture(kTexDims,
346                                                            format,
347                                                            GrTextureType::k2D,
348                                                            colorType,
349                                                            renderable,
350                                                            1,
351                                                            skgpu::Budgeted::kNo,
352                                                            skgpu::Mipmapped::kNo,
353                                                            GrProtected::kNo,
354                                                            &data,
355                                                            /*label=*/{});
356     if (!tex) {
357         return;
358     }
359 
360     if (GrCaps::SurfaceReadPixelsSupport::kSupported !=
361         caps->surfaceSupportsReadPixels(tex.get())) {
362         return;
363     }
364     // GL requires a texture to be framebuffer bindable to call glReadPixels. However, we have not
365     // incorporated that test into surfaceSupportsReadPixels(). TODO: Remove this once we handle
366     // drawing to a bindable format.
367     if (!caps->isFormatAsColorTypeRenderable(colorType, tex->backendFormat())) {
368         return;
369     }
370 
371     // Create the transfer buffer.
372     auto allowedRead =
373             caps->supportedReadPixelsColorType(colorType, tex->backendFormat(), colorType);
374     if (!allowedRead.fOffsetAlignmentForTransferBuffer) {
375         return;
376     }
377     GrImageInfo readInfo(allowedRead.fColorType, kUnpremul_SkAlphaType, nullptr, kTexDims);
378 
379     size_t bpp = GrColorTypeBytesPerPixel(allowedRead.fColorType);
380     size_t fullBufferRowBytes = SkAlignTo(kTexDims.fWidth * bpp,
381                                           caps->transferBufferRowBytesAlignment());
382     size_t partialBufferRowBytes = SkAlignTo(kPartialWidth * bpp,
383                                              caps->transferBufferRowBytesAlignment());
384     size_t offsetAlignment = allowedRead.fOffsetAlignmentForTransferBuffer;
385     SkASSERT(offsetAlignment);
386 
387     size_t bufferSize = fullBufferRowBytes * kTexDims.fHeight;
388     // Arbitrary starting offset for the partial read.
389     static constexpr size_t kStartingOffset = 11;
390     size_t partialReadOffset = kStartingOffset +
391                                (offsetAlignment - kStartingOffset%offsetAlignment)%offsetAlignment;
392     bufferSize = std::max(bufferSize,
393                           partialReadOffset + partialBufferRowBytes * kPartialHeight);
394 
395     sk_sp<GrGpuBuffer> buffer = resourceProvider->createBuffer(bufferSize,
396                                                                GrGpuBufferType::kXferGpuToCpu,
397                                                                kDynamic_GrAccessPattern,
398                                                                GrResourceProvider::ZeroInit::kNo);
399     REPORTER_ASSERT(reporter, buffer);
400     if (!buffer) {
401         return;
402     }
403 
404     int expectedTransferCnt = 0;
405     gpu->stats()->reset();
406 
407     //////////////////////////
408     // transfer full data
409     bool result = gpu->transferPixelsFrom(tex.get(),
410                                           SkIRect::MakeSize(kTexDims),
411                                           colorType,
412                                           allowedRead.fColorType,
413                                           buffer,
414                                           0);
415     if (!result) {
416         ERRORF(reporter, "transferPixelsFrom failed.");
417         return;
418     }
419     ++expectedTransferCnt;
420 
421     if (context->priv().caps()->mapBufferFlags() & GrCaps::kAsyncRead_MapFlag) {
422         GrSubmitInfo info;
423         info.fSync = GrSyncCpu::kYes;
424 
425         gpu->submitToGpu(info);
426     }
427 
428     // Copy the transfer buffer contents to a temporary so we can manipulate it.
429     const auto* map = reinterpret_cast<const char*>(buffer->map());
430     REPORTER_ASSERT(reporter, map);
431     if (!map) {
432         ERRORF(reporter, "Failed to map transfer buffer.");
433         return;
434     }
435     std::unique_ptr<char[]> transferData(new char[kTexDims.fHeight * fullBufferRowBytes]);
436     memcpy(transferData.get(), map, fullBufferRowBytes * kTexDims.fHeight);
437     buffer->unmap();
438 
439     GrImageInfo transferInfo(allowedRead.fColorType, kUnpremul_SkAlphaType, nullptr, kTexDims);
440 
441     float tol[4];
442     determine_tolerances(allowedRead.fColorType, colorType, tol);
443     auto error = std::function<ComparePixmapsErrorReporter>(
444             [reporter, colorType](int x, int y, const float diffs[4]) {
445                 ERRORF(reporter,
446                        "Error at (%d %d) in transfer, color type: %s, diffs: (%f, %f, %f, %f)",
447                        x, y, GrColorTypeToStr(colorType),
448                        diffs[0], diffs[1], diffs[2], diffs[3]);
449             });
450     GrImageInfo textureDataInfo(colorType, kUnpremul_SkAlphaType, nullptr, kTexDims);
451     ComparePixels(GrCPixmap(textureDataInfo,  textureData.get(), textureDataRowBytes),
452                   GrCPixmap(   transferInfo, transferData.get(),  fullBufferRowBytes),
453                   tol,
454                   error);
455 
456     ///////////////////////
457     // Now test a partial read at an offset into the buffer.
458     result = gpu->transferPixelsFrom(
459             tex.get(),
460             SkIRect::MakeXYWH(kPartialLeft, kPartialTop, kPartialWidth, kPartialHeight),
461             colorType,
462             allowedRead.fColorType,
463             buffer,
464             partialReadOffset);
465     if (!result) {
466         ERRORF(reporter, "transferPixelsFrom failed.");
467         return;
468     }
469     ++expectedTransferCnt;
470 
471     if (context->priv().caps()->mapBufferFlags() & GrCaps::kAsyncRead_MapFlag) {
472         GrSubmitInfo info;
473         info.fSync = GrSyncCpu::kYes;
474 
475         gpu->submitToGpu(info);
476     }
477 
478     map = reinterpret_cast<const char*>(buffer->map());
479     REPORTER_ASSERT(reporter, map);
480     if (!map) {
481         ERRORF(reporter, "Failed to map transfer buffer.");
482         return;
483     }
484     const char* bufferStart = reinterpret_cast<const char*>(map) + partialReadOffset;
485     memcpy(transferData.get(), bufferStart, partialBufferRowBytes * kTexDims.fHeight);
486     buffer->unmap();
487 
488     transferInfo = transferInfo.makeWH(kPartialWidth, kPartialHeight);
489     const char* textureDataStart =
490             textureData.get() + textureDataRowBytes * kPartialTop + textureDataBpp * kPartialLeft;
491     textureDataInfo = textureDataInfo.makeWH(kPartialWidth, kPartialHeight);
492     ComparePixels(GrCPixmap(textureDataInfo,   textureDataStart,   textureDataRowBytes),
493                   GrCPixmap(transferInfo   , transferData.get(), partialBufferRowBytes),
494                   tol,
495                   error);
496 #if GR_GPU_STATS
497     REPORTER_ASSERT(reporter, gpu->stats()->transfersFromSurface() == expectedTransferCnt);
498 #else
499     (void)expectedTransferCnt;
500 #endif
501 }
502 
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TransferPixelsToTextureTest,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)503 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TransferPixelsToTextureTest,
504                                        reporter,
505                                        ctxInfo,
506                                        CtsEnforcement::kApiLevel_T) {
507     if (!ctxInfo.directContext()->priv().caps()->transferFromBufferToTextureSupport()) {
508         return;
509     }
510     for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
511         for (auto colorType : {
512                      GrColorType::kAlpha_8,
513                      GrColorType::kBGR_565,
514                      GrColorType::kRGB_565,
515                      GrColorType::kABGR_4444,
516                      GrColorType::kRGBA_8888,
517                      GrColorType::kRGBA_8888_SRGB,
518                      GrColorType::kRGB_888x,
519                      GrColorType::kRG_88,
520                      GrColorType::kBGRA_8888,
521                      GrColorType::kRGBA_1010102,
522                      GrColorType::kBGRA_1010102,
523                      GrColorType::kRGB_101010x,
524                      GrColorType::kRGBA_10x6,
525                      GrColorType::kGray_8,
526                      GrColorType::kAlpha_F16,
527                      GrColorType::kRGBA_F16,
528                      GrColorType::kRGBA_F16_Clamped,
529                      GrColorType::kRGB_F16F16F16x,
530                      GrColorType::kRGBA_F32,
531                      GrColorType::kAlpha_16,
532                      GrColorType::kRG_1616,
533                      GrColorType::kRGBA_16161616,
534                      GrColorType::kRG_F16,
535              }) {
536             basic_transfer_to_test(reporter, ctxInfo.directContext(), colorType, renderable);
537         }
538     }
539 }
540 
541 // TODO(bsalomon): Metal
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TransferPixelsFromTextureTest,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)542 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TransferPixelsFromTextureTest,
543                                        reporter,
544                                        ctxInfo,
545                                        CtsEnforcement::kApiLevel_T) {
546     if (!ctxInfo.directContext()->priv().caps()->transferFromSurfaceToBufferSupport()) {
547         return;
548     }
549     for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
550         for (auto colorType : {
551                      GrColorType::kAlpha_8,
552                      GrColorType::kAlpha_16,
553                      GrColorType::kBGR_565,
554                      GrColorType::kRGB_565,
555                      GrColorType::kABGR_4444,
556                      GrColorType::kRGBA_8888,
557                      GrColorType::kRGBA_8888_SRGB,
558                      GrColorType::kRGB_888x,
559                      GrColorType::kRG_88,
560                      GrColorType::kBGRA_8888,
561                      GrColorType::kRGBA_1010102,
562                      GrColorType::kBGRA_1010102,
563                      GrColorType::kRGB_101010x,
564                      GrColorType::kRGBA_10x6,
565                      GrColorType::kGray_8,
566                      GrColorType::kAlpha_F16,
567                      GrColorType::kRGBA_F16,
568                      GrColorType::kRGBA_F16_Clamped,
569                      GrColorType::kRGB_F16F16F16x,
570                      GrColorType::kRGBA_F32,
571                      GrColorType::kRG_1616,
572                      GrColorType::kRGBA_16161616,
573                      GrColorType::kRG_F16,
574              }) {
575             basic_transfer_from_test(reporter, ctxInfo, colorType, renderable);
576         }
577     }
578 }
579