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

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

Issue 991943002: Use global GrMemoryPools protected by mutex for GrProcessor/GrBatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixed 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
« src/gpu/GrBatch.cpp ('K') | « 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 namespace {
101 SK_DECLARE_STATIC_MUTEX(gProcessorPoolMutex);
102 class MemoryPoolAccessor {
100 public: 103 public:
101 static GrMemoryPool* GetTLS() { 104 MemoryPoolAccessor() {
102 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); 105 gProcessorPoolMutex.acquire();
106 static SkAutoTDelete<GrMemoryPool> gPool(SkNEW_ARGS(GrMemoryPool, (4096, 4096)));
107 fPool = gPool;
103 } 108 }
104 109
110 ~MemoryPoolAccessor() { gProcessorPoolMutex.release(); }
111
112 GrMemoryPool* pool() const { return fPool; }
113
105 private: 114 private:
106 static void* CreateTLS() { 115 GrMemoryPool* fPool;
107 return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
108 }
109 116
110 static void DeleteTLS(void* pool) {
111 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
112 }
113 }; 117 };
118 }
114 119
115 int32_t GrProcessor::gCurrProcessorClassID = 120 int32_t GrProcessor::gCurrProcessorClassID = GrProcessor::kIllegalProcessorClass ID;
116 GrProcessor::kIllegalProcessorClassID;
117 121
118 /////////////////////////////////////////////////////////////////////////////// 122 ///////////////////////////////////////////////////////////////////////////////
119 123
120 GrProcessor::~GrProcessor() {} 124 GrProcessor::~GrProcessor() {}
121 125
122 void GrProcessor::addTextureAccess(const GrTextureAccess* access) { 126 void GrProcessor::addTextureAccess(const GrTextureAccess* access) {
123 fTextureAccesses.push_back(access); 127 fTextureAccesses.push_back(access);
124 this->addGpuResource(access->getProgramTexture()); 128 this->addGpuResource(access->getProgramTexture());
125 } 129 }
126 130
127 void* GrProcessor::operator new(size_t size) { 131 void* GrProcessor::operator new(size_t size) {
128 return GrProcessor_Globals::GetTLS()->allocate(size); 132 return MemoryPoolAccessor().pool()->allocate(size);
129 } 133 }
130 134
131 void GrProcessor::operator delete(void* target) { 135 void GrProcessor::operator delete(void* target) {
132 GrProcessor_Globals::GetTLS()->release(target); 136 return MemoryPoolAccessor().pool()->release(target);
133 } 137 }
134 138
135 bool GrProcessor::hasSameTextureAccesses(const GrProcessor& that) const { 139 bool GrProcessor::hasSameTextureAccesses(const GrProcessor& that) const {
136 if (this->numTextures() != that.numTextures()) { 140 if (this->numTextures() != that.numTextures()) {
137 return false; 141 return false;
138 } 142 }
139 for (int i = 0; i < this->numTextures(); ++i) { 143 for (int i = 0; i < this->numTextures(); ++i) {
140 if (this->textureAccess(i) != that.textureAccess(i)) { 144 if (this->textureAccess(i) != that.textureAccess(i)) {
141 return false; 145 return false;
142 } 146 }
(...skipping 24 matching lines...) Expand all
167 171
168 void GrFragmentProcessor::computeInvariantOutput(GrInvariantOutput* inout) const { 172 void GrFragmentProcessor::computeInvariantOutput(GrInvariantOutput* inout) const {
169 this->onComputeInvariantOutput(inout); 173 this->onComputeInvariantOutput(inout);
170 } 174 }
171 175
172 //////////////////////////////////////////////////////////////////////////////// /////////////////// 176 //////////////////////////////////////////////////////////////////////////////// ///////////////////
173 177
174 // Initial static variable from GrXPFactory 178 // Initial static variable from GrXPFactory
175 int32_t GrXPFactory::gCurrXPFClassID = 179 int32_t GrXPFactory::gCurrXPFClassID =
176 GrXPFactory::kIllegalXPFClassID; 180 GrXPFactory::kIllegalXPFClassID;
OLDNEW
« src/gpu/GrBatch.cpp ('K') | « src/gpu/GrBatch.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698