Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Enumerations | Functions
BackendAllocationTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkString.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/SkColorData.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/gpu/RefCntedCallback.h"
#include "src/gpu/Swizzle.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrColorInfo.h"
#include "src/gpu/ganesh/GrDataUtils.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrFragmentProcessor.h"
#include "src/gpu/ganesh/GrImageInfo.h"
#include "src/gpu/ganesh/GrPixmap.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrResourceCache.h"
#include "src/gpu/ganesh/GrSamplerState.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "src/gpu/ganesh/SurfaceContext.h"
#include "src/gpu/ganesh/SurfaceFillContext.h"
#include "src/gpu/ganesh/effects/GrTextureEffect.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
#include "tools/ToolUtils.h"
#include "tools/gpu/ContextType.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include "tools/gpu/ProxyUtils.h"
#include <array>
#include <functional>
#include <initializer_list>
#include <memory>
#include <utility>

Go to the source code of this file.

Enumerations

enum class  VkLayout { kUndefined , kReadOnlyOptimal }
 

Functions

void test_wrapping (GrDirectContext *dContext, skiatest::Reporter *reporter, const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, skgpu::Mipmapped, GrRenderable)> &create, GrColorType grColorType, skgpu::Mipmapped mipmapped, GrRenderable renderable)
 
static bool isBGRA8 (const GrBackendFormat &format)
 
static bool isRGB (const GrBackendFormat &format)
 
static void check_solid_pixmap (skiatest::Reporter *reporter, const SkColor4f &expected, const SkPixmap &actual, GrColorType ct, const char *label1, const char *label2)
 
static SkColor4f get_expected_color (SkColor4f orig, GrColorType ct)
 
static void check_mipmaps (GrDirectContext *, const GrBackendTexture &, GrColorType, const SkColor4f expectedColors[6], skiatest::Reporter *, const char *label)
 
static void check_base_readbacks (GrDirectContext *dContext, const GrBackendTexture &backendTex, GrColorType colorType, GrRenderable renderableTexture, const SkColor4f &color, skiatest::Reporter *reporter, const char *label)
 
void test_color_init (GrDirectContext *dContext, skiatest::Reporter *reporter, const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, const SkColor4f &, skgpu::Mipmapped, GrRenderable)> &create, GrColorType colorType, const SkColor4f &color, skgpu::Mipmapped mipmapped, GrRenderable renderable)
 
void test_pixmap_init (GrDirectContext *dContext, skiatest::Reporter *reporter, const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, const SkPixmap srcData[], int numLevels, GrSurfaceOrigin, GrRenderable)> &create, SkColorType skColorType, GrSurfaceOrigin origin, skgpu::Mipmapped mipmapped, GrRenderable renderable)
 
void check_vk_tiling (const GrBackendTexture &backendTex)
 
void color_type_backend_allocation_test (const sk_gpu_test::ContextInfo &ctxInfo, skiatest::Reporter *reporter)
 
 DEF_GANESH_TEST (ColorTypeBackendAllocationTest, reporter, options, CtsEnforcement::kApiLevel_T)
 

Enumeration Type Documentation

◆ VkLayout

enum class VkLayout
strong
Enumerator
kUndefined 
kReadOnlyOptimal 

Definition at line 583 of file BackendAllocationTest.cpp.

583 {
586};
@ kReadOnlyOptimal

Function Documentation

◆ check_base_readbacks()

static void check_base_readbacks ( GrDirectContext dContext,
const GrBackendTexture backendTex,
GrColorType  colorType,
GrRenderable  renderableTexture,
const SkColor4f color,
skiatest::Reporter reporter,
const char *  label 
)
static

Definition at line 301 of file BackendAllocationTest.cpp.

