aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/GrDrawContext.cpp10
-rw-r--r--src/gpu/GrDrawingManager.cpp4
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp178
-rw-r--r--src/gpu/text/GrAtlasTextContext.h55
-rw-r--r--src/gpu/text/GrStencilAndCoverTextContext.cpp70
-rw-r--r--src/gpu/text/GrStencilAndCoverTextContext.h12
-rw-r--r--src/gpu/text/GrTextContext.cpp4
-rw-r--r--src/gpu/text/GrTextContext.h10
8 files changed, 171 insertions, 172 deletions
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 549663a23e..d971f58ece 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -120,7 +120,7 @@ void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint,
fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
}
- fTextContext->drawText(this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
+ fTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
text, byteLength, x, y, clipBounds);
}
@@ -139,8 +139,8 @@ void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
}
- fTextContext->drawPosText(this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps, text,
- byteLength, pos, scalarsPerPosition, offset, clipBounds);
+ fTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
+ text, byteLength, pos, scalarsPerPosition, offset, clipBounds);
}
@@ -157,8 +157,8 @@ void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
}
- fTextContext->drawTextBlob(this, clip, skPaint, viewMatrix, fSurfaceProps, blob, x, y, filter,
- clipBounds);
+ fTextContext->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 30bdfe1c3d..a063c398ed 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -126,7 +126,7 @@ GrTextContext* GrDrawingManager::textContext(const SkSurfaceProps& props, GrRend
GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt);
if (sb) {
if (!fNVPRTextContext) {
- fNVPRTextContext = GrStencilAndCoverTextContext::Create(fContext);
+ fNVPRTextContext = GrStencilAndCoverTextContext::Create();
}
return fNVPRTextContext;
@@ -134,7 +134,7 @@ GrTextContext* GrDrawingManager::textContext(const SkSurfaceProps& props, GrRend
}
if (!fAtlasTextContext) {
- fAtlasTextContext = GrAtlasTextContext::Create(fContext);
+ fAtlasTextContext = GrAtlasTextContext::Create();
}
return fAtlasTextContext;
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index ac2df24e48..8f45731bc3 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -8,53 +8,27 @@
#include "GrDrawContext.h"
#include "GrDrawTarget.h"
-#include "GrFontScaler.h"
-#include "GrStrokeInfo.h"
#include "GrTextBlobCache.h"
-#include "GrTexturePriv.h"
#include "GrTextUtils.h"
-#include "GrVertexBuffer.h"
-#include "SkAutoKern.h"
-#include "SkColorPriv.h"
-#include "SkColorFilter.h"
-#include "SkDistanceFieldGen.h"
#include "SkDraw.h"
#include "SkDrawFilter.h"
-#include "SkDrawProcs.h"
-#include "SkFindAndPlaceGlyph.h"
-#include "SkGlyphCache.h"
-#include "SkGpuDevice.h"
#include "SkGrPriv.h"
-#include "SkPath.h"
-#include "SkRTConf.h"
-#include "SkStrokeRec.h"
-#include "SkTextBlob.h"
-#include "SkTextMapStateProc.h"
-
-#include "batches/GrAtlasTextBatch.h"
-
-GrAtlasTextContext::GrAtlasTextContext(GrContext* context)
- : INHERITED(context)
- , fDistanceAdjustTable(new GrDistanceFieldAdjustTable) {
- // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
- // vertexStride
- static_assert(GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kColorTextVASize &&
- GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kLCDTextVASize,
- "vertex_attribute_changed");
- fCache = context->getTextBlobCache();
+
+GrAtlasTextContext::GrAtlasTextContext()
+ : fDistanceAdjustTable(new GrDistanceFieldAdjustTable) {
}
-GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context) {
- return new GrAtlasTextContext(context);
+GrAtlasTextContext* GrAtlasTextContext::Create() {
+ return new GrAtlasTextContext();
}
bool GrAtlasTextContext::canDraw(const SkPaint& skPaint,
const SkMatrix& viewMatrix,
- const SkSurfaceProps& props) {
- return GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props,
- *fContext->caps()->shaderCaps()) ||
+ const SkSurfaceProps& props,
+ const GrShaderCaps& shaderCaps) {
+ return GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props, shaderCaps) ||
!SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix);
}
@@ -92,14 +66,14 @@ bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) {
return false;
}
-void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
+void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const SkTextBlob* blob,
SkScalar x, SkScalar y,
SkDrawFilter* drawFilter, const SkIRect& clipBounds) {
// If we have been abandoned, then don't draw
- if (fContext->abandoned()) {
+ if (context->abandoned()) {
return;
}
@@ -113,6 +87,7 @@ void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
(mf && !mf->asABlur(&blurRec)) ||
drawFilter);
+ GrTextBlobCache* cache = context->getTextBlobCache();
if (canCache) {
bool hasLCD = HasLCD(blob);
@@ -131,7 +106,7 @@ void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
key.fStyle = skPaint.getStyle();
key.fHasBlur = SkToBool(mf);
key.fCanonicalColor = canonicalColor;
- cacheBlob.reset(SkSafeRef(fCache->find(key)));
+ cacheBlob.reset(SkSafeRef(cache->find(key)));
}
SkScalar transX = 0.f;
@@ -140,7 +115,7 @@ void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
// Though for the time being runs in the textblob can override the paint, they only touch font
// info.
GrPaint grPaint;
- if (!SkPaintToGrPaint(fContext, skPaint, viewMatrix, &grPaint)) {
+ if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &grPaint)) {
return;
}
@@ -150,39 +125,47 @@ void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
// We have to remake the blob because changes may invalidate our masks.
// TODO we could probably get away reuse most of the time if the pointer is unique,
// but we'd have to clear the subrun information
- fCache->remove(cacheBlob);
- cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint)));
- this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix, props,
- blob, x, y, drawFilter);
+ cache->remove(cacheBlob);
+ cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, skPaint)));
+ RegenerateTextBlob(cacheBlob, context->getBatchFontCache(),
+ *context->caps()->shaderCaps(), skPaint, grPaint.getColor(),
+ viewMatrix, props,
+ blob, x, y, drawFilter);
} else {
- fCache->makeMRU(cacheBlob);
+ cache->makeMRU(cacheBlob);
if (CACHE_SANITY_CHECK) {
int glyphCount = 0;
int runCount = 0;
GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob);
- SkAutoTUnref<GrAtlasTextBlob> sanityBlob(fCache->createBlob(glyphCount, runCount));
+ SkAutoTUnref<GrAtlasTextBlob> sanityBlob(cache->createBlob(glyphCount, runCount));
sanityBlob->setupKey(key, blurRec, skPaint);
- this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor(), viewMatrix, props,
- blob, x, y, drawFilter);
+ RegenerateTextBlob(sanityBlob, context->getBatchFontCache(),
+ *context->caps()->shaderCaps(), skPaint,
+ grPaint.getColor(), viewMatrix, props,
+ blob, x, y, drawFilter);
GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob);
}
}
} else {
if (canCache) {
- cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint)));
+ cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, skPaint)));
} else {
- cacheBlob.reset(fCache->createBlob(blob));
+ cacheBlob.reset(cache->createBlob(blob));
}
- this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix, props,
- blob, x, y, drawFilter);
+ RegenerateTextBlob(cacheBlob, context->getBatchFontCache(),
+ *context->caps()->shaderCaps(), skPaint, grPaint.getColor(),
+ viewMatrix, props,
+ blob, x, y, drawFilter);
}
- cacheBlob->flushCached(fContext, dc, blob, props, fDistanceAdjustTable, skPaint,
+ cacheBlob->flushCached(context, dc, blob, props, fDistanceAdjustTable, skPaint,
grPaint, drawFilter, clip, viewMatrix, clipBounds, x, y, transX, transY);
}
-void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
+void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob,
+ GrBatchFontCache* fontCache,
+ const GrShaderCaps& shaderCaps,
const SkPaint& skPaint, GrColor color,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
@@ -211,11 +194,10 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
cacheBlob->push_back_run(run);
- if (GrTextUtils::CanDrawAsDistanceFields(runPaint, viewMatrix, props,
- *fContext->caps()->shaderCaps())) {
+ if (GrTextUtils::CanDrawAsDistanceFields(runPaint, viewMatrix, props, shaderCaps)) {
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: {
- GrTextUtils::DrawDFText(cacheBlob, run, fContext->getBatchFontCache(),
+ GrTextUtils::DrawDFText(cacheBlob, run, fontCache,
props, runPaint, color, viewMatrix,
(const char *)it.glyphs(), textLen,
x + offset.x(), y + offset.y());
@@ -223,7 +205,7 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
}
case SkTextBlob::kHorizontal_Positioning: {
SkPoint dfOffset = SkPoint::Make(x, y + offset.y());
- GrTextUtils::DrawDFPosText(cacheBlob, run, fContext->getBatchFontCache(),
+ GrTextUtils::DrawDFPosText(cacheBlob, run, fontCache,
props, runPaint, color, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(),
1, dfOffset);
@@ -231,7 +213,7 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
}
case SkTextBlob::kFull_Positioning: {
SkPoint dfOffset = SkPoint::Make(x, y);
- GrTextUtils::DrawDFPosText(cacheBlob, run, fContext->getBatchFontCache(),
+ GrTextUtils::DrawDFPosText(cacheBlob, run, fontCache,
props, runPaint, color, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(),
2, dfOffset);
@@ -243,19 +225,19 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
} else {
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
- GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchFontCache(),
+ GrTextUtils::DrawBmpText(cacheBlob, run, fontCache,
props, runPaint, color, viewMatrix,
(const char *)it.glyphs(), textLen,
x + offset.x(), y + offset.y());
break;
case SkTextBlob::kHorizontal_Positioning:
- GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBatchFontCache(),
+ GrTextUtils::DrawBmpPosText(cacheBlob, run, fontCache,
props, runPaint, color, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(), 1,
SkPoint::Make(x, y + offset.y()));
break;
case SkTextBlob::kFull_Positioning:
- GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBatchFontCache(),
+ GrTextUtils::DrawBmpPosText(cacheBlob, run, fontCache,
props, runPaint, color, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(), 2,
SkPoint::Make(x, y));
@@ -271,7 +253,10 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
}
inline GrAtlasTextBlob*
-GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint,
+GrAtlasTextContext::CreateDrawTextBlob(GrTextBlobCache* blobCache,
+ GrBatchFontCache* fontCache,
+ const GrShaderCaps& shaderCaps,
+ const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
@@ -279,68 +264,74 @@ GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint,
SkScalar x, SkScalar y) {
int glyphCount = skPaint.countText(text, byteLength);
- GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1);
+ GrAtlasTextBlob* blob = blobCache->createBlob(glyphCount, 1);
blob->initThrowawayBlob(viewMatrix, x, y);
- if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props,
- *fContext->caps()->shaderCaps())) {
- GrTextUtils::DrawDFText(blob, 0, fContext->getBatchFontCache(), props,
+ if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props, shaderCaps)) {
+ GrTextUtils::DrawDFText(blob, 0, fontCache, props,
skPaint, paint.getColor(), viewMatrix, text,
byteLength, x, y);
} else {
- GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), props, skPaint,
+ GrTextUtils::DrawBmpText(blob, 0, fontCache, props, skPaint,
paint.getColor(), viewMatrix, text, byteLength, x, y);
}
return blob;
}
inline GrAtlasTextBlob*
-GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& skPaint,
+GrAtlasTextContext::CreateDrawPosTextBlob(GrTextBlobCache* blobCache, GrBatchFontCache* fontCache,
+ const GrShaderCaps& shaderCaps, const GrPaint& paint,
+ const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkSurfaceProps& props,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) {
int glyphCount = skPaint.countText(text, byteLength);
- GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1);
+ GrAtlasTextBlob* blob = blobCache->createBlob(glyphCount, 1);
blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y());
- if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props,
- *fContext->caps()->shaderCaps())) {
- GrTextUtils::DrawDFPosText(blob, 0, fContext->getBatchFontCache(), props,
+ if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props, shaderCaps)) {
+ GrTextUtils::DrawDFPosText(blob, 0, fontCache, props,
skPaint, paint.getColor(), viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset);
} else {
- GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), props, skPaint,
+ GrTextUtils::DrawBmpPosText(blob, 0, fontCache, props, skPaint,
paint.getColor(), viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset);
}
return blob;
}
-void GrAtlasTextContext::drawText(GrDrawContext* dc,
+void GrAtlasTextContext::drawText(GrContext* context,
+ GrDrawContext* dc,
const GrClip& clip,
const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
- if (fContext->abandoned()) {
+ if (context->abandoned()) {
return;
- } else if (this->canDraw(skPaint, viewMatrix, props)) {
+ } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shaderCaps())) {
SkAutoTUnref<GrAtlasTextBlob> blob(
- this->createDrawTextBlob(paint, skPaint, viewMatrix, props, text, byteLength, x, y));
- blob->flushThrowaway(fContext, dc, props, fDistanceAdjustTable, skPaint, paint,
+ CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFontCache(),
+ *context->caps()->shaderCaps(),
+ paint, skPaint,
+ viewMatrix, props,
+ text, byteLength, x, y));
+ blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint,
clip, regionClipBounds);
return;
}
// fall back to drawing as a path
- GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
+ GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
regionClipBounds);
}
-void GrAtlasTextContext::drawPosText(GrDrawContext* dc,
+void GrAtlasTextContext::drawPosText(GrContext* context,
+ GrDrawContext* dc,
const GrClip& clip,
const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
@@ -348,21 +339,24 @@ void GrAtlasTextContext::drawPosText(GrDrawContext* dc,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& regionClipBounds) {
- if (fContext->abandoned()) {
+ if (context->abandoned()) {
return;
- } else if (this->canDraw(skPaint, viewMatrix, props)) {
+ } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shaderCaps())) {
SkAutoTUnref<GrAtlasTextBlob> blob(
- this->createDrawPosTextBlob(paint, skPaint, viewMatrix, props,
- text, byteLength,
- pos, scalarsPerPosition,
- offset));
- blob->flushThrowaway(fContext, dc, props, fDistanceAdjustTable, skPaint, paint,
+ CreateDrawPosTextBlob(context->getTextBlobCache(),
+ context->getBatchFontCache(),
+ *context->caps()->shaderCaps(),
+ paint, skPaint, viewMatrix, props,
+ text, byteLength,
+ pos, scalarsPerPosition,
+ offset));
+ blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint,
clip, regionClipBounds);
return;
}
// fall back to drawing as a path
- GrTextUtils::DrawPosTextAsPath(fContext, dc, props, clip, skPaint, viewMatrix, text,
+ GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, skPaint, viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset, regionClipBounds);
}
@@ -382,7 +376,7 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
// We don't yet test the fall back to paths in the GrTextContext base class. This is mostly
// because we don't really want to have a gpu device here.
// We enable distance fields by twiddling a knob on the paint
- gTextContext = GrAtlasTextContext::Create(context);
+ gTextContext = GrAtlasTextContext::Create();
}
// Setup dummy SkPaint / GrPaint
@@ -408,8 +402,12 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
// right now we don't handle textblobs, nor do we handle drawPosText. Since we only
// intend to test the batch with this unit test, that is okay.
SkAutoTUnref<GrAtlasTextBlob> blob(
- gTextContext->createDrawTextBlob(grPaint, skPaint, viewMatrix, gSurfaceProps, text,
- static_cast<size_t>(textLen), 0, 0));
+ GrAtlasTextContext::CreateDrawTextBlob(context->getTextBlobCache(),
+ context->getBatchFontCache(),
+ *context->caps()->shaderCaps(), grPaint, skPaint,
+ viewMatrix,
+ gSurfaceProps, text,
+ static_cast<size_t>(textLen), 0, 0));
// We'd like to be able to test this with random translations, but currently the vertex
// bounds and vertices will get out of sync
diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h
index f2536b34db..c4948db8f6 100644
--- a/src/gpu/text/GrAtlasTextContext.h
+++ b/src/gpu/text/GrAtlasTextContext.h
@@ -31,50 +31,57 @@ class SkGlyph;
*/
class GrAtlasTextContext : public GrTextContext {
public:
- static GrAtlasTextContext* Create(GrContext*);
+ static GrAtlasTextContext* Create();
- bool canDraw(const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&);
- void drawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&,
+ bool canDraw(const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&,
+ const GrShaderCaps&);
+ void drawText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
size_t byteLength, SkScalar x, SkScalar y,
const SkIRect& regionClipBounds) override;
- void drawPosText(GrDrawContext*, const GrClip&, const GrPaint&,
+ void drawPosText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&,
const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&,
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&,
+ void drawTextBlob(GrContext*, GrDrawContext*, const GrClip&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*,
SkScalar x, SkScalar y,
SkDrawFilter*, const SkIRect& clipBounds) override;
private:
- GrAtlasTextContext(GrContext*);
+ GrAtlasTextContext();
// 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,
- const SkMatrix& viewMatrix,
- const SkSurfaceProps&,
- const SkTextBlob* blob, SkScalar x, SkScalar y,
- SkDrawFilter* drawFilter);
+ static void RegenerateTextBlob(GrAtlasTextBlob* bmp,
+ GrBatchFontCache*,
+ const GrShaderCaps&,
+ const SkPaint& skPaint, GrColor,
+ const SkMatrix& viewMatrix,
+ const SkSurfaceProps&,
+ const SkTextBlob* blob, SkScalar x, SkScalar y,
+ SkDrawFilter* drawFilter);
inline static bool HasLCD(const SkTextBlob*);
- // Test methods
- inline GrAtlasTextBlob* createDrawTextBlob(const GrPaint&,
- const SkPaint&, const SkMatrix& viewMatrix,
- const SkSurfaceProps&,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y);
- inline GrAtlasTextBlob* createDrawPosTextBlob(const GrPaint&,
- const SkPaint&, const SkMatrix& viewMatrix,
- const SkSurfaceProps&,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset);
+ static inline GrAtlasTextBlob* CreateDrawTextBlob(GrTextBlobCache*,
+ GrBatchFontCache*, const GrShaderCaps&,
+ const GrPaint&,
+ const SkPaint&, const SkMatrix& viewMatrix,
+ const SkSurfaceProps&,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y);
+ static inline GrAtlasTextBlob* CreateDrawPosTextBlob(GrTextBlobCache*, GrBatchFontCache*,
+ const GrShaderCaps&,
+ const GrPaint&,
+ const SkPaint&, const SkMatrix& viewMatrix,
+ const SkSurfaceProps&,
+ const char text[], size_t byteLength,
+ const SkScalar pos[],
+ int scalarsPerPosition,
+ const SkPoint& offset);
const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; }
- GrTextBlobCache* fCache;
SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
#ifdef GR_TEST_UTILS
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp
index 50ec4f23fa..08487d9859 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp
@@ -37,17 +37,15 @@ template<typename T> static void delete_hash_table_entry(T* val) {
delete *val;
}
-GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context)
- : INHERITED(context)
- , fFallbackTextContext(nullptr)
+GrStencilAndCoverTextContext::GrStencilAndCoverTextContext()
+ : fFallbackTextContext(nullptr)
, fCacheSize(0) {
}
GrStencilAndCoverTextContext*
-GrStencilAndCoverTextContext::Create(GrContext* context) {
- GrStencilAndCoverTextContext* textContext =
- new GrStencilAndCoverTextContext(context);
- textContext->fFallbackTextContext = GrAtlasTextContext::Create(context);
+GrStencilAndCoverTextContext::Create() {
+ GrStencilAndCoverTextContext* textContext = new GrStencilAndCoverTextContext();
+ textContext->fFallbackTextContext = GrAtlasTextContext::Create();
return textContext;
}
@@ -74,33 +72,34 @@ bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) {
return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrokeWidth();
}
-void GrStencilAndCoverTextContext::drawText(GrDrawContext* dc,
+void GrStencilAndCoverTextContext::drawText(GrContext* context, GrDrawContext* dc,
const GrClip& clip, const GrPaint& paint,
const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& clipBounds) {
- if (fContext->abandoned()) {
+ if (context->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, props, 0, 0,
+ run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, props, 0, 0,
clipBounds, fFallbackTextContext, skPaint);
return;
- } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props)) {
- fFallbackTextContext->drawText(dc, clip, paint, skPaint, viewMatrix, props, text,
+ } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props,
+ *context->caps()->shaderCaps())) {
+ fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMatrix, props, text,
byteLength, x, y, clipBounds);
return;
}
// fall back to drawing as a path
- GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
+ GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
clipBounds);
}
-void GrStencilAndCoverTextContext::drawPosText(GrDrawContext* dc,
+void GrStencilAndCoverTextContext::drawPosText(GrContext* context, GrDrawContext* dc,
const GrClip& clip,
const GrPaint& paint,
const SkPaint& skPaint,
@@ -112,28 +111,30 @@ void GrStencilAndCoverTextContext::drawPosText(GrDrawContext* dc,
int scalarsPerPosition,
const SkPoint& offset,
const SkIRect& clipBounds) {
- if (fContext->abandoned()) {
+ if (context->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, props, 0, 0,
+ run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, props, 0, 0,
clipBounds, fFallbackTextContext, skPaint);
return;
- } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props)) {
- fFallbackTextContext->drawPosText(dc, clip, paint, skPaint, viewMatrix, props,
+ } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props,
+ *context->caps()->shaderCaps())) {
+ fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, viewMatrix, props,
text, byteLength, pos,
scalarsPerPosition, offset, clipBounds);
return;
}
// fall back to drawing as a path
- GrTextUtils::DrawPosTextAsPath(fContext, dc, props, clip, skPaint, viewMatrix, text,
+ GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, skPaint, viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset, clipBounds);
}
-void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrDrawContext* dc,
+void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrContext* context,
+ GrDrawContext* dc,
const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
@@ -161,24 +162,24 @@ void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrDrawContext* dc,
runPaint.setFlags(FilterTextFlags(props, runPaint));
GrPaint grPaint;
- if (!SkPaintToGrPaint(fContext, runPaint, viewMatrix, &grPaint)) {
+ if (!SkPaintToGrPaint(context, runPaint, viewMatrix, &grPaint)) {
return;
}
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
- this->drawText(dc, clip, grPaint, runPaint, viewMatrix, props,
+ this->drawText(context, dc, clip, grPaint, runPaint, viewMatrix, props,
(const char *)it.glyphs(),
textLen, x + offset.x(), y + offset.y(), clipBounds);
break;
case SkTextBlob::kHorizontal_Positioning:
- this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, props,
+ this->drawPosText(context, dc, clip, grPaint, runPaint, viewMatrix, props,
(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, props,
+ this->drawPosText(context, dc, clip, grPaint, runPaint, viewMatrix, props,
(const char*)it.glyphs(),
textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
break;
@@ -191,32 +192,32 @@ void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrDrawContext* dc,
}
}
-void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc,
+void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const SkTextBlob* skBlob, SkScalar x, SkScalar y,
SkDrawFilter* drawFilter,
const SkIRect& clipBounds) {
- if (fContext->abandoned()) {
+ if (context->abandoned()) {
return;
}
if (!this->internalCanDraw(skPaint)) {
- fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, props, skBlob, x, y,
- drawFilter, clipBounds);
+ fFallbackTextContext->drawTextBlob(context, dc, clip, skPaint, viewMatrix, props, skBlob,
+ x, y, drawFilter, clipBounds);
return;
}
if (drawFilter || skPaint.getPathEffect()) {
// This draw can't be cached.
- this->uncachedDrawTextBlob(dc, clip, skPaint, viewMatrix, props, skBlob, x, y, drawFilter,
- clipBounds);
+ this->uncachedDrawTextBlob(context, dc, clip, skPaint, viewMatrix, props, skBlob, x, y,
+ drawFilter, clipBounds);
return;
}
GrPaint paint;
- if (!SkPaintToGrPaint(fContext, skPaint, viewMatrix, &paint)) {
+ if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &paint)) {
return;
}
@@ -225,7 +226,7 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc,
TextBlob::Iter iter(blob);
for (TextRun* run = iter.get(); run; run = iter.next()) {
- run->draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, props, x, y,
+ run->draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, props, x, y,
clipBounds, fFallbackTextContext, skPaint);
run->releaseGlyphCache();
}
@@ -620,8 +621,9 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
fallbackSkPaint.setStrokeWidth(fStroke.getWidth() * fTextRatio);
}
- fallbackTextContext->drawTextBlob(dc, pipelineBuilder->clip(), fallbackSkPaint, viewMatrix,
- props, fFallbackTextBlob, x, y, nullptr, clipBounds);
+ fallbackTextContext->drawTextBlob(ctx, dc, pipelineBuilder->clip(), fallbackSkPaint,
+ viewMatrix, props, fFallbackTextBlob, x, y, nullptr,
+ clipBounds);
}
}
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.h b/src/gpu/text/GrStencilAndCoverTextContext.h
index 053fbd3d69..302df0b5fc 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.h
+++ b/src/gpu/text/GrStencilAndCoverTextContext.h
@@ -28,20 +28,20 @@ class SkSurfaceProps;
*/
class GrStencilAndCoverTextContext : public GrTextContext {
public:
- static GrStencilAndCoverTextContext* Create(GrContext*);
+ static GrStencilAndCoverTextContext* Create();
- void drawText(GrDrawContext* dc,
+ void drawText(GrContext*, GrDrawContext* dc,
const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
size_t byteLength, SkScalar x,
SkScalar y, const SkIRect& clipBounds) override;
- void drawPosText(GrDrawContext*,
+ void drawPosText(GrContext*, GrDrawContext*,
const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&,
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&,
+ void drawTextBlob(GrContext*, GrDrawContext*, const GrClip&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*,
SkScalar x, SkScalar y,
SkDrawFilter*, const SkIRect& clipBounds) override;
@@ -49,7 +49,7 @@ public:
virtual ~GrStencilAndCoverTextContext();
private:
- GrStencilAndCoverTextContext(GrContext*);
+ GrStencilAndCoverTextContext();
bool canDraw(const SkPaint& skPaint, const SkMatrix&) {
return this->internalCanDraw(skPaint);
@@ -57,7 +57,7 @@ private:
bool internalCanDraw(const SkPaint&);
- void uncachedDrawTextBlob(GrDrawContext* dc,
+ void uncachedDrawTextBlob(GrContext*, GrDrawContext* dc,
const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const SkSurfaceProps&,
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 7885c5a578..1e2d290e90 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -10,10 +10,6 @@
#include "SkGlyphCache.h"
-GrTextContext::GrTextContext(GrContext* context)
- : fContext(context) {
-}
-
bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) {
if (!SkXfermode::AsMode(paint.getXfermode(), nullptr) ||
paint.getMaskFilter() ||
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
index 90ae4f35e8..04959a05aa 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -28,19 +28,19 @@ class GrTextContext {
public:
virtual ~GrTextContext() {}
- virtual void drawText(GrDrawContext* dc,
+ virtual void drawText(GrContext*, GrDrawContext* dc,
const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& clipBounds) = 0;
- virtual void drawPosText(GrDrawContext* dc,
+ virtual void drawPosText(GrContext*, GrDrawContext* dc,
const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
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&,
+ virtual void drawTextBlob(GrContext*, GrDrawContext* dc, const GrClip&,
const SkPaint&, const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const SkTextBlob*,
SkScalar x, SkScalar y,
@@ -49,10 +49,6 @@ public:
static bool ShouldDisableLCD(const SkPaint& paint);
protected:
- GrContext* fContext;
-
- GrTextContext(GrContext*);
-
static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint);