aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-02-16 10:36:53 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-16 10:36:53 -0800
commit96880d9e366d58e5960aa0ee6aa67260797679eb (patch)
tree4aec09d45ade79453eaedb86b676b9dbf5d60952 /src
parent3341d428d3e49803e4f31f439a193e9e2c199daa (diff)
Create GrPathRenderingDrawContext
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrDrawContext.cpp27
-rw-r--r--src/gpu/GrDrawingManager.cpp48
-rw-r--r--src/gpu/GrDrawingManager.h7
-rw-r--r--src/gpu/GrPathRenderingDrawContext.cpp74
-rw-r--r--src/gpu/GrPathRenderingDrawContext.h43
5 files changed, 147 insertions, 52 deletions
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index d971f58ece..f31e0b23b0 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -59,7 +59,7 @@ GrDrawContext::GrDrawContext(GrContext* context,
: fDrawingManager(drawingMgr)
, fRenderTarget(rt)
, fDrawTarget(SkSafeRef(rt->getLastDrawTarget()))
- , fTextContext(nullptr)
+ , fAtlasTextContext(nullptr)
, fContext(context)
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
, fAuditTrail(auditTrail)
@@ -116,12 +116,12 @@ void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint,
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawText");
- if (!fTextContext) {
- fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
+ if (!fAtlasTextContext) {
+ fAtlasTextContext = GrAtlasTextContext::Create();
}
- fTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
- text, byteLength, x, y, clipBounds);
+ fAtlasTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
+ text, byteLength, x, y, clipBounds);
}
void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
@@ -135,12 +135,13 @@ void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPosText");
- if (!fTextContext) {
- fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
+ if (!fAtlasTextContext) {
+ fAtlasTextContext = GrAtlasTextContext::Create();
}
- fTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
- text, byteLength, pos, scalarsPerPosition, offset, clipBounds);
+ fAtlasTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix,
+ fSurfaceProps, text, byteLength, pos, scalarsPerPosition,
+ offset, clipBounds);
}
@@ -153,12 +154,12 @@ void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawTextBlob");
- if (!fTextContext) {
- fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
+ if (!fAtlasTextContext) {
+ fAtlasTextContext = GrAtlasTextContext::Create();
}
- fTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob, x,
- y, filter, clipBounds);
+ fAtlasTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob,
+ x, y, filter, clipBounds);
}
void GrDrawContext::discard() {
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index a063c398ed..ca50fe4502 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -8,6 +8,7 @@
#include "GrDrawContext.h"
#include "GrDrawingManager.h"
#include "GrDrawTarget.h"
+#include "GrPathRenderingDrawContext.h"
#include "GrResourceProvider.h"
#include "GrSoftwarePathRenderer.h"
#include "SkTTopoSort.h"
@@ -28,12 +29,6 @@ void GrDrawingManager::cleanup() {
fDrawTargets.reset();
- delete fNVPRTextContext;
- fNVPRTextContext = nullptr;
-
- delete fAtlasTextContext;
- fAtlasTextContext = nullptr;
-
delete fPathRendererChain;
fPathRendererChain = nullptr;
SkSafeSetNull(fSoftwarePathRenderer);
@@ -114,32 +109,6 @@ void GrDrawingManager::flush() {
fFlushing = false;
}
-GrTextContext* GrDrawingManager::textContext(const SkSurfaceProps& props, GrRenderTarget* rt) {
- if (this->abandoned()) {
- return nullptr;
- }
-
- bool useDIF = props.isUseDeviceIndependentFonts();
-
- if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
- rt->isStencilBufferMultisampled()) {
- GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt);
- if (sb) {
- if (!fNVPRTextContext) {
- fNVPRTextContext = GrStencilAndCoverTextContext::Create();
- }
-
- return fNVPRTextContext;
- }
- }
-
- if (!fAtlasTextContext) {
- fAtlasTextContext = GrAtlasTextContext::Create();
- }
-
- return fAtlasTextContext;
-}
-
GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) {
SkASSERT(fContext);
@@ -196,6 +165,21 @@ GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt,
return nullptr;
}
+
+ bool useDIF = false;
+ if (surfaceProps) {
+ useDIF = surfaceProps->isUseDeviceIndependentFonts();
+ }
+
+ if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
+ rt->isStencilBufferMultisampled()) {
+ GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt);
+ if (sb) {
+ return new GrPathRenderingDrawContext(fContext, this, rt, surfaceProps,
+ fContext->getAuditTrail(), fSingleOwner);
+ }
+ }
+
return new GrDrawContext(fContext, this, rt, surfaceProps, fContext->getAuditTrail(),
fSingleOwner);
}
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index a6d0104583..d82a3a2d41 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -38,8 +38,6 @@ public:
GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps*);
- GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt);
-
// The caller automatically gets a ref on the returned drawTarget. It must
// be balanced by an unref call.
GrDrawTarget* newDrawTarget(GrRenderTarget* rt);
@@ -60,8 +58,6 @@ private:
, fOptionsForDrawTargets(optionsForDrawTargets)
, fSingleOwner(singleOwner)
, fAbandoned(false)
- , fNVPRTextContext(nullptr)
- , fAtlasTextContext(nullptr)
, fPathRendererChain(nullptr)
, fSoftwarePathRenderer(nullptr)
, fFlushState(context->getGpu(), context->resourceProvider())
@@ -87,9 +83,6 @@ private:
bool fAbandoned;
SkTDArray<GrDrawTarget*> fDrawTargets;
- GrTextContext* fNVPRTextContext;
- GrTextContext* fAtlasTextContext;
-
GrPathRendererChain* fPathRendererChain;
GrSoftwarePathRenderer* fSoftwarePathRenderer;
diff --git a/src/gpu/GrPathRenderingDrawContext.cpp b/src/gpu/GrPathRenderingDrawContext.cpp
new file mode 100644
index 0000000000..a29af843b7
--- /dev/null
+++ b/src/gpu/GrPathRenderingDrawContext.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrPathRenderingDrawContext.h"
+
+#include "GrDrawingManager.h"
+
+#include "text/GrStencilAndCoverTextContext.h"
+
+#define ASSERT_SINGLE_OWNER \
+ SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
+#define RETURN_IF_ABANDONED if (this->drawingManager()->abandoned()) { return; }
+
+void GrPathRenderingDrawContext::drawText(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) {
+ ASSERT_SINGLE_OWNER
+ RETURN_IF_ABANDONED
+ SkDEBUGCODE(this->validate();)
+ GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawText");
+
+ if (!fStencilAndCoverTextContext) {
+ fStencilAndCoverTextContext = GrStencilAndCoverTextContext::Create();
+ }
+
+ fStencilAndCoverTextContext->drawText(this->drawingManager()->getContext(), this, clip, grPaint,
+ skPaint, viewMatrix, this->surfaceProps(),
+ text, byteLength, x, y, clipBounds);
+}
+
+void GrPathRenderingDrawContext::drawPosText(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) {
+ ASSERT_SINGLE_OWNER
+ RETURN_IF_ABANDONED
+ SkDEBUGCODE(this->validate();)
+ GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawPosText");
+
+ if (!fStencilAndCoverTextContext) {
+ fStencilAndCoverTextContext = GrStencilAndCoverTextContext::Create();
+ }
+
+ fStencilAndCoverTextContext->drawPosText(this->drawingManager()->getContext(), this, clip,
+ grPaint, skPaint, viewMatrix, this->surfaceProps(),
+ text, byteLength, pos, scalarsPerPosition, offset,
+ clipBounds);
+}
+
+void GrPathRenderingDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix, const SkTextBlob* blob,
+ SkScalar x, SkScalar y,
+ SkDrawFilter* filter, const SkIRect& clipBounds) {
+ ASSERT_SINGLE_OWNER
+ RETURN_IF_ABANDONED
+ SkDEBUGCODE(this->validate();)
+ GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawTextBlob");
+
+ if (!fStencilAndCoverTextContext) {
+ fStencilAndCoverTextContext = GrStencilAndCoverTextContext::Create();
+ }
+
+ fStencilAndCoverTextContext->drawTextBlob(this->drawingManager()->getContext(), this, clip,
+ skPaint, viewMatrix, this->surfaceProps(), blob, x,
+ y, filter, clipBounds);
+}
diff --git a/src/gpu/GrPathRenderingDrawContext.h b/src/gpu/GrPathRenderingDrawContext.h
new file mode 100644
index 0000000000..ab36955ae0
--- /dev/null
+++ b/src/gpu/GrPathRenderingDrawContext.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrPathRenderingDrawContext_DEFINED
+#define GrPathRenderingDrawContext_DEFINED
+
+#include "GrDrawContext.h"
+
+class GrStencilAndCoverTextContext;
+
+class GrPathRenderingDrawContext : public GrDrawContext {
+public:
+ void drawText(const GrClip&, const GrPaint&, const SkPaint&,
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength,
+ SkScalar x, SkScalar y, const SkIRect& clipBounds) override;
+ void drawPosText(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) override;
+ void drawTextBlob(const GrClip&, const SkPaint&,
+ const SkMatrix& viewMatrix, const SkTextBlob*,
+ SkScalar x, SkScalar y,
+ SkDrawFilter*, const SkIRect& clipBounds) override;
+protected:
+ GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, GrRenderTarget* rt,
+ const SkSurfaceProps* surfaceProps, GrAuditTrail* at,
+ GrSingleOwner* so)
+ : INHERITED(ctx, mgr, rt, surfaceProps, at, so)
+ , fStencilAndCoverTextContext(nullptr) {}
+
+private:
+ GrStencilAndCoverTextContext* fStencilAndCoverTextContext;
+
+ friend class GrDrawingManager; // for ctor
+
+ typedef GrDrawContext INHERITED;
+};
+
+#endif