307 {
308 if (isRGB(backendTex.getBackendFormat())) {
309 // readPixels is busted for the RGB backend format (skbug.com/8862)
310 // TODO: add a GrColorType::kRGB_888 to fix the situation
311 return;
312 }
313
315
316 SkAutoPixmapStorage actual;
317
318 {
319 SkImageInfo readBackII = SkImageInfo::Make(32, 32,
322
323 SkAssertResult(actual.tryAlloc(readBackII));
324 }
325 for (GrRenderable renderableCtx : {GrRenderable::kNo, GrRenderable::kYes}) {
326 if (renderableCtx == GrRenderable::kYes && renderableTexture == GrRenderable::kNo) {
327 continue;
328 }
330 if (renderableCtx == GrRenderable::kYes) {
331 proxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture(
332 backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, nullptr);
333 } else {
334 proxy = dContext->priv().proxyProvider()->wrapBackendTexture(
336 }
337 if (!proxy) {
338 ERRORF(reporter, "Could not make proxy from backend texture");
339 return;
340 }
341 auto swizzle = dContext->priv().caps()->getReadSwizzle(backendTex.getBackendFormat(),
342 colorType);
343 GrSurfaceProxyView readView(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
345 auto surfaceContext = dContext->priv().makeSC(readView, info);
346 if (!surfaceContext) {
347 ERRORF(reporter, "Could not create surface context for colorType: %d\n",
348 (int)colorType);
349 }
350
351 if (!surfaceContext->readPixels(dContext, actual, {0, 0})) {
352 // TODO: we need a better way to tell a priori if readPixels will work for an
353 // arbitrary colorType
354#if 0
355 ERRORF(reporter, "Couldn't readback from SurfaceContext for colorType: %d\n",
356 (int)colorType);
357#endif
358 } else {
359 auto name = SkStringPrintf("%s::readPixels",
360 (renderableCtx == GrRenderable::kYes ? "SurfaceFillContext"
361 : "SurfaceContext"));
362 check_solid_pixmap(reporter, expectedColor, actual, colorType, label, name.c_str());
363 }
364 }
365}
static void check_solid_pixmap(skiatest::Reporter *reporter, const SkColor4f &expected, const SkPixmap &actual, GrColorType ct, const char *label1, const char *label2)
static bool isRGB(const GrBackendFormat &format)
static SkColor4f get_expected_color(SkColor4f orig, GrColorType ct)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
@ kRW_GrIOType
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
SkColor4f color
kUnpremul_SkAlphaType
#define SkAssertResult(cond)
Definition SkAssert.h:123
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
#define ERRORF(r,...)
Definition Test.h:293
GrBackendFormat getBackendFormat() const
const GrCaps * caps() const
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition GrCaps.cpp:443
GrDirectContextPriv priv()
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
sk_sp< GrTextureProxy > wrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback > releaseHelper)
GrProxyProvider * proxyProvider()
std::unique_ptr< skgpu::ganesh::SurfaceContext > makeSC(GrSurfaceProxyView readView, const GrColorInfo &)
bool tryAlloc(const SkImageInfo &)
const char * name
Definition fuchsia.cc:50
Renderable
Definition GpuTypes.h:69
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ check_mipmaps()

static void check_mipmaps ( GrDirectContext dContext,
const GrBackendTexture backendTex,
GrColorType  colorType,
const SkColor4f  expectedColors[6],
skiatest::Reporter reporter,
const char *  label 
)
static

Definition at line 415 of file BackendAllocationTest.cpp.

420 {
421#ifdef SK_GL
422 // skbug.com/9141 (RGBA_F32 mipmaps appear to be broken on some Mali devices)
423 if (GrBackendApi::kOpenGL == dContext->backend()) {
424 GrGLGpu* glGPU = static_cast<GrGLGpu*>(dContext->priv().getGpu());
425
427 glGPU->ctxInfo().standard() == kGLES_GrGLStandard) {
428 return;
429 }
430 }
431#endif
432
433 if (isRGB(backendTex.getBackendFormat())) {
434 // readPixels is busted for the RGB backend format (skbug.com/8862)
435 // TODO: add a GrColorType::kRGB_888 to fix the situation
436 return;
437 }
438
440 auto dstFillContext = dContext->priv().makeSFC(info, /*label=*/{});
441 if (!dstFillContext) {
442 ERRORF(reporter, "Could not make dst fill context.");
443 return;
444 }
445
446 constexpr int kNumMipLevels = 6;
447
448 auto proxy = dContext->priv().proxyProvider()->wrapBackendTexture(backendTex,
452 if (!proxy) {
453 ERRORF(reporter, "Could not make proxy from backend texture");
454 return;
455 }
456 auto swizzle = dContext->priv().caps()->getReadSwizzle(backendTex.getBackendFormat(),
457 colorType);
458 GrSurfaceProxyView readView(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
459
460 for (int i = 0, rectSize = 32; i < kNumMipLevels; ++i, rectSize /= 2) {
461 SkASSERT(rectSize >= 1);
462 dstFillContext->clear(SK_PMColor4fTRANSPARENT);
463
464 SkMatrix texMatrix;
465 texMatrix.setScale(1 << i, 1 << i);
466 static constexpr GrSamplerState kNearestNearest(GrSamplerState::Filter::kNearest,
467 GrSamplerState::MipmapMode::kNearest);
468 auto fp = GrTextureEffect::Make(readView,
470 texMatrix,
471 kNearestNearest,
472 *dstFillContext->caps());
473 dstFillContext->fillRectWithFP(SkIRect::MakeWH(rectSize, rectSize), std::move(fp));
474
475 SkImageInfo readbackII = SkImageInfo::Make(rectSize, rectSize,
478 SkAutoPixmapStorage actual;
479 SkAssertResult(actual.tryAlloc(readbackII));
481
482 bool result = dstFillContext->readPixels(dContext, actual, {0, 0});
484
485 SkString str;
486 str.appendf("mip-level %d", i);
487
488 check_solid_pixmap(reporter, expectedColors[i], actual, colorType, label, str.c_str());
489 }
490}
@ kGLES_GrGLStandard
Definition GrGLTypes.h:22
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
SK_API GrBackendApi backend() const
GrGLStandard standard() const
Definition GrGLContext.h:30
const GrGLContextInfo & ctxInfo() const
Definition GrGLGpu.h:104
std::unique_ptr< skgpu::ganesh::SurfaceFillContext > makeSFC(GrImageInfo, std::string_view label, SkBackingFit=SkBackingFit::kExact, int sampleCount=1, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Protected=skgpu::Protected::kNo, GrSurfaceOrigin=kTopLeft_GrSurfaceOrigin, skgpu::Budgeted=skgpu::Budgeted::kYes)
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:296
bool erase(SkColor color, const SkIRect &subset) const
Definition SkPixmap.cpp:742
const char * c_str() const
Definition SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550
GAsyncResult * result
constexpr SkColor4f kTransparent
Definition SkColor.h:434
const uint32_t fp
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56

◆ check_solid_pixmap()

static void check_solid_pixmap ( skiatest::Reporter reporter,
const SkColor4f expected,
const SkPixmap actual,
GrColorType  ct,
const char *  label1,
const char *  label2 
)
static

Definition at line 256 of file BackendAllocationTest.cpp.

261 {
262 // we need 0.001f across the board just for noise
263 // we need 0.01f across the board for 1010102
264 const float tols[4] = { 0.01f, 0.01f, 0.01f, 0.01f };
265
266 auto error = std::function<ComparePixmapsErrorReporter>(
267 [reporter, ct, label1, label2, expected](int x, int y, const float diffs[4]) {
268 SkASSERT(x >= 0 && y >= 0);
269 ERRORF(reporter, "%s %s %s - mismatch at %d, %d "
270 "expected (%.2f, %.2f, %.2f %.2f) "
271 "- diffs (%.2f, %.2f, %.2f %.2f)",
272 GrColorTypeToStr(ct), label1, label2, x, y,
273 expected.fR, expected.fG, expected.fB, expected.fA,
274 diffs[0], diffs[1], diffs[2], diffs[3]);
275 });
276
277 CheckSolidPixels(expected, actual, tols, error);
278}
bool CheckSolidPixels(const SkColor4f &col, const SkPixmap &pixmap, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
const uint8_t uint32_t uint32_t GError ** error
double y
double x

◆ check_vk_tiling()

void check_vk_tiling ( const GrBackendTexture backendTex)

Definition at line 588 of file BackendAllocationTest.cpp.

588 {
589#if defined(SK_VULKAN) && defined(SK_DEBUG)
590 GrVkImageInfo vkII;
591 if (GrBackendTextures::GetVkImageInfo(backendTex, &vkII)) {
593 }
594#endif
595}
SK_API bool GetVkImageInfo(const GrBackendTexture &, GrVkImageInfo *)
VkImageTiling fImageTiling
Definition GrVkTypes.h:28
@ VK_IMAGE_TILING_OPTIMAL

◆ color_type_backend_allocation_test()

void color_type_backend_allocation_test ( const sk_gpu_test::ContextInfo ctxInfo,
skiatest::Reporter reporter 
)

Definition at line 598 of file BackendAllocationTest.cpp.

599 {
600 using namespace skgpu;
601
602 auto context = ctxInfo.directContext();
603 const GrCaps* caps = context->priv().caps();
604
605 Protected isProtected = Protected(caps->supportsProtectedContent());
606
607 constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
608 constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f };
609
610 struct {
612 SkColor4f fColor;
613 } combinations[] = {
614 { kAlpha_8_SkColorType, kTransCol },
618 { kSRGBA_8888_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f}},
620 // TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
621 { kBGRA_8888_SkColorType, { 1, 0, 0, 1.0f } },
622 // TODO: readback is busted for *10A2 when alpha = 0.5f (perhaps premul vs. unpremul)
623 { kRGBA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
624 { kBGRA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
625 // RGB/BGR 101010x have no Ganesh correlate
626 { kRGB_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
627 { kBGR_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
628 { kBGR_101010x_XR_SkColorType, { 0, 0.5f, 0, 0.5f } },
629 { kRGBA_10x6_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
630 { kBGRA_10101010_XR_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
631 { kGray_8_SkColorType, kGrayCol },
635 { kR8G8_unorm_SkColorType, { .25f, .75f, 0, 1 } },
637 { kA16_unorm_SkColorType, kTransCol },
638 { kA16_float_SkColorType, kTransCol },
639 { kR16G16_float_SkColorType, { .25f, .75f, 0, 1 } },
640 { kR16G16B16A16_unorm_SkColorType,{ .25f, .5f, .75f, 1 } },
641 { kR8_unorm_SkColorType, { .25f, 0, 0, 1 } },
642 };
643
644 static_assert(kLastEnum_SkColorType == std::size(combinations));
645
646 for (auto combo : combinations) {
647 SkColorType colorType = combo.fColorType;
648
649 if (GrBackendApi::kMetal == context->backend()) {
650 // skbug.com/9086 (Metal caps may not be handling RGBA32 correctly)
651 if (kRGBA_F32_SkColorType == combo.fColorType) {
652 continue;
653 }
654 }
655
657 // Creating a texture with kBGR_101010x_XR_SkColorType is not
658 // implemented.
659 continue;
660 }
661
662 for (auto mipmapped : { Mipmapped::kNo, Mipmapped::kYes}) {
663 if (Mipmapped::kYes == mipmapped && !caps->mipmapSupport()) {
664 continue;
665 }
666
667 for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
669 renderable).isValid()) {
670 continue;
671 }
672
673 if (GrRenderable::kYes == renderable) {
674 if (kRGB_888x_SkColorType == combo.fColorType) {
675 // Ganesh can't perform the blends correctly when rendering this format
676 continue;
677 }
678 }
679
680 {
681 auto uninitCreateMtd = [&](GrDirectContext* dContext,
682 Mipmapped mipmapped,
683 GrRenderable renderable) {
684 auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
685 32, 32,
686 colorType,
687 mipmapped,
688 renderable,
689 isProtected);
690 check_vk_tiling(mbet->texture());
691#ifdef SK_DEBUG
692 {
694 renderable);
695 SkASSERT(format == mbet->texture().getBackendFormat());
696 }
697#endif
698
699 return mbet;
700 };
701
702 test_wrapping(context, reporter, uninitCreateMtd,
703 SkColorTypeToGrColorType(colorType), mipmapped, renderable);
704 }
705
706 {
707 auto createWithColorMtd = [&](GrDirectContext* dContext,
708 const SkColor4f& color,
709 Mipmapped mipmapped,
710 GrRenderable renderable) {
711 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
712 32, 32,
713 colorType,
714 color,
715 mipmapped,
716 renderable,
717 isProtected);
718 check_vk_tiling(mbet->texture());
719
720#ifdef SK_DEBUG
721 {
723 renderable);
724 SkASSERT(format == mbet->texture().getBackendFormat());
725 }
726#endif
727
728 return mbet;
729 };
730 test_color_init(context, reporter, createWithColorMtd,
731 SkColorTypeToGrColorType(colorType), combo.fColor, mipmapped,
732 renderable);
733 }
734
736 auto createWithSrcDataMtd = [&](GrDirectContext* dContext,
737 const SkPixmap srcData[],
738 int numLevels,
739 GrSurfaceOrigin origin,
740 GrRenderable renderable) {
741 SkASSERT(srcData && numLevels);
742 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
743 srcData,
744 numLevels,
745 origin,
746 renderable,
747 isProtected);
748 check_vk_tiling(mbet->texture());
749#ifdef SK_DEBUG
750 {
751 auto format = dContext->defaultBackendFormat(srcData[0].colorType(),
752 renderable);
753 SkASSERT(format == mbet->texture().getBackendFormat());
754 }
755#endif
756 return mbet;
757 };
758
759 test_pixmap_init(context,
760 reporter,
761 createWithSrcDataMtd,
762 colorType,
763 origin,
764 mipmapped,
765 renderable);
766 }
767 }
768 }
769 }
770}
void check_vk_tiling(const GrBackendTexture &backendTex)
void test_color_init(GrDirectContext *dContext, skiatest::Reporter *reporter, const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, const SkColor4f &, skgpu::Mipmapped, GrRenderable)> &create, GrColorType colorType, const SkColor4f &color, skgpu::Mipmapped mipmapped, GrRenderable renderable)
void test_pixmap_init(GrDirectContext *dContext, skiatest::Reporter *reporter, const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, const SkPixmap srcData[], int numLevels, GrSurfaceOrigin, GrRenderable)> &create, SkColorType skColorType, GrSurfaceOrigin origin, skgpu::Mipmapped mipmapped, GrRenderable renderable)
void test_wrapping(GrDirectContext *dContext, skiatest::Reporter *reporter, const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, skgpu::Mipmapped, GrRenderable)> &create, GrColorType grColorType, skgpu::Mipmapped mipmapped, GrRenderable renderable)
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
GrSurfaceOrigin
Definition GrTypes.h:147
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
skgpu::Protected Protected
SkColorType fColorType
SkColorType
Definition SkColorType.h:19
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition SkColorType.h:50
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
Definition SkColorType.h:33
@ kR8_unorm_SkColorType
Definition SkColorType.h:54
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
Definition SkColorType.h:30
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition SkColorType.h:23
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
Definition SkColorType.h:43
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition SkColorType.h:48
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:29
@ kLastEnum_SkColorType
last valid value
Definition SkColorType.h:56
@ kSRGBA_8888_SkColorType
Definition SkColorType.h:53
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
Definition SkColorType.h:32
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:25
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
Definition SkColorType.h:28
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition SkColorType.h:45
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition SkColorType.h:40
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition SkColorType.h:27
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
Definition SkColorType.h:31
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition SkColorType.h:49
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition SkColorType.h:36
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition SkColorType.h:46
bool isValid() const
bool mipmapSupport() const
Definition GrCaps.h:72
bool supportsProtectedContent() const
Definition GrCaps.h:422
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition GrCaps.cpp:400
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const
GrDirectContext * directContext() const
uint32_t uint32_t * format
constexpr SkColor4f kLtGray
Definition SkColor.h:438
constexpr SkColor4f kGreen
Definition SkColor.h:441
constexpr SkColor4f kRed
Definition SkColor.h:440
constexpr SkColor4f kCyan
Definition SkColor.h:444
constexpr SkColor4f kGray
Definition SkColor.h:437
constexpr SkColor4f kBlue
Definition SkColor.h:442
constexpr SkColor4f kYellow
Definition SkColor.h:443
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61

◆ DEF_GANESH_TEST()

DEF_GANESH_TEST ( ColorTypeBackendAllocationTest  ,
reporter  ,
options  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 772 of file BackendAllocationTest.cpp.

772 {
773 for (int t = 0; t < skgpu::kContextTypeCount; ++t) {
774 auto type = static_cast<skgpu::ContextType>(t);
776 continue;
777 }
779 sk_gpu_test::ContextInfo info = factory.getContextInfo(type);
780 if (!info.directContext()) {
781 continue;
782 }
784 // The GL backend must support contexts that don't allow GL_UNPACK_ROW_LENGTH. Other
785 // backends are not required to work with this cap disabled.
786 if (info.directContext()->priv().caps()->writePixelsRowBytesSupport() &&
787 info.directContext()->backend() == GrBackendApi::kOpenGL) {
788 GrContextOptions overrideOptions = options;
789 overrideOptions.fDisallowWriteAndTransferPixelRowBytes = true;
790 sk_gpu_test::GrContextFactory overrideFactory(overrideOptions);
791 info = overrideFactory.getContextInfo(type);
793 }
794 }
795}
void color_type_backend_allocation_test(const sk_gpu_test::ContextInfo &ctxInfo, skiatest::Reporter *reporter)
const char * options
static const int kContextTypeCount
Definition ContextType.h:42
bool IsRenderingContext(skgpu::ContextType type)

