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.
Committed: https://skia.googlesource.com/skia/+/5b16e740fe6ab6d679083d06f07651602265081b
Review URL: https://codereview.chromium.org/1175553002
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 64f4cb3..d5f9f9c 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -9,7 +9,6 @@
#include "GrContext.h"
#include "GrAARectRenderer.h"
-#include "GrAtlasTextContext.h"
#include "GrBatch.h"
#include "GrBatchFontCache.h"
#include "GrBatchTarget.h"
@@ -32,7 +31,6 @@
#include "GrResourceCache.h"
#include "GrResourceProvider.h"
#include "GrSoftwarePathRenderer.h"
-#include "GrStencilAndCoverTextContext.h"
#include "GrStrokeInfo.h"
#include "GrSurfacePriv.h"
#include "GrTextBlobCache.h"
@@ -62,24 +60,37 @@
////////////////////////////////////////////////////////////////////////////////
void GrContext::DrawingMgr::init(GrContext* context) {
+ fContext = context;
+
#ifdef IMMEDIATE_MODE
fDrawTarget = SkNEW_ARGS(GrImmediateDrawTarget, (context));
#else
fDrawTarget = SkNEW_ARGS(GrInOrderDrawBuffer, (context));
#endif
+}
- fDrawContext = SkNEW_ARGS(GrDrawContext, (context, fDrawTarget));
+void GrContext::DrawingMgr::cleanup() {
+ SkSafeSetNull(fDrawTarget);
+ for (int i = 0; i < kNumPixelGeometries; ++i) {
+ SkSafeSetNull(fDrawContext[i][0]);
+ SkSafeSetNull(fDrawContext[i][1]);
+ }
}
GrContext::DrawingMgr::~DrawingMgr() {
- SkSafeUnref(fDrawTarget);
- SkSafeUnref(fDrawContext);
+ this->cleanup();
}
void GrContext::DrawingMgr::abandon() {
SkSafeSetNull(fDrawTarget);
- SkSafeSetNull(fDrawContext->fDrawTarget);
- SkSafeSetNull(fDrawContext);
+ for (int i = 0; i < kNumPixelGeometries; ++i) {
+ for (int j = 0; j < kNumDFTOptions; ++j) {
+ if (fDrawContext[i][j]) {
+ SkSafeSetNull(fDrawContext[i][j]->fDrawTarget);
+ SkSafeSetNull(fDrawContext[i][j]);
+ }
+ }
+ }
}
void GrContext::DrawingMgr::purgeResources() {
@@ -100,11 +111,29 @@
}
}
-GrDrawContext* GrContext::DrawingMgr::drawContext() {
+GrDrawContext* GrContext::DrawingMgr::drawContext(const SkDeviceProperties* devProps, bool useDFT) {
if (this->abandoned()) {
return NULL;
}
- return fDrawContext;
+
+ const SkDeviceProperties defProps;
+ if (!devProps) {
+ devProps = &defProps;
+ }
+
+ SkASSERT(devProps->pixelGeometry() < kNumPixelGeometries);
+ if (!fDrawContext[devProps->pixelGeometry()][useDFT]) {
+ fDrawContext[devProps->pixelGeometry()][useDFT] =
+ SkNEW_ARGS(GrDrawContext, (fContext, fDrawTarget, *devProps, useDFT));
+ }
+
+ SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->pixelGeometry() ==
+ devProps->pixelGeometry());
+ SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->gamma() ==
+ devProps->gamma());
+ SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fUseDFT == useDFT);
+
+ return fDrawContext[devProps->pixelGeometry()][useDFT];
}
////////////////////////////////////////////////////////////////////////////////
@@ -185,6 +214,8 @@
this->flush();
+ fDrawingMgr.cleanup();
+
for (int i = 0; i < fCleanUpData.count(); ++i) {
(*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
}
@@ -246,21 +277,6 @@
}
}
-GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
- const SkDeviceProperties&
- leakyProperties,
- bool enableDistanceFieldFonts) {
- if (fGpu->caps()->shaderCaps()->pathRenderingSupport() &&
- renderTarget->isStencilBufferMultisampled()) {
- GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencilAttachment();
- if (sb) {
- return GrStencilAndCoverTextContext::Create(this, leakyProperties);
- }
- }
-
- return GrAtlasTextContext::Create(this, leakyProperties, enableDistanceFieldFonts);
-}
-
////////////////////////////////////////////////////////////////////////////////
void GrContext::OverBudgetCB(void* data) {