From cc2d0730202f0d44d98c2d46292f95de26653846 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Thu, 17 Jun 2021 09:36:58 -0400 Subject: [PATCH] Remove SkPaint::getHash This was a particularly bad hash (A == B didn't imply hash(A) == hash(B)). It was also entirely unused. Change-Id: Id923bf1035effce04e12b1cc01d1c6aa4d11fdb6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/419336 Commit-Queue: Brian Osman Reviewed-by: Mike Reed --- RELEASE_NOTES.txt | 3 ++- docs/examples/Paint_getHash.cpp | 14 ------------- include/core/SkPaint.h | 16 -------------- src/core/SkPaint.cpp | 9 -------- tests/PaintTest.cpp | 21 ------------------- tools/fiddle/all_examples.cpp | 1 - tools/fiddle/documumentation_examples_map.txt | 4 ---- 7 files changed, 2 insertions(+), 66 deletions(-) delete mode 100644 docs/examples/Paint_getHash.cpp diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index d93866753c..e671525077 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -6,7 +6,8 @@ This file includes a list of high level updates for each milestone release. Milestone 93 ------------ - * + * Removed SkPaint::getHash + https://review.skia.org/419336 * * * diff --git a/docs/examples/Paint_getHash.cpp b/docs/examples/Paint_getHash.cpp deleted file mode 100644 index a23a1af81a..0000000000 --- a/docs/examples/Paint_getHash.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2019 Google LLC. -// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. -#include "tools/fiddle/examples.h" -// HASH=7f7e1b701361912b344f90ae6b530393 -REG_FIDDLE(Paint_getHash, 256, 256, true, 0) { -void draw(SkCanvas* canvas) { - SkPaint paint1, paint2; - paint1.setColor(SK_ColorRED); - paint2.setColor(0xFFFF0000); - SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); - SkDebugf("paint1.getHash() %c= paint2.getHash()\n", - paint1.getHash() == paint2.getHash() ? '=' : '!'); -} -} // END FIDDLE diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 9836d14774..cab1555770 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -144,22 +144,6 @@ public: return !(a == b); } - /** Returns a hash generated from SkPaint values and pointers. - Identical hashes guarantee that the paints are - equivalent, but differing hashes do not guarantee that the paints have differing - contents. - - If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints, - their hashes are also equal. - - The hash returned is platform and implementation specific. - - @return a shallow hash - - example: https://fiddle.skia.org/c/@Paint_getHash - */ - uint32_t getHash() const; - /** Sets all SkPaint contents to their initial values. This is equivalent to replacing SkPaint with the result of SkPaint(). diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 5047b83c81..de6e3c7ef1 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -439,12 +439,3 @@ bool SkPaint::nothingToDraw() const { } return false; } - -uint32_t SkPaint::getHash() const { - // We're going to hash 5 pointers and 6 floats, finishing up with fBitfields, - // so fBitfields should be 5 pointers and 6 floats from the start. - static_assert(offsetof(SkPaint, fBitfieldsUInt) == 5 * sizeof(void*) + 6 * sizeof(float), - "SkPaint_notPackedTightly"); - return SkOpts::hash(reinterpret_cast(this), - offsetof(SkPaint, fBitfieldsUInt) + sizeof(fBitfieldsUInt)); -} diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index c37bf1f1f1..560f020a59 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -31,7 +31,6 @@ DEF_TEST(Paint_copy, reporter) { // copy the paint using the copy constructor and check they are the same SkPaint copiedPaint = paint; - REPORTER_ASSERT(reporter, paint.getHash() == copiedPaint.getHash()); REPORTER_ASSERT(reporter, paint == copiedPaint); // copy the paint using the equal operator and check they are the same @@ -163,26 +162,6 @@ DEF_TEST(Paint_MoreFlattening, r) { ASSERT(other.getBlendMode() == paint.getBlendMode()); } -DEF_TEST(Paint_getHash, r) { - // Try not to inspect the actual hash values in here. - // We might want to change the hash function. - - SkPaint paint; - const uint32_t defaultHash = paint.getHash(); - - // Check that some arbitrary field affects the hash. - paint.setColor(0xFF00FF00); - REPORTER_ASSERT(r, paint.getHash() != defaultHash); - paint.setColor(SK_ColorBLACK); // Reset to default value. - REPORTER_ASSERT(r, paint.getHash() == defaultHash); - - // This is part of fBitfields, the last field we hash. - paint.setBlendMode(SkBlendMode::kSrc); - REPORTER_ASSERT(r, paint.getHash() != defaultHash); - paint.setBlendMode(SkBlendMode::kSrcOver); - REPORTER_ASSERT(r, paint.getHash() == defaultHash); -} - #include "include/effects/SkColorMatrixFilter.h" DEF_TEST(Paint_nothingToDraw, r) { diff --git a/tools/fiddle/all_examples.cpp b/tools/fiddle/all_examples.cpp index 4170533853..82c308aafb 100644 --- a/tools/fiddle/all_examples.cpp +++ b/tools/fiddle/all_examples.cpp @@ -530,7 +530,6 @@ #include "../../docs/examples/Paint_getFlags.cpp" #include "../../docs/examples/Paint_getFontMetrics.cpp" #include "../../docs/examples/Paint_getFontSpacing.cpp" -#include "../../docs/examples/Paint_getHash.cpp" #include "../../docs/examples/Paint_getHinting.cpp" #include "../../docs/examples/Paint_getImageFilter.cpp" #include "../../docs/examples/Paint_getMaskFilter.cpp" diff --git a/tools/fiddle/documumentation_examples_map.txt b/tools/fiddle/documumentation_examples_map.txt index d2d9928b5a..c768e2d943 100644 --- a/tools/fiddle/documumentation_examples_map.txt +++ b/tools/fiddle/documumentation_examples_map.txt @@ -2044,10 +2044,6 @@ SkScalar getFontMetrics(SkFontMetrics* metrics) const; SkPaint SkScalar getFontSpacing() const; -[Paint_getHash] -SkPaint -uint32_t getHash() const; - [Paint_getHinting] SkPaint SkFontHinting getHinting() const;