◆ get_expected_color()

static SkColor4f get_expected_color ( SkColor4f  orig,
GrColorType  ct 
)
static

Definition at line 281 of file BackendAllocationTest.cpp.

281 {
282 GrImageInfo ii(ct, kUnpremul_SkAlphaType, nullptr, {1, 1});
283 std::unique_ptr<char[]> data(new char[ii.minRowBytes()]);
284 GrClearImage(ii, data.get(), ii.minRowBytes(), orig.array());
285
286 // Read back to SkColor4f.
288 GrImageInfo resultII(GrColorType::kRGBA_F32, kUnpremul_SkAlphaType, nullptr, {1, 1});
289 GrConvertPixels(GrPixmap(resultII, &result.fR, sizeof(result)),
290 GrPixmap( ii, data.get(), ii.minRowBytes()));
291 return result;
292}
bool GrConvertPixels(const GrPixmap &dst, const GrCPixmap &src, bool flipY)
bool GrClearImage(const GrImageInfo &dstInfo, void *dst, size_t dstRB, std::array< float, 4 > color)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ isBGRA8()

static bool isBGRA8 ( const GrBackendFormat format)
static

Definition at line 180 of file BackendAllocationTest.cpp.

180 {
181 switch (format.backend()) {
183#ifdef SK_GL
185#else
186 return false;
187#endif
189#ifdef SK_VULKAN
190 VkFormat vkFormat;
192 return vkFormat == VK_FORMAT_B8G8R8A8_UNORM;
193#else
194 return false;
195#endif
196 }
198#ifdef SK_METAL
199 return GrMtlFormatIsBGRA8(GrBackendFormats::AsMtlFormat(format));
200#else
201 return false;
202#endif
204#ifdef SK_DIRECT3D
205 DXGI_FORMAT d3dFormat;
206 format.asDxgiFormat(&d3dFormat);
207 return d3dFormat == DXGI_FORMAT_B8G8R8A8_UNORM;
208#else
209 return false;
210#endif
211 }
212 case GrBackendApi::kMock: {
213 SkTextureCompressionType compression = format.asMockCompressionType();
214 if (compression != SkTextureCompressionType::kNone) {
215 return false; // No compressed formats are BGRA
216 }
217
218 return format.asMockColorType() == GrColorType::kBGRA_8888;
219 }
221 return false;
222 }
223 }
225}
#define SkUNREACHABLE
Definition SkAssert.h:135
SK_API GrMTLPixelFormat AsMtlFormat(const GrBackendFormat &)
SK_API GrGLFormat AsGLFormat(const GrBackendFormat &)
SK_API bool AsVkFormat(const GrBackendFormat &, VkFormat *)
VkFormat
@ VK_FORMAT_B8G8R8A8_UNORM

