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

Side by Side Diff: src/gpu/GrProcessor.cpp

Issue 990953003: Use global GrMemoryPools protected by mutex for GrProcessor/GrBatch (Closed) Base URL: https://skia.googlesource.com/skia.git@m42
Patch Set: Created 5 years, 9 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/GrBatch.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 2012 Google Inc. 2 * Copyright 2012 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 "GrProcessor.h" 8 #include "GrProcessor.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrCoordTransform.h" 10 #include "GrCoordTransform.h"
11 #include "GrGeometryProcessor.h" 11 #include "GrGeometryProcessor.h"
12 #include "GrInvariantOutput.h" 12 #include "GrInvariantOutput.h"
13 #include "GrMemoryPool.h" 13 #include "GrMemoryPool.h"
14 #include "GrXferProcessor.h" 14 #include "GrXferProcessor.h"
15 #include "SkTLS.h" 15 #include "SkMutex.h"
16 16
17 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 17 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
18 18
19 class GrFragmentProcessor; 19 class GrFragmentProcessor;
20 class GrGeometryProcessor; 20 class GrGeometryProcessor;
21 21
22 /* 22 /*
23 * Originally these were both in the processor unit test header, but then it see med to cause linker 23 * Originally these were both in the processor unit test header, but then it see med to cause linker
24 * problems on android. 24 * problems on android.
25 */ 25 */
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); 89 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf);
90 gMatrices[4].setRotate(SkIntToScalar(215)); 90 gMatrices[4].setRotate(SkIntToScalar(215));
91 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); 91 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
92 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); 92 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
93 gOnce = true; 93 gOnce = true;
94 } 94 }
95 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; 95 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))];
96 } 96 }
97 } 97 }
98 98
99 class GrProcessor_Globals { 99
100 // We use a global pool protected by a mutex. Chrome may use the same GrContext on different
101 // threads. The GrContext is not used concurrently on different threads and ther e is a memory
102 // barrier between accesses of a context on different threads. Also, there may b e multiple
103 // GrContexts and those contexts may be in use concurrently on different threads .
104 namespace {
105 SK_DECLARE_STATIC_MUTEX(gProcessorPoolMutex);
106 class MemoryPoolAccessor {
100 public: 107 public:
101 static GrMemoryPool* GetTLS() { 108 MemoryPoolAccessor() { gProcessorPoolMutex.acquire(); }
102 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
103 }
104 109
105 private: 110 ~MemoryPoolAccessor() { gProcessorPoolMutex.release(); }
106 static void* CreateTLS() {
107 return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
108 }
109 111
110 static void DeleteTLS(void* pool) { 112 GrMemoryPool* pool() const {
111 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool)); 113 static GrMemoryPool gPool(4096, 4096);
114 return &gPool;
112 } 115 }
113 }; 116 };
117 }
114 118
115 int32_t GrProcessor::gCurrProcessorClassID = 119 int32_t GrProcessor::gCurrProcessorClassID = GrProcessor::kIllegalProcessorClass ID;
116 GrProcessor::kIllegalProcessorClassID;
117 120
118 /////////////////////////////////////////////////////////////////////////////// 121 ///////////////////////////////////////////////////////////////////////////////
119 122
120 GrProcessor::~GrProcessor() {} 123 GrProcessor::~GrProcessor() {}
121 124
122 void GrProcessor::addTextureAccess(const GrTextureAccess* access) { 125 void GrProcessor::addTextureAccess(const GrTextureAccess* access) {
123 fTextureAccesses.push_back(access); 126 fTextureAccesses.push_back(access);
124 this->addGpuResource(access->getProgramTexture()); 127 this->addGpuResource(access->getProgramTexture());
125 } 128 }
126 129
127 void* GrProcessor::operator new(size_t size) { 130 void* GrProcessor::operator new(size_t size) {
128 return GrProcessor_Globals::GetTLS()->allocate(size); 131 return MemoryPoolAccessor().pool()->allocate(size);
129 } 132 }
130 133
131 void GrProcessor::operator delete(void* target) { 134 void GrProcessor::operator delete(void* target) {
132 GrProcessor_Globals::GetTLS()->release(target); 135 return MemoryPoolAccessor().pool()->release(target);
133 } 136 }
134 137
135 bool GrProcessor::hasSameTextureAccesses(const GrProcessor& that) const { 138 bool GrProcessor::hasSameTextureAccesses(const GrProcessor& that) const {
136 if (this->numTextures() != that.numTextures()) { 139 if (this->numTextures() != that.numTextures()) {
137 return false; 140 return false;
138 } 141 }
139 for (int i = 0; i < this->numTextures(); ++i) { 142 for (int i = 0; i < this->numTextures(); ++i) {
140 if (this->textureAccess(i) != that.textureAccess(i)) { 143 if (this->textureAccess(i) != that.textureAccess(i)) {
141 return false; 144 return false;
142 } 145 }
(...skipping 24 matching lines...) Expand all
167 170
168 void GrFragmentProcessor::computeInvariantOutput(GrInvariantOutput* inout) const { 171 void GrFragmentProcessor::computeInvariantOutput(GrInvariantOutput* inout) const {
169 this->onComputeInvariantOutput(inout); 172 this->onComputeInvariantOutput(inout);
170 } 173 }
171 174
172 //////////////////////////////////////////////////////////////////////////////// /////////////////// 175 //////////////////////////////////////////////////////////////////////////////// ///////////////////
173 176
174 // Initial static variable from GrXPFactory 177 // Initial static variable from GrXPFactory
175 int32_t GrXPFactory::gCurrXPFClassID = 178 int32_t GrXPFactory::gCurrXPFClassID =
176 GrXPFactory::kIllegalXPFClassID; 179 GrXPFactory::kIllegalXPFClassID;
OLDNEW
« no previous file with comments | « src/gpu/GrBatch.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698