Alter createTestingOnlyBackendTexture methods
This intended to bring this API more into line with the proposed GrBackendObject API with an eye towards replacing the former with the latter.
TBR=bsalomon@google.com
Change-Id: I4367f03fb10fff788749f21c4843060111a6df1c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213220
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 2f84e62..d7fc702 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1391,7 +1391,8 @@
break;
case SkCommandLineConfigGpu::SurfType::kBackendTexture:
backendTexture = context->priv().getGpu()->createTestingOnlyBackendTexture(
- nullptr, info.width(), info.height(), info.colorType(), true, GrMipMapped::kNo);
+ info.width(), info.height(), info.colorType(),
+ GrMipMapped::kNo, GrRenderable::kYes);
surface = SkSurface::MakeFromBackendTexture(context, backendTexture,
kTopLeft_GrSurfaceOrigin, fSampleCount,
fColorType, info.refColorSpace(), &props);
diff --git a/gm/flippity.cpp b/gm/flippity.cpp
index 24c7879..deb6775 100644
--- a/gm/flippity.cpp
+++ b/gm/flippity.cpp
@@ -130,7 +130,8 @@
auto origin = bottomLeftOrigin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
- auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, false, kImageSize, kImageSize,
+ auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo,
+ kImageSize, kImageSize,
bm.colorType(), origin, bm.getPixels(),
bm.rowBytes());
if (!proxy) {
diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp
index a491a6a..828170e 100644
--- a/gm/imagefromyuvtextures.cpp
+++ b/gm/imagefromyuvtextures.cpp
@@ -130,11 +130,12 @@
for (int i = 0; i < 3; ++i) {
SkASSERT(fYUVBmps[i].width() == SkToInt(fYUVBmps[i].rowBytes()));
- yuvTextures[i] = gpu->createTestingOnlyBackendTexture(fYUVBmps[i].getPixels(),
- fYUVBmps[i].width(),
+ yuvTextures[i] = gpu->createTestingOnlyBackendTexture(fYUVBmps[i].width(),
fYUVBmps[i].height(),
- GrColorType::kAlpha_8,
- false, GrMipMapped::kNo);
+ kAlpha_8_SkColorType,
+ GrMipMapped::kNo,
+ GrRenderable::kNo,
+ fYUVBmps[i].getPixels());
}
context->resetContext();
}
@@ -147,7 +148,7 @@
}
*resultTexture = gpu->createTestingOnlyBackendTexture(
- nullptr, width, height, GrColorType::kRGBA_8888, true, GrMipMapped::kNo);
+ width, height, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes);
context->resetContext();
}
diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp
index 379c817..6b2e21a 100644
--- a/gm/wacky_yuv_formats.cpp
+++ b/gm/wacky_yuv_formats.cpp
@@ -773,6 +773,8 @@
static GrBackendTexture create_yuva_texture(GrGpu* gpu, const SkBitmap& bm,
SkYUVAIndex yuvaIndices[4], int texIndex) {
+ const GrCaps* caps = gpu->caps();
+
SkASSERT(texIndex >= 0 && texIndex <= 3);
int channelCount = 0;
for (int i = 0; i < SkYUVAIndex::kIndexCount; ++i) {
@@ -794,24 +796,22 @@
currPixel += 2;
}
}
+ GrBackendFormat format = caps->getBackendFormatFromGrColorType(GrColorType::kRG_88,
+ GrSRGBEncoded::kNo);
tex = gpu->createTestingOnlyBackendTexture(
- pixels,
bm.width(),
bm.height(),
- GrColorType::kRG_88,
- false,
- GrMipMapped::kNo,
- 2*bm.width());
+ format,
+ GrMipMapped::kNo, GrRenderable::kNo,
+ pixels, 2*bm.width());
}
if (!tex.isValid()) {
tex = gpu->createTestingOnlyBackendTexture(
- bm.getPixels(),
bm.width(),
bm.height(),
bm.colorType(),
- false,
- GrMipMapped::kNo,
- bm.rowBytes());
+ GrMipMapped::kNo, GrRenderable::kNo,
+ bm.getPixels(), bm.rowBytes());
}
return tex;
}
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index 350887e..20f217d 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -113,14 +113,14 @@
GrBackendFormat(const GrPixelConfig config);
GrBackendApi fBackend;
- bool fValid;
+ bool fValid;
union {
GrGLenum fGLFormat; // the sized, internal format of the GL resource
struct {
VkFormat fFormat;
GrVkYcbcrConversionInfo fYcbcrConversionInfo;
- } fVk;
+ } fVk;
#ifdef SK_METAL
GrMTLPixelFormat fMtlFormat;
#endif
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 35522d8..2d40cb6 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -217,6 +217,14 @@
kYes = true
};
+/*
+ * Can a GrBackendObject be rendered to?
+ */
+enum class GrRenderable : bool {
+ kNo = false,
+ kYes = true
+};
+
///////////////////////////////////////////////////////////////////////////////
/**
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index f500944..b0ff943 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -458,13 +458,17 @@
#endif
#if GR_TEST_UTILS
-GrBackendTexture GrGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- SkColorType colorType, bool isRenderTarget,
- GrMipMapped isMipped, size_t rowBytes) {
- GrColorType grCT = SkColorTypeToGrColorType(colorType);
+GrBackendTexture GrGpu::createTestingOnlyBackendTexture(int w, int h, SkColorType colorType,
+ GrMipMapped mipMapped,
+ GrRenderable renderable,
+ const void* pixels, size_t rowBytes) {
+ GrBackendFormat format = this->caps()->getBackendFormatFromColorType(colorType);
+ if (!format.isValid()) {
+ return GrBackendTexture();
+ }
- return this->createTestingOnlyBackendTexture(pixels, w, h, grCT, isRenderTarget, isMipped,
- rowBytes);
+ return this->createTestingOnlyBackendTexture(w, h, format, mipMapped, renderable,
+ pixels, rowBytes);
}
#if GR_GPU_STATS
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index e40e80b..f812d3a 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -395,16 +395,18 @@
void dumpJSON(SkJSONWriter*) const;
#if GR_TEST_UTILS
- GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- SkColorType, bool isRenderTarget,
- GrMipMapped, size_t rowBytes = 0);
+ GrBackendTexture createTestingOnlyBackendTexture(int w, int h, SkColorType,
+ GrMipMapped, GrRenderable,
+ const void* pixels = nullptr,
+ size_t rowBytes = 0);
/** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is
only to be used for testing (particularly for testing the methods that import an externally
created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */
- virtual GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType, bool isRenderTarget,
- GrMipMapped, size_t rowBytes = 0) = 0;
+ virtual GrBackendTexture createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat&,
+ GrMipMapped, GrRenderable,
+ const void* pixels = nullptr,
+ size_t rowBytes = 0) = 0;
/** Check a handle represents an actual texture in the backend API that has not been freed. */
virtual bool isTestingOnlyBackendTexture(const GrBackendTexture&) const = 0;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 6e2f58d..577ab0a 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3970,13 +3970,83 @@
}
#if GR_TEST_UTILS
-GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType colorType, bool /*isRT*/,
+static bool gl_format_to_pixel_config(GrGLenum format, GrPixelConfig* config) {
+ GrPixelConfig dontCare;
+ if (!config) {
+ config = &dontCare;
+ }
+
+ switch (format) {
+ case GR_GL_RGBA8:
+ *config = kRGBA_8888_GrPixelConfig;
+ return true;
+ case GR_GL_RGB8:
+ *config = kRGB_888_GrPixelConfig;
+ return true;
+ case GR_GL_RG8:
+ *config = kRG_88_GrPixelConfig;
+ return true;
+ case GR_GL_BGRA8:
+ *config = kBGRA_8888_GrPixelConfig;
+ return true;
+ case GR_GL_LUMINANCE8:
+ *config = kGray_8_GrPixelConfig;
+ return true;
+ case GR_GL_SRGB8_ALPHA8:
+ *config = kSRGBA_8888_GrPixelConfig; // aliasing kSBGRA_8888 here
+ return true;
+ case GR_GL_RGB10_A2:
+ *config = kRGBA_1010102_GrPixelConfig;
+ return true;
+ case GR_GL_RGB565:
+ *config = kRGB_565_GrPixelConfig;
+ return true;
+ case GR_GL_RGBA4:
+ *config = kRGBA_4444_GrPixelConfig;
+ return true;
+ case GR_GL_ALPHA8: // fall through
+ case GR_GL_R8:
+ *config = kAlpha_8_GrPixelConfig;
+ return true;
+ case GR_GL_RGBA32F:
+ *config = kRGBA_float_GrPixelConfig;
+ return true;
+ case GR_GL_RG32F:
+ *config = kRG_float_GrPixelConfig;
+ return true;
+ case GR_GL_RGBA16F:
+ *config = kRGBA_half_GrPixelConfig;
+ return true;
+ case GR_GL_COMPRESSED_RGB8_ETC2:
+ *config = kRGB_ETC1_GrPixelConfig;
+ return true;
+ case GR_GL_R16F:
+ *config = kAlpha_half_GrPixelConfig;
+ return true;
+ }
+
+ SK_ABORT("Unexpected config");
+ return false;
+}
+
+GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(int w, int h,
+ const GrBackendFormat& format,
GrMipMapped mipMapped,
- size_t rowBytes) {
+ GrRenderable /* renderable */,
+ const void* pixels, size_t rowBytes) {
this->handleDirtyContext();
- GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo);
+ const GrGLenum* glFormat = format.getGLFormat();
+ if (!glFormat) {
+ return GrBackendTexture(); // invalid
+ }
+
+ GrPixelConfig config;
+
+ if (!gl_format_to_pixel_config(*glFormat, &config)) {
+ return GrBackendTexture(); // invalid
+ }
+
if (!this->caps()->isConfigTexturable(config)) {
return GrBackendTexture(); // invalid
}
@@ -3993,7 +4063,7 @@
if (mipMapped == GrMipMapped::kYes && !this->caps()->mipMapSupport()) {
return GrBackendTexture();
}
- int bpp = GrColorTypeBytesPerPixel(colorType);
+ int bpp = GrBytesPerPixel(config);
const size_t trimRowBytes = w * bpp;
if (!rowBytes) {
rowBytes = trimRowBytes;
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index a93b42b..e8d5be1 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -137,9 +137,9 @@
int width,
int height) override;
#if GR_TEST_UTILS
- GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType colorType, bool isRenderTarget,
- GrMipMapped mipMapped,
+ GrBackendTexture createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat&,
+ GrMipMapped, GrRenderable,
+ const void* pixels = nullptr,
size_t rowBytes = 0) override;
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp
index 5512a1c..9989cff 100644
--- a/src/gpu/gl/GrGLUtil.cpp
+++ b/src/gpu/gl/GrGLUtil.cpp
@@ -559,4 +559,3 @@
return gTable[(int)test];
}
-
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index 1c0df8f..2a8d4b3 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -197,18 +197,24 @@
}
#if GR_TEST_UTILS
-GrBackendTexture GrMockGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType colorType, bool isRT,
+GrBackendTexture GrMockGpu::createTestingOnlyBackendTexture(int w, int h,
+ const GrBackendFormat& format,
GrMipMapped mipMapped,
+ GrRenderable renderable,
+ const void* pixels,
size_t rowBytes) {
- GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo);
- if (!this->caps()->isConfigTexturable(config)) {
+ const GrPixelConfig* pixelConfig = format.getMockFormat();
+ if (!pixelConfig) {
+ return GrBackendTexture(); // invalid
+ }
+
+ if (!this->caps()->isConfigTexturable(*pixelConfig)) {
return GrBackendTexture(); // invalid
}
GrMockTextureInfo info;
- info.fConfig = config;
+ info.fConfig = *pixelConfig;
info.fID = NextExternalTextureID();
fOutstandingTestingOnlyTextureIDs.add(info.fID);
return GrBackendTexture(w, h, mipMapped, info);
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 85938a4..f037676 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -122,9 +122,10 @@
int width,
int height) override;
#if GR_TEST_UTILS
- GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType, bool isRT,
- GrMipMapped, size_t rowBytes = 0) override;
+ GrBackendTexture createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat&,
+ GrMipMapped, GrRenderable,
+ const void* pixels = nullptr,
+ size_t rowBytes = 0) override;
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index f500377..54b6f34 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -61,9 +61,12 @@
void submitCommandBuffer(SyncQueue sync);
#if GR_TEST_UTILS
- GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType colorType, bool isRT,
- GrMipMapped, size_t rowBytes = 0) override;
+ GrBackendTexture createTestingOnlyBackendTexture(int w, int h,
+ const GrBackendFormat& format,
+ GrMipMapped mipMapped,
+ GrRenderable renderable,
+ const void* pixels = nullptr,
+ size_t rowBytes = 0) override;
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
@@ -212,7 +215,8 @@
int height) override;
#if GR_TEST_UTILS
- bool createTestingOnlyMtlTextureInfo(GrColorType colorType, int w, int h, bool texturable,
+ bool createTestingOnlyMtlTextureInfo(GrPixelConfig, MTLPixelFormat,
+ int w, int h, bool texturable,
bool renderable, GrMipMapped mipMapped,
const void* srcData, size_t rowBytes,
GrMtlTextureInfo* info);
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index cfa1652..9b0f42e 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -609,7 +609,8 @@
}
#if GR_TEST_UTILS
-bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrColorType colorType, int w, int h, bool texturable,
+bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrPixelConfig config, MTLPixelFormat format,
+ int w, int h, bool texturable,
bool renderable, GrMipMapped mipMapped,
const void* srcData, size_t srcRowBytes,
GrMtlTextureInfo* info) {
@@ -619,12 +620,6 @@
SkASSERT(!srcData);
}
- GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo);
-
- MTLPixelFormat format;
- if (!GrPixelConfigToMTLFormat(config, &format)) {
- return false;
- }
if (texturable && !fMtlCaps->isConfigTexturable(config)) {
return false;
}
@@ -652,7 +647,7 @@
desc.usage |= renderable ? MTLTextureUsageRenderTarget : 0;
id<MTLTexture> testTexture = [fDevice newTextureWithDescriptor: desc];
- size_t bpp = GrColorTypeBytesPerPixel(colorType);
+ size_t bpp = GrBytesPerPixel(config);
if (!srcRowBytes) {
srcRowBytes = w * bpp;
#ifdef SK_BUILD_FOR_MAC
@@ -708,19 +703,97 @@
return true;
}
-GrBackendTexture GrMtlGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType colorType, bool isRT,
- GrMipMapped mipMapped, size_t rowBytes) {
+static bool mtl_format_to_pixel_config(MTLPixelFormat format, GrPixelConfig* config) {
+ GrPixelConfig dontCare;
+ if (!config) {
+ config = &dontCare;
+ }
+
+ switch (format) {
+ case MTLPixelFormatInvalid:
+ *config = kUnknown_GrPixelConfig;
+ return false;
+ case MTLPixelFormatRGBA8Unorm:
+ *config = kRGBA_8888_GrPixelConfig;
+ return true;
+ case MTLPixelFormatRG8Unorm:
+ *config = kRG_88_GrPixelConfig;
+ return true;
+ case MTLPixelFormatBGRA8Unorm:
+ *config = kBGRA_8888_GrPixelConfig;
+ return true;
+ case MTLPixelFormatRGBA8Unorm_sRGB:
+ *config = kSRGBA_8888_GrPixelConfig;
+ return true;
+ case MTLPixelFormatBGRA8Unorm_sRGB:
+ *config = kSBGRA_8888_GrPixelConfig;
+ return true;
+ case MTLPixelFormatRGB10A2Unorm:
+ *config = kRGBA_1010102_GrPixelConfig;
+ return true;
+#ifdef SK_BUILD_FOR_IOS
+ case MTLPixelFormatB5G6R5Unorm:
+ *config = kRGB_565_GrPixelConfig;
+ return true;
+ case MTLPixelFormatABGR4Unorm:
+ *config = kRGBA_4444_GrPixelConfig;
+ return true;
+#endif
+ case MTLPixelFormatR8Unorm:
+ *config = kAlpha_8_GrPixelConfig;
+ return true;
+ case MTLPixelFormatRGBA32Float:
+ *config = kRGBA_float_GrPixelConfig;
+ return true;
+ case MTLPixelFormatRG32Float:
+ *config = kRG_float_GrPixelConfig;
+ return true;
+ case MTLPixelFormatRGBA16Float:
+ *config = kRGBA_half_GrPixelConfig;
+ return true;
+ case MTLPixelFormatR16Float:
+ *config = kAlpha_half_GrPixelConfig;
+ return true;
+#ifdef SK_BUILD_FOR_IOS
+ case MTLPixelFormatETC2_RGB8:
+ *config = kRGB_ETC1_GrPixelConfig;
+ return true;
+#endif
+ default:
+ return false;
+ }
+
+ SK_ABORT("Unexpected config");
+ return false;
+}
+
+GrBackendTexture GrMtlGpu::createTestingOnlyBackendTexture(int w, int h,
+ const GrBackendFormat& format,
+ GrMipMapped mipMapped,
+ GrRenderable renderable,
+ const void* pixels, size_t rowBytes) {
if (w > this->caps()->maxTextureSize() || h > this->caps()->maxTextureSize()) {
return GrBackendTexture();
}
- GrMtlTextureInfo info;
- if (!this->createTestingOnlyMtlTextureInfo(colorType, w, h, true, isRT, mipMapped, pixels,
- rowBytes, &info)) {
- return {};
+
+ const GrMTLPixelFormat* mtlFormat = format.getMtlFormat();
+ if (!mtlFormat) {
+ return GrBackendTexture();
}
- GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo);
+ GrPixelConfig config;
+
+ if (!mtl_format_to_pixel_config(static_cast<MTLPixelFormat>(*mtlFormat), &config)) {
+ return GrBackendTexture();
+ }
+
+ GrMtlTextureInfo info;
+ if (!this->createTestingOnlyMtlTextureInfo(config, static_cast<MTLPixelFormat>(*mtlFormat),
+ w, h, true,
+ GrRenderable::kYes == renderable, mipMapped,
+ pixels, rowBytes, &info)) {
+ return {};
+ }
GrBackendTexture backendTex(w, h, mipMapped, info);
backendTex.fConfig = config;
@@ -757,13 +830,18 @@
return GrBackendRenderTarget();
}
- GrMtlTextureInfo info;
- if (!this->createTestingOnlyMtlTextureInfo(ct, w, h, false, true, GrMipMapped::kNo, nullptr,
- 0, &info)) {
- return {};
+ GrPixelConfig config = GrColorTypeToPixelConfig(ct, GrSRGBEncoded::kNo);
+
+ MTLPixelFormat format;
+ if (!GrPixelConfigToMTLFormat(config, &format)) {
+ return GrBackendRenderTarget();
}
- GrPixelConfig config = GrColorTypeToPixelConfig(ct, GrSRGBEncoded::kNo);
+ GrMtlTextureInfo info;
+ if (!this->createTestingOnlyMtlTextureInfo(config, format, w, h, false, true,
+ GrMipMapped::kNo, nullptr, 0, &info)) {
+ return {};
+ }
GrBackendRenderTarget backendRT(w, h, 1, info);
backendRT.fConfig = config;
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 37acd73..1e04813 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -22,6 +22,7 @@
#include "src/gpu/GrRenderTargetPriv.h"
#include "src/gpu/GrTexturePriv.h"
#include "src/gpu/SkGpuDevice.h"
+#include "src/gpu/SkGr.h"
#include "src/gpu/vk/GrVkAMDMemoryAllocator.h"
#include "src/gpu/vk/GrVkCommandBuffer.h"
#include "src/gpu/vk/GrVkCommandPool.h"
@@ -1774,24 +1775,100 @@
return true;
}
-GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(const void* srcData, int w, int h,
- GrColorType colorType,
- bool isRenderTarget,
- GrMipMapped mipMapped, size_t rowBytes) {
+static bool vk_format_to_pixel_config(VkFormat format, GrPixelConfig* config) {
+ GrPixelConfig dontCare;
+ if (!config) {
+ config = &dontCare;
+ }
+
+ switch (format) {
+ case VK_FORMAT_UNDEFINED:
+ *config = kUnknown_GrPixelConfig;
+ return false;
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ *config = kRGBA_8888_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R8G8B8_UNORM:
+ *config = kRGB_888_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R8G8_UNORM:
+ *config = kRG_88_GrPixelConfig;
+ return true;
+ case VK_FORMAT_B8G8R8A8_UNORM:
+ *config = kBGRA_8888_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R8G8B8A8_SRGB:
+ *config = kSRGBA_8888_GrPixelConfig;
+ return true;
+ case VK_FORMAT_B8G8R8A8_SRGB:
+ *config = kSBGRA_8888_GrPixelConfig;
+ return true;
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+ *config = kRGBA_1010102_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R5G6B5_UNORM_PACK16:
+ *config = kRGB_565_GrPixelConfig;
+ return true;
+ case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
+ *config = kRGBA_4444_GrPixelConfig; // we're swizzling in this case
+ return true;
+ case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
+ *config = kRGBA_4444_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R8_UNORM:
+ *config = kAlpha_8_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R32G32B32A32_SFLOAT:
+ *config = kRGBA_float_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R32G32_SFLOAT:
+ *config = kRG_float_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R16G16B16A16_SFLOAT:
+ *config = kRGBA_half_GrPixelConfig;
+ return true;
+ case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
+ *config = kRGB_ETC1_GrPixelConfig;
+ return true;
+ case VK_FORMAT_R16_SFLOAT:
+ *config = kAlpha_half_GrPixelConfig;
+ return true;
+ default:
+ return false;
+ }
+ SK_ABORT("Unexpected config");
+ return false;
+}
+
+GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(int w, int h,
+ const GrBackendFormat& format,
+ GrMipMapped mipMapped,
+ GrRenderable renderable,
+ const void* srcData, size_t rowBytes) {
this->handleDirtyContext();
+
if (w > this->caps()->maxTextureSize() || h > this->caps()->maxTextureSize()) {
return GrBackendTexture();
}
- GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo);
+ const VkFormat* vkFormat = format.getVkFormat();
+ if (!vkFormat) {
+ return GrBackendTexture();
+ }
+
+ GrPixelConfig config;
+
+ if (!vk_format_to_pixel_config(*vkFormat, &config)) {
+ return GrBackendTexture();
+ }
if (!this->caps()->isConfigTexturable(config)) {
return GrBackendTexture();
}
GrVkImageInfo info;
- if (!this->createTestingOnlyVkImage(config, w, h, true, isRenderTarget, mipMapped, srcData,
- rowBytes, &info)) {
+ if (!this->createTestingOnlyVkImage(config, w, h, true, GrRenderable::kYes == renderable,
+ mipMapped, srcData, rowBytes, &info)) {
return {};
}
GrBackendTexture beTex = GrBackendTexture(w, h, info);
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 3ca94c4..a07c643 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -81,9 +81,10 @@
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
#if GR_TEST_UTILS
- GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
- GrColorType colorType, bool isRenderTarget,
- GrMipMapped, size_t rowBytes = 0) override;
+ GrBackendTexture createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat&,
+ GrMipMapped, GrRenderable,
+ const void* pixels = nullptr,
+ size_t rowBytes = 0) override;
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp
index e12495d..e1a841e 100644
--- a/tests/CopySurfaceTest.cpp
+++ b/tests/CopySurfaceTest.cpp
@@ -70,16 +70,16 @@
for (auto sOrigin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
for (auto dOrigin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
- for (auto sRT : {true, false}) {
- for (auto dRT : {true, false}) {
+ for (auto sRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
+ for (auto dRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
for (auto srcRect : kSrcRects) {
for (auto dstPoint : kDstPoints) {
for (auto ii: kImageInfos) {
auto src = sk_gpu_test::MakeTextureProxyFromData(
- context, sRT, kW, kH, ii.colorType(), sOrigin,
+ context, sRenderable, kW, kH, ii.colorType(), sOrigin,
srcPixels.get(), kRowBytes);
auto dst = sk_gpu_test::MakeTextureProxyFromData(
- context, dRT, kW, kH, ii.colorType(), dOrigin,
+ context, dRenderable, kW, kH, ii.colorType(), dOrigin,
dstPixels.get(), kRowBytes);
// Should always work if the color type is RGBA, but may not work
diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp
index fbaea76..ab95161 100644
--- a/tests/DeferredDisplayListTest.cpp
+++ b/tests/DeferredDisplayListTest.cpp
@@ -185,8 +185,8 @@
fColorType, fColorSpace, &fSurfaceProps);
}
- *backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight,
- fColorType, true, mipmapped);
+ *backend = gpu->createTestingOnlyBackendTexture(fWidth, fHeight, fColorType,
+ mipmapped, GrRenderable::kYes);
if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) {
return nullptr;
}
@@ -584,7 +584,7 @@
GrContext* context = ctxInfo.grContext();
GrGpu* gpu = context->priv().getGpu();
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
+ kSize, kSize, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
if (!backendTex.isValid()) {
return;
}
@@ -743,7 +743,7 @@
GrBackendTexture backendTexture;
if (!create_backend_texture(context, &backendTexture, ii, GrMipMapped::kNo, SK_ColorCYAN,
- Renderable::kNo)) {
+ GrRenderable::kNo)) {
REPORTER_ASSERT(reporter, false);
return;
}
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 42f13e5..a4e8dcc 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -88,8 +88,8 @@
GrGpu* gpu1 = context1->priv().getGpu();
static const int kSize = 100;
backendTexture1 =
- gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, GrColorType::kRGBA_8888,
- false, GrMipMapped::kNo);
+ gpu1->createTestingOnlyBackendTexture(kSize, kSize, kRGBA_8888_SkColorType,
+ GrMipMapped::kNo, GrRenderable::kNo);
if (!backendTexture1.isValid() || !gpu1->isTestingOnlyBackendTexture(backendTexture1)) {
ERRORF(reporter, "Error creating texture for EGL Image");
diff --git a/tests/FloatingPointTextureTest.cpp b/tests/FloatingPointTextureTest.cpp
index 9a09e0e..c65e4d1 100644
--- a/tests/FloatingPointTextureTest.cpp
+++ b/tests/FloatingPointTextureTest.cpp
@@ -46,8 +46,9 @@
}
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
- auto fpProxy = sk_gpu_test::MakeTextureProxyFromData(context, true, DEV_W, DEV_H, colorType,
- origin, controlPixelData.begin(), 0);
+ auto fpProxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kYes,
+ DEV_W, DEV_H, colorType, origin,
+ controlPixelData.begin(), 0);
// Floating point textures are NOT supported everywhere
if (!fpProxy) {
continue;
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index 592d399..3a1aae9 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -37,16 +37,16 @@
GrGpu* gpu = context->priv().getGpu();
for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
- for (auto isRT : {false, true}) {
+ for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
// CreateTestingOnlyBackendTexture currently doesn't support uploading data to mip maps
// so we don't send any. However, we pretend there is data for the checks below which is
// fine since we are never actually using these textures for any work on the gpu.
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, GrColorType::kRGBA_8888, isRT, mipMapped);
+ kSize, kSize, kRGBA_8888_SkColorType, mipMapped, renderable);
sk_sp<GrTextureProxy> proxy;
sk_sp<SkImage> image;
- if (isRT) {
+ if (GrRenderable::kYes == renderable) {
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
context,
backendTex,
@@ -83,7 +83,7 @@
if (GrMipMapped::kYes == mipMapped) {
REPORTER_ASSERT(reporter, GrMipMapped::kYes == texture->texturePriv().mipMapped());
- if (isRT) {
+ if (GrRenderable::kYes == renderable) {
REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty());
} else {
REPORTER_ASSERT(reporter, !texture->texturePriv().mipMapsAreDirty());
@@ -108,7 +108,7 @@
for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
for (auto willUseMips : {false, true}) {
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, mipMapped);
+ kSize, kSize, kRGBA_8888_SkColorType, mipMapped, GrRenderable::kNo);
sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex,
kTopLeft_GrSurfaceOrigin,
@@ -250,7 +250,7 @@
GrMipMapped mipMapped = willUseMips ? GrMipMapped::kYes : GrMipMapped::kNo;
sk_sp<SkSurface> surface;
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, GrColorType::kRGBA_8888, true, mipMapped);
+ kSize, kSize, kRGBA_8888_SkColorType, mipMapped, GrRenderable::kYes);
if (isWrapped) {
surface = SkSurface::MakeFromBackendTexture(context,
backendTex,
diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp
index 372d864..b4d11e3 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -998,8 +998,8 @@
}
GrBackendTexture backendTex =
- gpu->createTestingOnlyBackendTexture(nullptr, 100, 100, GrColorType::kRGBA_8888,
- false, GrMipMapped::kNo);
+ gpu->createTestingOnlyBackendTexture(100, 100, kRGBA_8888_SkColorType,
+ GrMipMapped::kNo, GrRenderable::kNo);
GrXferProcessor::DstProxy fakeDstProxy;
{
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index d90cd4d..dca3982 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -54,7 +54,7 @@
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, 256, 256, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
+ 256, 256, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
sk_sp<GrSurface> texRT2 = resourceProvider->wrapRenderableBackendTexture(
backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
@@ -285,7 +285,8 @@
// kRead for the right reason.
for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) {
auto backendTex = context->priv().getGpu()->createTestingOnlyBackendTexture(
- pixels.addr(), kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kNo);
+ kSize, kSize, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes,
+ pixels.addr());
auto proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, ioType);
@@ -330,7 +331,7 @@
// Mip regen should not work with a read only texture.
if (context->priv().caps()->mipMapSupport()) {
backendTex = context->priv().getGpu()->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kYes);
+ kSize, kSize, kRGBA_8888_SkColorType, GrMipMapped::kYes, GrRenderable::kYes);
proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
ioType);
@@ -343,11 +344,11 @@
}
}
-static sk_sp<GrTexture> make_wrapped_texture(GrContext* context, bool renderable) {
+static sk_sp<GrTexture> make_wrapped_texture(GrContext* context, GrRenderable renderable) {
auto backendTexture = context->priv().getGpu()->createTestingOnlyBackendTexture(
- nullptr, 10, 10, GrColorType::kRGBA_8888, renderable, GrMipMapped::kNo);
+ 10, 10, kRGBA_8888_SkColorType, GrMipMapped::kNo, renderable);
sk_sp<GrTexture> texture;
- if (renderable) {
+ if (GrRenderable::kYes == renderable) {
texture = context->priv().resourceProvider()->wrapRenderableBackendTexture(
backendTexture, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
} else {
@@ -372,23 +373,30 @@
return texture;
}
-static sk_sp<GrTexture> make_normal_texture(GrContext* context, bool renderable) {
+static sk_sp<GrTexture> make_normal_texture(GrContext* context, GrRenderable renderable) {
GrSurfaceDesc desc;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fWidth = desc.fHeight = 10;
- desc.fFlags = renderable ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
+ desc.fFlags = GrRenderable::kYes == renderable ? kRenderTarget_GrSurfaceFlag
+ : kNone_GrSurfaceFlags;
return context->priv().resourceProvider()->createTexture(
desc, SkBudgeted::kNo, GrResourceProvider::Flags::kNoPendingIO);
}
DEF_GPUTEST(TextureIdleProcTest, reporter, options) {
// Various ways of making textures.
- auto makeWrapped = [](GrContext* context) { return make_wrapped_texture(context, false); };
- auto makeWrappedRenderable = [](GrContext* context) {
- return make_wrapped_texture(context, true);
+ auto makeWrapped = [](GrContext* context) {
+ return make_wrapped_texture(context, GrRenderable::kNo);
};
- auto makeNormal = [](GrContext* context) { return make_normal_texture(context, false); };
- auto makeRenderable = [](GrContext* context) { return make_normal_texture(context, true); };
+ auto makeWrappedRenderable = [](GrContext* context) {
+ return make_wrapped_texture(context, GrRenderable::kYes);
+ };
+ auto makeNormal = [](GrContext* context) {
+ return make_normal_texture(context, GrRenderable::kNo);
+ };
+ auto makeRenderable = [](GrContext* context) {
+ return make_normal_texture(context, GrRenderable::kYes);
+ };
std::function<sk_sp<GrTexture>(GrContext*)> makers[] = {makeWrapped, makeWrappedRenderable,
makeNormal, makeRenderable};
@@ -626,8 +634,8 @@
for (const auto& otherMaker : {make_wrapped_texture, make_normal_texture}) {
for (auto idleState :
{GrTexture::IdleState::kFlushed, GrTexture::IdleState::kFinished}) {
- auto idleTexture = idleMaker(context, false);
- auto otherTexture = otherMaker(context, false);
+ auto idleTexture = idleMaker(context, GrRenderable::kNo);
+ auto otherTexture = otherMaker(context, GrRenderable::kNo);
otherTexture->ref();
idleTexture->addIdleProc(idleProc, otherTexture.get(), idleState);
otherTexture.reset();
@@ -647,7 +655,7 @@
for (const auto& idleMaker : {make_wrapped_texture, make_normal_texture}) {
for (auto idleState : {GrTexture::IdleState::kFlushed, GrTexture::IdleState::kFinished}) {
- auto idleTexture = idleMaker(context, false);
+ auto idleTexture = idleMaker(context, GrRenderable::kNo);
idleTexture->addIdleProc(idleProc, context, idleState);
auto info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
auto surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 1, nullptr);
@@ -659,7 +667,7 @@
GrBackendTexture backendTexture;
if (!create_backend_texture(context, &backendTexture, info,
- GrMipMapped::kNo, SK_ColorBLACK, Renderable::kNo)) {
+ GrMipMapped::kNo, SK_ColorBLACK, GrRenderable::kNo)) {
REPORTER_ASSERT(reporter, false);
continue;
}
@@ -683,7 +691,7 @@
auto releaseProc = [](void* isReleased) { *reinterpret_cast<bool*>(isReleased) = true; };
for (auto idleState : {GrTexture::IdleState::kFlushed, GrTexture::IdleState::kFinished}) {
bool isReleased = false;
- auto idleTexture = make_normal_texture(context, false);
+ auto idleTexture = make_normal_texture(context, GrRenderable::kNo);
// This test assumes the texture won't be cached (or else the release proc doesn't get
// called).
idleTexture->resourcePriv().removeScratchKey();
@@ -701,7 +709,7 @@
DEF_GPUTEST_FOR_ALL_CONTEXTS(TextureIdleStateTest, reporter, contextInfo) {
GrContext* context = contextInfo.grContext();
for (const auto& idleMaker : {make_wrapped_texture, make_normal_texture}) {
- auto idleTexture = idleMaker(context, false);
+ auto idleTexture = idleMaker(context, GrRenderable::kNo);
uint32_t flags = 0;
static constexpr uint32_t kFlushFlag = 0x1;
diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp
index 0d4f205..638f850 100644
--- a/tests/GrTestingBackendTextureUploadTest.cpp
+++ b/tests/GrTestingBackendTextureUploadTest.cpp
@@ -11,11 +11,13 @@
#include "src/core/SkConvertPixels.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrGpu.h"
+#include "src/gpu/SkGr.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
-void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, GrColorType ct,
- bool renderTarget, bool doDataUpload, GrMipMapped mipMapped) {
+void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct,
+ GrRenderable renderable, bool doDataUpload, GrMipMapped mipMapped) {
+
const int kWidth = 16;
const int kHeight = 16;
SkAutoTMalloc<GrColor> srcBuffer;
@@ -27,26 +29,29 @@
GrGpu* gpu = context->priv().getGpu();
- GrPixelConfig config = GrColorTypeToPixelConfig(ct, GrSRGBEncoded::kNo);
+ GrPixelConfig config = SkColorType2GrPixelConfig(ct);
if (!gpu->caps()->isConfigTexturable(config)) {
return;
}
- if (gpu->caps()->supportedReadPixelsColorType(config, ct) != ct) {
+
+ GrColorType grCT = SkColorTypeToGrColorType(ct);
+ if (GrColorType::kUnknown == grCT) {
return;
}
- GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(srcBuffer,
- kWidth,
- kHeight,
- ct,
- renderTarget,
- mipMapped);
+ if (gpu->caps()->supportedReadPixelsColorType(config, grCT) != grCT) {
+ return;
+ }
+
+ GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
+ kWidth, kHeight, ct,
+ mipMapped, renderable, srcBuffer);
if (!backendTex.isValid()) {
return;
}
sk_sp<GrTexture> wrappedTex;
- if (renderTarget) {
+ if (GrRenderable::kYes == renderable) {
wrappedTex = gpu->wrapRenderableBackendTexture(
backendTex, 1, GrWrapOwnership::kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
} else {
@@ -55,9 +60,9 @@
}
REPORTER_ASSERT(reporter, wrappedTex);
- int rowBytes = GrColorTypeBytesPerPixel(ct) * kWidth;
+ int rowBytes = GrColorTypeBytesPerPixel(grCT) * kWidth;
bool result = gpu->readPixels(wrappedTex.get(), 0, 0, kWidth,
- kHeight, ct, dstBuffer, rowBytes);
+ kHeight, grCT, dstBuffer, rowBytes);
if (!doDataUpload) {
// createTestingOnlyBackendTexture will fill the texture with 0's if no data is provided, so
@@ -71,8 +76,8 @@
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTestingBackendTextureUploadTest, reporter, ctxInfo) {
- for (auto colorType: { GrColorType::kRGBA_8888, GrColorType::kBGRA_8888 }) {
- for (bool renderable: {true, false}) {
+ for (auto colorType: { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType }) {
+ for (auto renderable: { GrRenderable::kYes, GrRenderable::kNo }) {
for (bool doDataUpload: {true, false}) {
testing_only_texture_test(reporter, ctxInfo.grContext(), colorType,
renderable, doDataUpload, GrMipMapped::kNo);
diff --git a/tests/GrUploadPixelsTests.cpp b/tests/GrUploadPixelsTests.cpp
index 8daeeea..c3b8250 100644
--- a/tests/GrUploadPixelsTests.cpp
+++ b/tests/GrUploadPixelsTests.cpp
@@ -20,7 +20,7 @@
using sk_gpu_test::GrContextFactory;
void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct,
- bool renderTarget) {
+ GrRenderable renderable) {
const int kWidth = 16;
const int kHeight = 16;
SkAutoTMalloc<GrColor> srcBuffer(kWidth*kHeight);
@@ -28,7 +28,7 @@
fill_pixel_data(kWidth, kHeight, srcBuffer.get());
- auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct,
+ auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderable, kWidth, kHeight, ct,
kTopLeft_GrSurfaceOrigin, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
@@ -58,7 +58,7 @@
2));
}
- proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct,
+ proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderable, kWidth, kHeight, ct,
kBottomLeft_GrSurfaceOrigin, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
@@ -92,10 +92,10 @@
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrUploadPixelsTests, reporter, ctxInfo) {
// RGBA
- basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, false);
- basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, true);
+ basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kNo);
+ basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kYes);
// BGRA
- basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, false);
- basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, true);
+ basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kNo);
+ basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kYes);
}
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index e49766a..e5b1257 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -488,7 +488,7 @@
bool can = ctxInfo.grContext()->colorTypeSupportedAsImage(colorType);
auto* gpu = ctxInfo.grContext()->priv().getGpu();
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, colorType, false, GrMipMapped::kNo);
+ kSize, kSize, colorType, GrMipMapped::kNo, GrRenderable::kNo);
auto img =
SkImage::MakeFromTexture(ctxInfo.grContext(), backendTex, kTopLeft_GrSurfaceOrigin,
colorType, kOpaque_SkAlphaType, nullptr);
@@ -833,7 +833,7 @@
GrBackendTexture backendTex;
if (!create_backend_texture(ctx, &backendTex, ii, GrMipMapped::kNo, SK_ColorRED,
- Renderable::kNo)) {
+ GrRenderable::kNo)) {
ERRORF(reporter, "couldn't create backend texture\n");
}
diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp
index e3a935f..6c613e4 100644
--- a/tests/LazyProxyTest.cpp
+++ b/tests/LazyProxyTest.cpp
@@ -473,7 +473,7 @@
desc.fConfig = kRGBA_8888_GrPixelConfig;
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
+ kSize, kSize, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy(
[instantiatePtr, releasePtr,
diff --git a/tests/PackedConfigsTextureTest.cpp b/tests/PackedConfigsTextureTest.cpp
index f69b1db..4e8a49e 100644
--- a/tests/PackedConfigsTextureTest.cpp
+++ b/tests/PackedConfigsTextureTest.cpp
@@ -112,8 +112,8 @@
SkImageInfo::Make(DEV_W, DEV_H, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
- auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, false, DEV_W, DEV_H,
- colorType,
+ auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo,
+ DEV_W, DEV_H, colorType,
origin, controlPixelData.begin(), 0);
SkASSERT(proxy);
diff --git a/tests/PromiseImageTest.cpp b/tests/PromiseImageTest.cpp
index 7aaf84c..eaa7866 100644
--- a/tests/PromiseImageTest.cpp
+++ b/tests/PromiseImageTest.cpp
@@ -168,7 +168,7 @@
GrGpu* gpu = ctx->priv().getGpu();
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo);
+ kWidth, kHeight, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes);
REPORTER_ASSERT(reporter, backendTex.isValid());
GrBackendFormat backendFormat = backendTex.getBackendFormat();
@@ -243,11 +243,11 @@
GrGpu* gpu = ctx->priv().getGpu();
GrBackendTexture backendTex1 = gpu->createTestingOnlyBackendTexture(
- nullptr, kWidth, kHeight, GrColorType::kGray_8, false, GrMipMapped::kNo);
+ kWidth, kHeight, kGray_8_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
REPORTER_ASSERT(reporter, backendTex1.isValid());
GrBackendTexture backendTex2 = gpu->createTestingOnlyBackendTexture(
- nullptr, kWidth, kHeight, GrColorType::kAlpha_8, false, GrMipMapped::kNo);
+ kWidth, kHeight, kAlpha_8_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
REPORTER_ASSERT(reporter, backendTex2.isValid());
if (backendTex1.getBackendFormat() != backendTex2.getBackendFormat()) {
gpu->deleteTestingOnlyBackendTexture(backendTex1);
@@ -354,7 +354,7 @@
GrGpu* gpu = ctx->priv().getGpu();
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kWidth, kHeight, GrColorType::kAlpha_8, false, GrMipMapped::kNo);
+ kWidth, kHeight, kAlpha_8_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
REPORTER_ASSERT(reporter, backendTex.isValid());
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType,
@@ -393,7 +393,7 @@
GrGpu* gpu = ctx->priv().getGpu();
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kWidth, kHeight, GrColorType::kAlpha_8, false, GrMipMapped::kNo);
+ kWidth, kHeight, kAlpha_8_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
REPORTER_ASSERT(reporter, backendTex.isValid());
SkImageInfo info =
@@ -457,7 +457,7 @@
// Do all this just to get a valid backend format for the image.
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo);
+ kWidth, kHeight, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes);
REPORTER_ASSERT(reporter, backendTex.isValid());
GrBackendFormat backendFormat = backendTex.getBackendFormat();
REPORTER_ASSERT(reporter, backendFormat.isValid());
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index bd646e8..74d3707 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -274,9 +274,10 @@
// Tests wrapBackendRenderTarget with a GrBackendTexture
{
GrBackendTexture backendTex =
- gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
- kWidthHeight, colorType,
- true, GrMipMapped::kNo);
+ gpu->createTestingOnlyBackendTexture(kWidthHeight, kWidthHeight,
+ colorType,
+ GrMipMapped::kNo,
+ GrRenderable::kYes);
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
backendTex, origin, supportedNumSamples);
if (!sProxy) {
@@ -298,9 +299,10 @@
// Tests wrapBackendTexture that is only renderable
{
GrBackendTexture backendTex =
- gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
- kWidthHeight, colorType,
- true, GrMipMapped::kNo);
+ gpu->createTestingOnlyBackendTexture(kWidthHeight, kWidthHeight,
+ colorType,
+ GrMipMapped::kNo,
+ GrRenderable::kYes);
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
backendTex, origin, supportedNumSamples, kBorrow_GrWrapOwnership,
@@ -325,9 +327,10 @@
{
// Internal offscreen texture
GrBackendTexture backendTex =
- gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
- kWidthHeight, colorType,
- false, GrMipMapped::kNo);
+ gpu->createTestingOnlyBackendTexture(kWidthHeight, kWidthHeight,
+ colorType,
+ GrMipMapped::kNo,
+ GrRenderable::kNo);
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
backendTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index e9b509d..dcb90d4 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -539,9 +539,9 @@
// On the GPU we will also try reading back from a non-renderable texture.
for (auto origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
- for (auto isRT : {false, true}) {
+ for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
sk_sp<GrTextureProxy> proxy = sk_gpu_test::MakeTextureProxyFromData(
- context, isRT, DEV_W, DEV_H, bmp.colorType(), origin, bmp.getPixels(),
+ context, renderable, DEV_W, DEV_H, bmp.colorType(), origin, bmp.getPixels(),
bmp.rowBytes());
sk_sp<GrSurfaceContext> sContext = context->priv().makeWrappedSurfaceContext(
std::move(proxy));
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index 2cb39e1..06f8457 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -159,9 +159,9 @@
GrColorType fColorType;
GrSRGBEncoded fSRGBEncoded;
} kInfos[] = {
- {GrColorType::kRGBA_8888, GrSRGBEncoded::kNo},
- {GrColorType::kBGRA_8888, GrSRGBEncoded::kNo},
- {GrColorType::kRGBA_8888, GrSRGBEncoded::kYes},
+ {GrColorType::kRGBA_8888, GrSRGBEncoded::kNo},
+ {GrColorType::kBGRA_8888, GrSRGBEncoded::kNo},
+ {GrColorType::kRGBA_8888, GrSRGBEncoded::kYes},
{GrColorType::kRGBA_1010102, GrSRGBEncoded::kNo},
};
@@ -178,7 +178,7 @@
// Attempt to read back just alpha from a RGBA/BGRA texture. Once with a texture-only src and
// once with a render target.
for (auto info : kInfos) {
- for (int rt = 0; rt < 2; ++rt) {
+ for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
uint32_t rgbaData[X_SIZE * Y_SIZE];
// Make the alpha channel of the rgba texture come from alphaData.
for (int y = 0; y < Y_SIZE; ++y) {
@@ -187,8 +187,9 @@
}
}
- auto origin = rt ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
- auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, rt, X_SIZE, Y_SIZE,
+ auto origin = GrRenderable::kYes == renderable ? kBottomLeft_GrSurfaceOrigin
+ : kTopLeft_GrSurfaceOrigin;
+ auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderable, X_SIZE, Y_SIZE,
info.fColorType, info.fSRGBEncoded,
origin, rgbaData, 0);
if (!proxy) {
@@ -211,7 +212,8 @@
// make sure the original & read back versions match
SkString msg;
- msg.printf("rt:%d, rb:%d 8888", rt, SkToU32(rowBytes));
+ msg.printf("rt:%d, rb:%d 8888", GrRenderable::kYes == renderable,
+ SkToU32(rowBytes));
validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZeroRowBytes,
alphaData, msg, info.fColorType);
}
diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp
index 11984f5..a4124ca 100644
--- a/tests/ResourceAllocatorTest.cpp
+++ b/tests/ResourceAllocatorTest.cpp
@@ -63,9 +63,8 @@
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
GrGpu* gpu = context->priv().getGpu();
- *backendTex = gpu->createTestingOnlyBackendTexture(nullptr, p.fSize, p.fSize,
- p.fColorType, false,
- GrMipMapped::kNo);
+ *backendTex = gpu->createTestingOnlyBackendTexture(p.fSize, p.fSize, p.fColorType,
+ GrMipMapped::kNo, GrRenderable::kNo);
if (!backendTex->isValid()) {
return nullptr;
}
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index c7bfc72..7cf5d4c 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -209,12 +209,10 @@
static const int kW = 100;
static const int kH = 100;
- backendTextures[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
- GrColorType::kRGBA_8888,
- false, GrMipMapped::kNo);
- backendTextures[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
- GrColorType::kRGBA_8888,
- false, GrMipMapped::kNo);
+ backendTextures[0] = gpu->createTestingOnlyBackendTexture(kW, kH, kRGBA_8888_SkColorType,
+ GrMipMapped::kNo, GrRenderable::kNo);
+ backendTextures[1] = gpu->createTestingOnlyBackendTexture(kW, kH, kRGBA_8888_SkColorType,
+ GrMipMapped::kNo, GrRenderable::kNo);
REPORTER_ASSERT(reporter, backendTextures[0].isValid());
REPORTER_ASSERT(reporter, backendTextures[1].isValid());
if (!backendTextures[0].isValid() || !backendTextures[1].isValid()) {
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index f3dc89c..5741d57 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -102,7 +102,7 @@
auto* gpu = ctxInfo.grContext()->priv().getGpu();
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo);
+ kSize, kSize, colorType, GrMipMapped::kNo, GrRenderable::kYes);
surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex,
kTopLeft_GrSurfaceOrigin, 0, colorType, nullptr,
nullptr);
@@ -129,8 +129,8 @@
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
colorType, can, SkToBool(surf));
- backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kSize, kSize, colorType, true,
- GrMipMapped::kNo);
+ backendTex = gpu->createTestingOnlyBackendTexture(kSize, kSize, colorType,
+ GrMipMapped::kNo, GrRenderable::kYes);
surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex,
kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType,
nullptr, nullptr);
@@ -197,7 +197,7 @@
}
auto* gpu = ctxInfo.grContext()->priv().getGpu();
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo);
+ kSize, kSize, colorType, GrMipMapped::kNo, GrRenderable::kYes);
if (!backendTex.isValid()) {
continue;
}
@@ -682,7 +682,8 @@
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
- if (!create_backend_texture(ctx, outTexture, ii, GrMipMapped::kNo, color, Renderable::kYes)) {
+ if (!create_backend_texture(ctx, outTexture, ii, GrMipMapped::kNo, color,
+ GrRenderable::kYes)) {
return nullptr;
}
@@ -706,7 +707,8 @@
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
- if (!create_backend_texture(ctx, outTexture, ii, GrMipMapped::kNo, color, Renderable::kYes)) {
+ if (!create_backend_texture(ctx, outTexture, ii, GrMipMapped::kNo, color,
+ GrRenderable::kYes)) {
return nullptr;
}
@@ -889,7 +891,7 @@
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
if (!create_backend_texture(ctx, &backendTex, ii, GrMipMapped::kNo, SK_ColorRED,
- Renderable::kYes)) {
+ GrRenderable::kYes)) {
continue;
}
diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp
index d33428c..5ed9d48 100644
--- a/tests/TestUtils.cpp
+++ b/tests/TestUtils.cpp
@@ -110,11 +110,11 @@
}
}
- for (auto isRT : {false, true}) {
+ for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
auto src = sk_gpu_test::MakeTextureProxyFromData(
- context, isRT, dstContext->width(),
- dstContext->height(), GrColorType::kRGBA_8888, origin, pixels.get(), 0);
+ context, renderable, dstContext->width(),
+ dstContext->height(), kRGBA_8888_SkColorType, origin, pixels.get(), 0);
dstContext->copy(src.get());
test_read_pixels(reporter, dstContext, pixels.get(), testName);
}
@@ -134,25 +134,20 @@
bool create_backend_texture(GrContext* context, GrBackendTexture* backendTex,
const SkImageInfo& ii, GrMipMapped mipMapped, SkColor color,
- Renderable renderable) {
- auto* gpu = context->priv().getGpu();
+ GrRenderable renderable) {
+ GrGpu* gpu = context->priv().getGpu();
if (!gpu) {
return false;
}
- GrColorType grCT = SkColorTypeToGrColorType(ii.colorType());
- if (GrColorType::kUnknown == grCT) {
- return false;
- }
-
SkBitmap bm;
bm.allocPixels(ii);
// TODO: a SkBitmap::eraseColor would be better here
sk_memset32(bm.getAddr32(0, 0), color, ii.width() * ii.height());
- *backendTex = gpu->createTestingOnlyBackendTexture(bm.getPixels(), ii.width(), ii.height(),
- grCT, Renderable::kYes == renderable,
- mipMapped, bm.rowBytes());
+ *backendTex = gpu->createTestingOnlyBackendTexture(ii.width(), ii.height(), ii.colorType(),
+ mipMapped, renderable,
+ bm.getPixels(), bm.rowBytes());
if (!backendTex->isValid() || !gpu->isTestingOnlyBackendTexture(*backendTex)) {
return false;
}
diff --git a/tests/TestUtils.h b/tests/TestUtils.h
index 16df4c6..ec4d835 100644
--- a/tests/TestUtils.h
+++ b/tests/TestUtils.h
@@ -35,15 +35,10 @@
// Fills data with a red-green gradient
void fill_pixel_data(int width, int height, GrColor* data);
-enum class Renderable : bool {
- kNo = false,
- kYes = true
-};
-
// Create a solid colored backend texture
bool create_backend_texture(GrContext*, GrBackendTexture* backendTex,
const SkImageInfo& ii, GrMipMapped mipMapped, SkColor color,
- Renderable);
+ GrRenderable);
void delete_backend_texture(GrContext*, const GrBackendTexture& backendTex);
diff --git a/tests/TextureBindingsResetTest.cpp b/tests/TextureBindingsResetTest.cpp
index 876722b..719bd55 100644
--- a/tests/TextureBindingsResetTest.cpp
+++ b/tests/TextureBindingsResetTest.cpp
@@ -16,7 +16,8 @@
#define GL(F) GR_GL_CALL(ctxInfo.glContext()->gl(), F)
GrContext* context = ctxInfo.grContext();
- GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu());
+ GrGpu* gpu = context->priv().getGpu();
+ GrGLGpu* glGpu = static_cast<GrGLGpu*>(context->priv().getGpu());
struct Target {
GrGLenum fName;
@@ -25,11 +26,11 @@
SkTDArray<Target> targets;
targets.push_back({GR_GL_TEXTURE_2D, GR_GL_TEXTURE_BINDING_2D});
bool supportExternal;
- if ((supportExternal = gpu->glCaps().shaderCaps()->externalTextureSupport())) {
+ if ((supportExternal = glGpu->glCaps().shaderCaps()->externalTextureSupport())) {
targets.push_back({GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_BINDING_EXTERNAL});
}
bool supportRectangle;
- if ((supportRectangle = gpu->glCaps().rectangleTextureSupport())) {
+ if ((supportRectangle = glGpu->glCaps().rectangleTextureSupport())) {
targets.push_back({GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_BINDING_RECTANGLE});
}
GrGLint numUnits;
@@ -101,7 +102,7 @@
if (supportExternal) {
GrBackendTexture texture2D = gpu->createTestingOnlyBackendTexture(
- nullptr, 10, 10, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
+ 10, 10, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
GrGLTextureInfo info2D;
REPORTER_ASSERT(reporter, texture2D.getGLTextureInfo(&info2D));
GrEGLImage eglImage = ctxInfo.glContext()->texture2DToEGLImage(info2D.fID);
diff --git a/tests/VkBackendSurfaceTest.cpp b/tests/VkBackendSurfaceTest.cpp
index bce65a8..076e263 100644
--- a/tests/VkBackendSurfaceTest.cpp
+++ b/tests/VkBackendSurfaceTest.cpp
@@ -31,12 +31,12 @@
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
- GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
+ GrGpu* gpu = context->priv().getGpu();
- GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(nullptr, 1, 1,
- GrColorType::kRGBA_8888,
- false,
- GrMipMapped::kNo);
+ GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(1, 1,
+ kRGBA_8888_SkColorType,
+ GrMipMapped::kNo,
+ GrRenderable::kNo);
REPORTER_ASSERT(reporter, backendTex.isValid());
GrVkImageInfo info;
@@ -132,16 +132,17 @@
// its original queue family.
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkReleaseExternalQueueTest, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
- GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
- if (!gpu->vkCaps().supportsExternalMemory()) {
+ GrGpu* gpu = context->priv().getGpu();
+ GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu);
+ if (!vkGpu->vkCaps().supportsExternalMemory()) {
return;
}
for (bool useExternal : {false, true}) {
- GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(nullptr, 1, 1,
- GrColorType::kRGBA_8888,
- false,
- GrMipMapped::kNo);
+ GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(1, 1,
+ kRGBA_8888_SkColorType,
+ GrMipMapped::kNo,
+ GrRenderable::kNo);
sk_sp<SkImage> image;
int count = 0;
if (useExternal) {
@@ -183,7 +184,7 @@
if (useExternal) {
// Testing helper so we claim that we don't need to transition from our fake external
// queue first.
- vkTex->setCurrentQueueFamilyToGraphicsQueue(gpu);
+ vkTex->setCurrentQueueFamilyToGraphicsQueue(vkGpu);
}
image.reset();
@@ -210,8 +211,9 @@
// in flush calls
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkPrepareForExternalIOQueueTransitionTest, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
- GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
- if (!gpu->vkCaps().supportsExternalMemory()) {
+ GrGpu* gpu = context->priv().getGpu();
+ GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu);
+ if (!vkGpu->vkCaps().supportsExternalMemory()) {
return;
}
@@ -222,7 +224,8 @@
continue;
}
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, 4, 4, GrColorType::kRGBA_8888, useSurface, GrMipMapped::kNo);
+ 4, 4, kRGBA_8888_SkColorType, GrMipMapped::kNo,
+ useSurface ? GrRenderable::kYes : GrRenderable::kNo);
// Make a backend texture with an external queue family and general layout.
GrVkImageInfo vkInfo;
@@ -235,7 +238,7 @@
if (preparePresent) {
// We don't transition to present to things that are going to external for foreign
// queues.
- vkInfo.fCurrentQueueFamily = gpu->queueIndex();
+ vkInfo.fCurrentQueueFamily = vkGpu->queueIndex();
} else {
vkInfo.fCurrentQueueFamily = VK_QUEUE_FAMILY_EXTERNAL;
}
@@ -272,7 +275,7 @@
// Testing helper so we claim that we don't need to transition from our fake external
// queue first.
- vkTex->setCurrentQueueFamilyToGraphicsQueue(gpu);
+ vkTex->setCurrentQueueFamilyToGraphicsQueue(vkGpu);
GrBackendTexture newBackendTexture;
if (useSurface) {
@@ -283,7 +286,7 @@
}
GrVkImageInfo newVkInfo;
REPORTER_ASSERT(reporter, newBackendTexture.getVkImageInfo(&newVkInfo));
- REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == gpu->queueIndex());
+ REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex());
VkImageLayout oldLayout = newVkInfo.fImageLayout;
GrPrepareForExternalIORequests externalRequests;
@@ -310,7 +313,7 @@
}
REPORTER_ASSERT(reporter, newBackendTexture.getVkImageInfo(&newVkInfo));
if (preparePresent) {
- REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == gpu->queueIndex());
+ REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex());
REPORTER_ASSERT(reporter,
newVkInfo.fImageLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
} else {
@@ -330,13 +333,14 @@
// Test to make sure we transition from the EXTERNAL queue even when no layout transition is needed.
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkTransitionExternalQueueTest, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
- GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
- if (!gpu->vkCaps().supportsExternalMemory()) {
+ GrGpu* gpu = context->priv().getGpu();
+ GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu);
+ if (!vkGpu->vkCaps().supportsExternalMemory()) {
return;
}
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, 1, 1, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
+ 1, 1, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo);
sk_sp<SkImage> image;
// Make a backend texture with an external queue family and general layout.
GrVkImageInfo vkInfo;
@@ -363,14 +367,14 @@
// Change our backend texture to the internal queue, with the same layout. This should force a
// queue transition even though the layouts match.
- vkTex->setImageLayout(gpu, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0,
+ vkTex->setImageLayout(vkGpu, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, false, false);
// Get our image info again and make sure we transitioned queues.
GrBackendTexture newBackendTexture = image->getBackendTexture(true);
GrVkImageInfo newVkInfo;
REPORTER_ASSERT(reporter, newBackendTexture.getVkImageInfo(&newVkInfo));
- REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == gpu->queueIndex());
+ REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex());
image.reset();
gpu->testingOnly_flushGpuAndSync();
diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp
index 00271d6..f93610a 100644
--- a/tests/VkWrapTests.cpp
+++ b/tests/VkWrapTests.cpp
@@ -30,15 +30,16 @@
const int kW = 1024;
const int kH = 1024;
const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig;
-const GrColorType kColorType = GrColorType::kRGBA_8888;
+const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType;
void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
- GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
+ GrGpu* gpu = context->priv().getGpu();
- GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
- kColorType, false,
- GrMipMapped::kNo);
+ GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(kW, kH,
+ kColorType,
+ GrMipMapped::kNo,
+ GrRenderable::kNo);
GrVkImageInfo imageInfo;
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
@@ -87,11 +88,12 @@
}
void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) {
- GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
+ GrGpu* gpu = context->priv().getGpu();
- GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
- kColorType, true,
- GrMipMapped::kNo);
+ GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(kW, kH,
+ kColorType,
+ GrMipMapped::kNo,
+ GrRenderable::kYes);
GrVkImageInfo imageInfo;
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
@@ -129,11 +131,12 @@
}
void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
- GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
+ GrGpu* gpu = context->priv().getGpu();
- GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
- kColorType, true,
- GrMipMapped::kNo);
+ GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(kW, kH,
+ kColorType,
+ GrMipMapped::kNo,
+ GrRenderable::kYes);
GrVkImageInfo imageInfo;
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index 30a4cc5..0dc9c11 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -456,7 +456,7 @@
for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
- nullptr, DEV_W, DEV_H, GrColorType::kRGBA_8888, true, GrMipMapped::kNo);
+ DEV_W, DEV_H, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes);
if (!backendTex.isValid()) {
continue;
}
diff --git a/tools/DDLPromiseImageHelper.cpp b/tools/DDLPromiseImageHelper.cpp
index 77db2f1..eff3f5b 100644
--- a/tools/DDLPromiseImageHelper.cpp
+++ b/tools/DDLPromiseImageHelper.cpp
@@ -59,6 +59,8 @@
// needed until we have SkRG_88_ColorType;
static GrBackendTexture create_yuva_texture(GrGpu* gpu, const SkPixmap& pm,
const SkYUVAIndex yuvaIndices[4], int texIndex) {
+ const GrCaps* caps = gpu->caps();
+
SkASSERT(texIndex >= 0 && texIndex <= 3);
int channelCount = 0;
for (int i = 0; i < SkYUVAIndex::kIndexCount; ++i) {
@@ -80,23 +82,18 @@
currPixel += 2;
}
}
+
+ GrBackendFormat format = caps->getBackendFormatFromGrColorType(GrColorType::kRG_88,
+ GrSRGBEncoded::kNo);
tex = gpu->createTestingOnlyBackendTexture(
- pixels,
- pm.width(),
- pm.height(),
- GrColorType::kRG_88,
- false,
- GrMipMapped::kNo,
- 2 * pm.width());
+ pm.width(), pm.height(), format,
+ GrMipMapped::kNo, GrRenderable::kNo,
+ pixels, 2 * pm.width());
} else {
tex = gpu->createTestingOnlyBackendTexture(
- pm.addr(),
- pm.width(),
- pm.height(),
- pm.colorType(),
- false,
- GrMipMapped::kNo,
- pm.rowBytes());
+ pm.width(), pm.height(), pm.colorType(),
+ GrMipMapped::kNo, GrRenderable::kNo,
+ pm.addr(), pm.rowBytes());
}
return tex;
}
@@ -131,12 +128,9 @@
const SkBitmap& bm = info.normalBitmap();
callbackContext->setBackendTexture(gpu->createTestingOnlyBackendTexture(
- bm.getPixels(),
- bm.width(),
- bm.height(),
- bm.colorType(),
- false, GrMipMapped::kNo,
- bm.rowBytes()));
+ bm.width(), bm.height(), bm.colorType(),
+ GrMipMapped::kNo, GrRenderable::kNo,
+ bm.getPixels(), bm.rowBytes()));
// The GMs sometimes request too large an image
//SkAssertResult(callbackContext->backendTexture().isValid());
diff --git a/tools/fm/fm.cpp b/tools/fm/fm.cpp
index ff4a01a..7eaa16e 100644
--- a/tools/fm/fm.cpp
+++ b/tools/fm/fm.cpp
@@ -281,12 +281,11 @@
case SurfaceType::kBackendTexture:
backendTexture = context->priv().getGpu()
- ->createTestingOnlyBackendTexture(nullptr,
- info.width(),
+ ->createTestingOnlyBackendTexture(info.width(),
info.height(),
info.colorType(),
- true,
- GrMipMapped::kNo);
+ GrMipMapped::kNo,
+ GrRenderable::kYes);
surface = SkSurface::MakeFromBackendTexture(context,
backendTexture,
kTopLeft_GrSurfaceOrigin,
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index 216118a..6a57ad9 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -10,29 +10,38 @@
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrGpu.h"
#include "src/gpu/GrProxyProvider.h"
+#include "src/gpu/SkGr.h"
#include "tools/gpu/ProxyUtils.h"
namespace sk_gpu_test {
-sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT,
+sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, GrRenderable renderable,
int width, int height,
GrColorType colorType, GrSRGBEncoded srgbEncoded,
- GrSurfaceOrigin origin, const void* data,
- size_t rowBytes) {
+ GrSurfaceOrigin origin,
+ const void* data, size_t rowBytes) {
if (context->priv().abandoned()) {
return nullptr;
}
+ const GrCaps* caps = context->priv().caps();
+
+ const GrBackendFormat format = caps->getBackendFormatFromGrColorType(colorType, srgbEncoded);
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrTextureProxy> proxy;
if (kBottomLeft_GrSurfaceOrigin == origin) {
// We (soon will) only support using kBottomLeft with wrapped textures.
auto backendTex = context->priv().getGpu()->createTestingOnlyBackendTexture(
- nullptr, width, height, colorType, isRT, GrMipMapped::kNo);
+ width, height, format, GrMipMapped::kNo, renderable);
if (!backendTex.isValid()) {
return nullptr;
}
+
// Adopt ownership so our caller doesn't have to worry about deleting the backend texture.
- if (isRT) {
+ if (GrRenderable::kYes == renderable) {
proxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
backendTex, origin, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, nullptr,
nullptr);
@@ -52,24 +61,19 @@
return nullptr;
}
- const GrBackendFormat format =
- context->priv().caps()->getBackendFormatFromGrColorType(colorType,
- srgbEncoded);
- if (!format.isValid()) {
- return nullptr;
- }
-
GrSurfaceDesc desc;
desc.fConfig = config;
desc.fWidth = width;
desc.fHeight = height;
- desc.fFlags = isRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
+ desc.fFlags = GrRenderable::kYes == renderable ? kRenderTarget_GrSurfaceFlag
+ : kNone_GrSurfaceFlags;
proxy = context->priv().proxyProvider()->createProxy(
format, desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
if (!proxy) {
return nullptr;
}
}
+
auto sContext = context->priv().makeWrappedSurfaceContext(proxy, nullptr);
if (!sContext) {
return nullptr;
diff --git a/tools/gpu/ProxyUtils.h b/tools/gpu/ProxyUtils.h
index e8526a9..b85a3cd 100644
--- a/tools/gpu/ProxyUtils.h
+++ b/tools/gpu/ProxyUtils.h
@@ -14,28 +14,33 @@
namespace sk_gpu_test {
/** Makes a texture proxy containing the passed in color data. */
-sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext*, bool isRT, int width, int height,
+sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext*, GrRenderable, int width, int height,
GrColorType, GrSRGBEncoded, GrSurfaceOrigin,
const void* data, size_t rowBytes);
-/** Version that assumes GrSRGBEncoded::kNo. */
+/** Version that takes GrColorType rather than SkColorType and assumes GrSRGBEncoded::kNo. */
inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
- bool isRT, int width,
- int height, GrColorType ct,
+ GrRenderable renderable, int width,
+ int height, GrColorType grCT,
GrSurfaceOrigin origin, const void* data,
size_t rowBytes) {
- return MakeTextureProxyFromData(context, isRT, width, height, ct, GrSRGBEncoded::kNo, origin,
- data, rowBytes);
+ return MakeTextureProxyFromData(context, renderable, width, height,
+ grCT, GrSRGBEncoded::kNo, origin, data, rowBytes);
}
/** Version that takes SkColorType rather than GrColorType and assumes GrSRGBEncoded::kNo. */
inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
- bool isRT, int width,
+ GrRenderable renderable, int width,
int height, SkColorType ct,
GrSurfaceOrigin origin, const void* data,
size_t rowBytes) {
- return MakeTextureProxyFromData(context, isRT, width, height, SkColorTypeToGrColorType(ct),
- origin, data, rowBytes);
+ GrColorType grCT = SkColorTypeToGrColorType(ct);
+ if (GrColorType::kUnknown == grCT) {
+ return nullptr;
+ }
+
+ return MakeTextureProxyFromData(context, renderable, width, height,
+ grCT, GrSRGBEncoded::kNo, origin, data, rowBytes);
}
} // namespace sk_gpu_test