aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-04-27 12:08:47 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-04-27 12:08:47 +0000
commitf4c2c527dd3cab979621fdfbc07eb22fee103472 (patch)
treef73dbdf1a28609c7f83b65fb09ae2499f6bfaf92
parentfa0588ff672564af1c235a63589573829035a60b (diff)
First portion of refactoring to bundle SW path rendering into GrPathRenderer
-rw-r--r--src/gpu/GrContext.cpp98
-rw-r--r--src/gpu/GrSoftwarePathRenderer.cpp35
-rw-r--r--src/gpu/GrSoftwarePathRenderer.h38
3 files changed, 132 insertions, 39 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 3fb944b6ce..8e45e15a0a 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1290,8 +1290,8 @@ SkPath::FillType gr_fill_to_sk_fill(GrPathFill fill) {
}
// gets device coord bounds of path (not considering the fill) and clip. The
-// path bounds will be a subset of the clip bounds. returns false if path bounds
-// would be empty.
+// path bounds will be a subset of the clip bounds. returns false if
+// path bounds would be empty.
bool get_path_and_clip_bounds(const GrDrawTarget* target,
const GrPath& path,
const GrVec* translate,
@@ -1341,7 +1341,8 @@ bool sw_draw_path_to_mask_texture(const GrPath& clientPath,
GrPathFill fill,
GrContext* context,
const GrPoint* translate,
- GrAutoScratchTexture* tex) {
+ GrAutoScratchTexture* tex,
+ bool antiAlias) {
SkPaint paint;
SkPath tmpPath;
const SkPath* pathToDraw = &clientPath;
@@ -1357,7 +1358,7 @@ bool sw_draw_path_to_mask_texture(const GrPath& clientPath,
pathToDraw = &tmpPath;
}
}
- paint.setAntiAlias(true);
+ paint.setAntiAlias(antiAlias);
paint.setColor(SK_ColorWHITE);
GrMatrix matrix = context->getMatrix();
@@ -1436,6 +1437,58 @@ void draw_around_inv_path(GrDrawTarget* target,
}
+
+
+// return true on success; false on failure
+bool onDrawPath(const SkPath& path,
+ GrPathFill fill,
+ const GrVec* translate,
+ GrDrawTarget* target,
+ GrDrawState::StageMask stageMask,
+ bool antiAlias,
+ GrContext* context) {
+
+ GrAutoScratchTexture ast;
+ GrIRect pathBounds, clipBounds;
+ if (!get_path_and_clip_bounds(target, path, translate,
+ &pathBounds, &clipBounds)) {
+ return true; // path is empty so there is nothing to do
+ }
+ if (sw_draw_path_to_mask_texture(path, pathBounds,
+ fill, context,
+ translate, &ast, antiAlias)) {
+ GrTexture* texture = ast.texture();
+ GrAssert(NULL != texture);
+ GrDrawTarget::AutoDeviceCoordDraw adcd(target, stageMask);
+ enum {
+ kPathMaskStage = GrPaint::kTotalStages,
+ };
+ target->drawState()->setTexture(kPathMaskStage, texture);
+ target->drawState()->sampler(kPathMaskStage)->reset();
+ GrScalar w = GrIntToScalar(pathBounds.width());
+ GrScalar h = GrIntToScalar(pathBounds.height());
+ GrRect maskRect = GrRect::MakeWH(w / texture->width(),
+ h / texture->height());
+ const GrRect* srcRects[GrDrawState::kNumStages] = {NULL};
+ srcRects[kPathMaskStage] = &maskRect;
+ stageMask |= 1 << kPathMaskStage;
+ GrRect dstRect = GrRect::MakeLTRB(
+ SK_Scalar1* pathBounds.fLeft,
+ SK_Scalar1* pathBounds.fTop,
+ SK_Scalar1* pathBounds.fRight,
+ SK_Scalar1* pathBounds.fBottom);
+ target->drawRect(dstRect, NULL, stageMask, srcRects, NULL);
+ target->drawState()->setTexture(kPathMaskStage, NULL);
+ if (GrIsFillInverted(fill)) {
+ draw_around_inv_path(target, stageMask,
+ clipBounds, pathBounds);
+ }
+ return true;
+ }
+
+ return false;
+}
+
void GrContext::drawPath(const GrPaint& paint, const GrPath& path,
GrPathFill fill, const GrPoint* translate) {
@@ -1473,41 +1526,8 @@ void GrContext::drawPath(const GrPaint& paint, const GrPath& path,
if (prAA) {
pr = this->getPathRenderer(path, fill, target, true);
if (NULL == pr) {
- GrAutoScratchTexture ast;
- GrIRect pathBounds, clipBounds;
- if (!get_path_and_clip_bounds(target, path, translate,
- &pathBounds, &clipBounds)) {
- return;
- }
- if (NULL == pr && sw_draw_path_to_mask_texture(path, pathBounds,
- fill, this,
- translate, &ast)) {
- GrTexture* texture = ast.texture();
- GrAssert(NULL != texture);
- GrDrawTarget::AutoDeviceCoordDraw adcd(target, stageMask);
- enum {
- kPathMaskStage = GrPaint::kTotalStages,
- };
- target->drawState()->setTexture(kPathMaskStage, texture);
- target->drawState()->sampler(kPathMaskStage)->reset();
- GrScalar w = GrIntToScalar(pathBounds.width());
- GrScalar h = GrIntToScalar(pathBounds.height());
- GrRect maskRect = GrRect::MakeWH(w / texture->width(),
- h / texture->height());
- const GrRect* srcRects[GrDrawState::kNumStages] = {NULL};
- srcRects[kPathMaskStage] = &maskRect;
- stageMask |= 1 << kPathMaskStage;
- GrRect dstRect = GrRect::MakeLTRB(
- SK_Scalar1* pathBounds.fLeft,
- SK_Scalar1* pathBounds.fTop,
- SK_Scalar1* pathBounds.fRight,
- SK_Scalar1* pathBounds.fBottom);
- target->drawRect(dstRect, NULL, stageMask, srcRects, NULL);
- target->drawState()->setTexture(kPathMaskStage, NULL);
- if (GrIsFillInverted(fill)) {
- draw_around_inv_path(target, stageMask,
- clipBounds, pathBounds);
- }
+ if (onDrawPath(path, fill, translate,
+ target, stageMask, prAA, this)) {
return;
}
}
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
new file mode 100644
index 0000000000..c591ac5bae
--- /dev/null
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -0,0 +1,35 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrSoftwarePathRenderer.h"
+
+
+bool GrSoftwarePathRenderer::canDrawPath(const SkPath& path,
+ GrPathFill fill,
+ const GrDrawTarget* target,
+ bool antiAlias) const {
+ if (!antiAlias) {
+ // TODO: the SW renderer can also handle non-AA paths
+ return false;
+ }
+
+ // TODO: set to true when filled out
+ return false;
+}
+
+bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path,
+ GrPathFill fill,
+ const GrVec* translate,
+ GrDrawTarget* target,
+ GrDrawState::StageMask stageMask,
+ bool antiAlias) {
+
+ // TODO: move onDrawPath routine (& its helpers) here from GrContext.cpp
+ return false;
+}
+
diff --git a/src/gpu/GrSoftwarePathRenderer.h b/src/gpu/GrSoftwarePathRenderer.h
new file mode 100644
index 0000000000..859a53d467
--- /dev/null
+++ b/src/gpu/GrSoftwarePathRenderer.h
@@ -0,0 +1,38 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrSoftwarePathRenderer_DEFINED
+#define GrSoftwarePathRenderer_DEFINED
+
+#include "GrPathRenderer.h"
+
+class GrSoftwarePathRenderer : public GrPathRenderer {
+public:
+ GrSoftwarePathRenderer(GrContext* context)
+ : fContext(context) {
+ }
+
+ virtual bool canDrawPath(const SkPath& path,
+ GrPathFill fill,
+ const GrDrawTarget* target,
+ bool antiAlias) const SK_OVERRIDE;
+protected:
+ virtual bool onDrawPath(const SkPath& path,
+ GrPathFill fill,
+ const GrVec* translate,
+ GrDrawTarget* target,
+ GrDrawState::StageMask stageMask,
+ bool antiAlias) SK_OVERRIDE;
+
+private:
+ GrContext* fContext;
+
+ typedef GrPathRenderer INHERITED;
+};
+
+#endif