aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-04-21 10:07:26 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-21 10:07:26 -0700
commit010db5346e425be8ce659b23b75943ee8ef9d537 (patch)
treec3165e75f24da099b7509a73020c4389e2d0c6c6 /src
parent409fd66a5afcef5f165f7ccec7c3473add231752 (diff)
Some simple optimizations for improving GrAtlasTextContext perf
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrAtlasTextContext.cpp69
-rw-r--r--src/gpu/GrBatchAtlas.h5
-rw-r--r--src/gpu/GrBatchFontCache.cpp18
-rw-r--r--src/gpu/GrBatchFontCache.h3
-rw-r--r--src/gpu/GrGlyph.h4
5 files changed, 49 insertions, 50 deletions
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 8c162220f9..c1a46fea9c 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -1201,7 +1201,7 @@ void GrAtlasTextContext::bmpAppendGlyph(BitmapTextBlob* blob, int runIndex,
}
GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler);
- if (!glyph || glyph->fBounds.isEmpty()) {
+ if (!glyph) {
return;
}
@@ -1225,7 +1225,7 @@ void GrAtlasTextContext::bmpAppendGlyph(BitmapTextBlob* blob, int runIndex,
#endif
// If the glyph is too large we fall back to paths
- if (fCurrStrike->glyphTooLargeForAtlas(glyph)) {
+ if (glyph->fTooLargeForAtlas) {
this->appendGlyphPath(blob, glyph, scaler, vx, vy);
return;
}
@@ -1264,7 +1264,7 @@ bool GrAtlasTextContext::dfAppendGlyph(BitmapTextBlob* blob, int runIndex,
}
GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler);
- if (!glyph || glyph->fBounds.isEmpty()) {
+ if (!glyph) {
return true;
}
@@ -1301,7 +1301,7 @@ bool GrAtlasTextContext::dfAppendGlyph(BitmapTextBlob* blob, int runIndex,
// TODO combine with the above
// If the glyph is too large we fall back to paths
- if (fCurrStrike->glyphTooLargeForAtlas(glyph)) {
+ if (glyph->fTooLargeForAtlas) {
this->appendGlyphPath(blob, glyph, scaler, SkScalarRoundToInt(sx - dx),
SkScalarRoundToInt(sy - dy));
return true;
@@ -1345,39 +1345,52 @@ inline void GrAtlasTextContext::appendGlyphCommon(BitmapTextBlob* blob, Run* run
intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVertexEndIndex);
- // V0
- SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
- position->set(positions.fLeft, positions.fTop);
if (useVertexColor) {
+ // V0
+ SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fLeft, positions.fTop);
SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
- }
- vertex += vertexStride;
+ vertex += vertexStride;
- // V1
- position = reinterpret_cast<SkPoint*>(vertex);
- position->set(positions.fLeft, positions.fBottom);
- if (useVertexColor) {
- SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+ // V1
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fLeft, positions.fBottom);
+ colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
- }
- vertex += vertexStride;
+ vertex += vertexStride;
- // V2
- position = reinterpret_cast<SkPoint*>(vertex);
- position->set(positions.fRight, positions.fBottom);
- if (useVertexColor) {
- SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+ // V2
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fRight, positions.fBottom);
+ colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
- }
- vertex += vertexStride;
+ vertex += vertexStride;
- // V3
- position = reinterpret_cast<SkPoint*>(vertex);
- position->set(positions.fRight, positions.fTop);
- if (useVertexColor) {
- SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+ // V3
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fRight, positions.fTop);
+ colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
+ } else {
+ // V0
+ SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fLeft, positions.fTop);
+ vertex += vertexStride;
+
+ // V1
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fLeft, positions.fBottom);
+ vertex += vertexStride;
+
+ // V2
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fRight, positions.fBottom);
+ vertex += vertexStride;
+
+ // V3
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(positions.fRight, positions.fTop);
}
subRun->fGlyphEndIndex++;
diff --git a/src/gpu/GrBatchAtlas.h b/src/gpu/GrBatchAtlas.h
index 77a49ce699..2b85da1f7d 100644
--- a/src/gpu/GrBatchAtlas.h
+++ b/src/gpu/GrBatchAtlas.h
@@ -112,6 +112,11 @@ public:
void setLastUseTokenBulk(const BulkUseTokenUpdater& reffer, BatchToken);
+ static const int kGlyphMaxDim = 256;
+ static bool GlyphTooLargeForAtlas(int width, int height) {
+ return width > kGlyphMaxDim || height > kGlyphMaxDim;
+ }
+
private:
static int GetIndexFromID(AtlasID id) {
return id & 0xffff;
diff --git a/src/gpu/GrBatchFontCache.cpp b/src/gpu/GrBatchFontCache.cpp
index 7e44fa5236..4f27cfcf8c 100644
--- a/src/gpu/GrBatchFontCache.cpp
+++ b/src/gpu/GrBatchFontCache.cpp
@@ -202,24 +202,6 @@ void GrBatchTextStrike::removeID(GrBatchAtlas::AtlasID id) {
}
}
-bool GrBatchTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) {
- int width = glyph->fBounds.width();
- int height = glyph->fBounds.height();
- bool useDistanceField =
- (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedID));
- int pad = useDistanceField ? 2 * SK_DistanceFieldPad : 0;
- int plotWidth = (kA8_GrMaskFormat == glyph->fMaskFormat) ? GR_FONT_ATLAS_A8_PLOT_WIDTH
- : GR_FONT_ATLAS_PLOT_WIDTH;
- if (width + pad > plotWidth) {
- return true;
- }
- if (height + pad > GR_FONT_ATLAS_PLOT_HEIGHT) {
- return true;
- }
-
- return false;
-}
-
bool GrBatchTextStrike::addGlyphToAtlas(GrBatchTarget* batchTarget, GrGlyph* glyph,
GrFontScaler* scaler) {
SkASSERT(glyph);
diff --git a/src/gpu/GrBatchFontCache.h b/src/gpu/GrBatchFontCache.h
index f60e2c8ebf..f1c56ac00c 100644
--- a/src/gpu/GrBatchFontCache.h
+++ b/src/gpu/GrBatchFontCache.h
@@ -40,9 +40,6 @@ public:
return glyph;
}
- // returns true if glyph (or glyph+padding for distance field)
- // is too large to ever fit in texture atlas subregions (GrPlots)
- bool glyphTooLargeForAtlas(GrGlyph*);
// returns true if glyph successfully added to texture atlas, false otherwise
bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*);
diff --git a/src/gpu/GrGlyph.h b/src/gpu/GrGlyph.h
index 2d3e945ddb..8750c763e5 100644
--- a/src/gpu/GrGlyph.h
+++ b/src/gpu/GrGlyph.h
@@ -39,6 +39,7 @@ struct GrGlyph {
GrMaskFormat fMaskFormat;
GrIRect16 fBounds;
SkIPoint16 fAtlasLocation;
+ bool fTooLargeForAtlas;
void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format) {
fID = GrBatchAtlas::kInvalidAtlasID;
@@ -48,6 +49,7 @@ struct GrGlyph {
fBounds.set(bounds);
fMaskFormat = format;
fAtlasLocation.set(0, 0);
+ fTooLargeForAtlas = GrBatchAtlas::GlyphTooLargeForAtlas(bounds.width(), bounds.height());
}
void free() {
@@ -97,7 +99,7 @@ struct GrGlyph {
}
static inline uint32_t Hash(GrGlyph::PackedID key) {
- return SkChecksum::Murmur3(&key, sizeof(key));
+ return SkChecksum::Mix(key);
}
};