diff options
author | 2015-06-16 12:23:47 -0700 | |
---|---|---|
committer | 2015-06-16 12:23:47 -0700 | |
commit | 5b16e740fe6ab6d679083d06f07651602265081b (patch) | |
tree | 3a6be38dc79d0bb7316a3fd71943403e2edf3171 /src/gpu/GrDrawContext.cpp | |
parent | 48297f72fb852bed08d4af4de23366dfae39c245 (diff) |
Make GrTextContext be owned by the GrDrawContext
This CL makes the GrTextContext be owned (and hidden) by the GrDrawContext. This funnels all the drawText* calls through the GrDrawContext and hides the (dispreferred) GrPipelineBuilder drawText variant.
Some consequences of this are:
GrDrawContext now has to get the text drawing settings (i.e., SkDeviceProperties & useDFT). This means that we need a separate GrDrawContext for each combination of pixel geometry and DFT-use.
All the GrTextContext-derived classes now get a back pointer to the originating GrDrawContext so their method calls no longer take one.
Review URL: https://codereview.chromium.org/1175553002
Diffstat (limited to 'src/gpu/GrDrawContext.cpp')
-rw-r--r-- | src/gpu/GrDrawContext.cpp | 74 |
1 files changed, 70 insertions, 4 deletions
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index 23c349ba17..7f9727516b 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -7,12 +7,16 @@ */ #include "GrAARectRenderer.h" +#include "GrAtlasTextContext.h" #include "GrBatch.h" #include "GrBatchTest.h" #include "GrDefaultGeoProcFactory.h" #include "GrDrawContext.h" #include "GrOvalRenderer.h" #include "GrPathRenderer.h" +#include "GrRenderTarget.h" +#include "GrRenderTargetPriv.h" +#include "GrStencilAndCoverTextContext.h" #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } @@ -28,13 +32,21 @@ private: GrContext* fContext; }; -GrDrawContext::GrDrawContext(GrContext* context, GrDrawTarget* drawTarget) +GrDrawContext::GrDrawContext(GrContext* context, + GrDrawTarget* drawTarget, + const SkDeviceProperties& devProps, + bool useDFT) : fContext(context) - , fDrawTarget(SkRef(drawTarget)) { + , fDrawTarget(SkRef(drawTarget)) + , fTextContext(NULL) + , fDevProps(SkNEW_ARGS(SkDeviceProperties, (devProps))) + , fUseDFT(useDFT) { } GrDrawContext::~GrDrawContext() { SkSafeUnref(fDrawTarget); + SkDELETE(fTextContext); + SkDELETE(fDevProps); } void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, @@ -46,8 +58,58 @@ void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, fDrawTarget->copySurface(dst, src, srcRect, dstPoint); } -void GrDrawContext::drawText(GrPipelineBuilder* pipelineBuilder, GrBatch* batch) { - fDrawTarget->drawBatch(pipelineBuilder, batch); +GrTextContext* GrDrawContext::createTextContext(GrRenderTarget* renderTarget, + const SkDeviceProperties& leakyProperties, + bool enableDistanceFieldFonts) { + if (fContext->caps()->shaderCaps()->pathRenderingSupport() && + renderTarget->isStencilBufferMultisampled()) { + GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencilAttachment(); + if (sb) { + return GrStencilAndCoverTextContext::Create(fContext, this, + leakyProperties, + enableDistanceFieldFonts); + } + } + + return GrAtlasTextContext::Create(fContext, this, leakyProperties, enableDistanceFieldFonts); +} + +void GrDrawContext::drawText(GrRenderTarget* rt, 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) { + if (!fTextContext) { + fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT); + } + + fTextContext->drawText(rt, clip, grPaint, skPaint, viewMatrix, + text, byteLength, x, y, clipBounds); + +} +void GrDrawContext::drawPosText(GrRenderTarget* rt, 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) { + if (!fTextContext) { + fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT); + } + + fTextContext->drawPosText(rt, clip, grPaint, skPaint, viewMatrix, text, byteLength, + pos, scalarsPerPosition, offset, clipBounds); + +} +void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const SkPaint& skPaint, + const SkMatrix& viewMatrix, const SkTextBlob* blob, + SkScalar x, SkScalar y, + SkDrawFilter* filter, const SkIRect& clipBounds) { + if (!fTextContext) { + fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT); + } + + fTextContext->drawTextBlob(rt, clip, skPaint, viewMatrix, blob, x, y, filter, clipBounds); } void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, @@ -1147,6 +1209,10 @@ bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { return true; } +void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch) { + fDrawTarget->drawBatch(pipelineBuilder, batch); +} + /////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef GR_TEST_UTILS |