◆ isRGB()

static bool isRGB ( const GrBackendFormat format)
static

Definition at line 227 of file BackendAllocationTest.cpp.

227 {
228 switch (format.backend()) {
230#ifdef SK_GL
232#else
233 return false;
234#endif
236#ifdef SK_VULKAN
237 VkFormat vkFormat;
239 return vkFormat == VK_FORMAT_R8G8B8_UNORM;
240#else
241 return false;
242#endif
243 }
245 return false; // Metal doesn't even pretend to support this
247 return false; // Not supported in Direct3D 12
249 return format.asMockColorType() == GrColorType::kRGB_888;
251 return false;
252 }
254}
@ VK_FORMAT_R8G8B8_UNORM

◆ test_color_init()

void test_color_init ( GrDirectContext dContext,
skiatest::Reporter reporter,
const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, const SkColor4f &, skgpu::Mipmapped, GrRenderable)> &  create,
GrColorType  colorType,
const SkColor4f color,
skgpu::Mipmapped  mipmapped,
GrRenderable  renderable 
)

Definition at line 368 of file BackendAllocationTest.cpp.

376 {
377 sk_sp<ManagedBackendTexture> mbet = create(dContext, color, mipmapped, renderable);
378 if (!mbet) {
379 // errors here should be reported by the test_wrapping test
380 return;
381 }
382
383 auto checkBackendTexture = [&](const SkColor4f& testColor) {
384 if (mipmapped == skgpu::Mipmapped::kYes) {
385 SkColor4f expectedColor = get_expected_color(testColor, colorType);
386 SkColor4f expectedColors[6] = {expectedColor, expectedColor, expectedColor,
387 expectedColor, expectedColor, expectedColor};
388 check_mipmaps(dContext, mbet->texture(), colorType, expectedColors, reporter,
389 "colorinit");
390 }
391
392 // The last step in this test will dirty the mipmaps so do it last
393 check_base_readbacks(dContext, mbet->texture(), colorType, renderable, testColor, reporter,
394 "colorinit");
395 };
396
397 checkBackendTexture(color);
398
399 SkColor4f newColor = {color.fB , color.fR, color.fG, color.fA };
400
402 // Our update method only works with SkColorTypes.
403 if (skColorType != kUnknown_SkColorType) {
404 dContext->updateBackendTexture(mbet->texture(),
405 skColorType,
406 newColor,
407 ManagedBackendTexture::ReleaseProc,
408 mbet->releaseContext());
409 checkBackendTexture(newColor);
410 }
411}
static void check_base_readbacks(GrDirectContext *dContext, const GrBackendTexture &backendTex, GrColorType colorType, GrRenderable renderableTexture, const SkColor4f &color, skiatest::Reporter *reporter, const char *label)
static void check_mipmaps(GrDirectContext *, const GrBackendTexture &, GrColorType, const SkColor4f expectedColors[6], skiatest::Reporter *, const char *label)
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
bool updateBackendTexture(const GrBackendTexture &, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)

