59#include <initializer_list>
80#if defined(SK_DIRECT3D)
94using sk_gpu_test::ManagedBackendTexture;
106 const int initialCount = cache->getResourceCount();
110 ERRORF(
reporter,
"Couldn't create backendTexture for grColorType %d renderable %s\n",
112 GrRenderable::kYes == renderable ?
"yes" :
"no");
129 int cacheEntriesPerProxy = 1;
134 cacheEntriesPerProxy++;
146 ERRORF(
reporter,
"Couldn't make SkSurface from backendTexture for %s\n",
150 initialCount + cacheEntriesPerProxy == cache->getResourceCount());
162 ERRORF(
reporter,
"Couldn't make SkImage from backendTexture for %s\n",
173 initialCount + cacheEntriesPerProxy == cache->getResourceCount());
181 switch (
format.backend()) {
205 DXGI_FORMAT d3dFormat;
206 format.asDxgiFormat(&d3dFormat);
207 return d3dFormat == DXGI_FORMAT_B8G8R8A8_UNORM;
228 switch (
format.backend()) {
261 const char* label2) {
264 const float tols[4] = { 0.01f, 0.01f, 0.01f, 0.01f };
266 auto error = std::function<ComparePixmapsErrorReporter>(
267 [
reporter, ct, label1, label2, expected](
int x,
int y,
const float diffs[4]) {
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]);
283 std::unique_ptr<char[]> data(
new char[ii.minRowBytes()]);
284 GrClearImage(ii, data.get(), ii.minRowBytes(), orig.array());
290 GrPixmap( ii, data.get(), ii.minRowBytes()));
325 for (
GrRenderable renderableCtx : {GrRenderable::kNo, GrRenderable::kYes}) {
326 if (renderableCtx == GrRenderable::kYes && renderableTexture == GrRenderable::kNo) {
330 if (renderableCtx == GrRenderable::kYes) {
346 if (!surfaceContext) {
347 ERRORF(
reporter,
"Could not create surface context for colorType: %d\n",
351 if (!surfaceContext->readPixels(dContext, actual, {0, 0})) {
355 ERRORF(
reporter,
"Couldn't readback from SurfaceContext for colorType: %d\n",
360 (renderableCtx == GrRenderable::kYes ?
"SurfaceFillContext"
361 :
"SurfaceContext"));
383 auto checkBackendTexture = [&](
const SkColor4f& testColor) {
384 if (mipmapped == skgpu::Mipmapped::kYes) {
386 SkColor4f expectedColors[6] = {expectedColor, expectedColor, expectedColor,
387 expectedColor, expectedColor, expectedColor};
397 checkBackendTexture(
color);
407 ManagedBackendTexture::ReleaseProc,
408 mbet->releaseContext());
409 checkBackendTexture(newColor);
441 if (!dstFillContext) {
446 constexpr int kNumMipLevels = 6;
460 for (
int i = 0, rectSize = 32; i < kNumMipLevels; ++i, rectSize /= 2) {
466 static constexpr GrSamplerState kNearestNearest(GrSamplerState::Filter::kNearest,
467 GrSamplerState::MipmapMode::kNearest);
472 *dstFillContext->caps());
473 dstFillContext->fillRectWithFP(
SkIRect::MakeWH(rectSize, rectSize), std::move(fp));
482 bool result = dstFillContext->readPixels(dContext, actual, {0, 0});
486 str.
appendf(
"mip-level %d", i);
505 std::unique_ptr<char[]> memForPixmaps;
507 { 1.0f, 0.0f, 0.0f, 1.0f },
508 { 0.0f, 1.0f, 0.0f, 0.9f },
509 { 0.0f, 0.0f, 1.0f, 0.7f },
510 { 0.0f, 1.0f, 1.0f, 0.5f },
511 { 1.0f, 0.0f, 1.0f, 0.3f },
512 { 1.0f, 1.0f, 0.0f, 0.2f },
517 mipmapped == skgpu::Mipmapped::kYes,
534 auto checkBackendTexture = [&](
const SkColor4f colors[6]) {
536 if (mipmapped == skgpu::Mipmapped::kYes) {
555 checkBackendTexture(kColors);
558 {1.0f, 1.0f, 0.0f, 0.2f},
559 {1.0f, 0.0f, 0.0f, 1.0f},
560 {0.0f, 1.0f, 0.0f, 0.9f},
561 {0.0f, 0.0f, 1.0f, 0.7f},
562 {0.0f, 1.0f, 1.0f, 0.5f},
563 {1.0f, 0.0f, 1.0f, 0.3f},
567 mipmapped == skgpu::Mipmapped::kYes,
577 ManagedBackendTexture::ReleaseProc,
578 mbet->releaseContext());
580 checkBackendTexture(kColorsNew);
589#if defined(SK_VULKAN) && defined(SK_DEBUG)
600 using namespace skgpu;
603 const GrCaps* caps = context->priv().caps();
607 constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
608 constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f };
646 for (
auto combo : combinations) {
662 for (
auto mipmapped : { Mipmapped::kNo, Mipmapped::kYes}) {
663 if (Mipmapped::kYes == mipmapped && !caps->
mipmapSupport()) {
667 for (
auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
673 if (GrRenderable::kYes == renderable) {
684 auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
711 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
742 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
761 createWithSrcDataMtd,
780 if (!
info.directContext()) {
786 if (
info.directContext()->priv().caps()->writePixelsRowBytesSupport() &&
789 overrideOptions.fDisallowWriteAndTransferPixelRowBytes =
true;
806 auto context = ctxInfo.directContext();
807 const GrGLCaps* glCaps =
static_cast<const GrGLCaps*
>(context->priv().caps());
809 constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
810 constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 1.f };
811 constexpr SkColor4f kTransGrayCol { 0.5f, 0.5f, 0.5f, .8f };
857 for (
auto combo : combinations) {
876 for (
auto mipmapped : {skgpu::Mipmapped::kNo, skgpu::Mipmapped::kYes}) {
877 if (skgpu::Mipmapped::kYes == mipmapped &&
882 for (
auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
883 if (GrRenderable::kYes == renderable) {
893 return ManagedBackendTexture::MakeWithoutData(dContext,
902 mipmapped, renderable);
915 switch (combo.fColorType) {
933 return ManagedBackendTexture::MakeWithData(dContext,
942 combo.fColor, mipmapped, renderable);
960 using namespace skgpu;
962 auto context = ctxInfo.directContext();
963 const GrVkCaps* vkCaps =
static_cast<const GrVkCaps*
>(context->priv().caps());
967 constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
968 constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 1 };
987 { 0.25f, 0.5f, 0.75f, 1.0f }},
989 { 0.25f, 0.5f, 0.75f, 1.0f }},
991 { 0.25f, 0.5f, 0.75f, 1.0f }},
1016 for (
auto combo : combinations) {
1023 for (
auto mipmapped : { Mipmapped::kNo, Mipmapped::kYes }) {
1024 if (Mipmapped::kYes == mipmapped && !vkCaps->
mipmapSupport()) {
1028 for (
auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
1030 if (GrRenderable::kYes == renderable) {
1043 auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
1067 switch (combo.fColorType) {
1095 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
1106 combo.fColor, mipmapped, renderable);
static void check_solid_pixmap(skiatest::Reporter *reporter, const SkColor4f &expected, const SkPixmap &actual, GrColorType ct, const char *label1, const char *label2)
void check_vk_tiling(const GrBackendTexture &backendTex)
static bool isRGB(const GrBackendFormat &format)
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)
static SkColor4f get_expected_color(SkColor4f orig, GrColorType ct)
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)
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)
static bool isBGRA8(const GrBackendFormat &format)
void color_type_backend_allocation_test(const sk_gpu_test::ContextInfo &ctxInfo, skiatest::Reporter *reporter)
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 void info(const char *fmt,...) SK_PRINTF_LIKE(1
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)
#define GR_GL_SRGB8_ALPHA8
#define GR_GL_LUMINANCE8_ALPHA8
#define GR_GL_LUMINANCE16F
#define GR_GL_TEXTURE_RECTANGLE
@ kBorrow_GrWrapOwnership
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
@ kBottomLeft_GrSurfaceOrigin
@ kTopLeft_GrSurfaceOrigin
skgpu::Protected Protected
#define SkAssertResult(cond)
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
@ kLastEnum_SkColorType
last valid value
@ kSRGBA_8888_SkColorType
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
@ kA16_float_SkColorType
pixel with a half float for alpha
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
@ kUnknown_SkColorType
uninitialized
@ kR16G16_float_SkColorType
pixel with a half float for red and green
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SK_API SkString static SkString SkStringPrintf()
bool CheckSolidPixels(const SkColor4f &col, const SkPixmap &pixmap, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
#define DEF_GANESH_TEST_FOR_VULKAN_CONTEXT(name, reporter, context_info, ctsEnforcement)
#define DEF_GANESH_TEST(name, reporter, options, ctsEnforcement)
#define REPORTER_ASSERT(r, cond,...)
#define DEF_GANESH_TEST_FOR_GL_CONTEXT(name, reporter, context_info, ctsEnforcement)
GrBackendFormat getBackendFormat() const
const GrCaps * caps() const
bool mipmapSupport() const
bool supportsProtectedContent() const
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
SK_API GrBackendApi backend() const
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const
GrResourceCache * getResourceCache()
SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const
bool updateBackendTexture(const GrBackendTexture &, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
GrDirectContextPriv priv()
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const override
bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const override
GrGLStandard standard() const
const GrGLContextInfo & ctxInfo() const
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 &)
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)
bool isInstantiated() const
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
skgpu::Mipmapped proxyMipmapped() const
skgpu::Mipmapped mipmapped() const
bool isVkFormatTexturable(VkFormat) const
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const override
bool tryAlloc(const SkImageInfo &)
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
bool erase(SkColor color, const SkIRect &subset) const
const char * c_str() const
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
GrDirectContext * directContext() const
const GrGLInterface * gl() const
ContextInfo getContextInfo(ContextType type, ContextOverrides=ContextOverrides::kNone)
constexpr std::array< float, 4 > applyTo(std::array< float, 4 > color) const
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
SK_API bool GetVkImageInfo(const GrBackendTexture &, GrVkImageInfo *)
constexpr SkColor4f kLtGray
constexpr SkColor4f kGreen
constexpr SkColor4f kCyan
constexpr SkColor4f kTransparent
constexpr SkColor4f kGray
constexpr SkColor4f kBlue
constexpr SkColor4f kYellow
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)
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
static const int kContextTypeCount
bool IsRenderingContext(skgpu::ContextType type)
VkImageTiling fImageTiling
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
@ VK_IMAGE_TILING_OPTIMAL
@ VK_FORMAT_R16G16B16A16_UNORM
@ VK_FORMAT_R8G8B8A8_SRGB
@ VK_FORMAT_B8G8R8A8_UNORM
@ VK_FORMAT_R16G16_SFLOAT
@ VK_FORMAT_B4G4R4A4_UNORM_PACK16
@ VK_FORMAT_R5G6B5_UNORM_PACK16
@ VK_FORMAT_R4G4B4A4_UNORM_PACK16
@ VK_FORMAT_A2B10G10R10_UNORM_PACK32
@ VK_FORMAT_R8G8B8A8_UNORM
@ VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16
@ VK_FORMAT_R16G16B16A16_SFLOAT
@ VK_FORMAT_A2R10G10B10_UNORM_PACK32