aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-02-10 12:52:21 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-10 12:52:21 -0800
commite55750e3fe12cbae30eebb10ecb6fcf89ffbea9b (patch)
tree4a58c24cc410624b7970f10c6a0309e62a252a5d /src
parentbd3dae8a970d6f4dea85729c124eeb4e89d4ab8a (diff)
Start whittling down GrTextContext
Diffstat (limited to 'src')
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp66
-rw-r--r--src/gpu/text/GrAtlasTextContext.h28
-rw-r--r--src/gpu/text/GrStencilAndCoverTextContext.cpp157
-rw-r--r--src/gpu/text/GrStencilAndCoverTextContext.h38
-rw-r--r--src/gpu/text/GrTextContext.cpp114
-rw-r--r--src/gpu/text/GrTextContext.h40
6 files changed, 210 insertions, 233 deletions
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 9e30476248..5e346452bd 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -42,7 +42,6 @@ GrAtlasTextContext::GrAtlasTextContext(GrContext* context, const SkSurfaceProps&
static_assert(GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kColorTextVASize &&
GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kLCDTextVASize,
"vertex_attribute_changed");
- fCurrStrike = nullptr;
fCache = context->getTextBlobCache();
}
@@ -314,33 +313,50 @@ GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
return blob;
}
-void GrAtlasTextContext::onDrawText(GrDrawContext* dc,
- const GrClip& clip,
- const GrPaint& paint, const SkPaint& skPaint,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
- SkAutoTUnref<GrAtlasTextBlob> blob(
- this->createDrawTextBlob(paint, skPaint, viewMatrix, text, byteLength, x, y));
- blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint,
- clip, regionClipBounds);
+void GrAtlasTextContext::drawText(GrDrawContext* dc,
+ const GrClip& clip,
+ const GrPaint& paint, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
+ if (fContext->abandoned()) {
+ return;
+ } else if (this->canDraw(skPaint, viewMatrix)) {
+ SkAutoTUnref<GrAtlasTextBlob> blob(
+ this->createDrawTextBlob(paint, skPaint, viewMatrix, text, byteLength, x, y));
+ blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint,
+ clip, regionClipBounds);
+ return;
+ }
+
+ // fall back to drawing as a path
+ GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
+ regionClipBounds);
}
-void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc,
- const GrClip& clip,
- const GrPaint& paint, const SkPaint& skPaint,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset, const SkIRect& regionClipBounds) {
- SkAutoTUnref<GrAtlasTextBlob> blob(
- this->createDrawPosTextBlob(paint, skPaint, viewMatrix,
- text, byteLength,
- pos, scalarsPerPosition,
- offset));
+void GrAtlasTextContext::drawPosText(GrDrawContext* dc,
+ const GrClip& clip,
+ const GrPaint& paint, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset, const SkIRect& regionClipBounds) {
+ if (fContext->abandoned()) {
+ return;
+ } else if (this->canDraw(skPaint, viewMatrix)) {
+ SkAutoTUnref<GrAtlasTextBlob> blob(
+ this->createDrawPosTextBlob(paint, skPaint, viewMatrix,
+ text, byteLength,
+ pos, scalarsPerPosition,
+ offset));
+ blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint,
+ clip, regionClipBounds);
+ return;
+ }
- blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint, clip,
- regionClipBounds);
+ // fall back to drawing as a path
+ GrTextUtils::DrawPosTextAsPath(fContext, dc, fSurfaceProps, clip, skPaint, viewMatrix, text,
+ byteLength, pos, scalarsPerPosition, offset, regionClipBounds);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h
index 94a9cffba1..2168b7e49d 100644
--- a/src/gpu/text/GrAtlasTextContext.h
+++ b/src/gpu/text/GrAtlasTextContext.h
@@ -33,24 +33,22 @@ class GrAtlasTextContext : public GrTextContext {
public:
static GrAtlasTextContext* Create(GrContext*, const SkSurfaceProps&);
-private:
- GrAtlasTextContext(GrContext*, const SkSurfaceProps&);
- ~GrAtlasTextContext() override {}
-
- bool canDraw(const SkPaint&, const SkMatrix& viewMatrix) override;
-
- void onDrawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&,
- const SkMatrix& viewMatrix, const char text[], size_t byteLength,
- SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
- void onDrawPosText(GrDrawContext*, 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& regionClipBounds) override;
+ bool canDraw(const SkPaint&, const SkMatrix& viewMatrix);
+ void drawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&,
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength,
+ SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
+ void drawPosText(GrDrawContext*, 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& regionClipBounds) override;
void drawTextBlob(GrDrawContext*, const GrClip&, const SkPaint&,
const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y,
SkDrawFilter*, const SkIRect& clipBounds) override;
+private:
+ GrAtlasTextContext(GrContext*, const SkSurfaceProps&);
+
// sets up the descriptor on the blob and returns a detached cache. Client must attach
inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
void regenerateTextBlob(GrAtlasTextBlob* bmp, const SkPaint& skPaint, GrColor,
@@ -60,7 +58,6 @@ private:
inline static bool HasLCD(const SkTextBlob*);
// Test methods
- // TODO this is really ugly. It'd be much nicer if positioning could be moved to batch
inline GrAtlasTextBlob* createDrawTextBlob(const GrPaint&,
const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
@@ -72,7 +69,6 @@ private:
const SkPoint& offset);
const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; }
- GrBatchTextStrike* fCurrStrike;
GrTextBlobCache* fCache;
SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp
index d28f1a803a..2fbaec8f32 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp
@@ -12,12 +12,14 @@
#include "GrPath.h"
#include "GrPathRange.h"
#include "GrResourceProvider.h"
+#include "GrTextUtils.h"
#include "SkAutoKern.h"
#include "SkDraw.h"
#include "SkDrawProcs.h"
#include "SkGlyphCache.h"
#include "SkGpuDevice.h"
#include "SkGrPriv.h"
+#include "SkDrawFilter.h"
#include "SkPath.h"
#include "SkTextBlobRunIterator.h"
#include "SkTextMapStateProc.h"
@@ -37,8 +39,9 @@ template<typename T> static void delete_hash_table_entry(T* val) {
GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context,
const SkSurfaceProps& surfaceProps)
- : INHERITED(context, surfaceProps),
- fCacheSize(0) {
+ : INHERITED(context, surfaceProps)
+ , fFallbackTextContext(nullptr)
+ , fCacheSize(0) {
}
GrStencilAndCoverTextContext*
@@ -51,6 +54,7 @@ GrStencilAndCoverTextContext::Create(GrContext* context, const SkSurfaceProps& s
}
GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() {
+ delete fFallbackTextContext;
fBlobIdCache.foreach(delete_hash_map_entry<uint32_t, TextBlob*>);
fBlobKeyCache.foreach(delete_hash_table_entry<TextBlob*>);
}
@@ -71,38 +75,115 @@ bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) {
return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrokeWidth();
}
-void GrStencilAndCoverTextContext::onDrawText(GrDrawContext* dc,
- const GrClip& clip,
- const GrPaint& paint,
- const SkPaint& skPaint,
- const SkMatrix& viewMatrix,
- const char text[],
- size_t byteLength,
- SkScalar x, SkScalar y,
- const SkIRect& clipBounds) {
- TextRun run(skPaint);
- GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip);
- run.setText(text, byteLength, x, y);
- run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds,
- fFallbackTextContext, skPaint);
+void GrStencilAndCoverTextContext::drawText(GrDrawContext* dc,
+ const GrClip& clip, const GrPaint& paint,
+ const SkPaint& skPaint, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y, const SkIRect& clipBounds) {
+ if (fContext->abandoned()) {
+ return;
+ } else if (this->canDraw(skPaint, viewMatrix)) {
+ TextRun run(skPaint);
+ GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip);
+ run.setText(text, byteLength, x, y);
+ run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds,
+ fFallbackTextContext, skPaint);
+ return;
+ } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix)) {
+ fFallbackTextContext->drawText(dc, clip, paint, skPaint, viewMatrix, text,
+ byteLength, x, y, clipBounds);
+ return;
+ }
+
+ // fall back to drawing as a path
+ GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
+ clipBounds);
}
-void GrStencilAndCoverTextContext::onDrawPosText(GrDrawContext* dc,
- const GrClip& clip,
- const GrPaint& paint,
- const SkPaint& skPaint,
- const SkMatrix& viewMatrix,
- const char text[],
- size_t byteLength,
- const SkScalar pos[],
- int scalarsPerPosition,
- const SkPoint& offset,
- const SkIRect& clipBounds) {
- TextRun run(skPaint);
- GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip);
- run.setPosText(text, byteLength, pos, scalarsPerPosition, offset);
- run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds,
- fFallbackTextContext, skPaint);
+void GrStencilAndCoverTextContext::drawPosText(GrDrawContext* dc,
+ const GrClip& clip,
+ const GrPaint& paint,
+ const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
+ const char text[],
+ size_t byteLength,
+ const SkScalar pos[],
+ int scalarsPerPosition,
+ const SkPoint& offset,
+ const SkIRect& clipBounds) {
+ if (fContext->abandoned()) {
+ return;
+ } else if (this->canDraw(skPaint, viewMatrix)) {
+ TextRun run(skPaint);
+ GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip);
+ run.setPosText(text, byteLength, pos, scalarsPerPosition, offset);
+ run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds,
+ fFallbackTextContext, skPaint);
+ return;
+ } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix)) {
+ fFallbackTextContext->drawPosText(dc, clip, paint, skPaint, viewMatrix,
+ text, byteLength, pos,
+ scalarsPerPosition, offset, clipBounds);
+ return;
+ }
+
+ // fall back to drawing as a path
+ GrTextUtils::DrawPosTextAsPath(fContext, dc, fSurfaceProps, clip, skPaint, viewMatrix, text,
+ byteLength, pos, scalarsPerPosition, offset, clipBounds);
+}
+
+void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrDrawContext* dc,
+ const GrClip& clip, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
+ const SkTextBlob* blob,
+ SkScalar x, SkScalar y,
+ SkDrawFilter* drawFilter,
+ const SkIRect& clipBounds) {
+ SkPaint runPaint = skPaint;
+
+ SkTextBlobRunIterator it(blob);
+ for (;!it.done(); it.next()) {
+ size_t textLen = it.glyphCount() * sizeof(uint16_t);
+ const SkPoint& offset = it.offset();
+
+ // applyFontToPaint() always overwrites the exact same attributes,
+ // so it is safe to not re-seed the paint for this reason.
+ it.applyFontToPaint(&runPaint);
+
+ if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
+ // A false return from filter() means we should abort the current draw.
+ runPaint = skPaint;
+ continue;
+ }
+
+ runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
+
+ GrPaint grPaint;
+ if (!SkPaintToGrPaint(fContext, runPaint, viewMatrix, &grPaint)) {
+ return;
+ }
+
+ switch (it.positioning()) {
+ case SkTextBlob::kDefault_Positioning:
+ this->drawText(dc, clip, grPaint, runPaint, viewMatrix, (const char *)it.glyphs(),
+ textLen, x + offset.x(), y + offset.y(), clipBounds);
+ break;
+ case SkTextBlob::kHorizontal_Positioning:
+ this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (const char*)it.glyphs(),
+ textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
+ clipBounds);
+ break;
+ case SkTextBlob::kFull_Positioning:
+ this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (const char*)it.glyphs(),
+ textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
+ break;
+ }
+
+ if (drawFilter) {
+ // A draw filter may change the paint arbitrarily, so we must re-seed in this case.
+ runPaint = skPaint;
+ }
+ }
}
void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc,
@@ -111,6 +192,10 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc,
const SkTextBlob* skBlob, SkScalar x, SkScalar y,
SkDrawFilter* drawFilter,
const SkIRect& clipBounds) {
+ if (fContext->abandoned()) {
+ return;
+ }
+
if (!this->internalCanDraw(skPaint)) {
fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, skBlob, x, y,
drawFilter, clipBounds);
@@ -119,12 +204,8 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc,
if (drawFilter || skPaint.getPathEffect()) {
// This draw can't be cached.
- INHERITED::drawTextBlob(dc, clip, skPaint, viewMatrix, skBlob, x, y, drawFilter,
- clipBounds);
- return;
- }
-
- if (fContext->abandoned()) {
+ this->uncachedDrawTextBlob(dc, clip, skPaint, viewMatrix, skBlob, x, y, drawFilter,
+ clipBounds);
return;
}
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.h b/src/gpu/text/GrStencilAndCoverTextContext.h
index dab71e0578..bc00a74406 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.h
+++ b/src/gpu/text/GrStencilAndCoverTextContext.h
@@ -16,6 +16,7 @@
#include "SkTLList.h"
#include "batches/GrDrawPathBatch.h"
+class GrAtlasTextContext;
class GrTextStrike;
class GrPath;
class SkSurfaceProps;
@@ -29,30 +30,38 @@ class GrStencilAndCoverTextContext : public GrTextContext {
public:
static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps&);
+ void drawText(GrDrawContext* dc,
+ 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(GrDrawContext*,
+ 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(GrDrawContext*, const GrClip&, const SkPaint&,
+ const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y,
+ SkDrawFilter*, const SkIRect& clipBounds) override;
+
virtual ~GrStencilAndCoverTextContext();
private:
GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&);
- bool canDraw(const SkPaint& skPaint, const SkMatrix&) override {
+ bool canDraw(const SkPaint& skPaint, const SkMatrix&) {
return this->internalCanDraw(skPaint);
}
bool internalCanDraw(const SkPaint&);
- void onDrawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y, const SkIRect& clipBounds) override;
- void onDrawPosText(GrDrawContext*,
- 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(GrDrawContext*, const GrClip&, const SkPaint&,
- const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y,
- SkDrawFilter*, const SkIRect& clipBounds) override;
+ void uncachedDrawTextBlob(GrDrawContext* dc,
+ const GrClip& clip, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
+ const SkTextBlob* blob,
+ SkScalar x, SkScalar y,
+ SkDrawFilter* drawFilter,
+ const SkIRect& clipBounds);
class FallbackBlobBuilder;
@@ -134,6 +143,7 @@ private:
const TextBlob& findOrCreateTextBlob(const SkTextBlob*, const SkPaint&);
void purgeToFit(const TextBlob&);
+ GrAtlasTextContext* fFallbackTextContext;
SkTHashMap<uint32_t, TextBlob*> fBlobIdCache;
SkTHashTable<TextBlob*, const TextBlob::Key&, TextBlob> fBlobKeyCache;
SkTInternalLList<TextBlob> fLRUList;
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 8ff2523a73..7f5ad55b09 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -6,75 +6,15 @@
*/
#include "GrTextContext.h"
-#include "GrContext.h"
#include "GrFontScaler.h"
-#include "GrTextUtils.h"
-#include "SkDrawFilter.h"
#include "SkGlyphCache.h"
-#include "SkGrPriv.h"
-#include "SkTextBlobRunIterator.h"
GrTextContext::GrTextContext(GrContext* context, const SkSurfaceProps& surfaceProps)
- : fFallbackTextContext(nullptr)
- , fContext(context)
+ : fContext(context)
, fSurfaceProps(surfaceProps) {
}
-GrTextContext::~GrTextContext() {
- delete fFallbackTextContext;
-}
-
-void GrTextContext::drawText(GrDrawContext* dc,
- const GrClip& clip, const GrPaint& paint,
- const SkPaint& skPaint, const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y, const SkIRect& clipBounds) {
- if (fContext->abandoned()) {
- return;
- }
-
- GrTextContext* textContext = this;
- do {
- if (textContext->canDraw(skPaint, viewMatrix)) {
- textContext->onDrawText(dc, clip, paint, skPaint, viewMatrix,
- text, byteLength, x, y, clipBounds);
- return;
- }
- textContext = textContext->fFallbackTextContext;
- } while (textContext);
-
- // fall back to drawing as a path
- GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
- clipBounds);
-}
-
-void GrTextContext::drawPosText(GrDrawContext* dc,
- const GrClip& clip, const GrPaint& paint,
- const SkPaint& skPaint, const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset, const SkIRect& clipBounds) {
- if (fContext->abandoned()) {
- return;
- }
-
- GrTextContext* textContext = this;
- do {
- if (textContext->canDraw(skPaint, viewMatrix)) {
- textContext->onDrawPosText(dc, clip, paint, skPaint, viewMatrix,
- text, byteLength, pos,
- scalarsPerPosition, offset, clipBounds);
- return;
- }
- textContext = textContext->fFallbackTextContext;
- } while (textContext);
-
- // fall back to drawing as a path
- GrTextUtils::DrawPosTextAsPath(fContext, dc, fSurfaceProps, clip, skPaint, viewMatrix, text,
- byteLength, pos, scalarsPerPosition, offset, clipBounds);
-}
-
bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) {
if (!SkXfermode::AsMode(paint.getXfermode(), nullptr) ||
paint.getMaskFilter() ||
@@ -103,58 +43,6 @@ uint32_t GrTextContext::FilterTextFlags(const SkSurfaceProps& surfaceProps, cons
return flags;
}
-void GrTextContext::drawTextBlob(GrDrawContext* dc,
- const GrClip& clip, const SkPaint& skPaint,
- const SkMatrix& viewMatrix, const SkTextBlob* blob,
- SkScalar x, SkScalar y,
- SkDrawFilter* drawFilter, const SkIRect& clipBounds) {
- SkPaint runPaint = skPaint;
-
- SkTextBlobRunIterator it(blob);
- for (;!it.done(); it.next()) {
- size_t textLen = it.glyphCount() * sizeof(uint16_t);
- const SkPoint& offset = it.offset();
- // applyFontToPaint() always overwrites the exact same attributes,
- // so it is safe to not re-seed the paint for this reason.
- it.applyFontToPaint(&runPaint);
-
- if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
- // A false return from filter() means we should abort the current draw.
- runPaint = skPaint;
- continue;
- }
-
- runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
-
- GrPaint grPaint;
- if (!SkPaintToGrPaint(fContext, runPaint, viewMatrix, &grPaint)) {
- return;
- }
-
- switch (it.positioning()) {
- case SkTextBlob::kDefault_Positioning:
- this->drawText(dc, clip, grPaint, runPaint, viewMatrix, (const char *)it.glyphs(),
- textLen, x + offset.x(), y + offset.y(), clipBounds);
- break;
- case SkTextBlob::kHorizontal_Positioning:
- this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (const char*)it.glyphs(),
- textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()), clipBounds);
- break;
- case SkTextBlob::kFull_Positioning:
- this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (const char*)it.glyphs(),
- textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
- break;
- default:
- SkFAIL("unhandled positioning mode");
- }
-
- if (drawFilter) {
- // A draw filter may change the paint arbitrarily, so we must re-seed in this case.
- runPaint = skPaint;
- }
- }
-}
-
static void GlyphCacheAuxProc(void* data) {
GrFontScaler* scaler = (GrFontScaler*)data;
SkSafeUnref(scaler);
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
index 206b34a403..3de2ae2416 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -26,45 +26,31 @@ class SkTextBlob;
*/
class GrTextContext {
public:
- virtual ~GrTextContext();
-
- void drawText(GrDrawContext* dc,
- const GrClip&, const GrPaint&, const SkPaint&,
- const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x,
- SkScalar y, const SkIRect& clipBounds);
- void drawPosText(GrDrawContext* dc,
- 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);
+ virtual ~GrTextContext() {}
+
+ virtual void drawText(GrDrawContext* dc,
+ const GrClip&, const GrPaint&, const SkPaint&,
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength,
+ SkScalar x, SkScalar y, const SkIRect& clipBounds) = 0;
+ virtual void drawPosText(GrDrawContext* dc,
+ 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) = 0;
virtual void drawTextBlob(GrDrawContext* dc, const GrClip&, const SkPaint&,
const SkMatrix& viewMatrix, const SkTextBlob*,
SkScalar x, SkScalar y,
- SkDrawFilter*, const SkIRect& clipBounds);
+ SkDrawFilter*, const SkIRect& clipBounds) = 0;
static bool ShouldDisableLCD(const SkPaint& paint);
protected:
- GrTextContext* fFallbackTextContext;
GrContext* fContext;
SkSurfaceProps fSurfaceProps;
GrTextContext(GrContext*, const SkSurfaceProps&);
- virtual bool canDraw(const SkPaint&, const SkMatrix& viewMatrix) = 0;
-
- virtual void onDrawText(GrDrawContext*, const GrClip&,
- const GrPaint&, const SkPaint&,
- const SkMatrix& viewMatrix, const char text[], size_t byteLength,
- SkScalar x, SkScalar y, const SkIRect& clipBounds) = 0;
- virtual void onDrawPosText(GrDrawContext*, 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) = 0;
-
static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint);