Revert "Wrap page index packing in helper methods."
This reverts commit cb93a20d9a961219bad674d6c168bfde03a16246.
Reason for revert: Still seeing some corruption issues with Chrome text that may be related to this.
Original change's description:
> Wrap page index packing in helper methods.
>
> Also simplifies the shaders if we know there's only one atlas texture.
>
> Change-Id: I81063d423fd56cf91caee83ba9eae9d988aa249b
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266566
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
TBR=jvanverth@google.com,herb@google.com,brianosman@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I031f27c07929b1f66581ed8e94e1056d9107bf75
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266633
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp
index 63f60ea..6106828 100644
--- a/src/gpu/GrDrawOpAtlas.cpp
+++ b/src/gpu/GrDrawOpAtlas.cpp
@@ -20,10 +20,6 @@
#include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTracing.h"
-#ifdef DUMP_ATLAS_DATA
-static bool gDumpAtlasData = false;
-#endif
-
// When proxy allocation is deferred until flush time the proxies acting as atlases require
// special handling. This is because the usage that can be determined from the ops themselves
// isn't sufficient. Independent of the ops there will be ASAP and inline uploads to the
@@ -60,31 +56,9 @@
return atlas;
}
-// The two bits that make up the texture index are packed into the lower bits of the u and v
-// coordinate respectively.
-std::pair<uint16_t, uint16_t> GrDrawOpAtlas::PackIndexInTexCoords(uint16_t u, uint16_t v,
- int pageIndex) {
- SkASSERT(pageIndex >= 0 && pageIndex < 4);
- uint16_t uBit = (pageIndex >> 1u) & 0x1u;
- uint16_t vBit = pageIndex & 0x1u;
- u <<= 1u;
- u |= uBit;
- v <<= 1u;
- v |= vBit;
- return std::make_pair(u, v);
-}
-
-std::tuple<uint16_t, uint16_t, int> GrDrawOpAtlas::UnpackIndexFromTexCoords(uint16_t u,
- uint16_t v) {
- int pageIndex = 0;
- if (u & 0x1) {
- pageIndex |= 0x2;
- }
- if (v & 0x1) {
- pageIndex |= 0x1;
- }
- return std::make_tuple(u >> 1, v >> 1, pageIndex);
-}
+#ifdef DUMP_ATLAS_DATA
+static bool gDumpAtlasData = false;
+#endif
////////////////////////////////////////////////////////////////////////////////
GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX, int offY,
diff --git a/src/gpu/GrDrawOpAtlas.h b/src/gpu/GrDrawOpAtlas.h
index dce8f8f..0caebe4 100644
--- a/src/gpu/GrDrawOpAtlas.h
+++ b/src/gpu/GrDrawOpAtlas.h
@@ -102,24 +102,6 @@
EvictionCallback* evictor);
/**
- * Packs a texture atlas page index into the uint16 texture coordinates.
- * @param u U texture coordinate
- * @param v V texture coordinate
- * @param pageIndex index of the texture these coordinates apply to.
- Must be in the range [0, 3].
- * @return The new u and v coordinates with the packed value
- */
- static std::pair<uint16_t, uint16_t> PackIndexInTexCoords(uint16_t u, uint16_t v,
- int pageIndex);
- /**
- * Unpacks a texture atlas page index from uint16 texture coordinates.
- * @param u Packed U texture coordinate
- * @param v Packed V texture coordinate
- * @return The unpacked u and v coordinates with the page index.
- */
- static std::tuple<uint16_t, uint16_t, int> UnpackIndexFromTexCoords(uint16_t u, uint16_t v);
-
- /**
* Adds a width x height subimage to the atlas. Upon success it returns 'kSucceeded' and returns
* the ID and the subimage's coordinates in the backing texture. 'kTryAgain' is returned if
* the subimage cannot fit in the atlas without overwriting texels that will be read in the
diff --git a/src/gpu/effects/GrAtlasedShaderHelpers.h b/src/gpu/effects/GrAtlasedShaderHelpers.h
index e614eaa..edf8d9d 100644
--- a/src/gpu/effects/GrAtlasedShaderHelpers.h
+++ b/src/gpu/effects/GrAtlasedShaderHelpers.h
@@ -15,7 +15,6 @@
#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
static void append_index_uv_varyings(GrGLSLPrimitiveProcessor::EmitArgs& args,
- int numTextureSamplers,
const char* inTexCoordsName,
const char* atlasDimensionsInvName,
GrGLSLVarying* uv,
@@ -29,22 +28,14 @@
if (args.fShaderCaps->integerSupport()) {
args.fVertBuilder->codeAppendf("int2 signedCoords = int2(%s.x, %s.y);",
inTexCoordsName, inTexCoordsName);
+ args.fVertBuilder->codeAppend("int texIdx = 2*(signedCoords.x & 0x1) + (signedCoords.y & 0x1);");
args.fVertBuilder->codeAppend("float2 unormTexCoords = float2(signedCoords.x/2, signedCoords.y/2);");
- if (numTextureSamplers <= 1) {
- args.fVertBuilder->codeAppend("int texIdx = 0;");
- } else {
- args.fVertBuilder->codeAppend("int texIdx = 2*(signedCoords.x & 0x1) + (signedCoords.y & 0x1);");
- }
} else {
args.fVertBuilder->codeAppendf("float2 indexTexCoords = float2(%s.x, %s.y);",
inTexCoordsName, inTexCoordsName);
args.fVertBuilder->codeAppend("float2 unormTexCoords = floor(0.5*indexTexCoords);");
- if (numTextureSamplers <= 1) {
- args.fVertBuilder->codeAppend("float texIdx = 0;");
- } else {
- args.fVertBuilder->codeAppend("float2 diff = indexTexCoords - 2.0*unormTexCoords;");
- args.fVertBuilder->codeAppend("float texIdx = 2.0*diff.x + diff.y;");
- }
+ args.fVertBuilder->codeAppend("float2 diff = indexTexCoords - 2.0*unormTexCoords;");
+ args.fVertBuilder->codeAppend("float texIdx = 2.0*diff.x + diff.y;");
}
// Multiply by 1/atlasDimensions to get normalized texture coordinates
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index f3a6be4..48b2397 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -39,8 +39,8 @@
GrGLSLVarying uv(kFloat2_GrSLType);
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
- append_index_uv_varyings(args, btgp.numTextureSamplers(), btgp.inTextureCoords().name(),
- atlasDimensionsInvName, &uv, &texIdx, nullptr);
+ append_index_uv_varyings(args, btgp.inTextureCoords().name(), atlasDimensionsInvName, &uv,
+ &texIdx, nullptr);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
index f8cab87..0fe675a 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
@@ -70,9 +70,8 @@
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
GrGLSLVarying st(kFloat2_GrSLType);
- append_index_uv_varyings(args, dfTexEffect.numTextureSamplers(),
- dfTexEffect.inTextureCoords().name(), atlasDimensionsInvName, &uv,
- &texIdx, &st);
+ append_index_uv_varyings(args, dfTexEffect.inTextureCoords().name(), atlasDimensionsInvName,
+ &uv, &texIdx, &st);
bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask) ==
kUniformScale_DistanceFieldEffectMask;
@@ -348,9 +347,8 @@
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
GrGLSLVarying st(kFloat2_GrSLType);
- append_index_uv_varyings(args, dfPathEffect.numTextureSamplers(),
- dfPathEffect.inTextureCoords().name(), atlasDimensionsInvName, &uv,
- &texIdx, &st);
+ append_index_uv_varyings(args, dfPathEffect.inTextureCoords().name(),
+ atlasDimensionsInvName, &uv, &texIdx, &st);
// setup pass through color
varyingHandler->addPassThroughAttribute(dfPathEffect.inColor(), args.fOutputColor);
@@ -654,9 +652,8 @@
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
GrGLSLVarying st(kFloat2_GrSLType);
- append_index_uv_varyings(args, dfTexEffect.numTextureSamplers(),
- dfTexEffect.inTextureCoords().name(), atlasDimensionsInvName, &uv,
- &texIdx, &st);
+ append_index_uv_varyings(args, dfTexEffect.inTextureCoords().name(), atlasDimensionsInvName,
+ &uv, &texIdx, &st);
GrGLSLVarying delta(kFloat_GrSLType);
varyingHandler->addVarying("Delta", &delta);
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index 32530b1..f790870 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -197,16 +197,12 @@
auto* blobCoordsRB = reinterpret_cast<const uint16_t*>(blobVertices + 3 * vertexStride +
coordOffset);
// Pull out the texel coordinates and texture index bits
- uint16_t coordsRectL = blobCoordsLT[0];
- uint16_t coordsRectT = blobCoordsLT[1];
- uint16_t coordsRectR = blobCoordsRB[0];
- uint16_t coordsRectB = blobCoordsRB[1];
- int index0, index1;
- std::tie(coordsRectL, coordsRectT, index0) =
- GrDrawOpAtlas::UnpackIndexFromTexCoords(coordsRectL, coordsRectT);
- std::tie(coordsRectR, coordsRectB, index1) =
- GrDrawOpAtlas::UnpackIndexFromTexCoords(coordsRectR, coordsRectB);
- SkASSERT(index0 == index1);
+ uint16_t coordsRectL = blobCoordsLT[0] >> 1;
+ uint16_t coordsRectT = blobCoordsLT[1] >> 1;
+ uint16_t coordsRectR = blobCoordsRB[0] >> 1;
+ uint16_t coordsRectB = blobCoordsRB[1] >> 1;
+ uint16_t pageIndexX = blobCoordsLT[0] & 0x1;
+ uint16_t pageIndexY = blobCoordsLT[1] & 0x1;
int positionRectWidth = positionRect.width();
int positionRectHeight = positionRect.height();
@@ -232,10 +228,10 @@
positionRect.fBottom -= delta;
// Repack texel coordinates and index
- std::tie(coordsRectL, coordsRectT) =
- GrDrawOpAtlas::PackIndexInTexCoords(coordsRectL, coordsRectT, index0);
- std::tie(coordsRectR, coordsRectB) =
- GrDrawOpAtlas::PackIndexInTexCoords(coordsRectR, coordsRectB, index1);
+ coordsRectL = coordsRectL << 1 | pageIndexX;
+ coordsRectT = coordsRectT << 1 | pageIndexY;
+ coordsRectR = coordsRectR << 1 | pageIndexX;
+ coordsRectB = coordsRectB << 1 | pageIndexY;
// Set new positions and coords
SkPoint* currPosition = reinterpret_cast<SkPoint*>(currVertex);
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index e2dadd9..7527e39 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -620,19 +620,17 @@
shapeData->fBounds.fRight /= scale;
shapeData->fBounds.fBottom /= scale;
- // Pack the page index into the u and v texture coords
+ // We pack the 2bit page index in the low bit of the u and v texture coords
uint16_t pageIndex = GrDrawOpAtlas::GetPageIndexFromID(id);
- uint16_t left, top, right, bottom;
- std::tie(left, top, right, bottom) =
- std::make_tuple(atlasLocation.fX + SK_DistanceFieldPad,
- atlasLocation.fY + SK_DistanceFieldPad,
- atlasLocation.fX + SK_DistanceFieldPad + devPathBounds.width(),
- atlasLocation.fY + SK_DistanceFieldPad + devPathBounds.height());
- std::tie(left, top) =
- GrDrawOpAtlas::PackIndexInTexCoords(left, top, pageIndex);
- std::tie(right, bottom) =
- GrDrawOpAtlas::PackIndexInTexCoords(right, bottom, pageIndex);
- shapeData->fTextureCoords.set(left, top, right, bottom);
+ SkASSERT(pageIndex < 4);
+ uint16_t uBit = (pageIndex >> 1) & 0x1;
+ uint16_t vBit = pageIndex & 0x1;
+ shapeData->fTextureCoords.set((atlasLocation.fX+SK_DistanceFieldPad) << 1 | uBit,
+ (atlasLocation.fY+SK_DistanceFieldPad) << 1 | vBit,
+ (atlasLocation.fX+SK_DistanceFieldPad+
+ devPathBounds.width()) << 1 | uBit,
+ (atlasLocation.fY+SK_DistanceFieldPad+
+ devPathBounds.height()) << 1 | vBit);
fShapeCache->add(shapeData);
fShapeList->addToTail(shapeData);
@@ -720,17 +718,14 @@
shapeData->fBounds = SkRect::Make(devPathBounds);
shapeData->fBounds.offset(-translateX, -translateY);
- // Pack the page index into the u and v texture coords
+ // We pack the 2bit page index in the low bit of the u and v texture coords
uint16_t pageIndex = GrDrawOpAtlas::GetPageIndexFromID(id);
- uint16_t left, top, right, bottom;
- std::tie(left, top, right, bottom) = std::make_tuple(atlasLocation.fX, atlasLocation.fY,
- atlasLocation.fX+width,
- atlasLocation.fY+height);
- std::tie(left, top) =
- GrDrawOpAtlas::PackIndexInTexCoords(left, top, pageIndex);
- std::tie(right, bottom) =
- GrDrawOpAtlas::PackIndexInTexCoords(right, bottom, pageIndex);
- shapeData->fTextureCoords.set(left, top, right, bottom);
+ SkASSERT(pageIndex < 4);
+ uint16_t uBit = (pageIndex >> 1) & 0x1;
+ uint16_t vBit = pageIndex & 0x1;
+ shapeData->fTextureCoords.set(atlasLocation.fX << 1 | uBit, atlasLocation.fY << 1 | vBit,
+ (atlasLocation.fX+width) << 1 | uBit,
+ (atlasLocation.fY+height) << 1 | vBit);
fShapeCache->add(shapeData);
fShapeList->addToTail(shapeData);
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index df9862d..c5f8797 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -253,8 +253,17 @@
// We pack the 2bit page index in the low bit of the u and v texture coords
uint32_t pageIndex = glyph->pageIndex();
- std::tie(u0, v0) = GrDrawOpAtlas::PackIndexInTexCoords(u0, v0, pageIndex);
- std::tie(u1, v1) = GrDrawOpAtlas::PackIndexInTexCoords(u1, v1, 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;
textureCoords[0] = u0;
textureCoords[1] = v0;