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

Unified Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 917373002: Use uint16s for texture coordinates when rendering text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use float uvs for distance field paths Created 5 years, 10 months 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/GrBitmapTextContext.cpp ('k') | src/gpu/GrFontAtlasSizes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDistanceFieldTextContext.cpp
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index d3b01703e484e686d8dfc28588f05cd635dabc0f..65e899960e16c3779ffd57ad4f3fc1ed10444a8e 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -374,8 +374,8 @@ static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
}
static size_t get_vertex_stride(bool useColorVerts) {
- return useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) :
- (2 * sizeof(SkPoint));
+ return useColorVerts ? (sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16)) :
+ (sizeof(SkPoint) + sizeof(SkIPoint16));
}
static void* alloc_vertices(GrDrawTarget* drawTarget,
@@ -443,12 +443,12 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
flags,
opaque));
#else
- fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::Create(color,
- fViewMatrix,
- fCurrTexture,
- params,
- flags,
- opaque));
+ fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(color,
+ fViewMatrix,
+ fCurrTexture,
+ params,
+ flags,
+ opaque));
#endif
}
fEffectTextureUniqueID = textureUniqueID;
@@ -600,36 +600,59 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
useColorVerts);
}
- SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset);
- SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset);
- SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset);
- SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset);
-
fVertexBounds.joinNonEmptyArg(glyphRect);
+ int u0 = glyph->fAtlasLocation.fX + SK_DistanceFieldInset;
+ int v0 = glyph->fAtlasLocation.fY + SK_DistanceFieldInset;
+ int u1 = u0 + glyph->fBounds.width() - 2*SK_DistanceFieldInset;
+ int v1 = v0 + glyph->fBounds.height() - 2*SK_DistanceFieldInset;
+
size_t vertSize = get_vertex_stride(useColorVerts);
+ intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex;
- SkPoint* positions = reinterpret_cast<SkPoint*>(
- reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
- positions->setRectFan(glyphRect.fLeft, glyphRect.fTop, glyphRect.fRight, glyphRect.fBottom,
- vertSize);
-
- // The texture coords are last in both the with and without color vertex layouts.
- SkPoint* textureCoords = reinterpret_cast<SkPoint*>(
- reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint));
- textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx)),
- SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty)),
- SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx + tw)),
- SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + th)),
- vertSize);
+ // V0
+ SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(glyphRect.fLeft, glyphRect.fTop);
if (useColorVerts) {
- // color comes after position.
- GrColor* colors = reinterpret_cast<GrColor*>(positions + 1);
- for (int i = 0; i < 4; ++i) {
- *colors = fPaint.getColor();
- colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors) + vertSize);
- }
+ SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+ *color = fPaint.getColor();
+ }
+ SkIPoint16* textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize -
+ sizeof(SkIPoint16));
+ textureCoords->set(u0, v0);
+ vertex += vertSize;
+
+ // V1
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(glyphRect.fLeft, glyphRect.fBottom);
+ if (useColorVerts) {
+ SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+ *color = fPaint.getColor();
+ }
+ textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(SkIPoint16));
+ textureCoords->set(u0, v1);
+ vertex += vertSize;
+
+ // V2
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(glyphRect.fRight, glyphRect.fBottom);
+ if (useColorVerts) {
+ SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+ *color = fPaint.getColor();
+ }
+ textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(SkIPoint16));
+ textureCoords->set(u1, v1);
+ vertex += vertSize;
+
+ // V3
+ position = reinterpret_cast<SkPoint*>(vertex);
+ position->set(glyphRect.fRight, glyphRect.fTop);
+ if (useColorVerts) {
+ SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+ *color = fPaint.getColor();
}
+ textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(SkIPoint16));
+ textureCoords->set(u1, v0);
fCurrVertex += 4;
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrFontAtlasSizes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698