◆ test_pixmap_init()

void test_pixmap_init ( GrDirectContext dContext,
skiatest::Reporter reporter,
const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, const SkPixmap srcData[], int numLevels, GrSurfaceOrigin, GrRenderable)> &  create,
SkColorType  skColorType,
GrSurfaceOrigin  origin,
skgpu::Mipmapped  mipmapped,
GrRenderable  renderable 
)

Definition at line 493 of file BackendAllocationTest.cpp.

503 {
504 SkPixmap pixmaps[6];
505 std::unique_ptr<char[]> memForPixmaps;
506 constexpr SkColor4f kColors[6] = {
507 { 1.0f, 0.0f, 0.0f, 1.0f }, // R
508 { 0.0f, 1.0f, 0.0f, 0.9f }, // G
509 { 0.0f, 0.0f, 1.0f, 0.7f }, // B
510 { 0.0f, 1.0f, 1.0f, 0.5f }, // C
511 { 1.0f, 0.0f, 1.0f, 0.3f }, // M
512 { 1.0f, 1.0f, 0.0f, 0.2f }, // Y
513 };
514
515 int numMipLevels = ToolUtils::make_pixmaps(skColorType,
517 mipmapped == skgpu::Mipmapped::kYes,
518 kColors,
519 pixmaps,
520 &memForPixmaps);
521 SkASSERT(numMipLevels);
522
523 sk_sp<ManagedBackendTexture> mbet = create(dContext, pixmaps, numMipLevels, origin, renderable);
524 if (!mbet) {
525 // errors here should be reported by the test_wrapping test
526 return;
527 }
528
529 if (skColorType == kBGRA_8888_SkColorType && !isBGRA8(mbet->texture().getBackendFormat())) {
530 // When kBGRA is backed by an RGBA something goes wrong in the swizzling
531 return;
532 }
533
534 auto checkBackendTexture = [&](const SkColor4f colors[6]) {
535 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
536 if (mipmapped == skgpu::Mipmapped::kYes) {
537 SkColor4f expectedColors[6] = {
538 get_expected_color(colors[0], grColorType),
539 get_expected_color(colors[1], grColorType),
540 get_expected_color(colors[2], grColorType),
541 get_expected_color(colors[3], grColorType),
542 get_expected_color(colors[4], grColorType),
543 get_expected_color(colors[5], grColorType),
544 };
545
546 check_mipmaps(dContext, mbet->texture(), grColorType, expectedColors, reporter,
547 "pixmap");
548 }
549
550 // The last step in this test will dirty the mipmaps so do it last
551 check_base_readbacks(dContext, mbet->texture(), grColorType, renderable, colors[0],
552 reporter, "pixmap");
553 };
554
555 checkBackendTexture(kColors);
556
557 constexpr SkColor4f kColorsNew[6] = {
558 {1.0f, 1.0f, 0.0f, 0.2f}, // Y
559 {1.0f, 0.0f, 0.0f, 1.0f}, // R
560 {0.0f, 1.0f, 0.0f, 0.9f}, // G
561 {0.0f, 0.0f, 1.0f, 0.7f}, // B
562 {0.0f, 1.0f, 1.0f, 0.5f}, // C
563 {1.0f, 0.0f, 1.0f, 0.3f}, // M
564 };
565 ToolUtils::make_pixmaps(skColorType,
567 mipmapped == skgpu::Mipmapped::kYes,
568 kColorsNew,
569 pixmaps,
570 &memForPixmaps);
571
572 // Upload new data and make sure everything still works
573 dContext->updateBackendTexture(mbet->texture(),
574 pixmaps,
575 numMipLevels,
576 origin,
577 ManagedBackendTexture::ReleaseProc,
578 mbet->releaseContext());
579
580 checkBackendTexture(kColorsNew);
581}
static bool isBGRA8(const GrBackendFormat &format)
GrColorType
PODArray< SkColor > colors
Definition SkRecords.h:276
int make_pixmaps(SkColorType ct, SkAlphaType at, bool withMips, const SkColor4f colors[6], SkPixmap pixmaps[6], std::unique_ptr< char[]> *mem)
const DlColor kColors[]

