ccpr: Add an MSAA atlas mode
Adds the option to use a multisampled (or mixed sampled) atlas, and
uses the sample mask and stencil buffer instead of coverage counts.
Bug: skia:
Change-Id: I9fb76d17895ae25208124f6c27e37977ac31b5eb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227428
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/ccpr/GrCCClipPath.cpp b/src/gpu/ccpr/GrCCClipPath.cpp
index 075e2b2..922e170 100644
--- a/src/gpu/ccpr/GrCCClipPath.cpp
+++ b/src/gpu/ccpr/GrCCClipPath.cpp
@@ -7,44 +7,42 @@
#include "src/gpu/ccpr/GrCCClipPath.h"
+#include "include/gpu/GrRenderTarget.h"
#include "include/gpu/GrTexture.h"
#include "src/gpu/GrOnFlushResourceProvider.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/ccpr/GrCCPerFlushResources.h"
-void GrCCClipPath::init(const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth,
- int rtHeight, const GrCaps& caps) {
+void GrCCClipPath::init(
+ const SkPath& deviceSpacePath, const SkIRect& accessRect,
+ GrCCAtlas::CoverageType atlasCoverageType, const GrCaps& caps) {
SkASSERT(!this->isInitialized());
- const GrBackendFormat format = caps.getBackendFormatFromColorType(GrColorType::kAlpha_F16);
+ fAtlasLazyProxy = GrCCAtlas::MakeLazyAtlasProxy([this](
+ GrResourceProvider* resourceProvider, GrPixelConfig pixelConfig, int sampleCount) {
+ SkASSERT(fHasAtlas);
+ SkASSERT(!fHasAtlasTransform);
- fAtlasLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
- [this](GrResourceProvider* resourceProvider)
- -> GrSurfaceProxy::LazyInstantiationResult {
- SkASSERT(fHasAtlas);
- SkASSERT(!fHasAtlasTransform);
+ GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
- GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
+ if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
+ fAtlasScale = fAtlasTranslate = {0, 0};
+ SkDEBUGCODE(fHasAtlasTransform = true);
+ return sk_sp<GrTexture>();
+ }
- if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
- fAtlasScale = fAtlasTranslate = {0, 0};
- SkDEBUGCODE(fHasAtlasTransform = true);
- return {};
- }
+ sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
+ SkASSERT(texture);
+ SkASSERT(texture->asRenderTarget()->numSamples() == sampleCount);
+ SkASSERT(textureProxy->origin() == kTopLeft_GrSurfaceOrigin);
- sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
- SkASSERT(texture);
- SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
+ fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
+ fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
+ fDevToAtlasOffset.fY * fAtlasScale.y());
+ SkDEBUGCODE(fHasAtlasTransform = true);
- fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
- fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
- fDevToAtlasOffset.fY * fAtlasScale.y());
- SkDEBUGCODE(fHasAtlasTransform = true);
-
- return std::move(texture);
- },
- format, GrProxyProvider::Renderable::kYes, GrProtected::kNo, kTopLeft_GrSurfaceOrigin,
- kAlpha_half_GrPixelConfig, caps);
+ return texture;
+ }, atlasCoverageType, caps);
fDeviceSpacePath = deviceSpacePath;
fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
@@ -67,7 +65,8 @@
GrOnFlushResourceProvider* onFlushRP) {
SkASSERT(this->isInitialized());
SkASSERT(!fHasAtlas);
- fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds,
- &fDevToAtlasOffset);
+ fAtlas = resources->renderDeviceSpacePathInAtlas(
+ fAccessRect, fDeviceSpacePath, fPathDevIBounds, GrFillRuleForSkPath(fDeviceSpacePath),
+ &fDevToAtlasOffset);
SkDEBUGCODE(fHasAtlas = true);
}