Do vertex color adjustment before atlas calculations

The atlas calculations and the color adjustment are do not interact, and
this has to happen no matter how many times the atlas is adjusted.

Change-Id: I571ca4bf18b133bea390787e5f58aef6334bdedb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261543
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Herb Derby 2019-12-26 15:23:49 -05:00 committed by Skia Commit-Bot
parent 91fd46a0f9
commit 6ca4f31896
2 changed files with 21 additions and 21 deletions

View File

@ -110,6 +110,7 @@ public:
bool needsTransform() const; bool needsTransform() const;
void updateTranslation(SkVector translation); void updateTranslation(SkVector translation);
void updateColor(GrColor newColor);
// df properties // df properties
void setUseLCDText(bool useLCDText); void setUseLCDText(bool useLCDText);
@ -281,8 +282,8 @@ bool GrTextBlob::SubRun::hasW() const {
void GrTextBlob::SubRun::updateTranslation(SkVector translation) { void GrTextBlob::SubRun::updateTranslation(SkVector translation) {
size_t vertexStride = this->vertexStride(); size_t vertexStride = this->vertexStride();
for(size_t i = 0; i < fGlyphs.size(); i++) { for(size_t quad = 0; quad < fGlyphs.size(); quad++) {
SkPoint* vertexCursor = reinterpret_cast<SkPoint*>(quadStart(i)); SkPoint* vertexCursor = reinterpret_cast<SkPoint*>(quadStart(quad));
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
*vertexCursor += translation; *vertexCursor += translation;
vertexCursor = SkTAddOffset<SkPoint>(vertexCursor, vertexStride); vertexCursor = SkTAddOffset<SkPoint>(vertexCursor, vertexStride);
@ -290,6 +291,19 @@ void GrTextBlob::SubRun::updateTranslation(SkVector translation) {
} }
} }
void GrTextBlob::SubRun::updateColor(GrColor newColor) {
size_t vertexStride = this->vertexStride();
size_t colorOffset = this->colorOffset();
for(size_t quad = 0; quad < fGlyphs.size(); quad++) {
GrColor* colorCursor = SkTAddOffset<GrColor>(quadStart(quad), colorOffset);
for (int i = 0; i < 4; ++i) {
*colorCursor = newColor;
colorCursor = SkTAddOffset<GrColor>(colorCursor, vertexStride);
}
}
this->fColor = newColor;
}
void GrTextBlob::SubRun::setUseLCDText(bool useLCDText) { fFlags.useLCDText = useLCDText; } void GrTextBlob::SubRun::setUseLCDText(bool useLCDText) { fFlags.useLCDText = useLCDText; }
bool GrTextBlob::SubRun::hasUseLCDText() const { return fFlags.useLCDText; } bool GrTextBlob::SubRun::hasUseLCDText() const { return fFlags.useLCDText; }
void GrTextBlob::SubRun::setAntiAliased(bool antiAliased) { fFlags.antiAliased = antiAliased; } void GrTextBlob::SubRun::setAntiAliased(bool antiAliased) { fFlags.antiAliased = antiAliased; }
@ -786,17 +800,6 @@ void GrTextBlob::processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawab
} }
// -- GrTextBlob::VertexRegenerator ---------------------------------------------------------------- // -- GrTextBlob::VertexRegenerator ----------------------------------------------------------------
static void regen_colors(char* vertex, size_t vertexStride, GrColor color) {
// This is a bit wonky, but sometimes we have LCD text, in which case we won't have color
// vertices, hence vertexStride - sizeof(SkIPoint16)
size_t colorOffset = vertexStride - sizeof(SkIPoint16) - sizeof(GrColor);
GrColor* vcolor = reinterpret_cast<GrColor*>(vertex + colorOffset);
for (int i = 0; i < 4; ++i) {
*vcolor = color;
vcolor = SkTAddOffset<GrColor>(vcolor, vertexStride);
}
}
static void regen_texcoords(char* vertex, size_t vertexStride, const GrGlyph* glyph, static void regen_texcoords(char* vertex, size_t vertexStride, const GrGlyph* glyph,
bool useDistanceFields) { bool useDistanceFields) {
// This is a bit wonky, but sometimes we have LCD text, in which case we won't have color // This is a bit wonky, but sometimes we have LCD text, in which case we won't have color
@ -899,7 +902,9 @@ GrTextBlob::VertexRegenerator::VertexRegenerator(GrResourceProvider* resourcePro
// updating our cache of the GrGlyph*s, we drop our ref on the old strike // updating our cache of the GrGlyph*s, we drop our ref on the old strike
fActions.regenTextureCoordinates = fSubRun->strike()->isAbandoned(); fActions.regenTextureCoordinates = fSubRun->strike()->isAbandoned();
fActions.regenStrike = fSubRun->strike()->isAbandoned(); fActions.regenStrike = fSubRun->strike()->isAbandoned();
fActions.regenColor = kARGB_GrMaskFormat != fSubRun->maskFormat() && fSubRun->color() != color; if (kARGB_GrMaskFormat != fSubRun->maskFormat() && fSubRun->color() != color) {
fSubRun->updateColor(color);
}
if (fDrawTranslation.x() != 0.f || fDrawTranslation.y() != 0.f) { if (fDrawTranslation.x() != 0.f || fDrawTranslation.y() != 0.f) {
fSubRun->updateTranslation(fDrawTranslation); fSubRun->updateTranslation(fDrawTranslation);
} }
@ -966,9 +971,6 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
tokenTracker->nextDrawToken()); tokenTracker->nextDrawToken());
} }
if (fActions.regenColor) {
regen_colors(currVertex, vertexStride, fColor);
}
if (fActions.regenTextureCoordinates) { if (fActions.regenTextureCoordinates) {
regen_texcoords(currVertex, vertexStride, glyph, fSubRun->drawAsDistanceFields()); regen_texcoords(currVertex, vertexStride, glyph, fSubRun->drawAsDistanceFields());
} }
@ -1000,8 +1002,7 @@ bool GrTextBlob::VertexRegenerator::regenerate(GrTextBlob::VertexRegenerator::Re
fActions.regenTextureCoordinates |= fSubRun->atlasGeneration() != currentAtlasGen; fActions.regenTextureCoordinates |= fSubRun->atlasGeneration() != currentAtlasGen;
if (fActions.regenStrike if (fActions.regenStrike
|fActions.regenTextureCoordinates |fActions.regenTextureCoordinates) {
|fActions.regenColor) {
return this->doRegen(result); return this->doRegen(result);
} else { } else {
auto vertexStride = fSubRun->vertexStride(); auto vertexStride = fSubRun->vertexStride();

View File

@ -332,10 +332,9 @@ private:
GrColor fColor; GrColor fColor;
SkVector fDrawTranslation; SkVector fDrawTranslation;
struct { struct {
bool regenColor:1;
bool regenTextureCoordinates:1; bool regenTextureCoordinates:1;
bool regenStrike:1; bool regenStrike:1;
} fActions = {false, false, false}; } fActions = {false, false};
int fCurrGlyph = 0; int fCurrGlyph = 0;
bool fBrokenRun = false; bool fBrokenRun = false;
}; };