aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-07-09 13:25:02 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-09 13:25:02 -0700
commit7b670db2b4eb0265e69038add7ae79441d77bbc5 (patch)
treeee459690b5d275b83cd51a6639daad7f5376892c
parent4f6dc521f5082a65f42be8a333afe3bbda4ec400 (diff)
Remove setFromPaint from GrPipelineBuilder
TBR=bsalomon@google.com BUG=skia: Review URL: https://codereview.chromium.org/1227153003
-rw-r--r--gm/constcolorprocessor.cpp3
-rw-r--r--include/gpu/GrDrawContext.h8
-rw-r--r--src/gpu/GrAtlasTextContext.cpp6
-rw-r--r--src/gpu/GrDrawContext.cpp47
-rw-r--r--src/gpu/GrPipelineBuilder.cpp4
-rw-r--r--src/gpu/GrPipelineBuilder.h8
-rw-r--r--src/gpu/GrStencilAndCoverTextContext.cpp41
-rw-r--r--src/gpu/GrStencilAndCoverTextContext.h2
8 files changed, 48 insertions, 71 deletions
diff --git a/gm/constcolorprocessor.cpp b/gm/constcolorprocessor.cpp
index cea7986cd3..661a5ea8a4 100644
--- a/gm/constcolorprocessor.cpp
+++ b/gm/constcolorprocessor.cpp
@@ -111,9 +111,8 @@ protected:
GrColor color = kColors[procColor];
SkAutoTUnref<GrFragmentProcessor> fp(GrConstColorProcessor::Create(color, mode));
- GrPipelineBuilder pipelineBuilder;
GrClip clip;
- pipelineBuilder.setFromPaint(grPaint, rt, clip);
+ GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
pipelineBuilder.addColorProcessor(fp);
tt.target()->drawSimpleRect(&pipelineBuilder,
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index 2a1d016541..4d59b8cd9d 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -244,15 +244,9 @@ private:
GrDrawContext(GrContext*, GrDrawTarget*, const SkSurfaceProps&);
- // Sets the paint. Returns true on success; false on failure.
- bool prepareToDraw(GrPipelineBuilder*,
- GrRenderTarget* rt,
- const GrClip&,
- const GrPaint* paint);
GrTextContext* createTextContext(GrRenderTarget*, const SkSurfaceProps&);
- // A simpler version of the above which just returns true on success; false on failure.
- // Clip is *NOT* set
+ // Checks if the context has been abandoned and if the rendertarget is owned by this context
bool prepareToDraw(GrRenderTarget* rt);
void internalDrawPath(GrDrawTarget*,
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index e0d452997b..f5bcefba76 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -2167,8 +2167,7 @@ void GrAtlasTextContext::flush(const SkTextBlob* blob,
SkScalar transX, SkScalar transY) {
// We loop through the runs of the blob, flushing each. If any run is too large, then we flush
// it as paths
- GrPipelineBuilder pipelineBuilder;
- pipelineBuilder.setFromPaint(grPaint, rt, clip);
+ GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
GrColor color = grPaint.getColor();
@@ -2194,8 +2193,7 @@ void GrAtlasTextContext::flush(BitmapTextBlob* cacheBlob,
const GrPaint& grPaint,
const GrClip& clip,
const SkIRect& clipBounds) {
- GrPipelineBuilder pipelineBuilder;
- pipelineBuilder.setFromPaint(grPaint, rt, clip);
+ GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
GrColor color = grPaint.getColor();
for (int run = 0; run < cacheBlob->fRunCount; run++) {
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index b957b9124e..5e950dc152 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -187,11 +187,11 @@ void GrDrawContext::drawPaint(GrRenderTarget* rt,
}
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(*paint, rt, clip);
fDrawTarget->drawBWRect(&pipelineBuilder,
paint->getColor(),
SkMatrix::I(),
@@ -435,11 +435,12 @@ void GrDrawContext::drawRect(GrRenderTarget* rt,
}
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(paint, rt, clip);
+
SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getWidth();
// Check if this is a full RT draw and can be replaced with a clear. We don't bother checking
@@ -536,11 +537,11 @@ void GrDrawContext::drawNonAARectToRect(GrRenderTarget* rt,
const SkMatrix* localMatrix) {
RETURN_IF_ABANDONED
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(paint, rt, clip);
fDrawTarget->drawBWRect(&pipelineBuilder,
paint.getColor(),
viewMatrix,
@@ -832,12 +833,12 @@ void GrDrawContext::drawVertices(GrRenderTarget* rt,
int indexCount) {
RETURN_IF_ABANDONED
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
-
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(paint, rt, clip);
+
// TODO clients should give us bounds
SkRect bounds;
if (!bounds.setBoundsCheck(positions, vertexCount)) {
@@ -885,11 +886,11 @@ void GrDrawContext::drawRRect(GrRenderTarget*rt,
}
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(paint, rt, clip);
GrColor color = paint.getColor();
if (!GrOvalRenderer::DrawRRect(fDrawTarget,
&pipelineBuilder,
@@ -920,11 +921,11 @@ void GrDrawContext::drawDRRect(GrRenderTarget* rt,
}
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(paint, rt, clip);
GrColor color = paint.getColor();
if (!GrOvalRenderer::DrawDRRect(fDrawTarget,
&pipelineBuilder,
@@ -967,11 +968,11 @@ void GrDrawContext::drawOval(GrRenderTarget* rt,
}
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(paint, rt, clip);
GrColor color = paint.getColor();
if (!GrOvalRenderer::DrawOval(fDrawTarget,
&pipelineBuilder,
@@ -1063,11 +1064,11 @@ void GrDrawContext::drawPath(GrRenderTarget* rt,
// the writePixels that uploads to the scratch will perform a flush so we're
// OK.
AutoCheckFlush acf(fContext);
- GrPipelineBuilder pipelineBuilder;
- if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) {
+ if (!this->prepareToDraw(rt)) {
return;
}
+ GrPipelineBuilder pipelineBuilder(paint, rt, clip);
if (!strokeInfo.isDashed()) {
bool useCoverageAA = paint.isAntiAlias() &&
!pipelineBuilder.getRenderTarget()->isUnifiedMultisampled();
@@ -1182,18 +1183,6 @@ void GrDrawContext::internalDrawPath(GrDrawTarget* target,
pr->drawPath(target, pipelineBuilder, color, viewMatrix, *pathPtr, *strokeInfoPtr, useCoverageAA);
}
-bool GrDrawContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder,
- GrRenderTarget* rt,
- const GrClip& clip,
- const GrPaint* paint) {
- RETURN_FALSE_IF_ABANDONED
-
- ASSERT_OWNED_RESOURCE(rt);
- SkASSERT(rt && paint);
- pipelineBuilder->setFromPaint(*paint, rt, clip);
- return true;
-}
-
bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) {
RETURN_FALSE_IF_ABANDONED
diff --git a/src/gpu/GrPipelineBuilder.cpp b/src/gpu/GrPipelineBuilder.cpp
index b31d105963..59d0556bae 100644
--- a/src/gpu/GrPipelineBuilder.cpp
+++ b/src/gpu/GrPipelineBuilder.cpp
@@ -48,8 +48,8 @@ GrPipelineBuilder& GrPipelineBuilder::operator=(const GrPipelineBuilder& that) {
return *this;
}
-void GrPipelineBuilder::setFromPaint(const GrPaint& paint, GrRenderTarget* rt, const GrClip& clip) {
- SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
+GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, const GrClip& clip) {
+ SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
fColorStages.reset();
fCoverageStages.reset();
diff --git a/src/gpu/GrPipelineBuilder.h b/src/gpu/GrPipelineBuilder.h
index 4f9016ba61..22ad865f41 100644
--- a/src/gpu/GrPipelineBuilder.h
+++ b/src/gpu/GrPipelineBuilder.h
@@ -38,15 +38,15 @@ public:
*this = pipelineBuilder;
}
- virtual ~GrPipelineBuilder();
-
/**
- * Initializes the GrPipelineBuilder based on a GrPaint, view matrix and render target. Note
+ * Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note
* that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
* no GrPaint equivalents are set to default values with the exception of vertex attribute state
* which is unmodified by this function and clipping which will be enabled.
*/
- void setFromPaint(const GrPaint&, GrRenderTarget*, const GrClip&);
+ GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&);
+
+ virtual ~GrPipelineBuilder();
///////////////////////////////////////////////////////////////////////////
/// @name Fragment Processors
diff --git a/src/gpu/GrStencilAndCoverTextContext.cpp b/src/gpu/GrStencilAndCoverTextContext.cpp
index b07a546b9a..980a494eaf 100644
--- a/src/gpu/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/GrStencilAndCoverTextContext.cpp
@@ -378,24 +378,6 @@ void GrStencilAndCoverTextContext::init(GrRenderTarget* rt,
&fGlyphCache->getDescriptor(), fStroke);
}
- fStateRestore.set(&fPipelineBuilder);
-
- fPipelineBuilder.setFromPaint(fPaint, fRenderTarget, fClip);
- SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiAlias());
- fPipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fPaint.isAntiAlias());
-
- GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
- kZero_StencilOp,
- kZero_StencilOp,
- kNotEqual_StencilFunc,
- 0xffff,
- 0x0000,
- 0xffff);
-
- *fPipelineBuilder.stencil() = kStencilPass;
-
- SkASSERT(0 == fQueuedGlyphCount);
- SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx);
}
bool GrStencilAndCoverTextContext::mapToFallbackContext(SkMatrix* inverse) {
@@ -445,7 +427,26 @@ void GrStencilAndCoverTextContext::flush() {
fViewMatrix,
fLocalMatrix));
- fDrawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs,
+ // We should only be flushing about once every run. However, if this impacts performance
+ // we could move the creation of the GrPipelineBuilder earlier.
+ GrPipelineBuilder pipelineBuilder(fPaint, fRenderTarget, fClip);
+ SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiAlias());
+ pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fPaint.isAntiAlias());
+
+ GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
+ kZero_StencilOp,
+ kZero_StencilOp,
+ kNotEqual_StencilFunc,
+ 0xffff,
+ 0x0000,
+ 0xffff);
+
+ *pipelineBuilder.stencil() = kStencilPass;
+
+ SkASSERT(0 == fQueuedGlyphCount);
+ SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx);
+
+ fDrawContext->drawPaths(&pipelineBuilder, pp, fGlyphs,
fGlyphIndices, GrPathRange::kU16_PathIndexType,
get_xy_scalar_array(fGlyphPositions),
GrPathRendering::kTranslate_PathTransformType,
@@ -490,8 +491,6 @@ void GrStencilAndCoverTextContext::finish() {
SkGlyphCache::AttachCache(fGlyphCache);
fGlyphCache = NULL;
- fPipelineBuilder.stencil()->setDisabled();
- fStateRestore.set(NULL);
fViewMatrix = fContextInitialMatrix;
}
diff --git a/src/gpu/GrStencilAndCoverTextContext.h b/src/gpu/GrStencilAndCoverTextContext.h
index 02d1d3f6a9..40591c8499 100644
--- a/src/gpu/GrStencilAndCoverTextContext.h
+++ b/src/gpu/GrStencilAndCoverTextContext.h
@@ -53,8 +53,6 @@ private:
kMaxPerformance_RenderMode,
};
- GrPipelineBuilder fPipelineBuilder;
- GrPipelineBuilder::AutoRestoreFragmentProcessors fStateRestore;
SkScalar fTextRatio;
float fTextInverseRatio;
SkGlyphCache* fGlyphCache;