aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkThreadedBMPDevice.h
diff options
context:
space:
mode:
authorGravatar Yuqian Li <liyuqian@google.com>2018-02-15 11:19:55 +0800
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-21 09:28:04 +0000
commitaefcccb5d84fb0e0cb8161d4021e8fbd724e2d9e (patch)
tree2a4f50a0abf549dd6d38782a221a849e288458b3 /src/core/SkThreadedBMPDevice.h
parent9fd8eb6fecb1d807809e2e58aa35a2f349ff9c2b (diff)
Enable DAA in the init-once phase of threaded backends
Bug: skia: Change-Id: Idb856fe12f0f9fa1014e7d15ef40bd7b456634d6 Reviewed-on: https://skia-review.googlesource.com/107540 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Yuqian Li <liyuqian@google.com>
Diffstat (limited to 'src/core/SkThreadedBMPDevice.h')
-rw-r--r--src/core/SkThreadedBMPDevice.h21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/core/SkThreadedBMPDevice.h b/src/core/SkThreadedBMPDevice.h
index a33715e340..c2e1aa375d 100644
--- a/src/core/SkThreadedBMPDevice.h
+++ b/src/core/SkThreadedBMPDevice.h
@@ -74,19 +74,26 @@ private:
, fDrawBounds(device->transformDrawBounds(rawDrawBounds)) {}
DrawElement(SkThreadedBMPDevice* device, InitFn&& initFn, const SkRect& rawDrawBounds)
: fInitialized(false)
+ , fNeedInit(true)
, fInitFn(std::move(initFn))
, fDS(device)
, fDrawBounds(device->transformDrawBounds(rawDrawBounds)) {}
SK_ALWAYS_INLINE bool tryInitOnce(SkArenaAlloc* alloc) {
- if (fInitialized) {
- return false;
- }
- std::call_once(fNeedInit, [this, alloc]{
+ bool t = true;
+ // If there are multiple threads reaching this point simutaneously,
+ // compare_exchange_strong ensures that only one thread can enter the if condition and
+ // do the initialization.
+ if (!fInitialized && fNeedInit && fNeedInit.compare_exchange_strong(t, false)) {
+#ifdef SK_DEBUG
+ fDrawFn = 0; // Invalidate fDrawFn
+#endif
fInitFn(alloc, this);
fInitialized = true;
- });
- return true;
+ SkASSERT(fDrawFn != 0); // Ensure that fInitFn does populate fDrawFn
+ return true;
+ }
+ return false;
}
SK_ALWAYS_INLINE bool tryDraw(const SkIRect& tileBounds, SkArenaAlloc* alloc) {
@@ -105,7 +112,7 @@ private:
private:
std::atomic<bool> fInitialized;
- std::once_flag fNeedInit;
+ std::atomic<bool> fNeedInit;
InitFn fInitFn;
DrawFn fDrawFn;
DrawState fDS;