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

Unified Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 149853002: Improved distance field sampling (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More clean up Created 6 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
Index: src/gpu/GrDistanceFieldTextContext.cpp
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index bd3927c648839232f655aaead473cee7a7892b21..077709fb78cfe548c1392a0d637fed832870f797 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -8,6 +8,7 @@
#include "GrDistanceFieldTextContext.h"
#include "GrAtlas.h"
#include "GrDrawTarget.h"
+#include "GrDrawTargetCaps.h"
#include "GrFontScaler.h"
#include "SkGlyphCache.h"
#include "GrIndexBuffer.h"
@@ -21,6 +22,7 @@
#include "effects/GrDistanceFieldTextureEffect.h"
static const int kGlyphCoordsAttributeIndex = 1;
+static const int kGlyphOffsetAttributeIndex = 2;
static const int kBaseDFFontSize = 32;
@@ -46,6 +48,7 @@ GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
return !paint.getRasterizer() && !paint.getMaskFilter() &&
paint.getStyle() == SkPaint::kFill_Style &&
+ fContext->getTextTarget()->caps()->shaderDerivativeSupport() &&
!SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());
}
@@ -67,14 +70,14 @@ void GrDistanceFieldTextContext::flushGlyphs() {
if (fCurrVertex > 0) {
// setup our sampler state for our text texture/atlas
- SkASSERT(GrIsALIGN4(fCurrVertex));
+ SkASSERT(fCurrVertex % 6 == 0);
SkASSERT(fCurrTexture);
GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode);
// This effect could be stored with one of the cache objects (atlas?)
drawState->addCoverageEffect(
GrDistanceFieldTextureEffect::Create(fCurrTexture, params),
- kGlyphCoordsAttributeIndex)->unref();
+ kGlyphCoordsAttributeIndex, kGlyphOffsetAttributeIndex)->unref();
if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
@@ -98,7 +101,7 @@ void GrDistanceFieldTextContext::flushGlyphs() {
drawState->setColor(fPaint.getColor());
}
- int nGlyphs = fCurrVertex / 4;
+ int nGlyphs = fCurrVertex / 6;
fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
nGlyphs,
@@ -115,8 +118,9 @@ namespace {
// position + texture coord
extern const GrVertexAttrib gTextVertexAttribs[] = {
- {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
- {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding}
+ {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
+ {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding},
+ {kVec2f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding}
};
};
@@ -248,7 +252,7 @@ HAS_ATLAS:
GrTCast<void**>(&fVertices),
NULL);
GrAlwaysAssert(success);
- SkASSERT(2*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize());
+ SkASSERT(3*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize());
}
SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft);
@@ -263,23 +267,30 @@ HAS_ATLAS:
sy += dy;
width *= scale;
height *= scale;
-
+
GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
GrFixed tw = SkIntToFixed(glyph->fBounds.width());
GrFixed th = SkIntToFixed(glyph->fBounds.height());
+ SkISize texSize = fStrike->getAtlasSize();
bsalomon 2014/02/05 20:19:10 AFAICT this is the same for the lifetime of the pr
jvanverth1 2014/02/10 18:34:02 Done.
+
fVertices[2*fCurrVertex].setRectFan(sx,
sy,
sx + width,
sy + height,
- 2 * sizeof(SkPoint));
+ 3 * sizeof(SkPoint));
bsalomon 2014/02/05 20:19:10 this 3 * sizeof(SkPoint) is repeated here three ti
jvanverth1 2014/02/10 18:34:02 Done.
fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)),
SkFixedToFloat(texture->normalizeFixedY(ty)),
SkFixedToFloat(texture->normalizeFixedX(tx + tw)),
SkFixedToFloat(texture->normalizeFixedY(ty + th)),
- 2 * sizeof(SkPoint));
- fCurrVertex += 4;
+ 3 * sizeof(SkPoint));
+ fVertices[2*fCurrVertex+2].setRectFan(SkIntToScalar(texSize.fWidth),
+ SkIntToScalar(texSize.fHeight),
+ SkIntToScalar(texSize.fWidth),
+ SkIntToScalar(texSize.fHeight),
+ 3 * sizeof(SkPoint));
+ fCurrVertex += 6;
}
inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {

Powered by Google App Engine
This is Rietveld 408576698