diff options
author | reed <reed@chromium.org> | 2015-02-17 18:38:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-17 18:38:38 -0800 |
commit | e4ef1ca5be11aed67c0ed0c7eb1862696fb063e3 (patch) | |
tree | 9f26b1d1e46b90b8367194d35c2931d641d2bea3 | |
parent | f320e04c50a1c8a861bc1d8f50bf732044ff9843 (diff) |
Revert of Use uint16s for texture coordinates when rendering text. (patchset #5 id:80001 of https://codereview.chromium.org/917373002/)
Reason for revert:
speculative revert for DEPS failures
https://codereview.chromium.org/932973002/
Original issue's description:
> Use uint16s for texture coordinates when rendering text.
>
> Allows us to push more vertices into a given vertex buffer, with
> a slight performance improvement.
>
> Committed: https://skia.googlesource.com/skia/+/059034d252007d0dd86fff5ffdbb53cbcb10d34b
TBR=joshualitt@google.com,robertphillips@google.com,bsalomon@google.com,reed@google.com,djsollen@google.com,jvanverth@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.chromium.org/920333003
-rw-r--r-- | gyp/gpu.gypi | 1 | ||||
-rw-r--r-- | include/gpu/GrTypesPriv.h | 14 | ||||
-rwxr-xr-x | src/gpu/GrAADistanceFieldPathRenderer.cpp | 42 | ||||
-rwxr-xr-x | src/gpu/GrBitmapTextContext.cpp | 87 | ||||
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 75 | ||||
-rw-r--r-- | src/gpu/GrFontAtlasSizes.h | 28 | ||||
-rw-r--r-- | src/gpu/GrFontCache.cpp | 22 | ||||
-rw-r--r-- | src/gpu/effects/GrBitmapTextGeoProc.cpp | 8 | ||||
-rwxr-xr-x | src/gpu/effects/GrDistanceFieldTextureEffect.cpp | 135 | ||||
-rw-r--r-- | src/gpu/gl/GrGLVertexArray.h | 2 |
10 files changed, 175 insertions, 239 deletions
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index fe21d830cf..68264f040c 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -84,7 +84,6 @@ '<(skia_src_path)/gpu/GrDrawTargetCaps.h', '<(skia_src_path)/gpu/GrFlushToGpuDrawTarget.cpp', '<(skia_src_path)/gpu/GrFlushToGpuDrawTarget.h', - '<(skia_src_path)/gpu/GrFontAtlasSizes.h', '<(skia_src_path)/gpu/GrFontScaler.cpp', '<(skia_src_path)/gpu/GrFontScaler.h', '<(skia_src_path)/gpu/GrGeometryBuffer.h', diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h index 412de897c6..1f86197295 100644 --- a/include/gpu/GrTypesPriv.h +++ b/include/gpu/GrTypesPriv.h @@ -116,11 +116,9 @@ enum GrVertexAttribType { kVec4f_GrVertexAttribType, kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage - kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors + kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors - kVec2s_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates - - kLast_GrVertexAttribType = kVec2s_GrVertexAttribType + kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType }; static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; @@ -129,7 +127,7 @@ static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; */ static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); - static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2 }; + static const int kCounts[] = { 1, 2, 3, 4, 1, 4 }; return kCounts[type]; GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); @@ -138,7 +136,6 @@ static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); - GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); } @@ -153,8 +150,7 @@ static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { 3*sizeof(float), // kVec3f_GrVertexAttribType 4*sizeof(float), // kVec4f_GrVertexAttribType 1*sizeof(char), // kUByte_GrVertexAttribType - 4*sizeof(char), // kVec4ub_GrVertexAttribType - 2*sizeof(int16_t) // kVec2s_GrVertexAttribType + 4*sizeof(char) // kVec4ub_GrVertexAttribType }; return kSizes[type]; @@ -164,7 +160,6 @@ static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); - GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); } @@ -178,7 +173,6 @@ static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { case kUByte_GrVertexAttribType: case kFloat_GrVertexAttribType: return kFloat_GrSLType; - case kVec2s_GrVertexAttribType: case kVec2f_GrVertexAttribType: return kVec2f_GrSLType; case kVec3f_GrVertexAttribType: diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp index 482358b94d..f2d618efcd 100755 --- a/src/gpu/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp @@ -19,10 +19,10 @@ #include "SkDistanceFieldGen.h" #include "SkRTConf.h" -#define ATLAS_TEXTURE_WIDTH 1024 +#define ATLAS_TEXTURE_WIDTH 1024 #define ATLAS_TEXTURE_HEIGHT 2048 -#define PLOT_WIDTH 256 -#define PLOT_HEIGHT 256 +#define PLOT_WIDTH 256 +#define PLOT_HEIGHT 256 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH) #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT) @@ -342,41 +342,39 @@ bool GrAADistanceFieldPathRenderer::internalDrawPath(GrDrawTarget* target, bool success = target->reserveVertexAndIndexSpace(4, fCachedGeometryProcessor->getVertexStride(), 0, &vertices, NULL); - SkASSERT(fCachedGeometryProcessor->getVertexStride() == sizeof(SkPoint) + sizeof(SkIPoint16)); + SkASSERT(fCachedGeometryProcessor->getVertexStride() == 2 * sizeof(SkPoint)); GrAlwaysAssert(success); SkScalar dx = pathData->fBounds.fLeft; SkScalar dy = pathData->fBounds.fTop; - // need to compute integer sizes for the glyph because we're using - // uint16_t tex coords and they need to lie on integer texel bounds - int iwidth = SkScalarCeilToInt(pathData->fBounds.width()); - int iheight = SkScalarCeilToInt(pathData->fBounds.height()); - // the quad rect before we scale needs to be the same size as the path data in the atlas - SkScalar width = SkIntToScalar(iwidth); - SkScalar height = SkIntToScalar(iheight); + SkScalar width = pathData->fBounds.width(); + SkScalar height = pathData->fBounds.height(); SkScalar invScale = 1.0f/pathData->fScale; dx *= invScale; dy *= invScale; width *= invScale; height *= invScale; - - int u0 = pathData->fAtlasLocation.fX; - int v0 = pathData->fAtlasLocation.fY; - int u1 = u0 + iwidth; - int v1 = v0 + iheight; + + SkFixed tx = SkIntToFixed(pathData->fAtlasLocation.fX); + SkFixed ty = SkIntToFixed(pathData->fAtlasLocation.fY); + SkFixed tw = SkScalarToFixed(pathData->fBounds.width()); + SkFixed th = SkScalarToFixed(pathData->fBounds.height()); + // vertex positions SkRect r = SkRect::MakeXYWH(dx, dy, width, height); - size_t vertSize = sizeof(SkPoint) + sizeof(SkIPoint16); + size_t vertSize = 2 * sizeof(SkPoint); SkPoint* positions = reinterpret_cast<SkPoint*>(vertices); positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertSize); // vertex texture coords - intptr_t textureCoords = reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkIPoint16); - ((SkIPoint16*)(textureCoords + 0 * vertSize))->set(u0, v0); - ((SkIPoint16*)(textureCoords + 1 * vertSize))->set(u0, v1); - ((SkIPoint16*)(textureCoords + 2 * vertSize))->set(u1, v1); - ((SkIPoint16*)(textureCoords + 3 * vertSize))->set(u1, v0); + intptr_t intPtr = reinterpret_cast<intptr_t>(positions); + SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + 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); viewMatrix.mapRect(&r); target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp index 21afc61d84..5e5aa6a3cd 100755 --- a/src/gpu/GrBitmapTextContext.cpp +++ b/src/gpu/GrBitmapTextContext.cpp @@ -34,12 +34,12 @@ SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, "Dump the contents of the font cache before every purge."); namespace { -static const size_t kLCDTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); +static const size_t kLCDTextVASize = 2 * sizeof(SkPoint); // position + local coord -static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); +static const size_t kColorTextVASize = 2 * sizeof(SkPoint); -static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16); +static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor); static const int kVerticesPerGlyph = 4; static const int kIndicesPerGlyph = 6; @@ -421,8 +421,8 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed, vy += SkIntToFixed(glyph->fBounds.fTop); // keep them as ints until we've done the clip-test - int width = glyph->fBounds.width(); - int height = glyph->fBounds.height(); + SkFixed width = glyph->fBounds.width(); + SkFixed height = glyph->fBounds.height(); // check if we clipped out int x = vx >> 16; @@ -463,6 +463,10 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed, GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); glyph->fPlot->setDrawToken(drawToken); + // now promote them to fixed (TODO: Rethink using fixed pt). + width = SkIntToFixed(width); + height = SkIntToFixed(height); + // the current texture/maskformat must match what the glyph needs GrTexture* texture = glyph->fPlot->texture(); SkASSERT(texture); @@ -480,66 +484,39 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed, fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskFormat); } + SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); + SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); + SkRect r; r.fLeft = SkFixedToFloat(vx); r.fTop = SkFixedToFloat(vy); - r.fRight = r.fLeft + width; - r.fBottom = r.fTop + height; + r.fRight = SkFixedToFloat(vx + width); + r.fBottom = SkFixedToFloat(vy + height); fVertexBounds.joinNonEmptyArg(r); - - int u0 = glyph->fAtlasLocation.fX; - int v0 = glyph->fAtlasLocation.fY; - int u1 = u0 + width; - int v1 = v0 + height; size_t vertSize = get_vertex_stride(fCurrMaskFormat); - intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex; - // V0 - SkPoint* position = reinterpret_cast<SkPoint*>(vertex); - position->set(r.fLeft, r.fTop); - if (kA8_GrMaskFormat == fCurrMaskFormat) { - 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(r.fLeft, r.fBottom); - if (kA8_GrMaskFormat == fCurrMaskFormat) { - 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(r.fRight, r.fBottom); + SkPoint* positions = reinterpret_cast<SkPoint*>( + reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); + positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.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 + width)), + SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + height)), + vertSize); if (kA8_GrMaskFormat == fCurrMaskFormat) { - 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(r.fRight, r.fTop); - if (kA8_GrMaskFormat == fCurrMaskFormat) { - SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); - *color = fPaint.getColor(); + // 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); + } } - textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(SkIPoint16)); - textureCoords->set(u1, v0); - fCurrVertex += 4; } diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index ee87385048..d3b01703e4 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 ? (sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16)) : - (sizeof(SkPoint) + sizeof(SkIPoint16)); + return useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : + (2 * sizeof(SkPoint)); } static void* alloc_vertices(GrDrawTarget* drawTarget, @@ -600,59 +600,36 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, useColorVerts); } - fVertexBounds.joinNonEmptyArg(glyphRect); + 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); - 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; + fVertexBounds.joinNonEmptyArg(glyphRect); size_t vertSize = get_vertex_stride(useColorVerts); - intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex; - // V0 - SkPoint* position = reinterpret_cast<SkPoint*>(vertex); - position->set(glyphRect.fLeft, glyphRect.fTop); - if (useColorVerts) { - 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); + 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); 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(); + // 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); + } } - textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(SkIPoint16)); - textureCoords->set(u1, v0); fCurrVertex += 4; diff --git a/src/gpu/GrFontAtlasSizes.h b/src/gpu/GrFontAtlasSizes.h deleted file mode 100644 index 24897e4a7a..0000000000 --- a/src/gpu/GrFontAtlasSizes.h +++ /dev/null @@ -1,28 +0,0 @@ - -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrFontAtlasSizes_DEFINED -#define GrFontAtlasSizes_DEFINED - -#define GR_FONT_ATLAS_TEXTURE_WIDTH 1024 -#define GR_FONT_ATLAS_TEXTURE_HEIGHT 2048 - -#define GR_FONT_ATLAS_PLOT_WIDTH 256 -#define GR_FONT_ATLAS_PLOT_HEIGHT 256 - -#define GR_FONT_ATLAS_NUM_PLOTS_X (GR_FONT_ATLAS_TEXTURE_WIDTH / GR_FONT_ATLAS_PLOT_WIDTH) -#define GR_FONT_ATLAS_NUM_PLOTS_Y (GR_FONT_ATLAS_TEXTURE_HEIGHT / GR_FONT_ATLAS_PLOT_HEIGHT) - -// one over width and height -#define GR_FONT_ATLAS_RECIP_WIDTH "0.0009765625" -#define GR_FONT_ATLAS_RECIP_HEIGHT "0.00048828125" - -// 1/(3*width) -#define GR_FONT_ATLAS_LCD_DELTA "0.00032552083" - -#endif diff --git a/src/gpu/GrFontCache.cpp b/src/gpu/GrFontCache.cpp index 2bc5567c19..3e83e6c950 100644 --- a/src/gpu/GrFontCache.cpp +++ b/src/gpu/GrFontCache.cpp @@ -6,7 +6,6 @@ */ #include "GrFontCache.h" -#include "GrFontAtlasSizes.h" #include "GrGpu.h" #include "GrRectanizer.h" #include "GrSurfacePriv.h" @@ -16,6 +15,15 @@ /////////////////////////////////////////////////////////////////////////////// +#define GR_ATLAS_TEXTURE_WIDTH 1024 +#define GR_ATLAS_TEXTURE_HEIGHT 2048 + +#define GR_PLOT_WIDTH 256 +#define GR_PLOT_HEIGHT 256 + +#define GR_NUM_PLOTS_X (GR_ATLAS_TEXTURE_WIDTH / GR_PLOT_WIDTH) +#define GR_NUM_PLOTS_Y (GR_ATLAS_TEXTURE_HEIGHT / GR_PLOT_HEIGHT) + #define FONT_CACHE_STATS 0 #if FONT_CACHE_STATS static int g_PurgeCount = 0; @@ -113,12 +121,12 @@ GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* u GrPixelConfig config = mask_format_to_pixel_config(format); int atlasIndex = mask_format_to_atlas_index(format); if (NULL == fAtlases[atlasIndex]) { - SkISize textureSize = SkISize::Make(GR_FONT_ATLAS_TEXTURE_WIDTH, - GR_FONT_ATLAS_TEXTURE_HEIGHT); + SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH, + GR_ATLAS_TEXTURE_HEIGHT); fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSurfaceFlags, textureSize, - GR_FONT_ATLAS_NUM_PLOTS_X, - GR_FONT_ATLAS_NUM_PLOTS_Y, + GR_NUM_PLOTS_X, + GR_NUM_PLOTS_Y, true)); } return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc); @@ -281,10 +289,10 @@ bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) { int width = glyph->fBounds.width(); int height = glyph->fBounds.height(); int pad = fUseDistanceField ? 2 * SK_DistanceFieldPad : 0; - if (width + pad > GR_FONT_ATLAS_PLOT_WIDTH) { + if (width + pad > GR_PLOT_WIDTH) { return true; } - if (height + pad > GR_FONT_ATLAS_PLOT_HEIGHT) { + if (height + pad > GR_PLOT_HEIGHT) { return true; } diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp index 54e88917ad..2487b65ada 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.cpp +++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp @@ -6,7 +6,6 @@ */ #include "GrBitmapTextGeoProc.h" -#include "GrFontAtlasSizes.h" #include "GrInvariantOutput.h" #include "GrTexture.h" #include "gl/GrGLProcessor.h" @@ -38,10 +37,7 @@ public: GrGLVertToFrag v(kVec2f_GrSLType); pb->addVarying("TextureCoords", &v); - // this is only used with text, so our texture bounds always match the glyph atlas - vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", " - GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", v.vsOut(), - cte.inTextureCoords()->fName); + vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fName); // Setup pass through color this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, cte.inColor(), @@ -126,7 +122,7 @@ GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture, this->setHasVertexColor(); } fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", - kVec2s_GrVertexAttribType)); + kVec2f_GrVertexAttribType)); this->addTextureAccess(&fTextureAccess); } diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp index cdf998ed6a..1a8a07e3a2 100755 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp @@ -6,7 +6,6 @@ */ #include "GrDistanceFieldTextureEffect.h" -#include "GrFontAtlasSizes.h" #include "GrInvariantOutput.h" #include "GrTexture.h" #include "SkDistanceFieldGen.h" @@ -30,6 +29,7 @@ public: GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, const GrBatchTracker&) : fColor(GrColor_ILLEGAL) + , fTextureSize(SkISize::Make(-1,-1)) #ifdef SK_GAMMA_APPLY_TO_A8 , fLuminance(-1.0f) #endif @@ -49,16 +49,9 @@ public: // emit attributes vsBuilder->emitAttributes(dfTexEffect); - GrGLVertToFrag st(kVec2f_GrSLType); - args.fPB->addVarying("IntTextureCoords", &st); - vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); - - GrGLVertToFrag uv(kVec2f_GrSLType); - args.fPB->addVarying("TextureCoords", &uv); - // this is only used with text, so our texture bounds always match the glyph atlas - vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", " - GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), - dfTexEffect.inTextureCoords()->fName); + GrGLVertToFrag v(kVec2f_GrSLType); + args.fPB->addVarying("TextureCoords", &v); + vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName); // Setup pass through color this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, @@ -71,10 +64,15 @@ public: this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName, dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut); + const char* textureSizeUniName = NULL; + fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, + kVec2f_GrSLType, kDefault_GrSLPrecision, + "TextureSize", &textureSizeUniName); + // Use highp to work around aliasing issues fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, pb->ctxInfo().standard())); - fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); + fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn()); fsBuilder->codeAppend("\tfloat texColor = "); fsBuilder->appendTextureLookup(args.fSamplers[0], @@ -89,7 +87,7 @@ public: // to ensure we're mapping 1:1 from texel space to pixel space. fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, pb->ctxInfo().standard())); - fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); + fsBuilder->codeAppendf("vec2 st = uv*%s;\n", textureSizeUniName); fsBuilder->codeAppend("\tfloat afwidth;\n"); if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { // this gives us a smooth step across approximately one fragment @@ -139,6 +137,16 @@ public: virtual void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& proc, const GrBatchTracker& bt) SK_OVERRIDE { + SkASSERT(fTextureSizeUni.isValid()); + + GrTexture* texture = proc.texture(0); + if (texture->width() != fTextureSize.width() || + texture->height() != fTextureSize.height()) { + fTextureSize = SkISize::Make(texture->width(), texture->height()); + pdman.set2f(fTextureSizeUni, + SkIntToScalar(fTextureSize.width()), + SkIntToScalar(fTextureSize.height())); + } #ifdef SK_GAMMA_APPLY_TO_A8 const GrDistanceFieldTextureEffect& dfTexEffect = proc.cast<GrDistanceFieldTextureEffect>(); @@ -176,6 +184,8 @@ public: private: GrColor fColor; UniformHandle fColorUniform; + UniformHandle fTextureSizeUni; + SkISize fTextureSize; UniformHandle fLuminanceUni; #ifdef SK_GAMMA_APPLY_TO_A8 float fLuminance; @@ -212,7 +222,7 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color, this->setHasVertexColor(); } fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", - kVec2s_GrVertexAttribType)); + kVec2f_GrVertexAttribType)); this->addTextureAccess(&fTextureAccess); #ifdef SK_GAMMA_APPLY_TO_A8 this->addTextureAccess(&fGammaTextureAccess); @@ -316,7 +326,7 @@ class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { public: GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&, const GrBatchTracker&) - : fColor(GrColor_ILLEGAL) {} + : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = @@ -334,25 +344,15 @@ public: // emit attributes vsBuilder->emitAttributes(dfTexEffect); - GrGLVertToFrag st(kVec2f_GrSLType); - args.fPB->addVarying("IntTextureCoords", &st); - vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); - - const char* recipTextureSizeUniName = NULL; - fRecipTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kVertex_Visibility, - kVec2f_GrSLType, kDefault_GrSLPrecision, - "RecipTextureSize", &recipTextureSizeUniName); - GrGLVertToFrag uv(kVec2f_GrSLType); - args.fPB->addVarying("TextureCoords", &uv); - // this GP can be used with either text or paths, so texture bound params need to - // be set by a uniform - vsBuilder->codeAppendf("%s = %s*%s;", uv.vsOut(), recipTextureSizeUniName, - dfTexEffect.inTextureCoords()->fName); + GrGLVertToFrag v(kVec2f_GrSLType); + args.fPB->addVarying("TextureCoords", &v); // setup pass through color this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, dfTexEffect.inColor(), &fColorUniform); + vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName); + // Setup position this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEffect.viewMatrix()); @@ -360,10 +360,15 @@ public: this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName, dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut); + const char* textureSizeUniName = NULL; + fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, + kVec2f_GrSLType, kDefault_GrSLPrecision, + "TextureSize", &textureSizeUniName); + // Use highp to work around aliasing issues fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, pb->ctxInfo().standard())); - fsBuilder->codeAppendf("vec2 uv = %s;", uv.fsIn()); + fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); fsBuilder->codeAppend("float texColor = "); fsBuilder->appendTextureLookup(args.fSamplers[0], @@ -378,7 +383,7 @@ public: // to ensure we're mapping 1:1 from texel space to pixel space. fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, pb->ctxInfo().standard())); - fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn()); + fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); fsBuilder->codeAppend("float afwidth;"); if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { // this gives us a smooth step across approximately one fragment @@ -413,15 +418,15 @@ public: virtual void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& proc, const GrBatchTracker& bt) SK_OVERRIDE { - SkASSERT(fRecipTextureSizeUni.isValid()); + SkASSERT(fTextureSizeUni.isValid()); GrTexture* texture = proc.texture(0); if (texture->width() != fTextureSize.width() || texture->height() != fTextureSize.height()) { fTextureSize = SkISize::Make(texture->width(), texture->height()); - pdman.set2f(fRecipTextureSizeUni, - 1.0f/SkIntToScalar(fTextureSize.width()), - 1.0f/SkIntToScalar(fTextureSize.height())); + pdman.set2f(fTextureSizeUni, + SkIntToScalar(fTextureSize.width()), + SkIntToScalar(fTextureSize.height())); } this->setUniformViewMatrix(pdman, proc.viewMatrix()); @@ -452,7 +457,7 @@ public: private: UniformHandle fColorUniform; - UniformHandle fRecipTextureSizeUni; + UniformHandle fTextureSizeUni; GrColor fColor; SkISize fTextureSize; @@ -480,7 +485,7 @@ GrDistanceFieldNoGammaTextureEffect::GrDistanceFieldNoGammaTextureEffect( this->setHasVertexColor(); } fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", - kVec2s_GrVertexAttribType)); + kVec2f_GrVertexAttribType)); this->addTextureAccess(&fTextureAccess); } @@ -567,6 +572,7 @@ public: GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, const GrBatchTracker&) : fColor(GrColor_ILLEGAL) + , fTextureSize(SkISize::Make(-1,-1)) , fTextColor(GrColor_ILLEGAL) {} void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ @@ -580,17 +586,10 @@ public: // emit attributes vsBuilder->emitAttributes(dfTexEffect); - GrGLVertToFrag st(kVec2f_GrSLType); - args.fPB->addVarying("IntTextureCoords", &st); - vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); - - GrGLVertToFrag uv(kVec2f_GrSLType); - args.fPB->addVarying("TextureCoords", &uv); - // this is only used with text, so our texture bounds always match the glyph atlas - vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", " - GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), - dfTexEffect.inTextureCoords()->fName); - + GrGLVertToFrag v(kVec2f_GrSLType); + args.fPB->addVarying("TextureCoords", &v); + vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName); + // setup pass through color this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, &fColorUniform); @@ -602,6 +601,12 @@ public: this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName, dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut); + const char* textureSizeUniName = NULL; + // width, height, 1/(3*width) + fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, + kVec3f_GrSLType, kDefault_GrSLPrecision, + "TextureSize", &textureSizeUniName); + GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); SkAssertResult(fsBuilder->enableFeature( @@ -611,24 +616,18 @@ public: // Use highp to work around aliasing issues fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, pb->ctxInfo().standard())); - fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); + fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn()); fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, pb->ctxInfo().standard())); - fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); + fsBuilder->codeAppendf("vec2 st = uv*%s.xy;\n", textureSizeUniName); bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask); - - if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { - fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n"); - } else { - fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n"); - } if (isUniformScale) { fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n"); - fsBuilder->codeAppend("\tvec2 offset = vec2(dx*delta, 0.0);\n"); + fsBuilder->codeAppendf("\tvec2 offset = vec2(dx*%s.z, 0.0);\n", textureSizeUniName); } else { fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n"); fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n"); - fsBuilder->codeAppend("\tvec2 offset = delta*Jdx;\n"); + fsBuilder->codeAppendf("\tvec2 offset = %s.z*Jdx;\n", textureSizeUniName); } // green is distance to uv center @@ -689,6 +688,7 @@ public: // adjust based on gamma const char* textColorUniName = NULL; + // width, height, 1/(3*width) fTextColorUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, kVec3f_GrSLType, kDefault_GrSLPrecision, "TextColor", &textColorUniName); @@ -717,10 +717,25 @@ public: virtual void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& processor, const GrBatchTracker& bt) SK_OVERRIDE { + SkASSERT(fTextureSizeUni.isValid()); SkASSERT(fTextColorUni.isValid()); const GrDistanceFieldLCDTextureEffect& dfTexEffect = processor.cast<GrDistanceFieldLCDTextureEffect>(); + GrTexture* texture = processor.texture(0); + if (texture->width() != fTextureSize.width() || + texture->height() != fTextureSize.height()) { + fTextureSize = SkISize::Make(texture->width(), texture->height()); + float delta = 1.0f/(3.0f*texture->width()); + if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { + delta = -delta; + } + pdman.set3f(fTextureSizeUni, + SkIntToScalar(fTextureSize.width()), + SkIntToScalar(fTextureSize.height()), + delta); + } + GrColor textColor = dfTexEffect.getTextColor(); if (textColor != fTextColor) { static const float ONE_OVER_255 = 1.f / 255.f; @@ -760,6 +775,8 @@ public: private: GrColor fColor; UniformHandle fColorUniform; + UniformHandle fTextureSizeUni; + SkISize fTextureSize; UniformHandle fTextColorUni; SkColor fTextColor; @@ -783,7 +800,7 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( this->initClassID<GrDistanceFieldLCDTextureEffect>(); fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", - kVec2s_GrVertexAttribType)); + kVec2f_GrVertexAttribType)); this->addTextureAccess(&fTextureAccess); this->addTextureAccess(&fGammaTextureAccess); } diff --git a/src/gpu/gl/GrGLVertexArray.h b/src/gpu/gl/GrGLVertexArray.h index 4143ad4e3b..f795ed85d2 100644 --- a/src/gpu/gl/GrGLVertexArray.h +++ b/src/gpu/gl/GrGLVertexArray.h @@ -34,7 +34,6 @@ static inline const GrGLAttribLayout& GrGLAttribTypeToLayout(GrVertexAttribType {4, GR_GL_FLOAT, false}, // kVec4f_GrVertexAttribType {1, GR_GL_UNSIGNED_BYTE, true}, // kUByte_GrVertexAttribType {4, GR_GL_UNSIGNED_BYTE, true}, // kVec4ub_GrVertexAttribType - {2, GR_GL_SHORT, false}, // kVec2s_GrVertexAttribType }; GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); @@ -42,7 +41,6 @@ static inline const GrGLAttribLayout& GrGLAttribTypeToLayout(GrVertexAttribType GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); - GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayouts) == kGrVertexAttribTypeCount); return kLayouts[type]; } |