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 Review URL: https://codereview.chromium.org/917373002
This commit is contained in:
parent
0aa94798c9
commit
5a105ff053
@ -84,6 +84,7 @@
|
||||
'<(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',
|
||||
|
@ -116,9 +116,11 @@ 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
|
||||
|
||||
kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType
|
||||
kVec2s_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
|
||||
|
||||
kLast_GrVertexAttribType = kVec2s_GrVertexAttribType
|
||||
};
|
||||
static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
|
||||
|
||||
@ -127,7 +129,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 };
|
||||
static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2 };
|
||||
return kCounts[type];
|
||||
|
||||
GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
|
||||
@ -136,6 +138,7 @@ 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);
|
||||
}
|
||||
|
||||
@ -150,7 +153,8 @@ 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
|
||||
4*sizeof(char), // kVec4ub_GrVertexAttribType
|
||||
2*sizeof(int16_t) // kVec2s_GrVertexAttribType
|
||||
};
|
||||
return kSizes[type];
|
||||
|
||||
@ -160,6 +164,7 @@ 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);
|
||||
}
|
||||
|
||||
@ -173,6 +178,7 @@ 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:
|
||||
|
@ -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 = 2 * sizeof(SkPoint);
|
||||
static const size_t kLCDTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
|
||||
|
||||
// position + local coord
|
||||
static const size_t kColorTextVASize = 2 * sizeof(SkPoint);
|
||||
static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
|
||||
|
||||
static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor);
|
||||
static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
|
||||
|
||||
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
|
||||
SkFixed width = glyph->fBounds.width();
|
||||
SkFixed height = glyph->fBounds.height();
|
||||
int width = glyph->fBounds.width();
|
||||
int height = glyph->fBounds.height();
|
||||
|
||||
// check if we clipped out
|
||||
int x = vx >> 16;
|
||||
@ -463,10 +463,6 @@ 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);
|
||||
@ -484,39 +480,66 @@ 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 = SkFixedToFloat(vx + width);
|
||||
r.fBottom = SkFixedToFloat(vy + height);
|
||||
r.fRight = r.fLeft + width;
|
||||
r.fBottom = r.fTop + 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;
|
||||
|
||||
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);
|
||||
// V0
|
||||
SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
|
||||
position->set(r.fLeft, r.fTop);
|
||||
if (kA8_GrMaskFormat == fCurrMaskFormat) {
|
||||
// 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(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);
|
||||
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();
|
||||
}
|
||||
textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(SkIPoint16));
|
||||
textureCoords->set(u1, v0);
|
||||
|
||||
fCurrVertex += 4;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
28
src/gpu/GrFontAtlasSizes.h
Normal file
28
src/gpu/GrFontAtlasSizes.h
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
/*
|
||||
* 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
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "GrFontCache.h"
|
||||
#include "GrFontAtlasSizes.h"
|
||||
#include "GrGpu.h"
|
||||
#include "GrRectanizer.h"
|
||||
#include "GrSurfacePriv.h"
|
||||
@ -15,15 +16,6 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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;
|
||||
@ -121,12 +113,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_ATLAS_TEXTURE_WIDTH,
|
||||
GR_ATLAS_TEXTURE_HEIGHT);
|
||||
SkISize textureSize = SkISize::Make(GR_FONT_ATLAS_TEXTURE_WIDTH,
|
||||
GR_FONT_ATLAS_TEXTURE_HEIGHT);
|
||||
fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSurfaceFlags,
|
||||
textureSize,
|
||||
GR_NUM_PLOTS_X,
|
||||
GR_NUM_PLOTS_Y,
|
||||
GR_FONT_ATLAS_NUM_PLOTS_X,
|
||||
GR_FONT_ATLAS_NUM_PLOTS_Y,
|
||||
true));
|
||||
}
|
||||
return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc);
|
||||
@ -289,10 +281,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_PLOT_WIDTH) {
|
||||
if (width + pad > GR_FONT_ATLAS_PLOT_WIDTH) {
|
||||
return true;
|
||||
}
|
||||
if (height + pad > GR_PLOT_HEIGHT) {
|
||||
if (height + pad > GR_FONT_ATLAS_PLOT_HEIGHT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "GrBitmapTextGeoProc.h"
|
||||
#include "GrFontAtlasSizes.h"
|
||||
#include "GrInvariantOutput.h"
|
||||
#include "GrTexture.h"
|
||||
#include "gl/GrGLProcessor.h"
|
||||
@ -37,7 +38,10 @@ public:
|
||||
|
||||
GrGLVertToFrag v(kVec2f_GrSLType);
|
||||
pb->addVarying("TextureCoords", &v);
|
||||
vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fName);
|
||||
// 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);
|
||||
|
||||
// Setup pass through color
|
||||
this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, cte.inColor(),
|
||||
@ -122,7 +126,7 @@ GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture,
|
||||
this->setHasVertexColor();
|
||||
}
|
||||
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
|
||||
kVec2f_GrVertexAttribType));
|
||||
kVec2s_GrVertexAttribType));
|
||||
this->addTextureAccess(&fTextureAccess);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "GrDistanceFieldTextureEffect.h"
|
||||
#include "GrFontAtlasSizes.h"
|
||||
#include "GrInvariantOutput.h"
|
||||
#include "GrTexture.h"
|
||||
#include "SkDistanceFieldGen.h"
|
||||
@ -29,7 +30,6 @@ 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,9 +49,16 @@ public:
|
||||
// emit attributes
|
||||
vsBuilder->emitAttributes(dfTexEffect);
|
||||
|
||||
GrGLVertToFrag v(kVec2f_GrSLType);
|
||||
args.fPB->addVarying("TextureCoords", &v);
|
||||
vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName);
|
||||
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);
|
||||
|
||||
// Setup pass through color
|
||||
this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor,
|
||||
@ -64,15 +71,10 @@ 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", v.fsIn());
|
||||
fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
|
||||
|
||||
fsBuilder->codeAppend("\tfloat texColor = ");
|
||||
fsBuilder->appendTextureLookup(args.fSamplers[0],
|
||||
@ -87,7 +89,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 = uv*%s;\n", textureSizeUniName);
|
||||
fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
|
||||
fsBuilder->codeAppend("\tfloat afwidth;\n");
|
||||
if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
|
||||
// this gives us a smooth step across approximately one fragment
|
||||
@ -137,16 +139,6 @@ 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>();
|
||||
@ -184,10 +176,8 @@ public:
|
||||
private:
|
||||
GrColor fColor;
|
||||
UniformHandle fColorUniform;
|
||||
UniformHandle fTextureSizeUni;
|
||||
SkISize fTextureSize;
|
||||
UniformHandle fLuminanceUni;
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
UniformHandle fLuminanceUni;
|
||||
float fLuminance;
|
||||
#endif
|
||||
|
||||
@ -222,7 +212,7 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color,
|
||||
this->setHasVertexColor();
|
||||
}
|
||||
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
|
||||
kVec2f_GrVertexAttribType));
|
||||
kVec2s_GrVertexAttribType));
|
||||
this->addTextureAccess(&fTextureAccess);
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
this->addTextureAccess(&fGammaTextureAccess);
|
||||
@ -572,7 +562,6 @@ 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{
|
||||
@ -586,10 +575,17 @@ public:
|
||||
// emit attributes
|
||||
vsBuilder->emitAttributes(dfTexEffect);
|
||||
|
||||
GrGLVertToFrag v(kVec2f_GrSLType);
|
||||
args.fPB->addVarying("TextureCoords", &v);
|
||||
vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName);
|
||||
|
||||
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);
|
||||
|
||||
// setup pass through color
|
||||
this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL,
|
||||
&fColorUniform);
|
||||
@ -601,12 +597,6 @@ 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(
|
||||
@ -616,18 +606,24 @@ public:
|
||||
// Use highp to work around aliasing issues
|
||||
fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
|
||||
pb->ctxInfo().standard()));
|
||||
fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn());
|
||||
fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
|
||||
fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
|
||||
pb->ctxInfo().standard()));
|
||||
fsBuilder->codeAppendf("vec2 st = uv*%s.xy;\n", textureSizeUniName);
|
||||
fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
|
||||
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->codeAppendf("\tvec2 offset = vec2(dx*%s.z, 0.0);\n", textureSizeUniName);
|
||||
fsBuilder->codeAppend("\tvec2 offset = vec2(dx*delta, 0.0);\n");
|
||||
} else {
|
||||
fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n");
|
||||
fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n");
|
||||
fsBuilder->codeAppendf("\tvec2 offset = %s.z*Jdx;\n", textureSizeUniName);
|
||||
fsBuilder->codeAppend("\tvec2 offset = delta*Jdx;\n");
|
||||
}
|
||||
|
||||
// green is distance to uv center
|
||||
@ -688,7 +684,6 @@ 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,25 +712,10 @@ 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;
|
||||
@ -775,8 +755,6 @@ public:
|
||||
private:
|
||||
GrColor fColor;
|
||||
UniformHandle fColorUniform;
|
||||
UniformHandle fTextureSizeUni;
|
||||
SkISize fTextureSize;
|
||||
UniformHandle fTextColorUni;
|
||||
SkColor fTextColor;
|
||||
|
||||
@ -800,7 +778,7 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
|
||||
this->initClassID<GrDistanceFieldLCDTextureEffect>();
|
||||
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType));
|
||||
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
|
||||
kVec2f_GrVertexAttribType));
|
||||
kVec2s_GrVertexAttribType));
|
||||
this->addTextureAccess(&fTextureAccess);
|
||||
this->addTextureAccess(&fGammaTextureAccess);
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ 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);
|
||||
@ -41,6 +42,7 @@ 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];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user