Index: src/gpu/GrDrawContext.cpp |
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp |
index 23c349ba173a0912e8af1f85ceae1044251adb1c..7f9727516b933eecb072255c6c02a8ef0173b88b 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 |