Add GrContext::defaultBackendFormat
TBR=bsalomon@google.com Bug: 987392 Change-Id: I38ff649b25e78c0a02a8fd20f513db4be62abf43 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229919 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
d9a44101f2
commit
d5e80ca8ea
@ -344,6 +344,15 @@ public:
|
||||
static size_t ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped,
|
||||
bool useNextPow2 = false);
|
||||
|
||||
/*
|
||||
* Retrieve the default GrBackendFormat for a given SkColorType and renderability.
|
||||
* It is guaranteed that this backend format will be the one used by the following
|
||||
* SkColorType and SkSurfaceCharacterization-based createBackendTexture methods.
|
||||
*
|
||||
* The caller should check that the returned format is valid.
|
||||
*/
|
||||
using GrRecordingContext::defaultBackendFormat;
|
||||
|
||||
/*
|
||||
* The explicitly allocated backend texture API allows clients to use Skia to create backend
|
||||
* objects outside of Skia proper (i.e., Skia's caching system will not know about them.)
|
||||
|
@ -27,6 +27,15 @@ class SK_API GrRecordingContext : public GrImageContext {
|
||||
public:
|
||||
~GrRecordingContext() override;
|
||||
|
||||
/*
|
||||
* Retrieve the default GrBackendFormat for a given SkColorType and renderability.
|
||||
* It is guaranteed that this backend format will be the one used by the GrContext
|
||||
* SkColorType and SkSurfaceCharacterization-based createBackendTexture methods.
|
||||
*
|
||||
* The caller should check that the returned format is valid.
|
||||
*/
|
||||
GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const;
|
||||
|
||||
// Provides access to functions that aren't part of the public API.
|
||||
GrRecordingContextPriv priv();
|
||||
const GrRecordingContextPriv priv() const;
|
||||
|
@ -394,6 +394,7 @@ public:
|
||||
virtual GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const = 0;
|
||||
|
||||
/** These are used when creating a new texture internally. */
|
||||
// TODO: also take a GrRenderable parameter.
|
||||
virtual GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const = 0;
|
||||
|
||||
virtual GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const = 0;
|
||||
|
@ -343,7 +343,7 @@ GrBackendTexture GrContext::createBackendTexture(int width, int height,
|
||||
}
|
||||
|
||||
GrBackendTexture GrContext::createBackendTexture(int width, int height,
|
||||
SkColorType colorType,
|
||||
SkColorType skColorType,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable,
|
||||
GrProtected isProtected) {
|
||||
@ -355,8 +355,7 @@ GrBackendTexture GrContext::createBackendTexture(int width, int height,
|
||||
return GrBackendTexture();
|
||||
}
|
||||
|
||||
GrBackendFormat format =
|
||||
this->caps()->getBackendFormatFromColorType(SkColorTypeToGrColorType(colorType));
|
||||
const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
|
||||
if (!format.isValid()) {
|
||||
return GrBackendTexture();
|
||||
}
|
||||
@ -384,8 +383,7 @@ GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization
|
||||
return {};
|
||||
}
|
||||
|
||||
const GrBackendFormat format =
|
||||
caps->getBackendFormatFromColorType(SkColorTypeToGrColorType(c.colorType()));
|
||||
const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes);
|
||||
if (!format.isValid()) {
|
||||
return GrBackendTexture();
|
||||
}
|
||||
@ -404,8 +402,6 @@ GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization
|
||||
|
||||
GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c,
|
||||
const SkColor4f& color) {
|
||||
const GrCaps* caps = this->caps();
|
||||
|
||||
if (!this->asDirectContext() || !c.isValid()) {
|
||||
return GrBackendTexture();
|
||||
}
|
||||
@ -423,13 +419,12 @@ GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization
|
||||
return {};
|
||||
}
|
||||
|
||||
const GrBackendFormat format =
|
||||
caps->getBackendFormatFromColorType(SkColorTypeToGrColorType(c.colorType()));
|
||||
const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes);
|
||||
if (!format.isValid()) {
|
||||
return GrBackendTexture();
|
||||
}
|
||||
|
||||
if (!SkSurface_Gpu::Valid(caps, format)) {
|
||||
if (!SkSurface_Gpu::Valid(this->caps(), format)) {
|
||||
return GrBackendTexture();
|
||||
}
|
||||
|
||||
@ -466,7 +461,7 @@ GrBackendTexture GrContext::createBackendTexture(int width, int height,
|
||||
}
|
||||
|
||||
GrBackendTexture GrContext::createBackendTexture(int width, int height,
|
||||
SkColorType colorType,
|
||||
SkColorType skColorType,
|
||||
const SkColor4f& color,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable,
|
||||
@ -479,12 +474,13 @@ GrBackendTexture GrContext::createBackendTexture(int width, int height,
|
||||
return GrBackendTexture();
|
||||
}
|
||||
|
||||
GrColorType ct = SkColorTypeToGrColorType(colorType);
|
||||
GrBackendFormat format = this->caps()->getBackendFormatFromColorType(ct);
|
||||
GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
|
||||
if (!format.isValid()) {
|
||||
return GrBackendTexture();
|
||||
}
|
||||
SkColor4f swizzledColor = this->caps()->getOutputSwizzle(format, ct).applyTo(color);
|
||||
|
||||
GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
|
||||
SkColor4f swizzledColor = this->caps()->getOutputSwizzle(format, grColorType).applyTo(color);
|
||||
|
||||
return this->createBackendTexture(width, height, format, swizzledColor, mipMapped, renderable,
|
||||
isProtected);
|
||||
|
@ -419,8 +419,7 @@ GrBackendTexture GrContextPriv::createBackendTexture(const SkPixmap srcData[], i
|
||||
}
|
||||
}
|
||||
|
||||
GrBackendFormat backendFormat =
|
||||
this->caps()->getBackendFormatFromColorType(SkColorTypeToGrColorType(colorType));
|
||||
GrBackendFormat backendFormat = fContext->defaultBackendFormat(colorType, renderable);
|
||||
if (!backendFormat.isValid()) {
|
||||
return {};
|
||||
}
|
||||
|
@ -396,3 +396,32 @@ sk_sp<GrRenderTargetContext> GrRecordingContextPriv::makeDeferredRenderTargetCon
|
||||
GrContext* GrRecordingContextPriv::backdoor() {
|
||||
return (GrContext*) fContext;
|
||||
}
|
||||
|
||||
GrBackendFormat GrRecordingContext::defaultBackendFormat(SkColorType skColorType,
|
||||
GrRenderable renderable) const {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
|
||||
if (this->abandoned()) {
|
||||
return GrBackendFormat();
|
||||
}
|
||||
|
||||
const GrCaps* caps = this->caps();
|
||||
|
||||
GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
|
||||
|
||||
// TODO: pass the 'renderable' parameter into getBackendFormatFromColorType and change
|
||||
// the texturabilit and renderability tests below into asserts
|
||||
GrBackendFormat format = caps->getBackendFormatFromColorType(grColorType);
|
||||
if (!caps->isFormatTexturable(grColorType, format)) {
|
||||
return GrBackendFormat();
|
||||
}
|
||||
|
||||
if (renderable == GrRenderable::kYes) {
|
||||
if (!caps->isFormatRenderable(grColorType, format)) {
|
||||
return GrBackendFormat();
|
||||
}
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
|
@ -353,6 +353,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CharacterizationBackendAllocationTest, report
|
||||
REPORTER_ASSERT(reporter, backendTex.isValid());
|
||||
REPORTER_ASSERT(reporter, c.isCompatible(backendTex));
|
||||
|
||||
{
|
||||
GrBackendFormat format = context->defaultBackendFormat(
|
||||
c.imageInfo().colorType(),
|
||||
GrRenderable::kYes);
|
||||
REPORTER_ASSERT(reporter, format == backendTex.getBackendFormat());
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> s2 = SkSurface::MakeFromBackendTexture(context, c,
|
||||
backendTex);
|
||||
REPORTER_ASSERT(reporter, s2);
|
||||
@ -370,6 +377,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CharacterizationBackendAllocationTest, report
|
||||
REPORTER_ASSERT(reporter, backendTex.isValid());
|
||||
REPORTER_ASSERT(reporter, c.isCompatible(backendTex));
|
||||
|
||||
{
|
||||
GrBackendFormat format = context->defaultBackendFormat(
|
||||
c.imageInfo().colorType(),
|
||||
GrRenderable::kYes);
|
||||
REPORTER_ASSERT(reporter, format == backendTex.getBackendFormat());
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> s2 = SkSurface::MakeFromBackendTexture(context, c,
|
||||
backendTex);
|
||||
REPORTER_ASSERT(reporter, s2);
|
||||
@ -454,6 +468,15 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo);
|
||||
check_vk_layout(result, VkLayout::kUndefined);
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
{
|
||||
GrBackendFormat format = context->defaultBackendFormat(colorType,
|
||||
renderable);
|
||||
SkASSERT(format == result.getBackendFormat());
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
@ -484,6 +507,15 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx
|
||||
check_vk_layout(result, GrRenderable::kYes == renderable
|
||||
? VkLayout::kColorAttachmentOptimal
|
||||
: VkLayout::kReadOnlyOptimal);
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
{
|
||||
GrBackendFormat format = context->defaultBackendFormat(colorType,
|
||||
renderable);
|
||||
SkASSERT(format == result.getBackendFormat());
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user