Convert dmsaa to an SkSurfaceProp
Bug: skia:11396
Change-Id: I1c2a72d80679df1c11529d05cbe781f6dfae6a79
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396810
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index b8743c0..60543d9 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -249,7 +249,6 @@
}
bool init(SkImageInfo info, Benchmark* bench) override {
GrContextOptions options = grContextOpts;
- options.fAlwaysAntialias = config.useDMSAA;
bench->modifyGrContextOptions(&options);
this->factory = std::make_unique<GrContextFactory>(options);
SkSurfaceProps props(this->config.surfaceFlags, kRGB_H_SkPixelGeometry);
@@ -472,7 +471,6 @@
const auto ctxType = gpuConfig->getContextType();
const auto ctxOverrides = gpuConfig->getContextOverrides();
const auto sampleCount = gpuConfig->getSamples();
- const auto useDMSAA = gpuConfig->getUseDMSAA();
const auto colorType = gpuConfig->getColorType();
auto colorSpace = gpuConfig->getColorSpace();
if (gpuConfig->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) {
@@ -503,7 +501,6 @@
kPremul_SkAlphaType,
sk_ref_sp(colorSpace),
sampleCount,
- useDMSAA,
ctxType,
ctxOverrides,
gpuConfig->getSurfaceFlags()
@@ -522,7 +519,7 @@
} \
Config config = { \
SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
- 0, false, kBogusContextType, kBogusContextOverrides, 0 \
+ 0, kBogusContextType, kBogusContextOverrides, 0 \
}; \
configs->push_back(config); \
return; \
diff --git a/bench/nanobench.h b/bench/nanobench.h
index 40dad18..cb203c1 100644
--- a/bench/nanobench.h
+++ b/bench/nanobench.h
@@ -25,7 +25,6 @@
SkAlphaType alpha;
sk_sp<SkColorSpace> colorSpace;
int samples;
- bool useDMSAA;
sk_gpu_test::GrContextFactory::ContextType ctxType;
sk_gpu_test::GrContextFactory::ContextOverrides ctxOverrides;
uint32_t surfaceFlags;
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 2d6832e..df4f764 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1479,7 +1479,6 @@
, fAlphaType(config->getAlphaType())
, fColorSpace(sk_ref_sp(config->getColorSpace()))
, fBaseContextOptions(grCtxOptions) {
- fBaseContextOptions.fAlwaysAntialias = config->getUseDMSAA();
if (FLAGS_programBinaryCache) {
fBaseContextOptions.fPersistentCache = &fMemoryCache;
}
diff --git a/include/core/SkSurfaceProps.h b/include/core/SkSurfaceProps.h
index f219294..4322795 100644
--- a/include/core/SkSurfaceProps.h
+++ b/include/core/SkSurfaceProps.h
@@ -52,6 +52,7 @@
public:
enum Flags {
kUseDeviceIndependentFonts_Flag = 1 << 0,
+ kLast_Flag = kUseDeviceIndependentFonts_Flag
};
/** Deprecated alias used by Chromium. Will be removed. */
static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag;
diff --git a/include/gpu/GrContextOptions.h b/include/gpu/GrContextOptions.h
index 7e9e0b9..2f1a45f 100644
--- a/include/gpu/GrContextOptions.h
+++ b/include/gpu/GrContextOptions.h
@@ -320,12 +320,6 @@
bool fDisallowWritePixelRowBytes = false;
/**
- * Forces all draws to use antialiasing. This allows Ganesh to use internal multisampling
- * as well as certain clip optimizations.
- */
- bool fAlwaysAntialias = false;
-
- /**
* Include or exclude specific GPU path renderers.
*/
GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault;
diff --git a/src/core/SkSurfacePriv.h b/src/core/SkSurfacePriv.h
index 26c7064..c07602a 100644
--- a/src/core/SkSurfacePriv.h
+++ b/src/core/SkSurfacePriv.h
@@ -16,6 +16,11 @@
return props ? *props : SkSurfaceProps();
}
+enum SkSurfacePropsPrivateFlags {
+ // Use internal MSAA to render to non-MSAA GPU surfaces.
+ kDMSAA_SkSurfacePropsPrivateFlag = SkSurfaceProps::kLast_Flag << 1
+};
+
constexpr size_t kIgnoreRowBytesValue = static_cast<size_t>(~0);
bool SkSurfaceValidateRasterInfo(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue);
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 7b7d9a0..5bc7998 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -184,9 +184,10 @@
const SkMatrix& origViewMatrix,
const GrStyledShape& shape,
int sampleCnt) {
- // We cache blur masks. Use default surface props here so we can use the same cached mask
- // regardless of the final dst surface.
- SkSurfaceProps defaultSurfaceProps;
+ // We cache blur masks. Use the same surface props every time so we can use the same cached mask
+ // regardless of the final dst surface. Also allow dynamic msaa if supported since our policy is
+ // to draw everything antialiased in blurs anyway.
+ SkSurfaceProps surfaceProps(kDMSAA_SkSurfacePropsPrivateFlag, kUnknown_SkPixelGeometry);
// Use GrResourceProvider::MakeApprox to implement our own approximate size matching, but demand
// a "SkBackingFit::kExact" size match on the actual render target. We do this because the
@@ -200,7 +201,7 @@
auto approxSize = GrResourceProvider::MakeApprox(maskRect.size());
auto rtContext = GrSurfaceDrawContext::MakeWithFallback(context, GrColorType::kAlpha_8, nullptr,
SkBackingFit::kExact, approxSize,
- defaultSurfaceProps, sampleCnt,
+ surfaceProps, sampleCnt,
GrMipmapped::kNo, GrProtected::kNo,
kMaskOrigin);
if (!rtContext) {
@@ -576,7 +577,7 @@
draw_shape_with_mask_filter(context, surfaceDrawContext, clip, std::move(grPaint),
viewMatrix, mf, shape);
} else {
- surfaceDrawContext->drawShape(clip, std::move(grPaint), context->priv().chooseAA(paint),
+ surfaceDrawContext->drawShape(clip, std::move(grPaint), surfaceDrawContext->chooseAA(paint),
viewMatrix, GrStyledShape(shape));
}
}
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 3d20936..a027a15 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -26,16 +26,6 @@
const GrContextOptions& options() const { return fContext->options(); }
-#if GR_TEST_UTILS
- bool alwaysAntialias() const { return fContext->options().fAlwaysAntialias; }
- GrAA chooseAA(const SkPaint& paint) const {
- return GrAA(paint.isAntiAlias() || this->alwaysAntialias());
- }
-#else
- bool alwaysAntialias() const { return false; }
- GrAA chooseAA(const SkPaint& paint) const { return GrAA(paint.isAntiAlias()); }
-#endif
-
const GrCaps* caps() const { return fContext->caps(); }
sk_sp<const GrCaps> refCaps() const;
diff --git a/src/gpu/GrSurfaceDrawContext.cpp b/src/gpu/GrSurfaceDrawContext.cpp
index e8bf3dd..e82b276 100644
--- a/src/gpu/GrSurfaceDrawContext.cpp
+++ b/src/gpu/GrSurfaceDrawContext.cpp
@@ -629,8 +629,7 @@
const SkMatrix& viewMatrix,
sk_sp<GrColorSpaceXform> colorSpaceXform) {
// If we are using dmsaa then go through GrFillRRectOp (via fillRectToRect).
- if ((fContext->priv().alwaysAntialias() || this->caps()->reducedShaderMode()) &&
- aa == GrAA::kYes) {
+ if ((this->alwaysAntialias() || this->caps()->reducedShaderMode()) && aa == GrAA::kYes) {
GrPaint paint;
paint.setColor4f(color);
std::unique_ptr<GrFragmentProcessor> fp;
@@ -756,8 +755,8 @@
aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone};
// If we are using dmsaa then attempt to draw the rect with GrFillRRectOp.
- if ((fContext->priv().caps()->reducedShaderMode() || fContext->priv().alwaysAntialias()) &&
- this->caps()->drawInstancedSupport() &&
+ if ((fContext->priv().caps()->reducedShaderMode() || this->alwaysAntialias()) &&
+ this->caps()->drawInstancedSupport() &&
aa == GrAA::kYes) { // If aa is kNo when using dmsaa, the rect is axis aligned. Don't use
// GrFillRRectOp because it might require dual source blending.
// http://skbug.com/11756
diff --git a/src/gpu/GrSurfaceDrawContext.h b/src/gpu/GrSurfaceDrawContext.h
index 1aa56d9..023c894 100644
--- a/src/gpu/GrSurfaceDrawContext.h
+++ b/src/gpu/GrSurfaceDrawContext.h
@@ -640,6 +640,14 @@
bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
GrMipmapped mipmapped() const;
+ bool alwaysAntialias() const {
+ return fSurfaceProps.flags() & kDMSAA_SkSurfacePropsPrivateFlag;
+ }
+
+ GrAA chooseAA(const SkPaint& paint) {
+ return GrAA(paint.isAntiAlias() || this->alwaysAntialias());
+ }
+
// This entry point should only be called if the backing GPU object is known to be
// instantiated.
GrRenderTarget* accessRenderTarget() { return this->asSurfaceProxy()->peekRenderTarget(); }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 3be5d90..41fb174 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -119,9 +119,9 @@
}
#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
-static bool force_aa_clip(const GrRecordingContext* context, const GrSurfaceDrawContext* sdc) {
+static bool force_aa_clip(const GrSurfaceDrawContext* sdc) {
return (sdc->numSamples() > 1 && !sdc->caps()->multisampleDisableSupport()) ||
- context->priv().alwaysAntialias();
+ sdc->alwaysAntialias();
}
#endif
@@ -135,7 +135,7 @@
#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
, fClip(SkIRect::MakeSize(fSurfaceDrawContext->dimensions()),
&this->asMatrixProvider(),
- force_aa_clip(fContext.get(), fSurfaceDrawContext.get())) {
+ force_aa_clip(fSurfaceDrawContext.get())) {
#else
, fClip(fSurfaceDrawContext->dimensions(), &this->cs(), &this->asMatrixProvider()) {
#endif
@@ -266,7 +266,7 @@
SkASSERT(op == SkClipOp::kIntersect || op == SkClipOp::kDifference);
// Regions don't actually need AA, but in DMSAA mode every clip element is antialiased.
- GrAA aa = GrAA(fContext->priv().alwaysAntialias());
+ GrAA aa = GrAA(fSurfaceDrawContext->alwaysAntialias());
if (globalRgn.isEmpty()) {
fClip.clipRect(SkMatrix::I(), SkRect::MakeEmpty(), aa, op);
@@ -301,7 +301,7 @@
if (e.fAA == GrAA::kYes) {
return true;
}
- SkASSERT(!fContext->priv().alwaysAntialias());
+ SkASSERT(!fSurfaceDrawContext->alwaysAntialias());
}
return false;
}
@@ -356,7 +356,7 @@
return;
}
- GrAA aa = fContext->priv().chooseAA(paint);
+ GrAA aa = fSurfaceDrawContext->chooseAA(paint);
if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
GrStyle style(paint, SkPaint::kStroke_Style);
@@ -441,7 +441,7 @@
}
fSurfaceDrawContext->drawRect(this->clip(), std::move(grPaint),
- fContext->priv().chooseAA(paint), this->localToDevice(), rect,
+ fSurfaceDrawContext->chooseAA(paint), this->localToDevice(), rect,
&style);
}
@@ -505,8 +505,8 @@
}
fSurfaceDrawContext->drawRRect(this->clip(), std::move(grPaint),
- fContext->priv().chooseAA(paint), this->localToDevice(), rrect,
- style);
+ fSurfaceDrawContext->chooseAA(paint), this->localToDevice(),
+ rrect, style);
}
static std::unique_ptr<GrFragmentProcessor> make_inverse_rrect_fp(const SkMatrix& viewMatrix,
@@ -540,7 +540,7 @@
// For axis-aligned filled DRRects, just draw a regular rrect with inner clipped out using a
// coverage FP instead of using path rendering.
if (auto fp = make_inverse_rrect_fp(this->localToDevice(), inner,
- fContext->priv().chooseAA(paint),
+ fSurfaceDrawContext->chooseAA(paint),
*fSurfaceDrawContext->caps()->shaderCaps())) {
GrPaint grPaint;
if (!SkPaintToGrPaint(this->recordingContext(), fSurfaceDrawContext->colorInfo(), paint,
@@ -550,8 +550,8 @@
SkASSERT(!grPaint.hasCoverageFragmentProcessor());
grPaint.setCoverageFragmentProcessor(std::move(fp));
fSurfaceDrawContext->drawRRect(this->clip(), std::move(grPaint),
- fContext->priv().chooseAA(paint), this->localToDevice(),
- outer, GrStyle());
+ fSurfaceDrawContext->chooseAA(paint),
+ this->localToDevice(), outer, GrStyle());
return;
}
}
@@ -587,8 +587,8 @@
}
fSurfaceDrawContext->drawRegion(this->clip(), std::move(grPaint),
- fContext->priv().chooseAA(paint), this->localToDevice(), region,
- GrStyle(paint));
+ fSurfaceDrawContext->chooseAA(paint), this->localToDevice(),
+ region, GrStyle(paint));
}
void SkGpuDevice::drawOval(const SkRect& oval, const SkPaint& paint) {
@@ -608,7 +608,7 @@
}
fSurfaceDrawContext->drawOval(this->clip(), std::move(grPaint),
- fContext->priv().chooseAA(paint), this->localToDevice(), oval,
+ fSurfaceDrawContext->chooseAA(paint), this->localToDevice(), oval,
GrStyle(paint));
}
@@ -626,9 +626,9 @@
return;
}
- fSurfaceDrawContext->drawArc(this->clip(), std::move(grPaint), fContext->priv().chooseAA(paint),
- this->localToDevice(), oval, startAngle, sweepAngle, useCenter,
- GrStyle(paint));
+ fSurfaceDrawContext->drawArc(this->clip(), std::move(grPaint),
+ fSurfaceDrawContext->chooseAA(paint), this->localToDevice(), oval,
+ startAngle, sweepAngle, useCenter, GrStyle(paint));
}
#include "include/core/SkMaskFilter.h"
@@ -651,7 +651,7 @@
return;
}
fSurfaceDrawContext->drawPath(this->clip(), std::move(grPaint),
- fContext->priv().chooseAA(paint), this->localToDevice(),
+ fSurfaceDrawContext->chooseAA(paint), this->localToDevice(),
origSrcPath, GrStyle(paint));
return;
}
@@ -762,7 +762,7 @@
const SkSamplingOptions& sampling, const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
ASSERT_SINGLE_OWNER
- GrAA aa = fContext->priv().chooseAA(paint);
+ GrAA aa = fSurfaceDrawContext->chooseAA(paint);
GrQuadAAFlags aaFlags = (aa == GrAA::kYes) ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone;
this->drawImageQuad(image, src, &dst, nullptr, aa, aaFlags, nullptr, sampling, paint,
constraint);
@@ -1033,7 +1033,7 @@
0x1>()
);
// Regions don't actually need AA, but in DMSAA mode everything is antialiased.
- GrAA aa = GrAA(fContext->priv().alwaysAntialias());
+ GrAA aa = GrAA(fSurfaceDrawContext->alwaysAntialias());
sdc->drawRegion(nullptr, std::move(grPaint), aa, SkMatrix::I(), clipRegion,
GrStyle::SimpleFill(), &kDrawToStencil);
return true;
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 384aa38..b12a502 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -673,7 +673,7 @@
SkMatrix srcToDst = SkMatrix::RectToRect(src, dst);
GrSamplerState sampler(GrSamplerState::WrapMode::kClamp, downgrade_to_filter(sampling));
- GrAA aa = fContext->priv().chooseAA(paint);
+ GrAA aa = fSurfaceDrawContext->chooseAA(paint);
GrQuadAAFlags aaFlags = (aa == GrAA::kYes) ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone;
GrColorInfo colorInfo(SkColorTypeToGrColorType(special->colorType()),
diff --git a/tools/flags/CommonFlagsConfig.cpp b/tools/flags/CommonFlagsConfig.cpp
index 8a4f69e..00e7520 100644
--- a/tools/flags/CommonFlagsConfig.cpp
+++ b/tools/flags/CommonFlagsConfig.cpp
@@ -11,6 +11,7 @@
#include "include/core/SkSurfaceProps.h"
#include "include/private/SkTHash.h"
#include "src/core/SkColorSpacePriv.h"
+#include "src/core/SkSurfacePriv.h"
#include <stdlib.h>
@@ -479,7 +480,6 @@
bool fakeGLESVersion2,
uint32_t surfaceFlags,
int samples,
- bool useDMSAA,
SkColorType colorType,
SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace,
@@ -496,7 +496,6 @@
, fContextOverrides(ContextOverrides::kNone)
, fSurfaceFlags(surfaceFlags)
, fSamples(samples)
- , fUseDMSAA(useDMSAA)
, fColorType(colorType)
, fAlphaType(alphaType)
, fColorSpace(std::move(colorSpace))
@@ -569,6 +568,9 @@
if (useDIText) {
surfaceFlags |= SkSurfaceProps::kUseDeviceIndependentFonts_Flag;
}
+ if (useDMSAA) {
+ surfaceFlags |= kDMSAA_SkSurfacePropsPrivateFlag;
+ }
return new SkCommandLineConfigGpu(tag,
vias,
@@ -576,7 +578,6 @@
fakeGLESVersion2,
surfaceFlags,
samples,
- useDMSAA,
colorType,
alphaType,
colorSpace,
diff --git a/tools/flags/CommonFlagsConfig.h b/tools/flags/CommonFlagsConfig.h
index 1283f6c..310baab 100644
--- a/tools/flags/CommonFlagsConfig.h
+++ b/tools/flags/CommonFlagsConfig.h
@@ -57,7 +57,6 @@
bool fakeGLESVer2,
uint32_t surfaceFlags,
int samples,
- bool useDMSAA,
SkColorType colorType,
SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace,
@@ -75,7 +74,6 @@
ContextOverrides getContextOverrides() const { return fContextOverrides; }
uint32_t getSurfaceFlags() const { return fSurfaceFlags; }
int getSamples() const { return fSamples; }
- bool getUseDMSAA() const { return fUseDMSAA; }
SkColorType getColorType() const { return fColorType; }
SkAlphaType getAlphaType() const { return fAlphaType; }
SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
@@ -92,7 +90,6 @@
ContextOverrides fContextOverrides;
uint32_t fSurfaceFlags;
int fSamples;
- bool fUseDMSAA;
SkColorType fColorType;
SkAlphaType fAlphaType;
sk_sp<SkColorSpace> fColorSpace;
diff --git a/tools/skpbench/skpbench.cpp b/tools/skpbench/skpbench.cpp
index 033bfd9..dcc324a 100644
--- a/tools/skpbench/skpbench.cpp
+++ b/tools/skpbench/skpbench.cpp
@@ -563,7 +563,6 @@
// Create a context.
GrContextOptions ctxOptions;
SetCtxOptionsFromCommonFlags(&ctxOptions);
- ctxOptions.fAlwaysAntialias = config->getUseDMSAA();
sk_gpu_test::GrContextFactory factory(ctxOptions);
sk_gpu_test::ContextInfo ctxInfo =
factory.getContextInfo(config->getContextType(), config->getContextOverrides());
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 9a85721..7c37b0c 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -21,6 +21,7 @@
#include "src/core/SkOSFile.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkScan.h"
+#include "src/core/SkSurfacePriv.h"
#include "src/core/SkTSort.h"
#include "src/core/SkTaskGroup.h"
#include "src/core/SkTextBlobPriv.h"
@@ -377,7 +378,11 @@
GrContextOptions::ShaderCacheStrategy::kSkSL;
displayParams.fGrContextOptions.fShaderErrorHandler = &gShaderErrorHandler;
displayParams.fGrContextOptions.fSuppressPrints = true;
- displayParams.fGrContextOptions.fAlwaysAntialias = FLAGS_dmsaa;
+ if (FLAGS_dmsaa) {
+ displayParams.fSurfaceProps = SkSurfaceProps(
+ displayParams.fSurfaceProps.flags() | kDMSAA_SkSurfacePropsPrivateFlag,
+ displayParams.fSurfaceProps.pixelGeometry());
+ }
fWindow->setRequestedDisplayParams(displayParams);
fDisplay = fWindow->getRequestedDisplayParams();
fRefresh = FLAGS_redraw;