ccpr: Set atlas proxy size to draw bounds rather than backing size
Bug: skia:
Change-Id: I6605754ecc5377b1c25847fdda478f8246979a2f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209808
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ccpr/GrCCAtlas.cpp b/src/gpu/ccpr/GrCCAtlas.cpp
index c3c8ed6..3cfb5d0 100644
--- a/src/gpu/ccpr/GrCCAtlas.cpp
+++ b/src/gpu/ccpr/GrCCAtlas.cpp
@@ -189,6 +189,10 @@
SkASSERT(SkTMax(fHeight, fWidth) <= fMaxTextureSize);
SkASSERT(fMaxTextureSize <= onFlushRP->caps()->maxRenderTargetSize());
+ // Finalize the content size of our proxy. The GPU can potentially make optimizations if it
+ // knows we only intend to write out a smaller sub-rectangle of the backing texture.
+ fTextureProxy->priv().setLazySize(fDrawBounds.width(), fDrawBounds.height());
+
if (backingTexture) {
SkASSERT(backingTexture->config() == kAlpha_half_GrPixelConfig);
SkASSERT(backingTexture->width() == fWidth);
diff --git a/src/gpu/ccpr/GrCCDrawPathsOp.cpp b/src/gpu/ccpr/GrCCDrawPathsOp.cpp
index 0c5002e..698ae4e 100644
--- a/src/gpu/ccpr/GrCCDrawPathsOp.cpp
+++ b/src/gpu/ccpr/GrCCDrawPathsOp.cpp
@@ -415,7 +415,11 @@
for (const InstanceRange& range : fInstanceRanges) {
SkASSERT(range.fEndInstanceIdx > baseInstance);
- GrCCPathProcessor pathProc(range.fAtlasProxy, fViewMatrixIfUsingLocalCoords);
+ const GrTextureProxy* atlas = range.fAtlasProxy;
+ SkASSERT(atlas->isInstantiated());
+
+ GrCCPathProcessor pathProc(
+ atlas->peekTexture(), atlas->origin(), fViewMatrixIfUsingLocalCoords);
GrTextureProxy* atlasProxy = range.fAtlasProxy;
fixedDynamicState.fPrimitiveProcessorTextures = &atlasProxy;
pathProc.drawPaths(flushState, pipeline, &fixedDynamicState, *resources, baseInstance,
diff --git a/src/gpu/ccpr/GrCCPathProcessor.cpp b/src/gpu/ccpr/GrCCPathProcessor.cpp
index 5ea9755..96d88a7 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.cpp
+++ b/src/gpu/ccpr/GrCCPathProcessor.cpp
@@ -10,6 +10,7 @@
#include "include/gpu/GrTexture.h"
#include "src/gpu/GrGpuCommandBuffer.h"
#include "src/gpu/GrOnFlushResourceProvider.h"
+#include "src/gpu/GrTexturePriv.h"
#include "src/gpu/ccpr/GrCCPerFlushResources.h"
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/glsl/GrGLSLGeometryProcessor.h"
@@ -78,13 +79,13 @@
}
}
-GrCCPathProcessor::GrCCPathProcessor(const GrTextureProxy* atlas,
+GrCCPathProcessor::GrCCPathProcessor(const GrTexture* atlasTexture, GrSurfaceOrigin atlasOrigin,
const SkMatrix& viewMatrixIfUsingLocalCoords)
: INHERITED(kGrCCPathProcessor_ClassID)
- , fAtlasAccess(atlas->textureType(), atlas->config(), GrSamplerState::Filter::kNearest,
- GrSamplerState::WrapMode::kClamp)
- , fAtlasSize(atlas->isize())
- , fAtlasOrigin(atlas->origin()) {
+ , fAtlasAccess(atlasTexture->texturePriv().textureType(), atlasTexture->config(),
+ GrSamplerState::Filter::kNearest, GrSamplerState::WrapMode::kClamp)
+ , fAtlasSize(SkISize::Make(atlasTexture->width(), atlasTexture->height()))
+ , fAtlasOrigin(atlasOrigin) {
// TODO: Can we just assert that atlas has GrCCAtlas::kTextureOrigin and remove fAtlasOrigin?
this->setInstanceAttributes(kInstanceAttribs, SK_ARRAY_COUNT(kInstanceAttribs));
SkASSERT(this->instanceStride() == sizeof(Instance));
@@ -104,10 +105,10 @@
private:
void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc,
FPCoordTransformIter&& transformIter) override {
- const GrCCPathProcessor& proc = primProc.cast<GrCCPathProcessor>();
- pdman.set2f(fAtlasAdjustUniform, 1.0f / proc.atlasSize().fWidth,
- 1.0f / proc.atlasSize().fHeight);
- this->setTransformDataHelper(proc.localMatrix(), pdman, &transformIter);
+ const auto& proc = primProc.cast<GrCCPathProcessor>();
+ pdman.set2f(
+ fAtlasAdjustUniform, 1.0f / proc.fAtlasSize.fWidth, 1.0f / proc.fAtlasSize.fHeight);
+ this->setTransformDataHelper(proc.fLocalMatrix, pdman, &transformIter);
}
GrGLSLUniformHandler::UniformHandle fAtlasAdjustUniform;
@@ -198,17 +199,17 @@
// Convert to atlas coordinates in order to do our texture lookup.
v->codeAppendf("float2 atlascoord = octocoord + float2(dev_to_atlas_offset);");
- if (kTopLeft_GrSurfaceOrigin == proc.atlasOrigin()) {
+ if (kTopLeft_GrSurfaceOrigin == proc.fAtlasOrigin) {
v->codeAppendf("%s.xy = atlascoord * %s;", texcoord.vsOut(), atlasAdjust);
} else {
- SkASSERT(kBottomLeft_GrSurfaceOrigin == proc.atlasOrigin());
+ SkASSERT(kBottomLeft_GrSurfaceOrigin == proc.fAtlasOrigin);
v->codeAppendf("%s.xy = float2(atlascoord.x * %s.x, 1 - atlascoord.y * %s.y);",
texcoord.vsOut(), atlasAdjust, atlasAdjust);
}
v->codeAppendf("%s.z = wind * .5;", texcoord.vsOut());
gpArgs->fPositionVar.set(kFloat2_GrSLType, "octocoord");
- this->emitTransforms(v, varyingHandler, uniHandler, gpArgs->fPositionVar, proc.localMatrix(),
+ this->emitTransforms(v, varyingHandler, uniHandler, gpArgs->fPositionVar, proc.fLocalMatrix,
args.fFPCoordTransformHandler);
// Fragment shader.
diff --git a/src/gpu/ccpr/GrCCPathProcessor.h b/src/gpu/ccpr/GrCCPathProcessor.h
index 0e2a22d..642cbdc 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.h
+++ b/src/gpu/ccpr/GrCCPathProcessor.h
@@ -61,14 +61,10 @@
static sk_sp<const GrGpuBuffer> FindVertexBuffer(GrOnFlushResourceProvider*);
static sk_sp<const GrGpuBuffer> FindIndexBuffer(GrOnFlushResourceProvider*);
- GrCCPathProcessor(const GrTextureProxy* atlas,
+ GrCCPathProcessor(const GrTexture* atlasTexture, GrSurfaceOrigin atlasOrigin,
const SkMatrix& viewMatrixIfUsingLocalCoords = SkMatrix::I());
const char* name() const override { return "GrCCPathProcessor"; }
- const SkISize& atlasSize() const { return fAtlasSize; }
- GrSurfaceOrigin atlasOrigin() const { return fAtlasOrigin; }
- const SkMatrix& localMatrix() const { return fLocalMatrix; }
-
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
diff --git a/src/gpu/ccpr/GrCCPerFlushResources.cpp b/src/gpu/ccpr/GrCCPerFlushResources.cpp
index ffec7fb..567a778 100644
--- a/src/gpu/ccpr/GrCCPerFlushResources.cpp
+++ b/src/gpu/ccpr/GrCCPerFlushResources.cpp
@@ -76,12 +76,15 @@
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
SkASSERT(fSrcProxy);
- GrPipeline::FixedDynamicState dynamicState;
auto srcProxy = fSrcProxy.get();
- dynamicState.fPrimitiveProcessorTextures = &srcProxy;
+ SkASSERT(srcProxy->isInstantiated());
+
+ GrCCPathProcessor pathProc(srcProxy->peekTexture(), srcProxy->origin());
GrPipeline pipeline(GrScissorTest::kDisabled, SkBlendMode::kSrc);
- GrCCPathProcessor pathProc(srcProxy);
+ GrPipeline::FixedDynamicState dynamicState;
+ dynamicState.fPrimitiveProcessorTextures = &srcProxy;
+
pathProc.drawPaths(flushState, pipeline, &dynamicState, *fResources, fBaseInstance,
fEndInstance, this->bounds());
}