aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-12-11 06:08:59 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-12-11 06:09:00 -0800
commit296779832fd6175547d991ca67c735a824cadb66 (patch)
tree6a96d3a5aa2d4edc3b877b1ae7ac4fd24797a8e7 /src/gpu
parent2eb1009b6e244dae6374dc009dc867a32f40236e (diff)
make internaldrawBmpText part of GrTextUtils
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrAtlasTextContext.cpp136
-rw-r--r--src/gpu/GrAtlasTextContext.h10
-rw-r--r--src/gpu/GrTextContext.h3
-rw-r--r--src/gpu/GrTextUtils.cpp106
-rw-r--r--src/gpu/GrTextUtils.h51
5 files changed, 167 insertions, 139 deletions
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 735693b48c..aca839cf2c 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -12,6 +12,7 @@
#include "GrStrokeInfo.h"
#include "GrTextBlobCache.h"
#include "GrTexturePriv.h"
+#include "GrTextUtils.h"
#include "GrVertexBuffer.h"
#include "SkAutoKern.h"
@@ -333,19 +334,22 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
false);
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
- this->internalDrawBMPText(cacheBlob, run, cache, runPaint, color, viewMatrix,
- (const char *)it.glyphs(), textLen,
- x + offset.x(), y + offset.y());
+ GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchFontCache(),
+ cache, runPaint, color, viewMatrix,
+ (const char *)it.glyphs(), textLen,
+ x + offset.x(), y + offset.y());
break;
case SkTextBlob::kHorizontal_Positioning:
- this->internalDrawBMPPosText(cacheBlob, run, cache, runPaint, color, viewMatrix,
- (const char*)it.glyphs(), textLen, it.pos(), 1,
- SkPoint::Make(x, y + offset.y()));
+ GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBatchFontCache(),
+ cache, runPaint, color, viewMatrix,
+ (const char*)it.glyphs(), textLen, it.pos(), 1,
+ SkPoint::Make(x, y + offset.y()));
break;
case SkTextBlob::kFull_Positioning:
- this->internalDrawBMPPosText(cacheBlob, run, cache, runPaint, color, viewMatrix,
- (const char*)it.glyphs(), textLen, it.pos(), 2,
- SkPoint::Make(x, y));
+ GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBatchFontCache(),
+ cache, runPaint, color, viewMatrix,
+ (const char*)it.glyphs(), textLen, it.pos(), 2,
+ SkPoint::Make(x, y));
break;
}
SkGlyphCache::AttachCache(cache);
@@ -432,9 +436,9 @@ inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob,
fSurfaceProps, &viewMatrix, false);
SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface,
run.fOverrideDescriptor->getDesc());
- this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, color, viewMatrix,
- fallbackTxt.begin(), fallbackTxt.count(),
- fallbackPos.begin(), scalarsPerPosition, offset);
+ GrTextUtils::DrawBmpPosText(blob, runIndex, fContext->getBatchFontCache(), cache, skPaint,
+ color, viewMatrix, fallbackTxt.begin(), fallbackTxt.count(),
+ fallbackPos.begin(), scalarsPerPosition, offset);
SkGlyphCache::AttachCache(cache);
}
@@ -484,8 +488,8 @@ GrAtlasTextContext::createDrawTextBlob(const GrClip& clip,
blob->fViewMatrix = viewMatrix;
SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMatrix, false);
- this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
- byteLength, x, y);
+ GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), cache, skPaint,
+ paint.getColor(), viewMatrix, text, byteLength, x, y);
SkGlyphCache::AttachCache(cache);
}
return blob;
@@ -519,8 +523,9 @@ GrAtlasTextContext::createDrawPosTextBlob(const GrClip& clip,
blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize);
blob->fViewMatrix = viewMatrix;
SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMatrix, false);
- this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
- byteLength, pos, scalarsPerPosition, offset);
+ GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), cache, skPaint,
+ paint.getColor(), viewMatrix, text,
+ byteLength, pos, scalarsPerPosition, offset);
SkGlyphCache::AttachCache(cache);
}
return blob;
@@ -556,72 +561,6 @@ void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc,
regionClipBounds);
}
-void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex,
- SkGlyphCache* cache, const SkPaint& skPaint,
- GrColor color,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y) {
- SkASSERT(byteLength == 0 || text != nullptr);
-
- // nothing to draw
- if (text == nullptr || byteLength == 0) {
- return;
- }
-
- fCurrStrike = nullptr;
-
- // Get GrFontScaler from cache
- GrFontScaler* fontScaler = GetGrFontScaler(cache);
-
- SkFindAndPlaceGlyph::ProcessText(
- skPaint.getTextEncoding(), text, byteLength,
- {x, y}, viewMatrix, skPaint.getTextAlign(),
- cache,
- [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
- position += rounding;
- this->bmpAppendGlyph(
- blob, runIndex, glyph,
- SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
- color, fontScaler);
- }
- );
-}
-
-void GrAtlasTextContext::internalDrawBMPPosText(GrAtlasTextBlob* blob, int runIndex,
- SkGlyphCache* cache, const SkPaint& skPaint,
- GrColor color,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset) {
- SkASSERT(byteLength == 0 || text != nullptr);
- SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
-
- // nothing to draw
- if (text == nullptr || byteLength == 0) {
- return;
- }
-
- fCurrStrike = nullptr;
-
- // Get GrFontScaler from cache
- GrFontScaler* fontScaler = GetGrFontScaler(cache);
-
- SkFindAndPlaceGlyph::ProcessPosText(
- skPaint.getTextEncoding(), text, byteLength,
- offset, viewMatrix, pos, scalarsPerPosition,
- skPaint.getTextAlign(), cache,
- [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
- position += rounding;
- this->bmpAppendGlyph(
- blob, runIndex, glyph,
- SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
- color, fontScaler);
- }
- );
-}
-
void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex,
const SkPaint& skPaint, GrColor color,
const SkMatrix& viewMatrix,
@@ -784,39 +723,6 @@ void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
SkGlyphCache::AttachCache(cache);
}
-void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
- const SkGlyph& skGlyph,
- int vx, int vy, GrColor color, GrFontScaler* scaler) {
- if (!fCurrStrike) {
- fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
- }
-
- GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
- skGlyph.getSubXFixed(),
- skGlyph.getSubYFixed(),
- GrGlyph::kCoverage_MaskStyle);
- GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler);
- if (!glyph) {
- return;
- }
-
- int x = vx + glyph->fBounds.fLeft;
- int y = vy + glyph->fBounds.fTop;
-
- // keep them as ints until we've done the clip-test
- int width = glyph->fBounds.width();
- int height = glyph->fBounds.height();
-
- SkRect r;
- r.fLeft = SkIntToScalar(x);
- r.fTop = SkIntToScalar(y);
- r.fRight = r.fLeft + SkIntToScalar(width);
- r.fBottom = r.fTop + SkIntToScalar(height);
-
- blob->appendGlyph(runIndex, r, color, fCurrStrike, glyph, scaler, skGlyph,
- SkIntToScalar(vx), SkIntToScalar(vy), 1.0f, false);
-}
-
bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
const SkGlyph& skGlyph,
SkScalar sx, SkScalar sy, GrColor color,
diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h
index fb132c21b5..47f05404de 100644
--- a/src/gpu/GrAtlasTextContext.h
+++ b/src/gpu/GrAtlasTextContext.h
@@ -73,16 +73,6 @@ private:
int scalarsPerPosition,
const SkPoint& offset);
- void internalDrawBMPText(GrAtlasTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
- GrColor color, const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y);
- void internalDrawBMPPosText(GrAtlasTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
- GrColor color, const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset);
-
void internalDrawDFText(GrAtlasTextBlob*, int runIndex, const SkPaint&,
GrColor color, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
diff --git a/src/gpu/GrTextContext.h b/src/gpu/GrTextContext.h
index 1e27caa935..206b34a403 100644
--- a/src/gpu/GrTextContext.h
+++ b/src/gpu/GrTextContext.h
@@ -69,7 +69,8 @@ protected:
static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint);
friend class GrAtlasTextBatch;
- friend class GrAtlasTextBlob; // for drawTextAsPath
+ friend class GrAtlasTextBlob; // for FilterTextFlags
+ friend class GrTextUtils; // for some static functions
};
#endif
diff --git a/src/gpu/GrTextUtils.cpp b/src/gpu/GrTextUtils.cpp
index e56b5cb29e..293ea4d891 100644
--- a/src/gpu/GrTextUtils.cpp
+++ b/src/gpu/GrTextUtils.cpp
@@ -7,16 +7,122 @@
#include "GrTextUtils.h"
+#include "GrAtlasTextBlob.h"
+#include "GrBatchFontCache.h"
#include "GrBlurUtils.h"
#include "GrContext.h"
#include "GrDrawContext.h"
+#include "GrTextContext.h"
#include "SkDrawProcs.h"
+#include "SkFindAndPlaceGlyph.h"
#include "SkGlyphCache.h"
#include "SkPaint.h"
#include "SkRect.h"
#include "SkTextMapStateProc.h"
#include "SkTextToPathIter.h"
+void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
+ GrBatchFontCache* fontCache,
+ SkGlyphCache* cache, const SkPaint& skPaint,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y) {
+ SkASSERT(byteLength == 0 || text != nullptr);
+
+ // nothing to draw
+ if (text == nullptr || byteLength == 0) {
+ return;
+ }
+
+ GrBatchTextStrike* currStrike = nullptr;
+
+ // Get GrFontScaler from cache
+ GrFontScaler* fontScaler = GrTextContext::GetGrFontScaler(cache);
+
+ SkFindAndPlaceGlyph::ProcessText(
+ skPaint.getTextEncoding(), text, byteLength,
+ {x, y}, viewMatrix, skPaint.getTextAlign(),
+ cache,
+ [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
+ position += rounding;
+ BmpAppendGlyph(
+ blob, runIndex, fontCache, &currStrike, glyph,
+ SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
+ color, fontScaler);
+ }
+ );
+}
+
+void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
+ GrBatchFontCache* fontCache,
+ SkGlyphCache* cache, const SkPaint& skPaint,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset) {
+ SkASSERT(byteLength == 0 || text != nullptr);
+ SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
+
+ // nothing to draw
+ if (text == nullptr || byteLength == 0) {
+ return;
+ }
+
+ GrBatchTextStrike* currStrike = nullptr;
+
+ // Get GrFontScaler from cache
+ GrFontScaler* fontScaler = GrTextContext::GetGrFontScaler(cache);
+
+ SkFindAndPlaceGlyph::ProcessPosText(
+ skPaint.getTextEncoding(), text, byteLength,
+ offset, viewMatrix, pos, scalarsPerPosition,
+ skPaint.getTextAlign(), cache,
+ [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
+ position += rounding;
+ BmpAppendGlyph(
+ blob, runIndex, fontCache, &currStrike, glyph,
+ SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
+ color, fontScaler);
+ }
+ );
+}
+
+void GrTextUtils::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
+ GrBatchFontCache* fontCache,
+ GrBatchTextStrike** strike, const SkGlyph& skGlyph,
+ int vx, int vy, GrColor color, GrFontScaler* scaler) {
+ if (!*strike) {
+ *strike = fontCache->getStrike(scaler);
+ }
+
+ GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
+ skGlyph.getSubXFixed(),
+ skGlyph.getSubYFixed(),
+ GrGlyph::kCoverage_MaskStyle);
+ GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, scaler);
+ if (!glyph) {
+ return;
+ }
+
+ int x = vx + glyph->fBounds.fLeft;
+ int y = vy + glyph->fBounds.fTop;
+
+ // keep them as ints until we've done the clip-test
+ int width = glyph->fBounds.width();
+ int height = glyph->fBounds.height();
+
+ SkRect r;
+ r.fLeft = SkIntToScalar(x);
+ r.fTop = SkIntToScalar(y);
+ r.fRight = r.fLeft + SkIntToScalar(width);
+ r.fBottom = r.fTop + SkIntToScalar(height);
+
+ blob->appendGlyph(runIndex, r, color, *strike, glyph, scaler, skGlyph,
+ SkIntToScalar(vx), SkIntToScalar(vy), 1.0f, false);
+}
+
void GrTextUtils::DrawTextAsPath(GrContext* context, GrDrawContext* dc,
const GrClip& clip,
const SkPaint& skPaint, const SkMatrix& viewMatrix,
diff --git a/src/gpu/GrTextUtils.h b/src/gpu/GrTextUtils.h
index cd2067f464..8f673afbed 100644
--- a/src/gpu/GrTextUtils.h
+++ b/src/gpu/GrTextUtils.h
@@ -8,15 +8,22 @@
#ifndef GrTextUtils_DEFINED
#define GrTextUtils_DEFINED
+#include "GrColor.h"
#include "SkScalar.h"
+class GrAtlasTextBlob;
+class GrBatchFontCache;
+class GrBatchTextStrike;
class GrClip;
class GrContext;
class GrDrawContext;
+class GrFontScaler;
+class SkGlyph;
class SkMatrix;
struct SkIRect;
class SkPaint;
struct SkPoint;
+class SkGlyphCache;
class SkSurfaceProps;
/*
@@ -26,20 +33,38 @@ class SkSurfaceProps;
*/
class GrTextUtils {
public:
+ // Functions for appending BMP text to GrAtlasTextBlob
+ static void DrawBmpText(GrAtlasTextBlob*, int runIndex,
+ GrBatchFontCache*, SkGlyphCache*, const SkPaint&,
+ GrColor, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y);
-static void DrawTextAsPath(GrContext*, GrDrawContext*, const GrClip& clip,
- const SkPaint& origPaint, const SkMatrix& viewMatrix,
- const char text[], size_t byteLength, SkScalar x, SkScalar y,
- const SkIRect& clipBounds);
-
-static void DrawPosTextAsPath(GrContext* context,
- GrDrawContext* dc,
- const SkSurfaceProps& props,
- const GrClip& clip,
- const SkPaint& origPaint, const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset, const SkIRect& clipBounds);
+ static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex,
+ GrBatchFontCache*, SkGlyphCache*, const SkPaint&,
+ GrColor, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset);
+
+ // Functions for drawing text as paths
+ static void DrawTextAsPath(GrContext*, GrDrawContext*, const GrClip& clip,
+ const SkPaint& origPaint, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength, SkScalar x, SkScalar y,
+ const SkIRect& clipBounds);
+
+ static void DrawPosTextAsPath(GrContext* context,
+ GrDrawContext* dc,
+ const SkSurfaceProps& props,
+ const GrClip& clip,
+ const SkPaint& origPaint, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset, const SkIRect& clipBounds);
+private:
+ static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*,
+ GrBatchTextStrike**, const SkGlyph&, int left, int top,
+ GrColor color, GrFontScaler*);
};
#endif