Revert x2 "Assert that all GrCaps colortype/format -> swizzle queries are legal."

This reverts commit b16f30bb92.

Bug: chromium:1066850

Change-Id: I57e233d370a7248867f709d52012726d19959379
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280900
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-04-01 09:10:38 -04:00
parent 28fe2c5175
commit e8d2080a34
14 changed files with 68 additions and 121 deletions

View File

@ -31,12 +31,6 @@ static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r
return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBounds, rect);
}
static constexpr auto kMaskOrigin = kTopLeft_GrSurfaceOrigin;
static GrSurfaceProxyView find_filtered_mask(GrProxyProvider* provider, const GrUniqueKey& key) {
return provider->findCachedProxyWithColorTypeFallback(key, kMaskOrigin, GrColorType::kAlpha_8);
}
// Draw a mask using the supplied paint. Since the coverage/geometry
// is already burnt into the mask this boils down to a rect draw.
// Return true if the mask was successfully drawn.
@ -87,11 +81,18 @@ static bool sw_draw_with_mask_filter(GrRecordingContext* context,
: SkStrokeRec::kFill_InitStyle;
if (key.isValid()) {
filteredMaskView = find_filtered_mask(proxyProvider, key);
// TODO: this cache look up is duplicated in draw_shape_with_mask_filter for gpu
static const GrSurfaceOrigin kCacheOrigin = kTopLeft_GrSurfaceOrigin;
auto filteredMask = proxyProvider->findOrCreateProxyByUniqueKey(key);
if (filteredMask) {
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(
filteredMask->backendFormat(), GrColorType::kAlpha_8);
filteredMaskView = GrSurfaceProxyView(std::move(filteredMask), kCacheOrigin, swizzle);
}
}
SkIRect drawRect;
if (filteredMaskView) {
if (filteredMaskView.proxy()) {
SkRect devBounds = shape.bounds();
viewMatrix.mapRect(&devBounds);
@ -156,7 +157,7 @@ static bool sw_draw_with_mask_filter(GrRecordingContext* context,
return false;
}
SkASSERT(kMaskOrigin == filteredMaskView.origin());
SkASSERT(kTopLeft_GrSurfaceOrigin == filteredMaskView.origin());
drawRect = dstM.fBounds;
@ -187,7 +188,7 @@ static std::unique_ptr<GrRenderTargetContext> create_mask_GPU(GrRecordingContext
auto approxSize = GrResourceProvider::MakeApprox(maskRect.size());
auto rtContext = GrRenderTargetContext::MakeWithFallback(
context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, approxSize, sampleCnt,
GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin);
GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!rtContext) {
return nullptr;
}
@ -201,8 +202,8 @@ static std::unique_ptr<GrRenderTargetContext> create_mask_GPU(GrRecordingContext
const SkIRect clipRect = SkIRect::MakeWH(maskRect.width(), maskRect.height());
GrFixedClip clip(clipRect);
// Draw the mask into maskTexture with the path's integerized top-left at the origin using
// maskPaint.
// Draw the mask into maskTexture with the path's integerized top-left at
// the origin using maskPaint.
SkMatrix viewMatrix = origViewMatrix;
viewMatrix.postTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop));
rtContext->drawShape(clip, std::move(maskPaint), GrAA::kYes, viewMatrix, shape);
@ -397,10 +398,18 @@ static void draw_shape_with_mask_filter(GrRecordingContext* context,
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
if (maskKey.isValid()) {
filteredMaskView = find_filtered_mask(proxyProvider, maskKey);
// TODO: this cache look up is duplicated in sw_draw_with_mask_filter for raster
static const GrSurfaceOrigin kCacheOrigin = kTopLeft_GrSurfaceOrigin;
auto filteredMask = proxyProvider->findOrCreateProxyByUniqueKey(maskKey);
if (filteredMask) {
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(
filteredMask->backendFormat(), GrColorType::kAlpha_8);
filteredMaskView = GrSurfaceProxyView(std::move(filteredMask), kCacheOrigin,
swizzle);
}
}
if (!filteredMaskView) {
if (!filteredMaskView.proxy()) {
std::unique_ptr<GrRenderTargetContext> maskRTC(create_mask_GPU(
context,
maskRect,
@ -422,7 +431,7 @@ static void draw_shape_with_mask_filter(GrRecordingContext* context,
}
}
if (filteredMaskView) {
if (filteredMaskView.proxy()) {
if (draw_mask(renderTargetContext, clip, viewMatrix, maskRect, std::move(paint),
std::move(filteredMaskView))) {
// This path is completely drawn

View File

@ -352,12 +352,6 @@ static void add_invalidate_on_pop_message(GrRecordingContext* context,
SkDEBUGFAIL("Gen ID was not found in stack.");
}
static constexpr auto kMaskOrigin = kTopLeft_GrSurfaceOrigin;
static GrSurfaceProxyView find_mask(GrProxyProvider* provider, const GrUniqueKey& key) {
return provider->findCachedProxyWithColorTypeFallback(key, kMaskOrigin, GrColorType::kAlpha_8);
}
GrSurfaceProxyView GrClipStackClip::createAlphaClipMask(GrRecordingContext* context,
const GrReducedClip& reducedClip) const {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
@ -365,14 +359,16 @@ GrSurfaceProxyView GrClipStackClip::createAlphaClipMask(GrRecordingContext* cont
create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(),
reducedClip.numAnalyticFPs(), &key);
if (auto cachedView = find_mask(context->priv().proxyProvider(), key)) {
return cachedView;
if (sk_sp<GrTextureProxy> proxy = proxyProvider->findOrCreateProxyByUniqueKey(key)) {
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kAlpha_8);
return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
}
auto rtc = GrRenderTargetContext::MakeWithFallback(
context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kApprox,
{reducedClip.width(), reducedClip.height()}, 1, GrMipMapped::kNo, GrProtected::kNo,
kMaskOrigin);
kTopLeft_GrSurfaceOrigin);
if (!rtc) {
return {};
}
@ -386,7 +382,7 @@ GrSurfaceProxyView GrClipStackClip::createAlphaClipMask(GrRecordingContext* cont
return {};
}
SkASSERT(result.origin() == kMaskOrigin);
SkASSERT(result.origin() == kTopLeft_GrSurfaceOrigin);
proxyProvider->assignUniqueKeyToProxy(key, result.asTextureProxy());
add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
@ -475,9 +471,12 @@ GrSurfaceProxyView GrClipStackClip::createSoftwareClipMask(
reducedClip.numAnalyticFPs(), &key);
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
const GrCaps* caps = context->priv().caps();
if (auto cachedView = find_mask(proxyProvider, key)) {
return cachedView;
if (sk_sp<GrTextureProxy> proxy = proxyProvider->findOrCreateProxyByUniqueKey(key)) {
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kAlpha_8);
return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
}
// The mask texture may be larger than necessary. We round out the clip bounds and pin the top
@ -491,7 +490,6 @@ GrSurfaceProxyView GrClipStackClip::createSoftwareClipMask(
GrSurfaceProxyView view;
if (taskGroup && renderTargetContext) {
const GrCaps* caps = context->priv().caps();
// Create our texture proxy
GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kAlpha_8,
GrRenderable::kNo);
@ -527,7 +525,7 @@ GrSurfaceProxyView GrClipStackClip::createSoftwareClipMask(
taskGroup->add(std::move(drawAndUploadMask));
proxy->texPriv().setDeferredUploader(std::move(uploader));
view = {std::move(proxy), kMaskOrigin, swizzle};
view = {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
} else {
GrSWMaskHelper helper;
if (!helper.init(maskSpaceIBounds)) {
@ -541,7 +539,7 @@ GrSurfaceProxyView GrClipStackClip::createSoftwareClipMask(
}
SkASSERT(view);
SkASSERT(view.origin() == kMaskOrigin);
SkASSERT(view.origin() == kTopLeft_GrSurfaceOrigin);
proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy());
add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
return view;

View File

@ -23,7 +23,6 @@
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageContextPriv.h"
#include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrSurfaceProxy.h"
#include "src/gpu/GrSurfaceProxyPriv.h"
@ -230,24 +229,6 @@ sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniq
return result;
}
GrSurfaceProxyView GrProxyProvider::findCachedProxyWithColorTypeFallback(const GrUniqueKey& key,
GrSurfaceOrigin origin,
GrColorType ct) {
auto proxy = this->findOrCreateProxyByUniqueKey(key);
if (!proxy) {
return {};
}
// Assume that we used a fallback color type if and only if the proxy is renderable.
if (proxy->asRenderTargetProxy()) {
GrBackendFormat expectedFormat;
std::tie(ct, expectedFormat) =
GrRenderTargetContext::GetFallbackColorTypeAndFormat(fImageContext, ct);
SkASSERT(expectedFormat == proxy->backendFormat());
}
GrSwizzle swizzle = fImageContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), ct);
return {std::move(proxy), origin, swizzle};
}
sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
GrMipMapped mipMapped,
SkBackingFit fit,

View File

@ -59,16 +59,6 @@ public:
sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&,
UseAllocator = UseAllocator::kYes);
/**
* A helper that uses findOrCreateProxyByUniqueKey() to find a proxy and if found creates a view
*a view for the found proxy using the passed in origin and color type. It is assumed that if
* the proxy is renderable then it was created by GrRenderTargetContext::MakeWithFallback and
* the fallback color type will be used to create the view.
*/
GrSurfaceProxyView findCachedProxyWithColorTypeFallback(const GrUniqueKey&,
GrSurfaceOrigin,
GrColorType);
/*
* Creates a new texture proxy for the bitmap, optionally with mip levels generated by the cpu.
* The bitmap is uploaded to the texture proxy assuming a kTopLeft_GrSurfaceOrigin.

View File

@ -9,7 +9,6 @@
#include "include/core/SkDrawable.h"
#include "include/gpu/GrBackendSemaphore.h"
#include "include/private/GrImageContext.h"
#include "include/private/GrRecordingContext.h"
#include "include/private/SkShadowFlags.h"
#include "include/utils/SkShadowUtils.h"
@ -33,7 +32,6 @@
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrFixedClip.h"
#include "src/gpu/GrGpuResourcePriv.h"
#include "src/gpu/GrImageContextPriv.h"
#include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrMemoryPool.h"
#include "src/gpu/GrPathRenderer.h"
@ -242,19 +240,6 @@ static inline GrColorType color_type_fallback(GrColorType ct) {
}
}
std::tuple<GrColorType, GrBackendFormat> GrRenderTargetContext::GetFallbackColorTypeAndFormat(
GrImageContext* context, GrColorType colorType) {
do {
auto format =
context->priv().caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes);
if (format.isValid()) {
return {colorType, format};
}
colorType = color_type_fallback(colorType);
} while (colorType != GrColorType::kUnknown);
return {GrColorType::kUnknown, {}};
}
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeWithFallback(
GrRecordingContext* context,
GrColorType colorType,
@ -267,12 +252,14 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeWithFallback(
GrSurfaceOrigin origin,
SkBudgeted budgeted,
const SkSurfaceProps* surfaceProps) {
auto [ct, format] = GetFallbackColorTypeAndFormat(context, colorType);
if (ct == GrColorType::kUnknown) {
return nullptr;
}
return GrRenderTargetContext::Make(context, ct, colorSpace, fit, dimensions, sampleCnt,
mipMapped, isProtected, origin, budgeted, surfaceProps);
std::unique_ptr<GrRenderTargetContext> rtc;
do {
rtc = GrRenderTargetContext::Make(context, colorType, colorSpace, fit, dimensions,
sampleCnt, mipMapped, isProtected, origin, budgeted,
surfaceProps);
colorType = color_type_fallback(colorType);
} while (!rtc && colorType != GrColorType::kUnknown);
return rtc;
}
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendTexture(

View File

@ -89,9 +89,6 @@ public:
SkBudgeted = SkBudgeted::kYes,
const SkSurfaceProps* = nullptr);
static std::tuple<GrColorType, GrBackendFormat> GetFallbackColorTypeAndFormat(GrImageContext*,
GrColorType);
// Same as previous factory but will try to use fallback GrColorTypes if the one passed in
// fails. The fallback GrColorType will have at least the number of channels and precision per
// channel as the passed in GrColorType. It may also swizzle the changes (e.g., BGRA -> RGBA).

View File

@ -74,10 +74,7 @@ std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* con
sk_sp<SkColorSpace> colorSpace,
SkBackingFit fit,
SkBudgeted budgeted) {
GrSwizzle swizzle("rgba");
if (!context->priv().caps()->isFormatCompressed(format)) {
swizzle = context->priv().caps()->getReadSwizzle(format, colorType);
}
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, colorType);
sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(
format, dimensions, renderable, renderTargetSampleCnt, mipMapped, fit, budgeted,

View File

@ -944,8 +944,7 @@ GrSwizzle GrD3DCaps::getReadSwizzle(const GrBackendFormat& format, GrColorType c
return ctInfo.fReadSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
GrSwizzle GrD3DCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
@ -958,8 +957,7 @@ GrSwizzle GrD3DCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType
return ctInfo.fWriteSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
uint64_t GrD3DCaps::computeFormatKey(const GrBackendFormat& format) const {

View File

@ -47,17 +47,16 @@ uniform half blurRadius;
}
builder.finish();
static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin;
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback(
key, kMaskOrigin, GrColorType::kAlpha_8)) {
return view;
if (sk_sp<GrTextureProxy> mask = proxyProvider->findOrCreateProxyByUniqueKey(key)) {
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(mask->backendFormat(),
GrColorType::kAlpha_8);
return {std::move(mask), kBottomLeft_GrSurfaceOrigin, swizzle};
}
auto rtc = GrRenderTargetContext::MakeWithFallback(
context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1,
GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin);
context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions);
if (!rtc) {
return {};
}

View File

@ -49,17 +49,16 @@ public:
}
builder.finish();
static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin;
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback(
key, kMaskOrigin, GrColorType::kAlpha_8)) {
return view;
if (sk_sp<GrTextureProxy> mask = proxyProvider->findOrCreateProxyByUniqueKey(key)) {
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(mask->backendFormat(),
GrColorType::kAlpha_8);
return {std::move(mask), kBottomLeft_GrSurfaceOrigin, swizzle};
}
auto rtc = GrRenderTargetContext::MakeWithFallback(
context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1,
GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin);
auto rtc = GrRenderTargetContext::MakeWithFallback(context, GrColorType::kAlpha_8, nullptr,
SkBackingFit::kExact, dimensions);
if (!rtc) {
return {};
}

View File

@ -4331,8 +4331,7 @@ GrSwizzle GrGLCaps::getReadSwizzle(const GrBackendFormat& format, GrColorType co
return ctInfo.fReadSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
GrSwizzle GrGLCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
@ -4343,8 +4342,7 @@ GrSwizzle GrGLCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType c
return ctInfo.fWriteSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
uint64_t GrGLCaps::computeFormatKey(const GrBackendFormat& format) const {

View File

@ -164,13 +164,11 @@ public:
return {};
}
GrSwizzle getReadSwizzle(const GrBackendFormat& format, GrColorType ct) const override {
SkASSERT(this->areColorTypeAndFormatCompatible(ct, format));
return GrSwizzle("rgba");
GrSwizzle getReadSwizzle(const GrBackendFormat&, GrColorType) const override {
return GrSwizzle();
}
GrSwizzle getWriteSwizzle(const GrBackendFormat& format, GrColorType ct) const override {
SkASSERT(this->areColorTypeAndFormatCompatible(ct, format));
return GrSwizzle("rgba");
return GrSwizzle();
}
uint64_t computeFormatKey(const GrBackendFormat&) const override;

View File

@ -943,8 +943,7 @@ GrSwizzle GrMtlCaps::getReadSwizzle(const GrBackendFormat& format, GrColorType c
return ctInfo.fReadSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
GrSwizzle GrMtlCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
@ -957,8 +956,7 @@ GrSwizzle GrMtlCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType
return ctInfo.fWriteSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
uint64_t GrMtlCaps::computeFormatKey(const GrBackendFormat& format) const {

View File

@ -1593,8 +1593,7 @@ GrSwizzle GrVkCaps::getReadSwizzle(const GrBackendFormat& format, GrColorType co
return ctInfo.fReadSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
GrSwizzle GrVkCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
@ -1607,8 +1606,7 @@ GrSwizzle GrVkCaps::getWriteSwizzle(const GrBackendFormat& format, GrColorType c
return ctInfo.fWriteSwizzle;
}
}
SkDEBUGFAIL("Illegal color type/format combination.");
return {};
return GrSwizzle::RGBA();
}
uint64_t GrVkCaps::computeFormatKey(const GrBackendFormat& format) const {