◆ test_wrapping()

void test_wrapping ( GrDirectContext dContext,
skiatest::Reporter reporter,
const std::function< sk_sp< ManagedBackendTexture >(GrDirectContext *, skgpu::Mipmapped, GrRenderable)> &  create,
GrColorType  grColorType,
skgpu::Mipmapped  mipmapped,
GrRenderable  renderable 
)

Definition at line 97 of file BackendAllocationTest.cpp.

103 {
105
106 const int initialCount = cache->getResourceCount();
107
108 sk_sp<ManagedBackendTexture> mbet = create(dContext, mipmapped, renderable);
109 if (!mbet) {
110 ERRORF(reporter, "Couldn't create backendTexture for grColorType %d renderable %s\n",
111 (int)grColorType,
112 GrRenderable::kYes == renderable ? "yes" : "no");
113 return;
114 }
115
116 // Skia proper should know nothing about the new backend object
117 REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
118
119 SkColorType skColorType = GrColorTypeToSkColorType(grColorType);
120
121 // Wrapping a backendTexture in an SkImage/SkSurface requires an SkColorType
122 if (skColorType == kUnknown_SkColorType) {
123 return;
124 }
125
126 // As we transition to using attachments instead of GrTextures and GrRenderTargets individual
127 // proxy instansiations may add multiple things to the cache. There would be an entry for the
128 // GrTexture/GrRenderTarget and entries for one or more attachments.
129 int cacheEntriesPerProxy = 1;
130 // We currently only have attachments on the vulkan and metal backends
131 if (dContext->backend() == GrBackend::kVulkan || dContext->backend() == GrBackend::kMetal) {
132 // If we ever make a rt with multisamples this would have an additional
133 // attachment as well.
134 cacheEntriesPerProxy++;
135 }
136
137 if (GrRenderable::kYes == renderable && dContext->colorTypeSupportedAsSurface(skColorType)) {
139 mbet->texture(),
141 0,
142 skColorType,
143 nullptr,
144 nullptr);
145 if (!surf) {
146 ERRORF(reporter, "Couldn't make SkSurface from backendTexture for %s\n",
147 ToolUtils::colortype_name(skColorType));
148 } else {
150 initialCount + cacheEntriesPerProxy == cache->getResourceCount());
151 }
152 }
153
154 {
156 mbet->texture(),
158 skColorType,
160 nullptr);
161 if (!img) {
162 ERRORF(reporter, "Couldn't make SkImage from backendTexture for %s\n",
163 ToolUtils::colortype_name(skColorType));
164 } else {
165 GrTextureProxy* proxy = sk_gpu_test::GetTextureImageProxy(img.get(), dContext);
167
168 REPORTER_ASSERT(reporter, mipmapped == proxy->proxyMipmapped());
170 REPORTER_ASSERT(reporter, mipmapped == proxy->mipmapped());
171
173 initialCount + cacheEntriesPerProxy == cache->getResourceCount());
174 }
175 }
176
177 REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
178}
GrResourceCache * getResourceCache()
SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const
bool isInstantiated() const
skgpu::Mipmapped proxyMipmapped() const
skgpu::Mipmapped mipmapped() const
T * get() const
Definition SkRefCnt.h:303
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
const char * colortype_name(SkColorType ct)
Definition ToolUtils.cpp:65
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)