Make rest of GrGpu::wrapBackend* methods take a GrColorType (take 2)
This CL is intended to further wean Ganesh off of using the GrBackendTexture's pixel config
TBR=bsalomon@google.com
Bug: skia:6718
Change-Id: Iedaa7811f9c4aac552f219c702627bc476325317
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228338
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index d3b2fc2..cb2a296 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -249,10 +249,9 @@
bool isSameTexture(const GrBackendTexture&);
#if GR_TEST_UTILS
- // We can remove the pixelConfig getter and setter once we remove the GrPixelConfig from the
- // GrBackendTexture and plumb the GrPixelconfig manually throughout our code (or remove all use
+ // We can remove the pixelConfig setter once we remove the GrPixelConfig from the
+ // GrBackendTexture and plumb the GrPixelConfig manually throughout our code (or remove all use
// of GrPixelConfig in general).
- GrPixelConfig pixelConfig() const { return fConfig; }
void setPixelConfig(GrPixelConfig config) { fConfig = config; }
static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&);
@@ -415,10 +414,9 @@
#if GR_TEST_UTILS
- // We can remove the pixelConfig getter and setter once we remove the pixel config from the
+ // We can remove the pixelConfig setter once we remove the pixel config from the
// GrBackendRenderTarget and plumb the pixel config manually throughout our code (or remove all
// use of GrPixelConfig in general).
- GrPixelConfig pixelConfig() const { return fConfig; }
void setPixelConfig(GrPixelConfig config) { fConfig = config; }
static bool TestingOnly_Equals(const GrBackendRenderTarget&, const GrBackendRenderTarget&);
diff --git a/include/gpu/mock/GrMockTypes.h b/include/gpu/mock/GrMockTypes.h
index ccdda50..6060f95 100644
--- a/include/gpu/mock/GrMockTypes.h
+++ b/include/gpu/mock/GrMockTypes.h
@@ -61,6 +61,8 @@
GrBackendFormat getBackendFormat() const;
+ GrColorType colorType() const { return fColorType; }
+
private:
GrColorType fColorType;
int fID;
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index 7c2b981..c6ad66b 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -19,6 +19,7 @@
#include "include/private/SkImageInfoPriv.h"
#include "include/private/SkWeakRefCnt.h"
+class GrBackendFormat;
class GrCaps;
// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might
@@ -1199,6 +1200,12 @@
SkUNREACHABLE;
}
+// This is a temporary means of mapping an SkColorType and format to a
+// GrColorType::kRGBA_8888_SRGB. Once we have an SRGB SkColorType this can go away.
+GrColorType SkColorTypeAndFormatToGrColorType(const GrCaps* caps,
+ SkColorType skCT,
+ const GrBackendFormat& format);
+
static constexpr uint32_t GrColorTypeComponentFlags(GrColorType ct) {
switch (ct) {
case GrColorType::kUnknown: return 0;
diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp
index e29094b..e84a873 100644
--- a/src/gpu/GrAHardwareBufferImageGenerator.cpp
+++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp
@@ -95,8 +95,9 @@
fBufferFormat,
false);
- GrPixelConfig pixelConfig = context->priv().caps()->getConfigFromBackendFormat(
- backendFormat, SkColorTypeToGrColorType(this->getInfo().colorType()));
+ GrColorType grColorType = SkColorTypeToGrColorType(this->getInfo().colorType());
+ GrPixelConfig pixelConfig = context->priv().caps()->getConfigFromBackendFormat(backendFormat,
+ grColorType);
if (pixelConfig == kUnknown_GrPixelConfig) {
return nullptr;
@@ -150,7 +151,7 @@
sk_sp<GrTextureProxy> texProxy = proxyProvider->createLazyProxy(
[direct, buffer = AutoAHBRelease(hardwareBuffer), width, height, pixelConfig,
- isProtectedContent, backendFormat](GrResourceProvider* resourceProvider)
+ isProtectedContent, backendFormat, grColorType](GrResourceProvider* resourceProvider)
-> GrSurfaceProxy::LazyInstantiationResult {
GrAHardwareBufferUtils::DeleteImageProc deleteImageProc = nullptr;
GrAHardwareBufferUtils::DeleteImageCtx deleteImageCtx = nullptr;
@@ -173,7 +174,8 @@
// is invoked. We know the owning SkIamge will send an invalidation message when the
// image is destroyed, so the texture will be removed at that time.
sk_sp<GrTexture> tex = resourceProvider->wrapBackendTexture(
- backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, kRead_GrIOType);
+ backendTex, grColorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
+ kRead_GrIOType);
if (!tex) {
deleteImageProc(deleteImageCtx);
return {};
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index b9444f3..da9bea1 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -51,15 +51,20 @@
context->priv().getResourceCache()->insertDelayedResourceUnref(texture.get());
GrBackendTexture backendTexture = texture->getBackendTexture();
- GrBackendFormat backendFormat = backendTexture.getBackendFormat();
- if (!backendFormat.isValid()) {
- return nullptr;
- }
- backendTexture.fConfig =
- context->priv().caps()->getConfigFromBackendFormat(backendFormat,
- SkColorTypeToGrColorType(colorType));
- if (backendTexture.fConfig == kUnknown_GrPixelConfig) {
- return nullptr;
+
+ // TODO: delete this block
+ {
+ GrBackendFormat backendFormat = backendTexture.getBackendFormat();
+ if (!backendFormat.isValid()) {
+ return nullptr;
+ }
+
+ backendTexture.fConfig = context->priv().caps()->getConfigFromBackendFormat(
+ backendFormat,
+ SkColorTypeToGrColorType(colorType));
+ if (backendTexture.fConfig == kUnknown_GrPixelConfig) {
+ return nullptr;
+ }
}
SkImageInfo info = SkImageInfo::Make(texture->width(), texture->height(), colorType, alphaType,
@@ -79,7 +84,6 @@
, fRefHelper(new RefHelper(texture, owningContextID))
, fSemaphore(std::move(semaphore))
, fBackendTexture(backendTex)
- , fConfig(backendTex.config())
, fSurfaceOrigin(origin) {}
GrBackendTextureImageGenerator::~GrBackendTextureImageGenerator() {
@@ -110,6 +114,7 @@
}
auto proxyProvider = context->priv().proxyProvider();
+ const GrCaps* caps = context->priv().caps();
fBorrowingMutex.acquire();
sk_sp<GrRefCntedCallback> releaseProcHelper;
@@ -141,20 +146,32 @@
SkASSERT(fRefHelper->fBorrowingContextID == context->priv().contextID());
+
+ GrBackendFormat backendFormat = fBackendTexture.getBackendFormat();
+ SkASSERT(backendFormat.isValid());
+
+ GrColorType grColorType = SkColorTypeToGrColorType(info.colorType());
+
+ GrPixelConfig config = caps->getConfigFromBackendFormat(backendFormat, grColorType);
+ if (kUnknown_GrPixelConfig == config) {
+ return nullptr;
+ }
+
+ SkASSERT(GrCaps::AreConfigsCompatible(fBackendTexture.config(),
+ caps->getConfigFromBackendFormat(backendFormat,
+ grColorType)));
+
GrSurfaceDesc desc;
desc.fWidth = fBackendTexture.width();
desc.fHeight = fBackendTexture.height();
- desc.fConfig = fConfig;
+ desc.fConfig = config;
GrMipMapped mipMapped = fBackendTexture.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo;
- GrBackendFormat format = fBackendTexture.getBackendFormat();
- SkASSERT(format.isValid());
-
// Must make copies of member variables to capture in the lambda since this image generator may
// be deleted before we actually execute the lambda.
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
[refHelper = fRefHelper, releaseProcHelper, semaphore = fSemaphore,
- backendTexture = fBackendTexture](GrResourceProvider* resourceProvider)
+ backendTexture = fBackendTexture, grColorType](GrResourceProvider* resourceProvider)
-> GrSurfaceProxy::LazyInstantiationResult {
if (semaphore) {
resourceProvider->priv().gpu()->waitSemaphore(semaphore);
@@ -180,8 +197,8 @@
// ever see the original texture, so this should be safe.
// We make the texture uncacheable so that the release proc is called ASAP.
tex = resourceProvider->wrapBackendTexture(
- backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ backendTexture, grColorType, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
if (!tex) {
return {};
}
@@ -192,10 +209,9 @@
// unrelated to the whatever SkImage key may be assigned to the proxy.
return {std::move(tex), GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
},
- format, desc, GrRenderable::kNo, 1, fSurfaceOrigin, mipMapped,
+ backendFormat, desc, GrRenderable::kNo, 1, fSurfaceOrigin, mipMapped,
GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, SkBudgeted::kNo,
GrProtected::kNo);
-
if (!proxy) {
return nullptr;
}
@@ -216,4 +232,3 @@
SkBudgeted::kYes);
}
}
-
diff --git a/src/gpu/GrBackendTextureImageGenerator.h b/src/gpu/GrBackendTextureImageGenerator.h
index 13616a3..8a82c5c 100644
--- a/src/gpu/GrBackendTextureImageGenerator.h
+++ b/src/gpu/GrBackendTextureImageGenerator.h
@@ -80,7 +80,6 @@
sk_sp<GrSemaphore> fSemaphore;
GrBackendTexture fBackendTexture;
- GrPixelConfig fConfig;
GrSurfaceOrigin fSurfaceOrigin;
typedef SkImageGenerator INHERITED;
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index 9311df1..0da7c10 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -403,7 +403,8 @@
* Special method only for YUVA images. Returns a config that matches the backend format or
* kUnknown if a config could not be determined.
*/
- virtual GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat& format) const = 0;
+ virtual GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const = 0;
+ virtual GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const = 0;
/** These are used when creating a new texture internally. */
virtual GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const = 0;
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 14795d2..a949078 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -106,7 +106,7 @@
ASSERT_SINGLE_OWNER
sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendTexture(
- tex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
+ tex, colorType, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
if (!proxy) {
return nullptr;
}
@@ -149,7 +149,7 @@
ASSERT_SINGLE_OWNER
sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget(
- backendRT, origin, releaseProc, releaseCtx);
+ backendRT, colorType, origin, releaseProc, releaseCtx);
if (!proxy) {
return nullptr;
}
@@ -168,7 +168,8 @@
ASSERT_SINGLE_OWNER
SkASSERT(sampleCnt > 0);
sk_sp<GrSurfaceProxy> proxy(
- this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, origin, sampleCnt));
+ this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, colorType,
+ origin, sampleCnt));
if (!proxy) {
return nullptr;
}
diff --git a/src/gpu/GrDataUtils.cpp b/src/gpu/GrDataUtils.cpp
index 939ac3b..1ee1bbf 100644
--- a/src/gpu/GrDataUtils.cpp
+++ b/src/gpu/GrDataUtils.cpp
@@ -582,3 +582,19 @@
}
return true;
}
+
+
+GrColorType SkColorTypeAndFormatToGrColorType(const GrCaps* caps,
+ SkColorType skCT,
+ const GrBackendFormat& format) {
+ GrColorType grCT = SkColorTypeToGrColorType(skCT);
+ // Until we support SRGB in the SkColorType we have to do this manual check here to make sure
+ // we use the correct GrColorType.
+ if (caps->isFormatSRGB(format)) {
+ if (grCT != GrColorType::kRGBA_8888) {
+ return GrColorType::kUnknown;
+ }
+ grCT = GrColorType::kRGBA_8888_SRGB;
+ }
+ return grCT;
+}
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 5bc4b1d..6b49fa5 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -226,19 +226,29 @@
}
sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
+ GrColorType colorType,
GrWrapOwnership ownership, GrWrapCacheable cacheable,
GrIOType ioType) {
SkASSERT(ioType != kWrite_GrIOType);
this->handleDirtyContext();
- SkASSERT(this->caps());
- if (!this->caps()->isConfigTexturable(backendTex.config())) {
+
+ const GrCaps* caps = this->caps();
+ SkASSERT(caps);
+
+ if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat())) {
return nullptr;
}
- if (backendTex.width() > this->caps()->maxTextureSize() ||
- backendTex.height() > this->caps()->maxTextureSize()) {
+ if (backendTex.width() > caps->maxTextureSize() ||
+ backendTex.height() > caps->maxTextureSize()) {
return nullptr;
}
- return this->onWrapBackendTexture(backendTex, ownership, cacheable, ioType);
+
+ SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+ caps->getConfigFromBackendFormat(
+ backendTex.getBackendFormat(),
+ colorType)));
+
+ return this->onWrapBackendTexture(backendTex, colorType, ownership, cacheable, ioType);
}
sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex,
@@ -272,25 +282,47 @@
return tex;
}
-sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
- if (0 == this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), backendRT.config())) {
+sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+ GrColorType colorType) {
+ this->handleDirtyContext();
+
+ const GrCaps* caps = this->caps();
+
+ SkASSERT(GrCaps::AreConfigsCompatible(backendRT.config(),
+ caps->getConfigFromBackendFormat(
+ backendRT.getBackendFormat(),
+ colorType)));
+
+ if (0 == caps->getRenderTargetSampleCount(backendRT.sampleCnt(), colorType,
+ backendRT.getBackendFormat())) {
return nullptr;
}
- this->handleDirtyContext();
- return this->onWrapBackendRenderTarget(backendRT);
+
+ return this->onWrapBackendRenderTarget(backendRT, colorType);
}
-sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
- int sampleCnt) {
- if (0 == this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config())) {
- return nullptr;
- }
- int maxSize = this->caps()->maxTextureSize();
- if (tex.width() > maxSize || tex.height() > maxSize) {
- return nullptr;
- }
+sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& backendTex,
+ int sampleCnt,
+ GrColorType colorType) {
this->handleDirtyContext();
- return this->onWrapBackendTextureAsRenderTarget(tex, sampleCnt);
+
+ const GrCaps* caps = this->caps();
+
+ int maxSize = caps->maxTextureSize();
+ if (backendTex.width() > maxSize || backendTex.height() > maxSize) {
+ return nullptr;
+ }
+
+ SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+ caps->getConfigFromBackendFormat(
+ backendTex.getBackendFormat(),
+ colorType)));
+
+ if (0 == caps->getRenderTargetSampleCount(sampleCnt, colorType,
+ backendTex.getBackendFormat())) {
+ return nullptr;
+ }
+ return this->onWrapBackendTextureAsRenderTarget(backendTex, sampleCnt, colorType);
}
sk_sp<GrRenderTarget> GrGpu::wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo,
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 5889f1f..d2447d6 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -123,8 +123,8 @@
/**
* Implements GrResourceProvider::wrapBackendTexture
*/
- sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
- GrIOType);
+ sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, GrColorType,
+ GrWrapOwnership, GrWrapCacheable, GrIOType);
/**
* Implements GrResourceProvider::wrapRenderableBackendTexture
@@ -135,13 +135,15 @@
/**
* Implements GrResourceProvider::wrapBackendRenderTarget
*/
- sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&);
+ sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrColorType colorType);
/**
* Implements GrResourceProvider::wrapBackendTextureAsRenderTarget
*/
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt);
+ int sampleCnt,
+ GrColorType colorType);
/**
* Implements GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget
@@ -537,14 +539,16 @@
virtual sk_sp<GrTexture> onCreateCompressedTexture(int width, int height,
SkImage::CompressionType, SkBudgeted,
const void* data) = 0;
- virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership,
- GrWrapCacheable, GrIOType) = 0;
+ virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType,
+ GrWrapOwnership, GrWrapCacheable, GrIOType) = 0;
virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
GrColorType, GrWrapOwnership,
GrWrapCacheable) = 0;
- virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0;
+ virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrColorType) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt) = 0;
+ int sampleCnt,
+ GrColorType) = 0;
virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&);
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 956d55b..cc76aa2 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -524,6 +524,7 @@
}
sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex,
+ GrColorType grColorType,
GrSurfaceOrigin origin,
GrWrapOwnership ownership,
GrWrapCacheable cacheable,
@@ -541,13 +542,21 @@
return nullptr;
}
- SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
- backendTex.config()));
+ const GrCaps* caps = this->caps();
+
+ SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+ caps->getConfigFromBackendFormat(
+ backendTex.getBackendFormat(),
+ grColorType)));
+
+ SkASSERT(validate_backend_format_and_colortype(caps, grColorType,
+ backendTex.getBackendFormat()));
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
sk_sp<GrTexture> tex =
- resourceProvider->wrapBackendTexture(backendTex, ownership, cacheable, ioType);
+ resourceProvider->wrapBackendTexture(backendTex, grColorType,
+ ownership, cacheable, ioType);
if (!tex) {
return nullptr;
}
@@ -560,8 +569,7 @@
// Make sure we match how we created the proxy with SkBudgeted::kNo
SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
- GrColorType colorType = GrPixelConfigToColorType(tex->config());
- GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(tex->backendFormat(), colorType);
+ GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), grColorType);
return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle));
}
@@ -619,8 +627,8 @@
}
sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget(
- const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin, ReleaseProc releaseProc,
- ReleaseContext releaseCtx) {
+ const GrBackendRenderTarget& backendRT, GrColorType grColorType,
+ GrSurfaceOrigin origin, ReleaseProc releaseProc, ReleaseContext releaseCtx) {
if (this->isAbandoned()) {
return nullptr;
}
@@ -631,16 +639,15 @@
return nullptr;
}
- GrColorType colorType = GrPixelConfigToColorType(backendRT.config());
#ifdef SK_DEBUG
GrPixelConfig testConfig =
- this->caps()->validateBackendRenderTarget(backendRT, colorType);
+ this->caps()->validateBackendRenderTarget(backendRT, grColorType);
SkASSERT(testConfig != kUnknown_GrPixelConfig);
#endif
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
- sk_sp<GrRenderTarget> rt = resourceProvider->wrapBackendRenderTarget(backendRT);
+ sk_sp<GrRenderTarget> rt = resourceProvider->wrapBackendRenderTarget(backendRT, grColorType);
if (!rt) {
return nullptr;
}
@@ -654,15 +661,16 @@
// Make sure we match how we created the proxy with SkBudgeted::kNo
SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
- GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), colorType);
- GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), colorType);
+ GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), grColorType);
+ GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), grColorType);
return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
outSwizzle));
}
sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendTextureAsRenderTarget(
- const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt) {
+ const GrBackendTexture& backendTex, GrColorType grColorType,
+ GrSurfaceOrigin origin, int sampleCnt) {
if (this->isAbandoned()) {
return nullptr;
}
@@ -673,13 +681,20 @@
return nullptr;
}
- SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
- backendTex.config()));
+ const GrCaps* caps = this->caps();
+
+ SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+ caps->getConfigFromBackendFormat(
+ backendTex.getBackendFormat(),
+ grColorType)));
+
+ SkASSERT(validate_backend_format_and_colortype(caps, grColorType,
+ backendTex.getBackendFormat()));
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
sk_sp<GrRenderTarget> rt =
- resourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt);
+ resourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt, grColorType);
if (!rt) {
return nullptr;
}
@@ -688,9 +703,8 @@
// This proxy should be unbudgeted because we're just wrapping an external resource
SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
- GrColorType colorType = GrPixelConfigToColorType(rt->config());
- GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), colorType);
- GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), colorType);
+ GrSwizzle texSwizzle = caps->getTextureSwizzle(rt->backendFormat(), grColorType);
+ GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType);
return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
outSwizzle));
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index dd75171..bfaca5d 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -113,7 +113,7 @@
* Create a texture proxy that wraps a (non-renderable) backend texture. GrIOType must be
* kRead or kRW.
*/
- sk_sp<GrTextureProxy> wrapBackendTexture(const GrBackendTexture&, GrSurfaceOrigin,
+ sk_sp<GrTextureProxy> wrapBackendTexture(const GrBackendTexture&, GrColorType, GrSurfaceOrigin,
GrWrapOwnership, GrWrapCacheable, GrIOType,
ReleaseProc = nullptr, ReleaseContext = nullptr);
@@ -129,14 +129,16 @@
/*
* Create a render target proxy that wraps a backend render target
*/
- sk_sp<GrSurfaceProxy> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrSurfaceOrigin,
+ sk_sp<GrSurfaceProxy> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrColorType,
+ GrSurfaceOrigin,
ReleaseProc = nullptr, ReleaseContext = nullptr);
/*
* Create a render target proxy that wraps a backend texture
*/
- sk_sp<GrSurfaceProxy> wrapBackendTextureAsRenderTarget(const GrBackendTexture& backendTex,
- GrSurfaceOrigin origin,
+ sk_sp<GrSurfaceProxy> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
+ GrColorType,
+ GrSurfaceOrigin,
int sampleCnt);
sk_sp<GrRenderTargetProxy> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index e048b3b..d9b4f92 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -361,6 +361,7 @@
}
sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture& tex,
+ GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable,
GrIOType ioType) {
@@ -368,7 +369,7 @@
if (this->isAbandoned()) {
return nullptr;
}
- return fGpu->wrapBackendTexture(tex, ownership, cacheable, ioType);
+ return fGpu->wrapBackendTexture(tex, colorType, ownership, cacheable, ioType);
}
sk_sp<GrTexture> GrResourceProvider::wrapRenderableBackendTexture(const GrBackendTexture& tex,
@@ -384,10 +385,10 @@
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
- const GrBackendRenderTarget& backendRT)
+ const GrBackendRenderTarget& backendRT, GrColorType colorType)
{
ASSERT_SINGLE_OWNER
- return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(backendRT);
+ return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(backendRT, colorType);
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget(
@@ -560,12 +561,12 @@
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget(
- const GrBackendTexture& tex, int sampleCnt)
+ const GrBackendTexture& tex, int sampleCnt, GrColorType colorType)
{
if (this->isAbandoned()) {
return nullptr;
}
- return fGpu->wrapBackendTextureAsRenderTarget(tex, sampleCnt);
+ return fGpu->wrapBackendTextureAsRenderTarget(tex, sampleCnt, colorType);
}
sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore(bool isOwned) {
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 695eb02..1a1d37d 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -111,7 +111,7 @@
*
* @return GrTexture object or NULL on failure.
*/
- sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership,
+ sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, GrColorType, GrWrapOwnership,
GrWrapCacheable, GrIOType);
/**
@@ -134,7 +134,8 @@
*
* @return GrRenderTarget object or NULL on failure.
*/
- sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&);
+ sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrColorType colorType);
sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&);
@@ -230,7 +231,8 @@
* @return GrRenderTarget object or NULL on failure.
*/
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt);
+ int sampleCnt,
+ GrColorType);
/**
* Assigns a unique key to a resource. If the key is associated with another resource that
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index a337d4e..e76b3eb 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3745,6 +3745,30 @@
return get_yuva_config(*glFormat);
}
+GrColorType GrGLCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const {
+ GrGLFormat grGLFormat = GrGLBackendFormatToGLFormat(format);
+
+ switch (grGLFormat) {
+ case GrGLFormat::kALPHA8: // fall through
+ case GrGLFormat::kR8: return GrColorType::kAlpha_8;
+ case GrGLFormat::kRG8: return GrColorType::kRG_88;
+ case GrGLFormat::kRGBA8: return GrColorType::kRGBA_8888;
+ case GrGLFormat::kRGB8: return GrColorType::kRGB_888x;
+ case GrGLFormat::kBGRA8: return GrColorType::kBGRA_8888;
+ case GrGLFormat::kRGB10_A2: return GrColorType::kRGBA_1010102;
+ case GrGLFormat::kLUMINANCE16F: // fall through
+ case GrGLFormat::kR16F: return GrColorType::kAlpha_F16;
+ case GrGLFormat::kR16: return GrColorType::kR_16;
+ case GrGLFormat::kRG16: return GrColorType::kRG_1616;
+ // Experimental (for Y416 and mutant P016/P010)
+ case GrGLFormat::kRGBA16: return GrColorType::kRGBA_16161616;
+ case GrGLFormat::kRG16F: return GrColorType::kRG_F16;
+ default: return GrColorType::kUnknown;
+ }
+
+ SkUNREACHABLE;
+}
+
GrBackendFormat GrGLCaps::getBackendFormatFromColorType(GrColorType ct) const {
auto format = this->getFormatFromColorType(ct);
if (format == GrGLFormat::kUnknown) {
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 45f3e13..a84c269 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -445,6 +445,7 @@
GrColorType) const override;
GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
+ GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const override;
GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override;
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 8821814..09a982e 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -684,8 +684,8 @@
}
sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
- GrWrapOwnership ownership, GrWrapCacheable cacheable,
- GrIOType ioType) {
+ GrColorType grColorType, GrWrapOwnership ownership,
+ GrWrapCacheable cacheable, GrIOType ioType) {
GrGLTexture::IDDesc idDesc;
if (!check_backend_texture(backendTex, this->glCaps(), &idDesc)) {
return nullptr;
@@ -699,10 +699,14 @@
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
}
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc surfDesc;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
- surfDesc.fConfig = backendTex.config();
+ surfDesc.fConfig = config;
GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kValid
: GrMipMapsStatus::kNotAllocated;
@@ -740,10 +744,14 @@
const GrCaps* caps = this->caps();
+ GrPixelConfig config = caps->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ colorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc surfDesc;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
- surfDesc.fConfig = backendTex.config();
+ surfDesc.fConfig = config;
sampleCnt =
caps->getRenderTargetSampleCount(sampleCnt, colorType, backendTex.getBackendFormat());
@@ -768,7 +776,8 @@
return std::move(texRT);
}
-sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
+sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+ GrColorType grColorType) {
GrGLFramebufferInfo info;
if (!backendRT.getGLFramebufferInfo(&info)) {
return nullptr;
@@ -785,19 +794,25 @@
idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
idDesc.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(),
+ grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc desc;
desc.fWidth = backendRT.width();
desc.fHeight = backendRT.height();
- desc.fConfig = backendRT.config();
+ desc.fConfig = config;
int sampleCount =
- this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), backendRT.config());
+ this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), grColorType,
+ backendRT.getBackendFormat());
return GrGLRenderTarget::MakeWrapped(this, desc, sampleCount, info.fFormat, idDesc,
backendRT.stencilBits());
}
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
- int sampleCnt) {
+ int sampleCnt,
+ GrColorType grColorType) {
GrGLTextureInfo info;
if (!tex.getGLTextureInfo(&info) || !info.fID) {
return nullptr;
@@ -811,11 +826,16 @@
return nullptr;
}
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(tex.getBackendFormat(),
+ grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc surfDesc;
surfDesc.fWidth = tex.width();
surfDesc.fHeight = tex.height();
- surfDesc.fConfig = tex.config();
- int sampleCount = this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config());
+ surfDesc.fConfig = config;
+ int sampleCount = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
+ tex.getBackendFormat());
GrGLRenderTarget::IDDesc rtIDDesc;
if (!this->createRenderTargetObjects(surfDesc, sampleCount, info, &rtIDDesc)) {
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 54a2b28..44f08fe 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -201,14 +201,15 @@
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern,
const void* data) override;
- sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
- GrIOType) override;
+ sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
+ GrWrapCacheable, GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
GrColorType, GrWrapOwnership,
GrWrapCacheable) override;
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrColorType) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt) override;
+ int sampleCnt, GrColorType) override;
// Given a GL format return the index into the stencil format array on GrGLCaps to a
// compatible stencil format, or negative if there is no compatible stencil format.
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index e8599e4..9d121c9 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -134,6 +134,14 @@
return GrColorTypeToPixelConfig(*format.getMockColorType());
}
+ GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const override {
+ if (!format.getMockColorType()) {
+ return GrColorType::kUnknown;
+ }
+
+ return *format.getMockColorType();
+ }
+
GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override {
return GrBackendFormat::MakeMock(ct);
}
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index 5de09e7..d45d334 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -174,22 +174,23 @@
return nullptr;
}
-sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex,
+sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable wrapType, GrIOType ioType) {
- GrMockTextureInfo info;
- SkAssertResult(tex.getMockTextureInfo(&info));
+ GrMockTextureInfo texInfo;
+ SkAssertResult(tex.getMockTextureInfo(&texInfo));
+ SkASSERT(colorType == texInfo.fColorType);
GrSurfaceDesc desc;
desc.fWidth = tex.width();
desc.fHeight = tex.height();
- desc.fConfig = info.pixelConfig();
+ desc.fConfig = texInfo.pixelConfig();
GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid
: GrMipMapsStatus::kNotAllocated;
auto isProtected = GrProtected(tex.isProtected());
return sk_sp<GrTexture>(
- new GrMockTexture(this, desc, isProtected, mipMapsStatus, info, wrapType, ioType));
+ new GrMockTexture(this, desc, isProtected, mipMapsStatus, texInfo, wrapType, ioType));
}
sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex,
@@ -217,10 +218,12 @@
this, desc, sampleCnt, isProtected, mipMapsStatus, texInfo, rtInfo, cacheable));
}
-sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) {
+sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt,
+ GrColorType colorType) {
GrMockRenderTargetInfo info;
SkAssertResult(rt.getMockRenderTargetInfo(&info));
+ SkASSERT(colorType == info.colorType());
GrSurfaceDesc desc;
desc.fWidth = rt.width();
desc.fHeight = rt.height();
@@ -232,10 +235,12 @@
}
sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
- int sampleCnt) {
+ int sampleCnt,
+ GrColorType colorType) {
GrMockTextureInfo texInfo;
SkAssertResult(tex.getMockTextureInfo(&texInfo));
+ SkASSERT(colorType == texInfo.fColorType);
GrSurfaceDesc desc;
desc.fWidth = tex.width();
desc.fHeight = tex.height();
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index b001787..8b4d809 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -67,8 +67,8 @@
sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType,
SkBudgeted, const void* data) override;
- sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
- GrIOType) override;
+ sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
+ GrWrapCacheable, GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
@@ -76,10 +76,11 @@
GrWrapOwnership,
GrWrapCacheable) override;
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrColorType) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt) override;
+ int sampleCnt, GrColorType) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
const void*) override;
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index e52f848..3b74efc 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -68,6 +68,7 @@
GrColorType) const override;
GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
+ GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const override;
GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override;
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index a608644..fe7417c 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -765,6 +765,32 @@
return get_yuva_config(*mtlFormat);
}
+GrColorType GrMtlCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const {
+ const GrMTLPixelFormat* grMtlFormat = format.getMtlFormat();
+ if (!grMtlFormat) {
+ return GrColorType::kUnknown;
+ }
+
+ MTLPixelFormat mtlFormat = static_cast<MTLPixelFormat>(*grMtlFormat);
+
+ switch (mtlFormat) {
+ case MTLPixelFormatA8Unorm: // fall through
+ case MTLPixelFormatR8Unorm: return GrColorType::kAlpha_8;
+ case MTLPixelFormatRG8Unorm: return GrColorType::kRG_88;
+ case MTLPixelFormatRGBA8Unorm: return GrColorType::kRGBA_8888;
+ case MTLPixelFormatBGRA8Unorm: return GrColorType::kBGRA_8888;
+ case MTLPixelFormatRGB10A2Unorm: return GrColorType::kRGBA_1010102;
+ case MTLPixelFormatR16Unorm: return GrColorType::kR_16;
+ case MTLPixelFormatRG16Unorm: return GrColorType::kRG_1616;
+ // Experimental (for Y416 and mutant P016/P010)
+ case MTLPixelFormatRGBA16Unorm: return GrColorType::kRGBA_16161616;
+ case MTLPixelFormatRG16Float: return GrColorType::kRG_F16;
+ default: return GrColorType::kUnknown;
+ }
+
+ SkUNREACHABLE;
+}
+
GrBackendFormat GrMtlCaps::getBackendFormatFromColorType(GrColorType ct) const {
GrPixelConfig config = GrColorTypeToPixelConfig(ct);
if (config == kUnknown_GrPixelConfig) {
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index 134a391..1a2f976 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -144,17 +144,19 @@
return nullptr;
}
- sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
- GrIOType) override;
+ sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType,
+ GrWrapOwnership, GrWrapCacheable, GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
GrColorType, GrWrapOwnership,
GrWrapCacheable) override;
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrColorType) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt) override;
+ int sampleCnt,
+ GrColorType) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t, GrGpuBufferType, GrAccessPattern,
const void*) override;
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index 118c95d..db2935c 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -521,6 +521,7 @@
}
sk_sp<GrTexture> GrMtlGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
+ GrColorType grColorType,
GrWrapOwnership,
GrWrapCacheable cacheable, GrIOType ioType) {
id<MTLTexture> mtlTexture = get_texture_from_backend(backendTex);
@@ -528,8 +529,12 @@
return nullptr;
}
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc surfDesc;
- init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kNo, backendTex.config());
+ init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kNo, config);
return GrMtlTexture::MakeWrappedTexture(this, surfDesc, mtlTexture, cacheable, ioType);
}
@@ -544,11 +549,17 @@
return nullptr;
}
- GrSurfaceDesc surfDesc;
- init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, backendTex.config());
+ const GrCaps* caps = this->caps();
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, colorType,
- backendTex.getBackendFormat());
+ GrPixelConfig config = caps->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ colorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
+ GrSurfaceDesc surfDesc;
+ init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
+
+ sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
+ backendTex.getBackendFormat());
if (!sampleCnt) {
return nullptr;
}
@@ -557,7 +568,8 @@
mtlTexture, cacheable);
}
-sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
+sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+ GrColorType grColorType) {
// TODO: Revisit this when the Metal backend is completed. It may support MSAA render targets.
if (backendRT.sampleCnt() > 1) {
return nullptr;
@@ -567,23 +579,32 @@
return nullptr;
}
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(),
+ grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc surfDesc;
- init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, backendRT.config());
+ init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
return GrMtlRenderTarget::MakeWrappedRenderTarget(this, surfDesc, backendRT.sampleCnt(),
mtlTexture);
}
sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendTextureAsRenderTarget(
- const GrBackendTexture& backendTex, int sampleCnt) {
+ const GrBackendTexture& backendTex, int sampleCnt, GrColorType grColorType) {
id<MTLTexture> mtlTexture = get_texture_from_backend(backendTex);
if (!mtlTexture) {
return nullptr;
}
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc surfDesc;
- init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, backendTex.config());
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, surfDesc.fConfig);
+ init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
+ sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
+ backendTex.getBackendFormat());
if (!sampleCnt) {
return nullptr;
}
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 09798d9..b1ca7f9 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -1109,6 +1109,30 @@
return get_yuva_config(*vkFormat);
}
+GrColorType GrVkCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const {
+ const VkFormat* vkFormat = format.getVkFormat();
+ if (!vkFormat) {
+ return GrColorType::kUnknown;
+ }
+
+ switch (*vkFormat) {
+ case VK_FORMAT_R8_UNORM: return GrColorType::kAlpha_8;
+ case VK_FORMAT_R8G8B8A8_UNORM: return GrColorType::kRGBA_8888;
+ case VK_FORMAT_R8G8B8_UNORM: return GrColorType::kRGB_888x;
+ case VK_FORMAT_R8G8_UNORM: return GrColorType::kRG_88;
+ case VK_FORMAT_B8G8R8A8_UNORM: return GrColorType::kBGRA_8888;
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102;
+ case VK_FORMAT_R16_UNORM: return GrColorType::kR_16;
+ case VK_FORMAT_R16G16_UNORM: return GrColorType::kRG_1616;
+ // Experimental (for Y416 and mutant P016/P010)
+ case VK_FORMAT_R16G16B16A16_UNORM: return GrColorType::kRGBA_16161616;
+ case VK_FORMAT_R16G16_SFLOAT: return GrColorType::kRG_F16;
+ default: return GrColorType::kUnknown;
+ }
+
+ SkUNREACHABLE;
+}
+
GrBackendFormat GrVkCaps::getBackendFormatFromColorType(GrColorType ct) const {
GrPixelConfig config = GrColorTypeToPixelConfig(ct);
if (config == kUnknown_GrPixelConfig) {
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index f5d35cb..f9bcb23 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -164,6 +164,7 @@
GrColorType) const override;
GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
+ GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const override;
GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override;
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 38dadc9..65f61f7 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1120,7 +1120,7 @@
static bool check_image_info(const GrVkCaps& caps,
const GrVkImageInfo& info,
- GrPixelConfig config,
+ GrColorType colorType,
bool needsAllocation) {
if (VK_NULL_HANDLE == info.fImage) {
return false;
@@ -1140,7 +1140,7 @@
return false;
}
- SkASSERT(GrVkFormatPixelConfigPairIsValid(info.fFormat, config));
+ SkASSERT(GrVkFormatColorTypePairIsValid(info.fFormat, colorType));
return true;
}
@@ -1166,14 +1166,14 @@
}
sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
- GrWrapOwnership ownership, GrWrapCacheable cacheable,
- GrIOType ioType) {
+ GrColorType colorType, GrWrapOwnership ownership,
+ GrWrapCacheable cacheable, GrIOType ioType) {
GrVkImageInfo imageInfo;
if (!backendTex.getVkImageInfo(&imageInfo)) {
return nullptr;
}
- if (!check_image_info(this->vkCaps(), imageInfo, backendTex.config(),
+ if (!check_image_info(this->vkCaps(), imageInfo, colorType,
kAdopt_GrWrapOwnership == ownership)) {
return nullptr;
}
@@ -1185,10 +1185,14 @@
return nullptr;
}
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ colorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc surfDesc;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
- surfDesc.fConfig = backendTex.config();
+ surfDesc.fConfig = config;
sk_sp<GrVkImageLayout> layout = backendTex.getGrVkImageLayout();
SkASSERT(layout);
@@ -1206,7 +1210,7 @@
return nullptr;
}
- if (!check_image_info(this->vkCaps(), imageInfo, backendTex.config(),
+ if (!check_image_info(this->vkCaps(), imageInfo, colorType,
kAdopt_GrWrapOwnership == ownership)) {
return nullptr;
}
@@ -1221,15 +1225,15 @@
return nullptr;
}
- SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
- this->caps()->getConfigFromBackendFormat(
- backendTex.getBackendFormat(),
- colorType)));
+
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ colorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
GrSurfaceDesc surfDesc;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
- surfDesc.fConfig = backendTex.config();
+ surfDesc.fConfig = config;
sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, colorType,
backendTex.getBackendFormat());
@@ -1240,7 +1244,8 @@
this, surfDesc, sampleCnt, ownership, cacheable, imageInfo, std::move(layout));
}
-sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT){
+sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+ GrColorType colorType) {
// Currently the Vulkan backend does not support wrapping of msaa render targets directly. In
// general this is not an issue since swapchain images in vulkan are never multisampled. Thus if
// you want a multisampled RT it is best to wrap the swapchain images and then let Skia handle
@@ -1254,7 +1259,11 @@
return nullptr;
}
- if (!check_image_info(this->vkCaps(), info, backendRT.config(), false)) {
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(),
+ colorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
+ if (!check_image_info(this->vkCaps(), info, colorType, false)) {
return nullptr;
}
if (!check_rt_image_info(this->vkCaps(), info)) {
@@ -1268,7 +1277,7 @@
GrSurfaceDesc desc;
desc.fWidth = backendRT.width();
desc.fHeight = backendRT.height();
- desc.fConfig = backendRT.config();
+ desc.fConfig = config;
sk_sp<GrVkImageLayout> layout = backendRT.getGrVkImageLayout();
@@ -1285,13 +1294,14 @@
}
sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
- int sampleCnt) {
+ int sampleCnt,
+ GrColorType grColorType) {
GrVkImageInfo imageInfo;
if (!tex.getVkImageInfo(&imageInfo)) {
return nullptr;
}
- if (!check_image_info(this->vkCaps(), imageInfo, tex.config(), false)) {
+ if (!check_image_info(this->vkCaps(), imageInfo, grColorType, false)) {
return nullptr;
}
if (!check_rt_image_info(this->vkCaps(), imageInfo)) {
@@ -1302,11 +1312,17 @@
return nullptr;
}
+ GrPixelConfig config = this->caps()->getConfigFromBackendFormat(tex.getBackendFormat(),
+ grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
GrSurfaceDesc desc;
desc.fWidth = tex.width();
desc.fHeight = tex.height();
- desc.fConfig = tex.config();
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config());
+ desc.fConfig = config;
+
+ sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
+ tex.getBackendFormat());
if (!sampleCnt) {
return nullptr;
}
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index e94274d..5b48fc1 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -197,17 +197,18 @@
sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType,
SkBudgeted, const void* data) override;
- sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
- GrIOType) override;
+ sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
+ GrWrapCacheable, GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
GrColorType colorType,
GrWrapOwnership,
GrWrapCacheable) override;
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrColorType) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt) override;
+ int sampleCnt, GrColorType) override;
sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&) override;
diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp
index 197d4a0..395c02f 100644
--- a/src/gpu/vk/GrVkUtil.cpp
+++ b/src/gpu/vk/GrVkUtil.cpp
@@ -99,56 +99,35 @@
}
#ifdef SK_DEBUG
-bool GrVkFormatPixelConfigPairIsValid(VkFormat format, GrPixelConfig config) {
+bool GrVkFormatColorTypePairIsValid(VkFormat format, GrColorType colorType) {
switch (format) {
- case VK_FORMAT_R8G8B8A8_UNORM:
- return kRGBA_8888_GrPixelConfig == config ||
- kRGB_888X_GrPixelConfig == config;
- case VK_FORMAT_B8G8R8A8_UNORM:
- return kBGRA_8888_GrPixelConfig == config;
- case VK_FORMAT_R8G8B8A8_SRGB:
- return kSRGBA_8888_GrPixelConfig == config;
- case VK_FORMAT_R8G8B8_UNORM:
- return kRGB_888_GrPixelConfig == config;
- case VK_FORMAT_R8G8_UNORM:
- return kRG_88_GrPixelConfig == config;
- case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
- return kRGBA_1010102_GrPixelConfig == config;
- case VK_FORMAT_R5G6B5_UNORM_PACK16:
- return kRGB_565_GrPixelConfig == config;
- case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
- // R4G4B4A4 is not required to be supported so we actually
- // store RGBA_4444 data as B4G4R4A4.
- return kRGBA_4444_GrPixelConfig == config;
- case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
- return kRGBA_4444_GrPixelConfig == config;
- case VK_FORMAT_R8_UNORM:
- return kAlpha_8_GrPixelConfig == config ||
- kAlpha_8_as_Red_GrPixelConfig == config ||
- kGray_8_GrPixelConfig == config ||
- kGray_8_as_Red_GrPixelConfig == config;
- case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
- return kRGB_ETC1_GrPixelConfig == config;
- case VK_FORMAT_R32G32B32A32_SFLOAT:
- return kRGBA_float_GrPixelConfig == config;
- case VK_FORMAT_R16G16B16A16_SFLOAT:
- return kRGBA_half_GrPixelConfig == config ||
- kRGBA_half_Clamped_GrPixelConfig == config;
- case VK_FORMAT_R16_SFLOAT:
- return kAlpha_half_GrPixelConfig == config ||
- kAlpha_half_as_Red_GrPixelConfig == config;
- case VK_FORMAT_R16_UNORM:
- return kR_16_GrPixelConfig == config;
- case VK_FORMAT_R16G16_UNORM:
- return kRG_1616_GrPixelConfig == config;
+ case VK_FORMAT_R8G8B8A8_UNORM: return GrColorType::kRGBA_8888 == colorType ||
+ GrColorType::kRGB_888x == colorType;
+ case VK_FORMAT_B8G8R8A8_UNORM: return GrColorType::kBGRA_8888 == colorType;
+ case VK_FORMAT_R8G8B8A8_SRGB: return GrColorType::kRGBA_8888_SRGB == colorType;
+ case VK_FORMAT_R8G8B8_UNORM: return GrColorType::kRGB_888x == colorType;
+ case VK_FORMAT_R8G8_UNORM: return GrColorType::kRG_88 == colorType;
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102 == colorType;
+ case VK_FORMAT_R5G6B5_UNORM_PACK16: return GrColorType::kBGR_565 == colorType;
+ // R4G4B4A4 is not required to be supported so we actually
+ // store RGBA_4444 data as B4G4R4A4.
+ case VK_FORMAT_B4G4R4A4_UNORM_PACK16: return GrColorType::kABGR_4444 == colorType;
+ case VK_FORMAT_R4G4B4A4_UNORM_PACK16: return GrColorType::kABGR_4444 == colorType;
+ case VK_FORMAT_R8_UNORM: return GrColorType::kAlpha_8 == colorType ||
+ GrColorType::kGray_8 == colorType;
+ case VK_FORMAT_R32G32B32A32_SFLOAT: return GrColorType::kRGBA_F32 == colorType;
+ case VK_FORMAT_R16G16B16A16_SFLOAT: return GrColorType::kRGBA_F16 == colorType ||
+ GrColorType::kRGBA_F16_Clamped == colorType;
+ case VK_FORMAT_R16_SFLOAT: return GrColorType::kAlpha_F16 == colorType;
+ case VK_FORMAT_R16_UNORM: return GrColorType::kR_16 == colorType;
+ case VK_FORMAT_R16G16_UNORM: return GrColorType::kRG_1616 == colorType;
// Experimental (for Y416 and mutant P016/P010)
- case VK_FORMAT_R16G16B16A16_UNORM:
- return kRGBA_16161616_GrPixelConfig == config;
- case VK_FORMAT_R16G16_SFLOAT:
- return kRG_half_GrPixelConfig == config;
- default:
- return false;
+ case VK_FORMAT_R16G16B16A16_UNORM: return GrColorType::kRGBA_16161616 == colorType;
+ case VK_FORMAT_R16G16_SFLOAT: return GrColorType::kRG_F16 == colorType;
+ default: return false;
}
+
+ SkUNREACHABLE;
}
#endif
diff --git a/src/gpu/vk/GrVkUtil.h b/src/gpu/vk/GrVkUtil.h
index 6c77c74..04c1acd 100644
--- a/src/gpu/vk/GrVkUtil.h
+++ b/src/gpu/vk/GrVkUtil.h
@@ -38,9 +38,9 @@
#ifdef SK_DEBUG
/**
- * Returns true if the passed in VkFormat and GrPixelConfig are compatible with each other.
+ * Returns true if the passed in VkFormat and GrColorType are compatible with each other.
*/
-bool GrVkFormatPixelConfigPairIsValid(VkFormat, GrPixelConfig);
+bool GrVkFormatColorTypePairIsValid(VkFormat, GrColorType);
#endif
bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples);
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 70b36c7..011a6de 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -116,7 +116,7 @@
static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
const GrBackendTexture& backendTex,
- GrSurfaceOrigin origin,
+ GrColorType colorType, GrSurfaceOrigin origin,
SkAlphaType at, sk_sp<SkColorSpace> colorSpace,
GrWrapOwnership ownership,
SkImage::TextureReleaseProc releaseProc,
@@ -127,8 +127,9 @@
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy =
- proxyProvider->wrapBackendTexture(backendTex, origin, ownership, GrWrapCacheable::kNo,
- kRead_GrIOType, releaseProc, releaseCtx);
+ proxyProvider->wrapBackendTexture(backendTex, colorType, origin, ownership,
+ GrWrapCacheable::kNo, kRead_GrIOType,
+ releaseProc, releaseCtx);
if (!proxy) {
return nullptr;
}
@@ -143,11 +144,20 @@
if (!ctx) {
return nullptr;
}
- GrBackendTexture texCopy = tex;
- if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, ct, at, cs)) {
+
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(ctx->priv().caps(), ct,
+ tex.getBackendFormat());
+ if (GrColorType::kUnknown == grColorType) {
return nullptr;
}
- return new_wrapped_texture_common(ctx, texCopy, origin, at, std::move(cs),
+
+ GrBackendTexture texCopy = tex;
+ if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, grColorType,
+ ct, at, cs)) {
+ return nullptr;
+ }
+
+ return new_wrapped_texture_common(ctx, texCopy, grColorType, origin, at, std::move(cs),
kBorrow_GrWrapOwnership, releaseP, releaseC);
}
@@ -159,11 +169,20 @@
// We have a DDL context and we don't support adopted textures for them.
return nullptr;
}
- GrBackendTexture texCopy = tex;
- if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, ct, at, cs)) {
+
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(ctx->priv().caps(), ct,
+ tex.getBackendFormat());
+ if (GrColorType::kUnknown == grColorType) {
return nullptr;
}
- return new_wrapped_texture_common(ctx, texCopy, origin, at, std::move(cs),
+
+ GrBackendTexture texCopy = tex;
+ if (!SkImage_GpuBase::ValidateBackendTexture(ctx, texCopy, &texCopy.fConfig, grColorType,
+ ct, at, cs)) {
+ return nullptr;
+ }
+
+ return new_wrapped_texture_common(ctx, texCopy, grColorType, origin, at, std::move(cs),
kAdopt_GrWrapOwnership, nullptr, nullptr);
}
@@ -243,11 +262,18 @@
GrSurfaceOrigin imageOrigin,
const GrBackendTexture& backendTexture,
sk_sp<SkColorSpace> imageColorSpace) {
- GrBackendTexture backendTextureCopy = backendTexture;
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(ctx->priv().caps(),
+ kRGBA_8888_SkColorType,
+ backendTexture.getBackendFormat());
+ if (GrColorType::kUnknown == grColorType) {
+ return nullptr;
+ }
+
+ GrBackendTexture backendTextureCopy = backendTexture;
SkAlphaType at = SkImage_GpuBase::GetAlphaTypeFromYUVAIndices(yuvaIndices);
if (!SkImage_Gpu::ValidateBackendTexture(ctx, backendTextureCopy, &backendTextureCopy.fConfig,
- kRGBA_8888_SkColorType, at, nullptr)) {
+ grColorType, kRGBA_8888_SkColorType, at, nullptr)) {
return nullptr;
}
@@ -255,7 +281,7 @@
// in order to draw to it for the yuv->rgb conversion.
sk_sp<GrRenderTargetContext> renderTargetContext(
ctx->priv().makeBackendTextureRenderTargetContext(backendTextureCopy, imageOrigin, 1,
- GrColorType::kRGBA_8888,
+ grColorType,
std::move(imageColorSpace)));
if (!renderTargetContext) {
@@ -414,15 +440,16 @@
return nullptr;
}
- GrPixelConfig config =
- context->priv().caps()->getConfigFromBackendFormat(backendFormat,
- SkColorTypeToGrColorType(colorType));
- if (config == kUnknown_GrPixelConfig) {
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(),
+ colorType,
+ backendFormat);
+ if (GrColorType::kUnknown == grColorType) {
return nullptr;
}
callDone.clear();
- auto proxy = MakePromiseImageLazyProxy(context, width, height, origin, config, backendFormat,
+ auto proxy = MakePromiseImageLazyProxy(context, width, height, origin,
+ grColorType, backendFormat,
mipMapped, textureFulfillProc, textureReleaseProc,
textureDoneProc, textureContext, version);
if (!proxy) {
@@ -601,8 +628,9 @@
SkColorType colorType =
GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format);
+ GrColorType grColorType = SkColorTypeToGrColorType(colorType);
backendTexture.fConfig = context->priv().caps()->getConfigFromBackendFormat(
- backendFormat, SkColorTypeToGrColorType(colorType));
+ backendFormat, grColorType);
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
if (!proxyProvider) {
@@ -611,7 +639,7 @@
}
sk_sp<GrTextureProxy> proxy =
- proxyProvider->wrapBackendTexture(backendTexture, surfaceOrigin,
+ proxyProvider->wrapBackendTexture(backendTexture, grColorType, surfaceOrigin,
kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
kRW_GrIOType, deleteImageProc, deleteImageCtx);
if (!proxy) {
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 830c7eb..e2f70ae 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -39,7 +39,8 @@
#endif
bool SkImage_GpuBase::ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
- GrPixelConfig* config, SkColorType ct, SkAlphaType at,
+ GrPixelConfig* config, GrColorType grCT,
+ SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs) {
if (!tex.isValid()) {
return false;
@@ -55,16 +56,6 @@
return false;
}
- GrColorType grCT = SkColorTypeToGrColorType(ct);
- // Until we support SRGB in the SkColorType we have to do this manual check here to make sure
- // we use the correct GrColorType.
- if (ctx->priv().caps()->isFormatSRGB(backendFormat)) {
- if (grCT != GrColorType::kRGBA_8888) {
- return false;
- }
- grCT = GrColorType::kRGBA_8888_SRGB;
- }
-
*config = ctx->priv().caps()->getConfigFromBackendFormat(backendFormat, grCT);
return *config != kUnknown_GrPixelConfig;
}
@@ -247,6 +238,7 @@
GrSurfaceOrigin imageOrigin,
sk_sp<GrTextureProxy> tempTextureProxies[4]) {
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
+ const GrCaps* caps = ctx->priv().caps();
// We need to make a copy of the input backend textures because we need to preserve the result
// of validate_backend_texture.
@@ -258,39 +250,48 @@
return false;
}
yuvaTexturesCopy[textureIndex].fConfig =
- ctx->priv().caps()->getYUVAConfigFromBackendFormat(backendFormat);
+ caps->getYUVAConfigFromBackendFormat(backendFormat);
if (yuvaTexturesCopy[textureIndex].fConfig == kUnknown_GrPixelConfig) {
return false;
}
+ GrColorType grColorType = caps->getYUVAColorTypeFromBackendFormat(backendFormat);
+ if (GrColorType::kUnknown == grColorType) {
+ return false;
+ }
+
SkASSERT(yuvaTexturesCopy[textureIndex].isValid());
tempTextureProxies[textureIndex] = proxyProvider->wrapBackendTexture(
- yuvaTexturesCopy[textureIndex], imageOrigin, kBorrow_GrWrapOwnership,
+ yuvaTexturesCopy[textureIndex], grColorType, imageOrigin, kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, kRead_GrIOType);
if (!tempTextureProxies[textureIndex]) {
return false;
}
// Check that each texture contains the channel data for the corresponding YUVA index
- GrPixelConfig config = yuvaTexturesCopy[textureIndex].fConfig;
+ auto componentFlags = GrColorTypeComponentFlags(grColorType);
for (int yuvaIndex = 0; yuvaIndex < SkYUVAIndex::kIndexCount; ++yuvaIndex) {
if (yuvaIndices[yuvaIndex].fIndex == textureIndex) {
switch (yuvaIndices[yuvaIndex].fChannel) {
case SkColorChannel::kR:
- if (kAlpha_8_as_Alpha_GrPixelConfig == config) {
+ // TODO: Chrome needs to be patched before this can be
+ // enforced.
+// if (!(kRed_SkColorTypeComponentFlag & componentFlags)) {
+// return false;
+// }
+ break;
+ case SkColorChannel::kG:
+ if (!(kGreen_SkColorTypeComponentFlag & componentFlags)) {
return false;
}
break;
- case SkColorChannel::kG:
case SkColorChannel::kB:
- if (kAlpha_8_as_Alpha_GrPixelConfig == config ||
- kAlpha_8_as_Red_GrPixelConfig == config) {
+ if (!(kBlue_SkColorTypeComponentFlag & componentFlags)) {
return false;
}
break;
case SkColorChannel::kA:
- default:
- if (kRGB_888_GrPixelConfig == config) {
+ if (!(kAlpha_SkColorTypeComponentFlag & componentFlags)) {
return false;
}
break;
@@ -327,7 +328,7 @@
}
sk_sp<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy(
- GrContext* context, int width, int height, GrSurfaceOrigin origin, GrPixelConfig config,
+ GrContext* context, int width, int height, GrSurfaceOrigin origin, GrColorType colorType,
GrBackendFormat backendFormat, GrMipMapped mipMapped,
PromiseImageTextureFulfillProc fulfillProc,
PromiseImageTextureReleaseProc releaseProc,
@@ -337,7 +338,7 @@
SkASSERT(context);
SkASSERT(width > 0 && height > 0);
SkASSERT(doneProc);
- SkASSERT(config != kUnknown_GrPixelConfig);
+ SkASSERT(colorType != GrColorType::kUnknown);
if (!fulfillProc || !releaseProc) {
doneProc(textureContext);
@@ -372,11 +373,11 @@
PromiseImageTextureReleaseProc releaseProc,
PromiseImageTextureDoneProc doneProc,
PromiseImageTextureContext context,
- GrPixelConfig config,
+ GrColorType colorType,
PromiseImageApiVersion version)
: fFulfillProc(fulfillProc)
, fReleaseProc(releaseProc)
- , fConfig(config)
+ , fColorType(colorType)
, fVersion(version) {
fDoneCallback = sk_make_sp<GrRefCntedCallback>(doneProc, context);
}
@@ -409,7 +410,7 @@
// Fulfill once. So return our cached result.
if (fTexture) {
return {sk_ref_sp(fTexture), kKeySyncMode};
- } else if (fConfig == kUnknown_GrPixelConfig) {
+ } else if (fColorType == GrColorType::kUnknown) {
// We've already called fulfill and it failed. Our contract says that we should only
// call each callback once.
return {};
@@ -422,22 +423,30 @@
auto releaseCallback = sk_make_sp<GrRefCntedCallback>(fReleaseProc, textureContext);
if (!promiseTexture) {
// This records that we have failed.
- fConfig = kUnknown_GrPixelConfig;
+ fColorType = GrColorType::kUnknown;
return {};
}
auto backendTexture = promiseTexture->backendTexture();
- backendTexture.fConfig = fConfig;
if (!backendTexture.isValid()) {
return {};
}
+ // TODO: delete this block
+ {
+ GrPixelConfig config = resourceProvider->caps()->getConfigFromBackendFormat(
+ backendTexture.getBackendFormat(),
+ fColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+ backendTexture.fConfig = config;
+ }
+
sk_sp<GrTexture> tex;
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 2, "promise");
builder[0] = promiseTexture->uniqueID();
- builder[1] = fConfig;
+ builder[1] = (uint32_t) fColorType;
builder.finish();
// A texture with this key may already exist from a different instance of this lazy
// callback. This could happen if the client fulfills a promise image with a texture
@@ -447,8 +456,8 @@
SkASSERT(tex);
} else {
if ((tex = resourceProvider->wrapBackendTexture(
- backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
- kRead_GrIOType))) {
+ backendTexture, fColorType, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kYes, kRead_GrIOType))) {
tex->resourcePriv().setUniqueKey(key);
} else {
return {};
@@ -477,12 +486,16 @@
sk_sp<GrRefCntedCallback> fDoneCallback;
GrTexture* fTexture = nullptr;
uint32_t fTextureContextID = SK_InvalidUniqueID;
- GrPixelConfig fConfig;
+ GrColorType fColorType;
PromiseImageApiVersion fVersion;
- } callback(fulfillProc, releaseProc, doneProc, textureContext, config, version);
+ } callback(fulfillProc, releaseProc, doneProc, textureContext, colorType, version);
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
+ GrPixelConfig config = context->priv().caps()->getConfigFromBackendFormat(
+ backendFormat,
+ colorType);
+
GrSurfaceDesc desc;
desc.fWidth = width;
desc.fHeight = height;
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index c48c48e..6a3c516 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -58,7 +58,8 @@
#endif
static bool ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
- GrPixelConfig* config, SkColorType ct, SkAlphaType at,
+ GrPixelConfig* config, GrColorType grCT,
+ SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs);
static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
int numTextures, const SkYUVAIndex [4],
@@ -84,7 +85,7 @@
// proxy along with the TextureFulfillProc and TextureReleaseProc. PromiseDoneProc must not
// be null.
static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(
- GrContext*, int width, int height, GrSurfaceOrigin, GrPixelConfig, GrBackendFormat,
+ GrContext*, int width, int height, GrSurfaceOrigin, GrColorType, GrBackendFormat,
GrMipMapped, PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc,
PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion);
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 7b938dd..7eef716 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -354,15 +354,16 @@
// Get lazy proxies
sk_sp<GrTextureProxy> proxies[4];
for (int texIdx = 0; texIdx < numTextures; ++texIdx) {
- GrPixelConfig config =
- context->priv().caps()->getYUVAConfigFromBackendFormat(yuvaFormats[texIdx]);
- if (config == kUnknown_GrPixelConfig) {
+ GrColorType colorType = context->priv().caps()->getYUVAColorTypeFromBackendFormat(
+ yuvaFormats[texIdx]);
+ if (GrColorType::kUnknown == colorType) {
return nullptr;
}
+
proxies[texIdx] = MakePromiseImageLazyProxy(
- context, yuvaSizes[texIdx].width(), yuvaSizes[texIdx].height(), imageOrigin, config,
- yuvaFormats[texIdx], GrMipMapped::kNo, textureFulfillProc, textureReleaseProc,
- promiseDoneProc, textureContexts[texIdx], version);
+ context, yuvaSizes[texIdx].width(), yuvaSizes[texIdx].height(), imageOrigin,
+ colorType, yuvaFormats[texIdx], GrMipMapped::kNo, textureFulfillProc,
+ textureReleaseProc, promiseDoneProc, textureContexts[texIdx], version);
++proxiesCreated;
if (!proxies[texIdx]) {
return nullptr;
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 6bc6d3d..1487328 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -426,21 +426,6 @@
return true;
}
-static GrColorType get_grcolortype_from_skcolortype_and_format(const GrCaps* caps,
- SkColorType skCT,
- const GrBackendFormat& format) {
- GrColorType grCT = SkColorTypeToGrColorType(skCT);
- // Until we support SRGB in the SkColorType we have to do this manual check here to make sure
- // we use the correct GrColorType.
- if (caps->isFormatSRGB(format)) {
- if (grCT != GrColorType::kRGBA_8888) {
- return GrColorType::kUnknown;
- }
- grCT = GrColorType::kRGBA_8888_SRGB;
- }
- return grCT;
-}
-
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
const SkSurfaceCharacterization& c,
const GrBackendTexture& backendTexture,
@@ -459,8 +444,8 @@
return nullptr;
}
- GrColorType grCT = get_grcolortype_from_skcolortype_and_format(
- context->priv().caps(), c.colorType(), backendTexture.getBackendFormat());
+ GrColorType grCT = SkColorTypeAndFormatToGrColorType(context->priv().caps(), c.colorType(),
+ backendTexture.getBackendFormat());
if (grCT == GrColorType::kUnknown) {
return nullptr;
}
@@ -551,8 +536,8 @@
}
sampleCnt = SkTMax(1, sampleCnt);
- GrColorType grColorType = get_grcolortype_from_skcolortype_and_format(
- context->priv().caps(), colorType, tex.getBackendFormat());
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), colorType,
+ tex.getBackendFormat());
if (grColorType == GrColorType::kUnknown) {
return nullptr;
}
@@ -672,8 +657,8 @@
return nullptr;
}
- GrColorType grColorType = get_grcolortype_from_skcolortype_and_format(
- context->priv().caps(), colorType, rt.getBackendFormat());
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), colorType,
+ rt.getBackendFormat());
if (grColorType == GrColorType::kUnknown) {
return nullptr;
}
@@ -718,8 +703,8 @@
}
sampleCnt = SkTMax(1, sampleCnt);
- GrColorType grColorType = get_grcolortype_from_skcolortype_and_format(
- context->priv().caps(), colorType, tex.getBackendFormat());
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), colorType,
+ tex.getBackendFormat());
if (grColorType == GrColorType::kUnknown) {
return nullptr;
}
diff --git a/tests/BackendAllocationTest.cpp b/tests/BackendAllocationTest.cpp
index c870e63..3429e06 100644
--- a/tests/BackendAllocationTest.cpp
+++ b/tests/BackendAllocationTest.cpp
@@ -593,13 +593,9 @@
continue;
}
- GrColorType grCT = SkColorTypeToGrColorType(combo.fColorType);
- // TODO: Once SkColorType has an SRGB type we can remove this manual setting.
- if (glCaps->isFormatSRGB(format)) {
- if (grCT != GrColorType::kRGBA_8888) {
- continue;
- }
- grCT = GrColorType::kRGBA_8888_SRGB;
+ GrColorType grCT = SkColorTypeAndFormatToGrColorType(glCaps, combo.fColorType, format);
+ if (GrColorType::kUnknown == grCT) {
+ continue;
}
if (!glCaps->isFormatTexturable(grCT, format)) {
diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp
index 362962d..7e399f0 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -1004,8 +1004,8 @@
GrXferProcessor::DstProxy fakeDstProxy;
{
sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
- backendTex, kTopLeft_GrSurfaceOrigin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ backendTex, GrColorType::kRGBA_8888, kTopLeft_GrSurfaceOrigin,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
fakeDstProxy.setProxy(std::move(proxy));
}
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 726f8fb..2630a82 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -355,7 +355,8 @@
GrRenderable::kYes,
GrProtected::kNo);
- auto proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
+ auto proxy = proxyProvider->wrapBackendTexture(backendTex, GrColorType::kRGBA_8888,
+ kTopLeft_GrSurfaceOrigin,
kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, ioType);
auto surfContext = context->priv().makeWrappedSurfaceContext(proxy, GrColorType::kRGBA_8888,
@@ -404,7 +405,8 @@
kSize, kSize, kRGBA_8888_SkColorType,
SkColors::kTransparent, GrMipMapped::kYes, GrRenderable::kYes,
GrProtected::kNo);
- proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
+ proxy = proxyProvider->wrapBackendTexture(backendTex, GrColorType::kRGBA_8888,
+ kTopLeft_GrSurfaceOrigin,
kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
ioType);
context->flush();
@@ -430,7 +432,8 @@
GrWrapCacheable::kNo);
} else {
texture = context->priv().resourceProvider()->wrapBackendTexture(
- backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
+ backendTexture, GrColorType::kRGBA_8888, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRW_GrIOType);
}
// Add a release proc that deletes the GrBackendTexture.
struct ReleaseContext {
diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp
index be4b514..f47bb94 100644
--- a/tests/GrTestingBackendTextureUploadTest.cpp
+++ b/tests/GrTestingBackendTextureUploadTest.cpp
@@ -69,8 +69,8 @@
GrWrapCacheable::kNo);
} else {
wrappedProxy = context->priv().proxyProvider()->wrapBackendTexture(
- backendTex, kTopLeft_GrSurfaceOrigin, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
- GrIOType::kRW_GrIOType);
+ backendTex, grCT, kTopLeft_GrSurfaceOrigin, kAdopt_GrWrapOwnership,
+ GrWrapCacheable::kNo, GrIOType::kRW_GrIOType);
}
REPORTER_ASSERT(reporter, wrappedProxy);
diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp
index 3764c7c..d051fc5 100644
--- a/tests/LazyProxyTest.cpp
+++ b/tests/LazyProxyTest.cpp
@@ -463,8 +463,9 @@
[instantiatePtr, releasePtr,
backendTex](GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult {
sk_sp<GrTexture> texture =
- rp->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership,
- GrWrapCacheable::kNo, kRead_GrIOType);
+ rp->wrapBackendTexture(backendTex, GrColorType::kRGBA_8888,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
+ kRead_GrIOType);
if (!texture) {
return {};
}
diff --git a/tests/ProxyConversionTest.cpp b/tests/ProxyConversionTest.cpp
index 878d104..2bbe164 100644
--- a/tests/ProxyConversionTest.cpp
+++ b/tests/ProxyConversionTest.cpp
@@ -26,7 +26,7 @@
GrSurfaceOrigin origin) {
auto ct = GrPixelConfigToColorType(desc.fConfig);
auto backendRT = gpu->createTestingOnlyBackendRenderTarget(desc.fWidth, desc.fHeight, ct);
- return provider->wrapBackendRenderTarget(backendRT, origin, nullptr, nullptr);
+ return provider->wrapBackendRenderTarget(backendRT, ct, origin, nullptr, nullptr);
}
void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index bce4eb4..88b2c3a 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -32,7 +32,9 @@
REPORTER_ASSERT(reporter, proxy->origin() == origin);
REPORTER_ASSERT(reporter, proxy->width() == width);
REPORTER_ASSERT(reporter, proxy->height() == height);
- REPORTER_ASSERT(reporter, proxy->config() == config);
+#ifdef SK_DEBUG
+ REPORTER_ASSERT(reporter, GrCaps::AreConfigsCompatible(config, proxy->config()));
+#endif
REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
}
@@ -223,6 +225,9 @@
for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
kRGBA_1010102_SkColorType }) {
GrColorType grColorType = SkColorTypeToGrColorType(colorType);
+ GrPixelConfig config = GrColorTypeToPixelConfig(grColorType);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+
// External on-screen render target.
// Tests wrapBackendRenderTarget with a GrBackendRenderTarget
// Our test-only function that creates a backend render target doesn't currently support
@@ -231,10 +236,10 @@
GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
kWidthHeight, kWidthHeight, grColorType);
sk_sp<GrSurfaceProxy> sProxy(
- proxyProvider->wrapBackendRenderTarget(backendRT, origin, nullptr,
- nullptr));
+ proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
+ origin, nullptr, nullptr));
check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
- backendRT.pixelConfig(), SkBudgeted::kNo);
+ config, SkBudgeted::kNo);
static constexpr int kExpectedNumSamples = 1;
check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
kExpectedNumSamples, SkBackingFit::kExact,
@@ -243,8 +248,6 @@
}
for (auto numSamples : {1, 4}) {
- GrPixelConfig config = GrColorTypeToPixelConfig(grColorType);
- SkASSERT(kUnknown_GrPixelConfig != config);
int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
if (!supportedNumSamples) {
@@ -264,11 +267,11 @@
kStencilBits, fboInfo);
backendRT.setPixelConfig(config);
sk_sp<GrSurfaceProxy> sProxy(
- proxyProvider->wrapBackendRenderTarget(backendRT, origin, nullptr,
- nullptr));
+ proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
+ origin, nullptr, nullptr));
check_surface(reporter, sProxy.get(), origin,
kWidthHeight, kWidthHeight,
- backendRT.pixelConfig(), SkBudgeted::kNo);
+ config, SkBudgeted::kNo);
check_rendertarget(reporter, caps, resourceProvider,
sProxy->asRenderTargetProxy(),
supportedNumSamples, SkBackingFit::kExact, 0);
@@ -284,7 +287,7 @@
GrRenderable::kYes,
GrProtected::kNo);
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
- backendTex, origin, supportedNumSamples);
+ backendTex, grColorType, origin, supportedNumSamples);
if (!sProxy) {
context->deleteBackendTexture(backendTex);
continue; // This can fail on Mesa
@@ -292,7 +295,7 @@
check_surface(reporter, sProxy.get(), origin,
kWidthHeight, kWidthHeight,
- backendTex.pixelConfig(), SkBudgeted::kNo);
+ config, SkBudgeted::kNo);
check_rendertarget(reporter, caps, resourceProvider,
sProxy->asRenderTargetProxy(),
supportedNumSamples, SkBackingFit::kExact,
@@ -322,7 +325,7 @@
check_surface(reporter, sProxy.get(), origin,
kWidthHeight, kWidthHeight,
- backendTex.pixelConfig(), SkBudgeted::kNo);
+ config, SkBudgeted::kNo);
check_rendertarget(reporter, caps, resourceProvider,
sProxy->asRenderTargetProxy(),
supportedNumSamples, SkBackingFit::kExact,
@@ -343,8 +346,8 @@
GrProtected::kNo);
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
- backendTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ backendTex, grColorType, origin, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
if (!sProxy) {
context->deleteBackendTexture(backendTex);
continue;
@@ -352,7 +355,7 @@
check_surface(reporter, sProxy.get(), origin,
kWidthHeight, kWidthHeight,
- backendTex.pixelConfig(), SkBudgeted::kNo);
+ config, SkBudgeted::kNo);
check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
SkBackingFit::kExact);
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index 4b8f0f7..3fe450a 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -161,7 +161,8 @@
}
sk_sp<GrTextureProxy> rectProxy = proxyProvider->wrapBackendTexture(
- rectangleTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
+ rectangleTex, GrColorType::kRGBA_8888, origin,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
if (!rectProxy) {
ERRORF(reporter, "Error creating proxy for rectangle texture.");
diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp
index dee8de8..9ee9212 100644
--- a/tests/ResourceAllocatorTest.cpp
+++ b/tests/ResourceAllocatorTest.cpp
@@ -24,7 +24,7 @@
struct ProxyParams {
int fSize;
GrRenderable fRenderable;
- SkColorType fColorType;
+ GrColorType fColorType;
SkBackingFit fFit;
int fSampleCnt;
GrSurfaceOrigin fOrigin;
@@ -34,15 +34,14 @@
static sk_sp<GrSurfaceProxy> make_deferred(GrProxyProvider* proxyProvider, const GrCaps* caps,
const ProxyParams& p) {
- GrColorType grCT = SkColorTypeToGrColorType(p.fColorType);
- GrPixelConfig config = GrColorTypeToPixelConfig(grCT);
+ GrPixelConfig config = GrColorTypeToPixelConfig(p.fColorType);
GrSurfaceDesc desc;
desc.fWidth = p.fSize;
desc.fHeight = p.fSize;
desc.fConfig = config;
- const GrBackendFormat format = caps->getBackendFormatFromColorType(grCT);
+ const GrBackendFormat format = caps->getBackendFormatFromColorType(p.fColorType);
return proxyProvider->createProxy(format, desc, p.fRenderable, p.fSampleCnt, p.fOrigin, p.fFit,
p.fBudgeted, GrProtected::kNo);
@@ -52,7 +51,10 @@
GrBackendTexture* backendTex) {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- *backendTex = context->createBackendTexture(p.fSize, p.fSize, p.fColorType,
+ SkColorType skColorType = GrColorTypeToSkColorType(p.fColorType);
+ SkASSERT(SkColorType::kUnknown_SkColorType != skColorType);
+
+ *backendTex = context->createBackendTexture(p.fSize, p.fSize, skColorType,
SkColors::kTransparent,
GrMipMapped::kNo, GrRenderable::kNo,
GrProtected::kNo);
@@ -60,8 +62,9 @@
return nullptr;
}
- return proxyProvider->wrapBackendTexture(*backendTex, p.fOrigin, kBorrow_GrWrapOwnership,
- GrWrapCacheable::kNo, kRead_GrIOType);
+ return proxyProvider->wrapBackendTexture(*backendTex, p.fColorType, p.fOrigin,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
+ kRead_GrIOType);
}
static void cleanup_backend(GrContext* context, const GrBackendTexture& backendTex) {
@@ -146,8 +149,8 @@
// Non-RT GrSurfaces are never recycled on some platforms.
bool kConditionallyShare = resourceProvider->caps()->reuseScratchTextures();
- const SkColorType kRGBA = kRGBA_8888_SkColorType;
- const SkColorType kBGRA = kBGRA_8888_SkColorType;
+ const GrColorType kRGBA = GrColorType::kRGBA_8888;
+ const GrColorType kBGRA = GrColorType::kBGRA_8888;
const SkBackingFit kE = SkBackingFit::kExact;
const SkBackingFit kA = SkBackingFit::kApprox;
@@ -268,8 +271,7 @@
sk_sp<GrSurfaceProxy> make_lazy(GrProxyProvider* proxyProvider, const GrCaps* caps,
const ProxyParams& p, bool deinstantiate) {
- GrColorType grCT = SkColorTypeToGrColorType(p.fColorType);
- GrPixelConfig config = GrColorTypeToPixelConfig(grCT);
+ GrPixelConfig config = GrColorTypeToPixelConfig(p.fColorType);
GrSurfaceDesc desc;
desc.fWidth = p.fSize;
@@ -290,7 +292,7 @@
}
return GrSurfaceProxy::LazyInstantiationResult(std::move(texture));
};
- const GrBackendFormat format = caps->getBackendFormatFromColorType(grCT);
+ const GrBackendFormat format = caps->getBackendFormatFromColorType(p.fColorType);
auto lazyType = deinstantiate ? GrSurfaceProxy::LazyInstantiationType ::kDeinstantiate
: GrSurfaceProxy::LazyInstantiationType ::kSingleUse;
GrInternalSurfaceFlags flags = GrInternalSurfaceFlags::kNone;
@@ -305,7 +307,7 @@
ProxyParams texParams;
texParams.fFit = SkBackingFit::kExact;
texParams.fOrigin = kTopLeft_GrSurfaceOrigin;
- texParams.fColorType = kRGBA_8888_SkColorType;
+ texParams.fColorType = GrColorType::kRGBA_8888;
texParams.fRenderable = GrRenderable::kNo;
texParams.fSampleCnt = 1;
texParams.fSize = 100;
@@ -359,7 +361,7 @@
// Force the resource allocator to always believe it is over budget
context->setResourceCacheLimits(0, 0);
- const ProxyParams params = { 64, GrRenderable::kNo, kRGBA_8888_SkColorType,
+ const ProxyParams params = { 64, GrRenderable::kNo, GrColorType::kRGBA_8888,
SkBackingFit::kExact, 1, kTopLeft_GrSurfaceOrigin,
SkBudgeted::kYes };
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 7eab755..2cef6e9 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -218,10 +218,12 @@
context->resetContext();
sk_sp<GrTexture> borrowed(resourceProvider->wrapBackendTexture(
- backendTextures[0], kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
+ backendTextures[0], GrColorType::kRGBA_8888,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
sk_sp<GrTexture> adopted(resourceProvider->wrapBackendTexture(
- backendTextures[1], kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
+ backendTextures[1], GrColorType::kRGBA_8888,
+ kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr);
if (!borrowed || !adopted) {
diff --git a/tests/TextureProxyTest.cpp b/tests/TextureProxyTest.cpp
index 9414c89..8dbbf99 100644
--- a/tests/TextureProxyTest.cpp
+++ b/tests/TextureProxyTest.cpp
@@ -115,9 +115,9 @@
GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
backendTex.setPixelConfig(desc.fConfig);
- return proxyProvider->wrapBackendTexture(backendTex, kBottomLeft_GrSurfaceOrigin,
- kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
- kRead_GrIOType);
+ return proxyProvider->wrapBackendTexture(backendTex, GrColorType::kRGBA_8888,
+ kBottomLeft_GrSurfaceOrigin, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kYes, kRead_GrIOType);
}
diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp
index 97917c6..09a1d4f 100644
--- a/tests/VkWrapTests.cpp
+++ b/tests/VkWrapTests.cpp
@@ -46,8 +46,9 @@
GrVkImageInfo imageInfo;
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
- sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership,
- GrWrapCacheable::kNo, kRead_GrIOType);
+ sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kGrColorType,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
+ kRead_GrIOType);
REPORTER_ASSERT(reporter, tex);
// image is null
@@ -56,11 +57,11 @@
backendCopy.fImage = VK_NULL_HANDLE;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
backendTex.setPixelConfig(kPixelConfig);
- tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex);
- tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex);
}
@@ -70,11 +71,11 @@
backendCopy.fAlloc = GrVkAlloc();
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
backendTex.setPixelConfig(kPixelConfig);
- tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
REPORTER_ASSERT(reporter, tex);
- tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex);
}
@@ -83,8 +84,8 @@
GrVkImageInfo backendCopy = imageInfo;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
backendTex.setPixelConfig(kPixelConfig);
- tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
- kRead_GrIOType);
+ tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
REPORTER_ASSERT(reporter, tex);
}
@@ -106,7 +107,7 @@
GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, imageInfo);
origBackendRT.setPixelConfig(kPixelConfig);
- sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT);
+ sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT, kGrColorType);
REPORTER_ASSERT(reporter, rt);
// image is null
@@ -115,7 +116,7 @@
backendCopy.fImage = VK_NULL_HANDLE;
GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
backendRT.setPixelConfig(kPixelConfig);
- rt = gpu->wrapBackendRenderTarget(backendRT);
+ rt = gpu->wrapBackendRenderTarget(backendRT, kGrColorType);
REPORTER_ASSERT(reporter, !rt);
}
@@ -126,7 +127,7 @@
// can wrap null alloc
GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
backendRT.setPixelConfig(kPixelConfig);
- rt = gpu->wrapBackendRenderTarget(backendRT);
+ rt = gpu->wrapBackendRenderTarget(backendRT, kGrColorType);
REPORTER_ASSERT(reporter, rt);
}
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index 54a4038..7f759ca 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -50,7 +50,8 @@
nullptr, nullptr);
} else {
proxy = context->priv().proxyProvider()->wrapBackendTexture(
- backendTex, origin, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
+ backendTex, colorType, origin, kAdopt_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRW_GrIOType);
}
if (!proxy) {