From 2334fb655f8d4ef5915770d32bf845c88d3627f4 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Wed, 17 Jun 2015 05:43:33 -0700 Subject: 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 --- include/gpu/GrContext.h | 51 +++++++++++++++++++++------------------------ include/gpu/GrDrawContext.h | 45 +++++++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 36 deletions(-) (limited to 'include') diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index acd7b1ad91..31cb4d0eb1 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,20 @@ 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: + void cleanup(); + 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; @@ -429,18 +441,6 @@ private: void initMockContext(); 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 @@ -461,9 +461,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 -- cgit v1.2.3