Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: src/gpu/GrTextUtils.cpp

Issue 1518883002: make internaldrawBmpText part of GrTextUtils (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanuptext10textutils
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrTextUtils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTextUtils.cpp
diff --git a/src/gpu/GrTextUtils.cpp b/src/gpu/GrTextUtils.cpp
index e56b5cb29e07c6901963cf5a141fe903b1c9b904..293ea4d891edac7888625522a1563b663bb9e675 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,
« no previous file with comments | « src/gpu/GrTextUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698