diff options
author | 2015-10-15 08:01:48 -0700 | |
---|---|---|
committer | 2015-10-15 08:01:49 -0700 | |
commit | 2e1e51f04985f7c258b96f0decc190456f5dd74d (patch) | |
tree | a7c76384e447455ba8fb95575a41696fa5777bcf /src/gpu | |
parent | 860e8a67190e024b7375e52e270e6bd0a17af86e (diff) |
GrDrawContext now holds GrRenderTarget pointer
Review URL: https://codereview.chromium.org/1404823005
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrBlurUtils.cpp | 18 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 18 | ||||
-rw-r--r-- | src/gpu/GrDrawContext.cpp | 200 | ||||
-rw-r--r-- | src/gpu/GrLayerCache.cpp | 5 | ||||
-rw-r--r-- | src/gpu/GrRenderTarget.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrYUVProvider.cpp | 4 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 51 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 5 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 15 |
9 files changed, 141 insertions, 179 deletions
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp index a396c3340d..5d691fb137 100644 --- a/src/gpu/GrBlurUtils.cpp +++ b/src/gpu/GrBlurUtils.cpp @@ -26,7 +26,6 @@ static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r // is already burnt into the mask this boils down to a rect draw. // Return true if the mask was successfully drawn. static bool draw_mask(GrDrawContext* drawContext, - GrRenderTarget* rt, const GrClip& clip, const SkMatrix& viewMatrix, const SkRect& maskRect, @@ -43,13 +42,12 @@ static bool draw_mask(GrDrawContext* drawContext, if (!viewMatrix.invert(&inverse)) { return false; } - drawContext->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), maskRect, inverse); + drawContext->drawNonAARectWithLocalMatrix(clip, *grp, SkMatrix::I(), maskRect, inverse); return true; } static bool draw_with_mask_filter(GrDrawContext* drawContext, GrTextureProvider* textureProvider, - GrRenderTarget* rt, const GrClip& clipData, const SkMatrix& viewMatrix, const SkPath& devPath, @@ -91,7 +89,7 @@ static bool draw_with_mask_filter(GrDrawContext* drawContext, SkRect maskRect = SkRect::Make(dstM.fBounds); - return draw_mask(drawContext, rt, clipData, viewMatrix, maskRect, grp, texture); + return draw_mask(drawContext, clipData, viewMatrix, maskRect, grp, texture); } // Create a mask of 'devPath' and place the result in 'mask'. @@ -126,12 +124,12 @@ static GrTexture* create_mask_GPU(GrContext* context, SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height()); - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); + SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(mask->asRenderTarget())); if (!drawContext) { return nullptr; } - drawContext->clear(mask->asRenderTarget(), nullptr, 0x0, true); + drawContext->clear(nullptr, 0x0, true); GrPaint tempPaint; tempPaint.setAntiAlias(doAA); @@ -144,7 +142,7 @@ static GrTexture* create_mask_GPU(GrContext* context, // the origin using tempPaint. SkMatrix translate; translate.setTranslate(-maskRect->fLeft, -maskRect->fTop); - drawContext->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, devPath, strokeInfo); + drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo); return mask; } @@ -247,7 +245,6 @@ void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, if (paint.getMaskFilter()->directFilterMaskGPU(context->textureProvider(), drawContext, - renderTarget, &grPaint, clip, viewMatrix, @@ -272,7 +269,6 @@ void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, // filterMaskGPU gives us ownership of a ref to the result SkAutoTUnref<GrTexture> atu(filtered); if (draw_mask(drawContext, - renderTarget, clip, viewMatrix, maskRect, @@ -289,12 +285,12 @@ void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, // GPU path fails SkPaint::Style style = strokeInfo.isHairlineStyle() ? SkPaint::kStroke_Style : SkPaint::kFill_Style; - draw_with_mask_filter(drawContext, context->textureProvider(), renderTarget, + draw_with_mask_filter(drawContext, context->textureProvider(), clip, viewMatrix, *devPathPtr, paint.getMaskFilter(), clipBounds, &grPaint, style); return; } - drawContext->drawPath(renderTarget, clip, grPaint, viewMatrix, *pathPtr, strokeInfo); + drawContext->drawPath(clip, grPaint, viewMatrix, *pathPtr, strokeInfo); } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index d402604198..82550d0d29 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -125,12 +125,13 @@ GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props, return fTextContexts[props.pixelGeometry()][useDIF]; } -GrDrawContext* GrContext::DrawingMgr::drawContext(const SkSurfaceProps* surfaceProps) { +GrDrawContext* GrContext::DrawingMgr::drawContext(GrRenderTarget* rt, + const SkSurfaceProps* surfaceProps) { if (this->abandoned()) { return nullptr; } - return new GrDrawContext(fContext, fDrawTarget, surfaceProps); + return new GrDrawContext(fContext, rt, fDrawTarget, surfaceProps); } //////////////////////////////////////////////////////////////////////////////// @@ -429,13 +430,13 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, } SkMatrix matrix; matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); - SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); + SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarget)); if (!drawContext) { return false; } paint.addColorFragmentProcessor(fp); SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); - drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matrix, rect, nullptr); + drawContext->drawRect(GrClip::WideOpen(), paint, matrix, rect, nullptr); if (kFlushWrites_PixelOp & pixelOpsFlags) { this->flushSurfaceWrites(surface); @@ -541,9 +542,8 @@ bool GrContext::readSurfacePixels(GrSurface* src, if (fp) { paint.addColorFragmentProcessor(fp); SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); - SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); - drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen(), paint, - SkMatrix::I(), rect, nullptr); + SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(temp->asRenderTarget())); + drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect, nullptr); surfaceToRead.reset(SkRef(temp.get())); left = 0; top = 0; @@ -617,12 +617,12 @@ void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe return; } - SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); + SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(dst->asRenderTarget())); if (!drawContext) { return; } - drawContext->copySurface(dst->asRenderTarget(), src, srcRect, dstPoint); + drawContext->copySurface(src, srcRect, dstPoint); if (kFlushWrites_PixelOp & pixelOpsFlags) { this->flush(); diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index 96bc3f3d95..dcf148f811 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -38,72 +38,81 @@ private: }; GrDrawContext::GrDrawContext(GrContext* context, + GrRenderTarget* rt, GrDrawTarget* drawTarget, const SkSurfaceProps* surfaceProps) : fContext(context) + , fRenderTarget(rt) , fDrawTarget(SkRef(drawTarget)) , fTextContext(nullptr) , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) { + SkDEBUGCODE(this->validate();) } GrDrawContext::~GrDrawContext() { SkSafeUnref(fDrawTarget); } -void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, - const SkIRect& srcRect, const SkIPoint& dstPoint) { - RETURN_IF_ABANDONED +#ifdef SK_DEBUG +void GrDrawContext::validate() const { + SkASSERT(fRenderTarget); + ASSERT_OWNED_RESOURCE(fRenderTarget); +} +#endif - if (!this->prepareToDraw(dst)) { - return; - } +void GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { + RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) - fDrawTarget->copySurface(dst, src, srcRect, dstPoint); + fDrawTarget->copySurface(fRenderTarget, src, srcRect, dstPoint); } -void GrDrawContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint, +void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, const SkPaint& skPaint, const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x, SkScalar y, const SkIRect& clipBounds) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) if (!fTextContext) { - fTextContext = fContext->textContext(fSurfaceProps, rt); + fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget); } - fTextContext->drawText(this, rt, clip, grPaint, skPaint, viewMatrix, + fTextContext->drawText(this, fRenderTarget, clip, grPaint, skPaint, viewMatrix, text, byteLength, x, y, clipBounds); } -void GrDrawContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint, +void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, const SkPaint& skPaint, const SkMatrix& viewMatrix, const char text[], size_t byteLength, const SkScalar pos[], int scalarsPerPosition, const SkPoint& offset, const SkIRect& clipBounds) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) if (!fTextContext) { - fTextContext = fContext->textContext(fSurfaceProps, rt); + fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget); } - fTextContext->drawPosText(this, rt, clip, grPaint, skPaint, viewMatrix, text, byteLength, + fTextContext->drawPosText(this, fRenderTarget, clip, grPaint, skPaint, viewMatrix, text, byteLength, pos, scalarsPerPosition, offset, clipBounds); } -void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const SkPaint& skPaint, +void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, const SkMatrix& viewMatrix, const SkTextBlob* blob, SkScalar x, SkScalar y, SkDrawFilter* filter, const SkIRect& clipBounds) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) if (!fTextContext) { - fTextContext = fContext->textContext(fSurfaceProps, rt); + fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget); } - fTextContext->drawTextBlob(this, rt, + fTextContext->drawTextBlob(this, fRenderTarget, clip, skPaint, viewMatrix, blob, x, y, filter, clipBounds); } @@ -115,47 +124,43 @@ void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder, GrPathRangeDraw* draw, int /*GrPathRendering::FillType*/ fill) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) fDrawTarget->drawPathsFromRange(*pipelineBuilder, viewMatrix, localMatrix, color, range, draw, (GrPathRendering::FillType) fill); } -void GrDrawContext::discard(GrRenderTarget* renderTarget) { +void GrDrawContext::discard() { RETURN_IF_ABANDONED - SkASSERT(renderTarget); + SkDEBUGCODE(this->validate();) + AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(renderTarget)) { - return; - } - fDrawTarget->discard(renderTarget); + fDrawTarget->discard(fRenderTarget); } -void GrDrawContext::clear(GrRenderTarget* renderTarget, - const SkIRect* rect, +void GrDrawContext::clear(const SkIRect* rect, const GrColor color, bool canIgnoreRect) { RETURN_IF_ABANDONED - SkASSERT(renderTarget); + SkDEBUGCODE(this->validate();) AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(renderTarget)) { - return; - } - fDrawTarget->clear(rect, color, canIgnoreRect, renderTarget); + fDrawTarget->clear(rect, color, canIgnoreRect, fRenderTarget); } -void GrDrawContext::drawPaint(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawPaint(const GrClip& clip, const GrPaint& origPaint, const SkMatrix& viewMatrix) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + // set rect to be big enough to fill the space, but not super-huge, so we // don't overflow fixed-point implementations SkRect r; r.setLTRB(0, 0, - SkIntToScalar(rt->width()), - SkIntToScalar(rt->height())); + SkIntToScalar(fRenderTarget->width()), + SkIntToScalar(fRenderTarget->height())); SkTCopyOnFirstWrite<GrPaint> paint(origPaint); // by definition this fills the entire clip, no need for AA @@ -175,7 +180,7 @@ void GrDrawContext::drawPaint(GrRenderTarget* rt, return; } inverse.mapRect(&r); - this->drawRect(rt, clip, *paint, viewMatrix, r); + this->drawRect(clip, *paint, viewMatrix, r); } else { SkMatrix localMatrix; if (!viewMatrix.invert(&localMatrix)) { @@ -184,11 +189,8 @@ void GrDrawContext::drawPaint(GrRenderTarget* rt, } AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(*paint, rt, clip); + GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); fDrawTarget->drawNonAARect(pipelineBuilder, paint->getColor(), SkMatrix::I(), @@ -202,27 +204,25 @@ static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po point.fY >= rect.fTop && point.fY <= rect.fBottom; } -void GrDrawContext::drawRect(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawRect(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, const SkRect& rect, const GrStrokeInfo* strokeInfo) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + if (strokeInfo && strokeInfo->isDashed()) { SkPath path; path.setIsVolatile(true); path.addRect(rect); - this->drawPath(rt, clip, paint, viewMatrix, path, *strokeInfo); + this->drawPath(clip, paint, viewMatrix, path, *strokeInfo); return; } AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); SkScalar width = nullptr == strokeInfo ? -1 : strokeInfo->getWidth(); @@ -253,7 +253,7 @@ void GrDrawContext::drawRect(GrRenderTarget* rt, // Will it blend? GrColor clearColor; if (paint.isConstantBlendedColor(&clearColor)) { - fDrawTarget->clear(nullptr, clearColor, true, rt); + fDrawTarget->clear(nullptr, clearColor, true, fRenderTarget); return; } } @@ -285,7 +285,7 @@ void GrDrawContext::drawRect(GrRenderTarget* rt, if (width >= 0) { // Non-AA hairlines are snapped to pixel centers to make which pixels are hit deterministic - bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); + bool snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisampled()); SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAStroke( color, viewMatrix, rect, width, snapToPixelCenters)); @@ -301,19 +301,17 @@ void GrDrawContext::drawRect(GrRenderTarget* rt, } } -void GrDrawContext::drawNonAARectToRect(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawNonAARectToRect(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, const SkRect& rectToDraw, const SkRect& localRect) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); fDrawTarget->drawNonAARect(pipelineBuilder, paint.getColor(), viewMatrix, @@ -321,19 +319,17 @@ void GrDrawContext::drawNonAARectToRect(GrRenderTarget* rt, localRect); } -void GrDrawContext::drawNonAARectWithLocalMatrix(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawNonAARectWithLocalMatrix(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, const SkRect& rectToDraw, const SkMatrix& localMatrix) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); fDrawTarget->drawNonAARect(pipelineBuilder, paint.getColor(), viewMatrix, @@ -341,8 +337,7 @@ void GrDrawContext::drawNonAARectWithLocalMatrix(GrRenderTarget* rt, localMatrix); } -void GrDrawContext::drawVertices(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawVertices(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, GrPrimitiveType primitiveType, @@ -353,12 +348,11 @@ void GrDrawContext::drawVertices(GrRenderTarget* rt, const uint16_t indices[], int indexCount) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); // TODO clients should give us bounds SkRect bounds; @@ -387,8 +381,7 @@ void GrDrawContext::drawVertices(GrRenderTarget* rt, /////////////////////////////////////////////////////////////////////////////// -void GrDrawContext::drawAtlas(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawAtlas(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, int spriteCount, @@ -396,12 +389,11 @@ void GrDrawContext::drawAtlas(GrRenderTarget* rt, const SkRect texRect[], const SkColor colors[]) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); GrDrawAtlasBatch::Geometry geometry; geometry.fColor = paint.getColor(); @@ -413,13 +405,14 @@ void GrDrawContext::drawAtlas(GrRenderTarget* rt, /////////////////////////////////////////////////////////////////////////////// -void GrDrawContext::drawRRect(GrRenderTarget*rt, - const GrClip& clip, +void GrDrawContext::drawRRect(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, const SkRRect& rrect, const GrStrokeInfo& strokeInfo) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + if (rrect.isEmpty()) { return; } @@ -428,17 +421,15 @@ void GrDrawContext::drawRRect(GrRenderTarget*rt, SkPath path; path.setIsVolatile(true); path.addRRect(rrect); - this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); + this->drawPath(clip, paint, viewMatrix, path, strokeInfo); return; } AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); GrColor color = paint.getColor(); + if (!GrOvalRenderer::DrawRRect(fDrawTarget, pipelineBuilder, color, @@ -456,23 +447,21 @@ void GrDrawContext::drawRRect(GrRenderTarget*rt, /////////////////////////////////////////////////////////////////////////////// -void GrDrawContext::drawDRRect(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawDRRect(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, const SkRRect& outer, const SkRRect& inner) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + if (outer.isEmpty()) { return; } AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); GrColor color = paint.getColor(); if (!GrOvalRenderer::DrawDRRect(fDrawTarget, pipelineBuilder, @@ -495,13 +484,14 @@ void GrDrawContext::drawDRRect(GrRenderTarget* rt, /////////////////////////////////////////////////////////////////////////////// -void GrDrawContext::drawOval(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawOval(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, const SkRect& oval, const GrStrokeInfo& strokeInfo) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + if (oval.isEmpty()) { return; } @@ -510,17 +500,15 @@ void GrDrawContext::drawOval(GrRenderTarget* rt, SkPath path; path.setIsVolatile(true); path.addOval(oval); - this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); + this->drawPath(clip, paint, viewMatrix, path, strokeInfo); return; } AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); GrColor color = paint.getColor(); + if (!GrOvalRenderer::DrawOval(fDrawTarget, pipelineBuilder, color, @@ -586,29 +574,28 @@ static bool is_nested_rects(const SkMatrix& viewMatrix, return allEq || allGoE1; } -void GrDrawContext::drawBatch(GrRenderTarget* rt, const GrClip& clip, +void GrDrawContext::drawBatch(const GrClip& clip, const GrPaint& paint, GrDrawBatch* batch) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); fDrawTarget->drawBatch(pipelineBuilder, batch); } -void GrDrawContext::drawPath(GrRenderTarget* rt, - const GrClip& clip, +void GrDrawContext::drawPath(const GrClip& clip, const GrPaint& paint, const SkMatrix& viewMatrix, const SkPath& path, const GrStrokeInfo& strokeInfo) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + if (path.isEmpty()) { if (path.isInverseFillType()) { - this->drawPaint(rt, clip, paint, viewMatrix); + this->drawPaint(clip, paint, viewMatrix); } return; } @@ -621,11 +608,8 @@ void GrDrawContext::drawPath(GrRenderTarget* rt, // the writePixels that uploads to the scratch will perform a flush so we're // OK. AutoCheckFlush acf(fContext); - if (!this->prepareToDraw(rt)) { - return; - } - GrPipelineBuilder pipelineBuilder(paint, rt, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); if (!strokeInfo.isDashed()) { bool useCoverageAA = paint.isAntiAlias() && !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); @@ -670,7 +654,6 @@ void GrDrawContext::internalDrawPath(GrDrawTarget* target, RETURN_IF_ABANDONED SkASSERT(!path.isEmpty()); - // An Assumption here is that path renderer would use some form of tweaking // the src color (either the input alpha or in the frag shader) to implement // aa. If we have some future driver-mojo path AA that can do the right @@ -749,16 +732,9 @@ void GrDrawContext::internalDrawPath(GrDrawTarget* target, pr->drawPath(args); } -bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { - RETURN_FALSE_IF_ABANDONED - - ASSERT_OWNED_RESOURCE(rt); - SkASSERT(rt); - return true; -} - void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* batch) { RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) fDrawTarget->drawBatch(*pipelineBuilder, batch); } diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp index 27cb55b9ee..b2d4c4ed76 100644 --- a/src/gpu/GrLayerCache.cpp +++ b/src/gpu/GrLayerCache.cpp @@ -467,10 +467,11 @@ void GrLayerCache::purgeAll() { SkASSERT(0 == fPictureHash.count()); - SkAutoTUnref<GrDrawContext> drawContext(fContext->drawContext()); + SkAutoTUnref<GrDrawContext> drawContext( + fContext->drawContext(fAtlas->getTexture()->asRenderTarget())); if (drawContext) { - drawContext->discard(fAtlas->getTexture()->asRenderTarget()); + drawContext->discard(); } } #endif diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp index 4bb01432ce..e81a9cfd83 100644 --- a/src/gpu/GrRenderTarget.cpp +++ b/src/gpu/GrRenderTarget.cpp @@ -22,12 +22,12 @@ void GrRenderTarget::discard() { return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); + SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this)); if (!drawContext) { return; } - drawContext->discard(this); + drawContext->discard(); } void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp index 071cd4d46d..93859483ad 100644 --- a/src/gpu/GrYUVProvider.cpp +++ b/src/gpu/GrYUVProvider.cpp @@ -130,12 +130,12 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc paint.addColorFragmentProcessor(yuvToRgbProcessor); const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].fHeight); - SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext()); + SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); if (!drawContext) { return nullptr; } - drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, SkMatrix::I(), r); + drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r); return result.detach(); } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index ab913164ee..cb532feb6b 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -198,7 +198,7 @@ SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, fLegacyBitmap.setInfo(info); fLegacyBitmap.setPixelRef(pr)->unref(); - fDrawContext.reset(fContext->drawContext(&this->surfaceProps())); + fDrawContext.reset(fContext->drawContext(rt, &this->surfaceProps())); } GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::Budgeted budgeted, @@ -336,7 +336,7 @@ void SkGpuDevice::clearAll() { GrColor color = 0; GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); - fDrawContext->clear(fRenderTarget, &rect, color, true); + fDrawContext->clear(&rect, color, true); fNeedClear = false; } @@ -375,7 +375,8 @@ void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); fLegacyBitmap.setPixelRef(pr)->unref(); - fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfaceProps())); + fDrawContext.reset(fRenderTarget->getContext()->drawContext(fRenderTarget, + &this->surfaceProps())); } /////////////////////////////////////////////////////////////////////////////// @@ -389,7 +390,7 @@ void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { return; } - fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); + fDrawContext->drawPaint(fClip, grPaint, *draw.fMatrix); } // must be in SkCanvas::PointMode order @@ -441,7 +442,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, path.setIsVolatile(true); path.moveTo(pts[0]); path.lineTo(pts[1]); - fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, path, strokeInfo); + fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, strokeInfo); return; } @@ -458,8 +459,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, return; } - fDrawContext->drawVertices(fRenderTarget, - fClip, + fDrawContext->drawVertices(fClip, grPaint, *draw.fMatrix, gPointMode2PrimtiveType[mode], @@ -521,7 +521,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, return; } - fDrawContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); + fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); } /////////////////////////////////////////////////////////////////////////////// @@ -557,7 +557,6 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, } if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext->textureProvider(), fDrawContext, - fRenderTarget, &grPaint, fClip, *draw.fMatrix, @@ -592,7 +591,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, return; } - fDrawContext->drawRRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, strokeInfo); + fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); } void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, @@ -609,7 +608,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, } if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect()) { - fDrawContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, outer, inner); + fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner); return; } } @@ -660,7 +659,7 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, return; } - fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, strokeInfo); + fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, strokeInfo); } #include "SkMaskFilter.h" @@ -1033,7 +1032,7 @@ static void draw_aa_bitmap(GrDrawContext* drawContext, GrContext* context, dstRect, devRect)); - drawContext->drawBatch(renderTarget, clip, grPaint, batch); + drawContext->drawBatch(clip, grPaint, batch); } static bool can_ignore_strict_subset_constraint(const SkBitmap& bitmap, const SkRect& subset) { @@ -1381,10 +1380,9 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { // We don't have local coords in this case and have previously set the transform // matrices directly on the texture processor. - fDrawContext->drawRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect); + fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); } else { - fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect, - paintRect); + fDrawContext->drawNonAARectToRect(fClip, grPaint, viewMatrix, dstRect, paintRect); } } @@ -1466,8 +1464,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, return; } - fDrawContext->drawNonAARectToRect(fRenderTarget, - fClip, + fDrawContext->drawNonAARectToRect(fClip, grPaint, SkMatrix::I(), SkRect::MakeXYWH(SkIntToScalar(left), @@ -1597,8 +1594,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), SK_Scalar1 * h / devTex->height()); - fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, SkMatrix::I(), dstRect, - srcRect); + fDrawContext->drawNonAARectToRect(fClip, grPaint, SkMatrix::I(), dstRect, srcRect); } bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { @@ -1749,8 +1745,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, lineIndices[i + 5] = state.f0; i += 6; } - fDrawContext->drawVertices(fRenderTarget, - fClip, + fDrawContext->drawVertices(fClip, grPaint, *draw.fMatrix, kLines_GrPrimitiveType, @@ -1813,8 +1808,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, } } - fDrawContext->drawVertices(fRenderTarget, - fClip, + fDrawContext->drawVertices(fClip, grPaint, *draw.fMatrix, primType, @@ -1855,8 +1849,7 @@ void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS } SkDEBUGCODE(this->validate();) - fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix, - count, xform, texRect, colors); + fDrawContext->drawAtlas(fClip, grPaint, *draw.fMatrix, count, xform, texRect, colors); } /////////////////////////////////////////////////////////////////////////////// @@ -1874,7 +1867,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, SkDEBUGCODE(this->validate();) - fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, + fDrawContext->drawText(fClip, grPaint, paint, *draw.fMatrix, (const char *)text, byteLength, x, y, draw.fClip->getBounds()); } @@ -1891,7 +1884,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL SkDEBUGCODE(this->validate();) - fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, + fDrawContext->drawPosText(fClip, grPaint, paint, *draw.fMatrix, (const char *)text, byteLength, pos, scalarsPerPos, offset, draw.fClip->getBounds()); } @@ -1903,7 +1896,7 @@ void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca SkDEBUGCODE(this->validate();) - fDrawContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix, + fDrawContext->drawTextBlob(fClip, paint, *draw.fMatrix, blob, x, y, drawFilter, draw.fClip->getBounds()); } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index ce4af0bfca..50cd5fa52a 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -285,13 +285,12 @@ GrTexture* stretch_texture(GrTexture* inputTexture, const SkGrStretch& stretch, SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtDesc.fHeight)); SkRect localRect = SkRect::MakeWH(1.f, 1.f); - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); + SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(stretched->asRenderTarget())); if (!drawContext) { return nullptr; } - drawContext->drawNonAARectToRect(stretched->asRenderTarget(), GrClip::WideOpen(), paint, - SkMatrix::I(), rect, localRect); + drawContext->drawNonAARectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect, localRect); return stretched.detach(); } diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 909e4614ef..8acf727bbf 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -224,14 +224,13 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context paint1.addColorFragmentProcessor(pmToUPM1); - SkAutoTUnref<GrDrawContext> readDrawContext(context->drawContext()); + SkAutoTUnref<GrDrawContext> readDrawContext(context->drawContext(readTex->asRenderTarget())); if (!readDrawContext) { failed = true; break; } - readDrawContext->drawNonAARectToRect(readTex->asRenderTarget(), - GrClip::WideOpen(), + readDrawContext->drawNonAARectToRect(GrClip::WideOpen(), paint1, SkMatrix::I(), kDstRect, @@ -241,13 +240,12 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context paint2.addColorFragmentProcessor(upmToPM); - SkAutoTUnref<GrDrawContext> tempDrawContext(context->drawContext()); + SkAutoTUnref<GrDrawContext> tempDrawContext(context->drawContext(tempTex->asRenderTarget())); if (!tempDrawContext) { failed = true; break; } - tempDrawContext->drawNonAARectToRect(tempTex->asRenderTarget(), - GrClip::WideOpen(), + tempDrawContext->drawNonAARectToRect(GrClip::WideOpen(), paint2, SkMatrix::I(), kDstRect, @@ -255,14 +253,13 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context paint3.addColorFragmentProcessor(pmToUPM2); - readDrawContext.reset(context->drawContext()); + readDrawContext.reset(context->drawContext(readTex->asRenderTarget())); if (!readDrawContext) { failed = true; break; } - readDrawContext->drawNonAARectToRect(readTex->asRenderTarget(), - GrClip::WideOpen(), + readDrawContext->drawNonAARectToRect(GrClip::WideOpen(), paint3, SkMatrix::I(), kDstRect, |