aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-06-16 12:23:47 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-16 12:23:47 -0700
commit5b16e740fe6ab6d679083d06f07651602265081b (patch)
tree3a6be38dc79d0bb7316a3fd71943403e2edf3171 /include
parent48297f72fb852bed08d4af4de23366dfae39c245 (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 'include')
-rw-r--r--include/gpu/GrContext.h49
-rw-r--r--include/gpu/GrDrawContext.h45
2 files changed, 58 insertions, 36 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index acd7b1ad91..e95f2c03df 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -43,7 +43,6 @@ class GrTextureParams;
class GrVertexBuffer;
class GrStrokeInfo;
class GrSoftwarePathRenderer;
-class SkGpuDevice;
class SK_API GrContext : public SkRefCnt {
public:
@@ -174,11 +173,16 @@ public:
/**
* Returns a helper object to orchestrate draws.
+ * Callers should take a ref if they rely on the GrDrawContext sticking around.
+ * NULL will be returned if the context has been abandoned.
+ *
+ * @param devProps the device properties (mainly defines text drawing)
+ * @param uesDFT should Distance Field Text be used?
*
* @return a draw context
*/
- GrDrawContext* drawContext() {
- return fDrawingMgr.drawContext();
+ GrDrawContext* drawContext(const SkDeviceProperties* devProps = NULL, bool useDFT = false) {
+ return fDrawingMgr.drawContext(devProps, useDFT);
}
///////////////////////////////////////////////////////////////////////////
@@ -390,15 +394,17 @@ private:
GrContext(); // init must be called after the constructor.
bool init(GrBackend, GrBackendContext, const GrContextOptions& options);
- // Currently the DrawingMgr just wraps the single GrDrawTarget in a single
- // GrDrawContext and hands it out. In the future this class will allocate
- // a new GrDrawContext for each GrRenderTarget/GrDrawTarget and manage
- // the DAG.
+ // Currently the DrawingMgr stores a separate GrDrawContext for each
+ // combination of text drawing options (pixel geometry x DFT use)
+ // and hands the appropriate one back given the user's request.
+ // All of the GrDrawContexts still land in the same GrDrawTarget!
+ //
+ // In the future this class will allocate a new GrDrawContext for
+ // each GrRenderTarget/GrDrawTarget and manage the DAG.
class DrawingMgr {
public:
- DrawingMgr()
- : fDrawTarget(NULL)
- , fDrawContext(NULL) {
+ DrawingMgr() : fDrawTarget(NULL) {
+ sk_bzero(fDrawContext, sizeof(fDrawContext));
}
~DrawingMgr();
@@ -414,14 +420,18 @@ private:
// Callers should take a ref if they rely on the GrDrawContext sticking around.
// NULL will be returned if the context has been abandoned.
- GrDrawContext* drawContext();
+ GrDrawContext* drawContext(const SkDeviceProperties* devProps, bool useDFT);
private:
friend class GrContext; // for access to fDrawTarget for testing
+ static const int kNumPixelGeometries = 5; // The different pixel geometries
+ static const int kNumDFTOptions = 2; // DFT or no DFT
+
+ GrContext* fContext;
GrDrawTarget* fDrawTarget;
- GrDrawContext* fDrawContext;
+ GrDrawContext* fDrawContext[kNumPixelGeometries][kNumDFTOptions];
};
DrawingMgr fDrawingMgr;
@@ -430,18 +440,6 @@ private:
void initCommon();
/**
- * Creates a new text rendering context that is optimal for the
- * render target and the context. Caller assumes the ownership
- * of the returned object. The returned object must be deleted
- * before the context is destroyed.
- * TODO bury this behind context!
- */
- GrTextContext* createTextContext(GrRenderTarget*,
- const SkDeviceProperties&,
- bool enableDistanceFieldFonts);
-
-
- /**
* These functions create premul <-> unpremul effects if it is possible to generate a pair
* of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they
* return NULL.
@@ -461,9 +459,6 @@ private:
*/
static void TextBlobCacheOverBudgetCB(void* data);
- // TODO see note on createTextContext
- friend class SkGpuDevice;
-
typedef SkRefCnt INHERITED;
};
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index 4b78c89f91..7e711260ce 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -22,14 +22,18 @@ class GrPipelineBuilder;
class GrRenderTarget;
class GrStrokeInfo;
class GrSurface;
+class GrTextContext;
+struct SkDeviceProperties;
+class SkDrawFilter;
struct SkIPoint;
struct SkIRect;
class SkMatrix;
+class SkPaint;
class SkPath;
struct SkPoint;
struct SkRect;
class SkRRect;
-
+class SkTextBlob;
/*
* A helper object to orchestrate draws
@@ -38,14 +42,28 @@ class SK_API GrDrawContext : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(GrDrawContext)
+ ~GrDrawContext() override;
+
void copySurface(GrRenderTarget* dst, GrSurface* src,
const SkIRect& srcRect, const SkIPoint& dstPoint);
- // drawText and drawPaths are thanks to the GrAtlasTextContext and the
- // GrStencilAndCoverTextContext respectively
- // TODO: remove these two
- void drawText(GrPipelineBuilder* pipelineBuilder, GrBatch* batch);
+ // TODO: it is odd that we need both the SkPaint in the following 3 methods.
+ // We should extract the text parameters from SkPaint and pass them separately
+ // akin to GrStrokeInfo (GrTextInfo?)
+ void drawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength,
+ SkScalar x, SkScalar y, const SkIRect& clipBounds);
+ void drawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength,
+ const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset, const SkIRect& clipBounds);
+ void drawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&,
+ const SkMatrix& viewMatrix, const SkTextBlob*,
+ SkScalar x, SkScalar y,
+ SkDrawFilter*, const SkIRect& clipBounds);
+ // drawPaths is thanks to GrStencilAndCoverTextContext
+ // TODO: remove
void drawPaths(GrPipelineBuilder* pipelineBuilder,
const GrPathProcessor* pathProc,
const GrPathRange* pathRange,
@@ -223,16 +241,17 @@ public:
private:
+ friend class GrAtlasTextContext; // for access to drawBatch
friend class GrContext; // for ctor
- GrDrawContext(GrContext* context, GrDrawTarget* drawTarget);
- ~GrDrawContext() override;
+ GrDrawContext(GrContext*, GrDrawTarget*, const SkDeviceProperties&, bool useDFT);
// Sets the paint. Returns true on success; false on failure.
bool prepareToDraw(GrPipelineBuilder*,
GrRenderTarget* rt,
const GrClip&,
const GrPaint* paint);
+ GrTextContext* createTextContext(GrRenderTarget*, const SkDeviceProperties&, bool useDFT);
// A simpler version of the above which just returns true on success; false on failure.
// Clip is *NOT* set
@@ -246,8 +265,16 @@ private:
const SkPath&,
const GrStrokeInfo&);
- GrContext* fContext; // owning context -> no ref
- GrDrawTarget* fDrawTarget;
+ // This entry point allows the GrTextContext-derived classes to add their batches to
+ // the drawTarget.
+ void drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch);
+
+ GrContext* fContext; // owning context -> no ref
+ GrDrawTarget* fDrawTarget;
+ GrTextContext* fTextContext; // lazily created
+
+ SkDeviceProperties* fDevProps; // ptr b.c. SkDeviceProperties isn't public
+ bool fUseDFT;
};
#endif