aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/shadowutils.cpp9
-rw-r--r--include/utils/SkShadowUtils.h1
-rw-r--r--src/utils/SkShadowUtils.cpp8
3 files changed, 17 insertions, 1 deletions
diff --git a/gm/shadowutils.cpp b/gm/shadowutils.cpp
index 96554f10e7..fd02d92133 100644
--- a/gm/shadowutils.cpp
+++ b/gm/shadowutils.cpp
@@ -8,6 +8,7 @@
#include "gm.h"
#include "SkCanvas.h"
#include "SkPath.h"
+#include "SkMutex.h"
#include "SkShadowUtils.h"
void draw_shadow(SkCanvas* canvas, const SkPath& path, int height, SkColor color, SkPoint3 lightPos,
@@ -22,6 +23,14 @@ static constexpr int kW = 700;
static constexpr int kH = 800;
DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) {
+ // SkShadowUtils uses a cache of SkVertices meshes. The vertices are created in a local
+ // coordinate system and then translated when reused. The coordinate system depends on
+ // parameters to the generating draw. To avoid slight rendering differences due to this property
+ // we only allow one thread into this GM at a time and we reset the cache before each run.
+ static SkMutex gMutex;
+ SkAutoMutexAcquire mutexLock(&gMutex);
+ SkShadowUtils::ClearCache();
+
SkTArray<SkPath> paths;
paths.push_back().addRoundRect(SkRect::MakeWH(50, 50), 10, 10);
SkRRect oddRRect;
diff --git a/include/utils/SkShadowUtils.h b/include/utils/SkShadowUtils.h
index 795c2cf2ce..60ce6ffe30 100644
--- a/include/utils/SkShadowUtils.h
+++ b/include/utils/SkShadowUtils.h
@@ -22,6 +22,7 @@ public:
const SkPoint3& lightPos, SkScalar lightRadius,
SkScalar ambientAlpha, SkScalar spotAlpha, SkColor color,
uint32_t flags = SkShadowFlags::kNone_ShadowFlag);
+ static void ClearCache();
};
#endif
diff --git a/src/utils/SkShadowUtils.cpp b/src/utils/SkShadowUtils.cpp
index 8374aef68f..86aba797d6 100644
--- a/src/utils/SkShadowUtils.cpp
+++ b/src/utils/SkShadowUtils.cpp
@@ -83,6 +83,10 @@ sk_sp<GrFragmentProcessor> SkGaussianColorFilter::asFragmentProcessor(GrContext*
namespace {
+uint64_t resource_cache_shared_id() {
+ return 0x2020776f64616873llu; // 'shadow '
+}
+
/** Factory for an ambient shadow mesh with particular shadow properties. */
struct AmbientVerticesFactory {
SkScalar fRadius = SK_ScalarNaN; // NaN so that isCompatible will always fail until init'ed.
@@ -381,7 +385,7 @@ void draw_shadow(const FACTORY& factory, SkCanvas* canvas, ShadowedPath& path, S
keyStorage.reset(keyDataBytes + sizeof(SkResourceCache::Key));
key = new (keyStorage.begin()) SkResourceCache::Key();
path.writeKey((uint32_t*)(keyStorage.begin() + sizeof(*key)));
- key->init(&kNamespace, 0, keyDataBytes);
+ key->init(&kNamespace, resource_cache_shared_id(), keyDataBytes);
SkResourceCache::Find(*key, FindVisitor<FACTORY>, &context);
}
@@ -522,3 +526,5 @@ void SkShadowUtils::DrawShadow(SkCanvas* canvas, const SkPath& path, SkScalar oc
draw_shadow(factory, canvas, shadowedPath, color);
}
}
+
+void SkShadowUtils::ClearCache() { SkResourceCache::PostPurgeSharedID(resource_cache_shared_id()); }