Add perspective matrix equality to GrTextBlob::Key

This will allow text blobs to be removed from GrTextBlobRedrawCoordinator
when they have perspective transformations.

Bug: skia:12966
Change-Id: I53d2a7f5ea1ba0560b49c2f6bb4c62ffa564dcc8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/540737
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Callum Moffat 2022-05-16 11:59:11 -04:00 committed by SkCQ
parent 48cc723716
commit b647498072
4 changed files with 35 additions and 2 deletions

View File

@ -17,6 +17,7 @@ Amazon, Inc <*@amazon.com>
Anthony Catel <paraboul@gmail.com>
ARM <*@arm.com>
Bharat Ahuja <ahujabharat93@gmail.com>
Callum Moffat <smartercallum@gmail.com>
Casey Banner <kcbanner@gmail.com>
Dawson Coleman <dawsonmcoleman@gmail.com>
Deepak Mohan <hop2deep@gmail.com>

View File

@ -2149,9 +2149,12 @@ bool GrTextBlob::Key::operator==(const GrTextBlob::Key& that) const {
}
if (fScalerContextFlags != that.fScalerContextFlags) { return false; }
// Just punt on perspective.
if (fPositionMatrix.hasPerspective()) {
return false;
if (fPositionMatrix[SkMatrix::kMPersp0] != that.fPositionMatrix[SkMatrix::kMPersp0] ||
fPositionMatrix[SkMatrix::kMPersp1] != that.fPositionMatrix[SkMatrix::kMPersp1] ||
fPositionMatrix[SkMatrix::kMPersp2] != that.fPositionMatrix[SkMatrix::kMPersp2]) {
return false;
}
}
if (fHasSomeDirectSubRuns != that.fHasSomeDirectSubRuns) {

View File

@ -2675,9 +2675,11 @@ generated_cc_atom(
":Test_hdr",
"//include/core:SkBitmap_hdr",
"//include/core:SkCanvas_hdr",
"//include/core:SkColorSpace_hdr",
"//include/core:SkSurface_hdr",
"//include/core:SkTextBlob_hdr",
"//src/core:SkSurfacePriv_hdr",
"//src/gpu/ganesh:GrColorInfo_hdr",
"//src/gpu/ganesh/text:GrTextBlob_hdr",
"//tools:ToolUtils_hdr",
],

View File

@ -7,9 +7,11 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTextBlob.h"
#include "src/core/SkSurfacePriv.h"
#include "src/gpu/ganesh/GrColorInfo.h"
#include "src/gpu/ganesh/text/GrTextBlob.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
@ -323,3 +325,28 @@ DEF_TEST(SubRunAllocator, r) {
REPORTER_ASSERT(r, ((intptr_t)ptr & 7) == 0);
}
}
DEF_TEST(KeyEqualityOnPerspective, r) {
SkTextBlobBuilder builder;
SkFont font(SkTypeface::MakeDefault(), 16);
builder.allocRun(font, 1, 0.0f, 0.0f);
auto blob = builder.make();
SkGlyphRunBuilder grBuilder;
auto glyphRunList = grBuilder.blobToGlyphRunList(*blob, {100, 100});
SkPaint paint;
SkSurfaceProps props;
GrColorInfo colorInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr);
SkMatrix matrix1;
matrix1.setAll(1, 0, 0, 0, 1, 0, 1, 1, 1);
SkMatrix matrix2;
matrix2.setAll(1, 0, 0, 0, 1, 0, 2, 2, 1);
GrSDFTControl control(false, false, 1, 100);
auto key1 = std::get<1>(
GrTextBlob::Key::Make(glyphRunList, paint, props, colorInfo, matrix1, control));
auto key2 = std::get<1>(
GrTextBlob::Key::Make(glyphRunList, paint, props, colorInfo, matrix1, control));
auto key3 = std::get<1>(
GrTextBlob::Key::Make(glyphRunList, paint, props, colorInfo, matrix2, control));
REPORTER_ASSERT(r, key1 == key2);
REPORTER_ASSERT(r, !(key1 == key3));
}