Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: src/gpu/batches/GrBatch.cpp

Issue 2293633003: Skip spinlock overhead on Android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrProcessor.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBatch.h" 8 #include "GrBatch.h"
9 9
10 #include "GrMemoryPool.h" 10 #include "GrMemoryPool.h"
11 #include "SkSpinlock.h" 11 #include "SkSpinlock.h"
12 12
13 // TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small, 13 // TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small,
14 // but seems to be mostly consistent. There is a lot in flux right now, but we should really 14 // but seems to be mostly consistent. There is a lot in flux right now, but we should really
15 // revisit this when batch is everywhere 15 // revisit this when batch is everywhere
16 16
17 17
18 // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on 18 // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
19 // different threads. The GrContext is not used concurrently on different thread s and there is a 19 // different threads. The GrContext is not used concurrently on different thread s and there is a
20 // memory barrier between accesses of a context on different threads. Also, ther e may be multiple 20 // memory barrier between accesses of a context on different threads. Also, ther e may be multiple
21 // GrContexts and those contexts may be in use concurrently on different threads . 21 // GrContexts and those contexts may be in use concurrently on different threads .
22 namespace { 22 namespace {
23 static SkSpinlock gBatchSpinlock; 23 static SkSpinlock gBatchSpinlock;
24 class MemoryPoolAccessor { 24 class MemoryPoolAccessor {
25 public: 25 public:
26
27 // We know in the Android framework there is only one GrContext.
28 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
29 MemoryPoolAccessor() {}
30 ~MemoryPoolAccessor() {}
31 #else
26 MemoryPoolAccessor() { gBatchSpinlock.acquire(); } 32 MemoryPoolAccessor() { gBatchSpinlock.acquire(); }
27
28 ~MemoryPoolAccessor() { gBatchSpinlock.release(); } 33 ~MemoryPoolAccessor() { gBatchSpinlock.release(); }
34 #endif
29 35
30 GrMemoryPool* pool() const { 36 GrMemoryPool* pool() const {
31 static GrMemoryPool gPool(16384, 16384); 37 static GrMemoryPool gPool(16384, 16384);
32 return &gPool; 38 return &gPool;
33 } 39 }
34 }; 40 };
35 } 41 }
36 42
37 int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchID; 43 int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchID;
38 44
39 int32_t GrBatch::gCurrBatchUniqueID = GrBatch::kIllegalBatchID; 45 int32_t GrBatch::gCurrBatchUniqueID = GrBatch::kIllegalBatchID;
40 46
41 void* GrBatch::operator new(size_t size) { 47 void* GrBatch::operator new(size_t size) {
42 return MemoryPoolAccessor().pool()->allocate(size); 48 return MemoryPoolAccessor().pool()->allocate(size);
43 } 49 }
44 50
45 void GrBatch::operator delete(void* target) { 51 void GrBatch::operator delete(void* target) {
46 return MemoryPoolAccessor().pool()->release(target); 52 return MemoryPoolAccessor().pool()->release(target);
47 } 53 }
48 54
49 GrBatch::GrBatch(uint32_t classID) 55 GrBatch::GrBatch(uint32_t classID)
50 : fClassID(classID) 56 : fClassID(classID)
51 , fUniqueID(kIllegalBatchID) { 57 , fUniqueID(kIllegalBatchID) {
52 SkASSERT(classID == SkToU32(fClassID)); 58 SkASSERT(classID == SkToU32(fClassID));
53 SkDEBUGCODE(fUsed = false;) 59 SkDEBUGCODE(fUsed = false;)
54 SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag); 60 SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag);
55 } 61 }
56 62
57 GrBatch::~GrBatch() {} 63 GrBatch::~GrBatch() {}
OLDNEW
« no previous file with comments | « src/gpu/GrProcessor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698