Skip spinlock overhead on Android
authormsarett <msarett@google.com>
Mon, 29 Aug 2016 21:52:24 +0000 (14:52 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 29 Aug 2016 21:52:24 +0000 (14:52 -0700)
Using the spinlock is only necessary when we multiple threads
might use a GrContext.  Android uses the GrContext from a
single thread, so these locks are not needed.

This is a temporary fix until we can refactor to avoid
creating GrContexts in a global memory pool.

BUG=skia:5696
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2293633003

Review-Url: https://codereview.chromium.org/2293633003

src/gpu/GrProcessor.cpp
src/gpu/batches/GrBatch.cpp

index 29482cc..b945b02 100644 (file)
@@ -84,9 +84,15 @@ namespace {
 static SkSpinlock gProcessorSpinlock;
 class MemoryPoolAccessor {
 public:
-    MemoryPoolAccessor() { gProcessorSpinlock.acquire(); }
 
+// We know in the Android framework there is only one GrContext.
+#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
+    MemoryPoolAccessor() {}
+    ~MemoryPoolAccessor() {}
+#else
+    MemoryPoolAccessor() { gProcessorSpinlock.acquire(); }
     ~MemoryPoolAccessor() { gProcessorSpinlock.release(); }
+#endif
 
     GrMemoryPool* pool() const {
         static GrMemoryPool gPool(4096, 4096);
index 50f94b3..6755cf9 100644 (file)
@@ -23,9 +23,15 @@ namespace {
 static SkSpinlock gBatchSpinlock;
 class MemoryPoolAccessor {
 public:
-    MemoryPoolAccessor() { gBatchSpinlock.acquire(); }
 
+// We know in the Android framework there is only one GrContext.
+#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
+    MemoryPoolAccessor() {}
+    ~MemoryPoolAccessor() {}
+#else
+    MemoryPoolAccessor() { gBatchSpinlock.acquire(); }
     ~MemoryPoolAccessor() { gBatchSpinlock.release(); }
+#endif
 
     GrMemoryPool* pool() const {
         static GrMemoryPool gPool(16384, 16384);