diff options
author | Brian Salomon <bsalomon@google.com> | 2017-02-22 13:49:09 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-22 19:28:12 +0000 |
commit | bc9956de31da06529b540918832f2435f884ac26 (patch) | |
tree | 2cfb21a296383c5a8de810f6d5a06ec4e9a53d46 | |
parent | e522f4c455d0d5dbe813f38d16c0d4cd46fa5dee (diff) |
Attempt to stabilize shadow_utils GM for replay configs
Change-Id: I0ed15ab102fa1e0a364d5f3a953bedd8afbda3c3
Reviewed-on: https://skia-review.googlesource.com/8853
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
-rw-r--r-- | gm/shadowutils.cpp | 9 | ||||
-rw-r--r-- | include/utils/SkShadowUtils.h | 1 | ||||
-rw-r--r-- | src/utils/SkShadowUtils.cpp | 8 |
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()); } |