Reland "Reland "Add new method for storing DrawOpAtlas texture index.""
This is a reland of dea2f34f09c3d0326b36099b406fa546f2b8fd96
Original change's description:
> Reland "Add new method for storing DrawOpAtlas texture index."
>
> This is a reland of c8b2e615400fe43b74dbbd2d7167bb97bd032f87
>
> Original change's description:
> > Add new method for storing DrawOpAtlas texture index.
> >
> > Storing the texture index in the lower bit of each texture coordinate
> > seems to have issues on certain iOS devices. Rather than do that, we
> > use the sign of the texture coordinate to act as our storage bit.
> > To manage encoding 0 we map [0, N] to [-1, -N-1] to represent a bit.
> >
> > Change-Id: Ic588ee92cf858915a1833cf482d4b23bd11c1000
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263561
> > Commit-Queue: Jim Van Verth <jvanverth@google.com>
> > Reviewed-by: Brian Osman <brianosman@google.com>
>
> Change-Id: I901502c3d83ff9727c51ad4447b0cee733257649
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/264566
> Reviewed-by: Jim Van Verth <jvanverth@google.com>
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
Change-Id: I000bb74ca57e321084ca2d1d9dc2f0274880c0da
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/264689
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 3ea483d..2951fa2 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -231,14 +231,14 @@
const size_t vertexStride = this->vertexStride();
const size_t texCoordOffset = this->texCoordOffset();
char* vertex = this->quadStart(begin);
- uint16_t* textureCoords = reinterpret_cast<uint16_t*>(vertex + texCoordOffset);
+ int16_t* textureCoords = reinterpret_cast<int16_t*>(vertex + texCoordOffset);
for (int i = begin; i < end; i++) {
GrGlyph* glyph = this->fGlyphs[i];
SkASSERT(glyph != nullptr);
int width = glyph->fBounds.width();
int height = glyph->fBounds.height();
- uint16_t u0, v0, u1, v1;
+ int16_t u0, v0, u1, v1;
if (this->drawAsDistanceFields()) {
u0 = glyph->fAtlasLocation.fX + SK_DistanceFieldInset;
v0 = glyph->fAtlasLocation.fY + SK_DistanceFieldInset;
@@ -251,32 +251,23 @@
v1 = v0 + height;
}
- // We pack the 2bit page index in the low bit of the u and v texture coords
+ // We pack the 2bit page index as the sign bit of the u and v texture coords
uint32_t pageIndex = glyph->pageIndex();
- SkASSERT(pageIndex < 4);
- uint16_t uBit = (pageIndex >> 1u) & 0x1u;
- uint16_t vBit = pageIndex & 0x1u;
- u0 <<= 1u;
- u0 |= uBit;
- v0 <<= 1u;
- v0 |= vBit;
- u1 <<= 1u;
- u1 |= uBit;
- v1 <<= 1u;
- v1 |= vBit;
+ std::tie(u0, v0) = GrDrawOpAtlas::PackIndexInTexCoords(u0, v0, pageIndex);
+ std::tie(u1, v1) = GrDrawOpAtlas::PackIndexInTexCoords(u1, v1, pageIndex);
textureCoords[0] = u0;
textureCoords[1] = v0;
- textureCoords = SkTAddOffset<uint16_t>(textureCoords, vertexStride);
+ textureCoords = SkTAddOffset<int16_t>(textureCoords, vertexStride);
textureCoords[0] = u0;
textureCoords[1] = v1;
- textureCoords = SkTAddOffset<uint16_t>(textureCoords, vertexStride);
+ textureCoords = SkTAddOffset<int16_t>(textureCoords, vertexStride);
textureCoords[0] = u1;
textureCoords[1] = v0;
- textureCoords = SkTAddOffset<uint16_t>(textureCoords, vertexStride);
+ textureCoords = SkTAddOffset<int16_t>(textureCoords, vertexStride);
textureCoords[0] = u1;
textureCoords[1] = v1;
- textureCoords = SkTAddOffset<uint16_t>(textureCoords, vertexStride);
+ textureCoords = SkTAddOffset<int16_t>(textureCoords, vertexStride);
}
}