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

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

Issue 1350523004: Move GrFragmentProcessor implementation to its own cpp file (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: whitespace Created 5 years, 2 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 | « gyp/gpu.gypi ('k') | src/gpu/GrProcessor.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrProcessor.h"
9 #include "GrContext.h"
10 #include "GrCoordTransform.h"
11 #include "GrGeometryProcessor.h"
12 #include "GrInvariantOutput.h"
13 #include "GrMemoryPool.h"
14 #include "GrXferProcessor.h"
15 #include "SkSpinlock.h"
16 #include "gl/GrGLFragmentProcessor.h"
17
18 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
19
20 class GrFragmentProcessor;
21 class GrGeometryProcessor;
22 1
23 /* 2 /*
24 * Originally these were both in the processor unit test header, but then it see med to cause linker 3 * Copyright 2015 Google Inc.
25 * problems on android. 4 *
26 */ 5 * Use of this source code is governed by a BSD-style license that can be
27 template<> 6 * found in the LICENSE file.
28 SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true>* 7 */
29 GrProcessorTestFactory<GrFragmentProcessor>::GetFactories() {
30 static SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true> gFactori es;
31 return &gFactories;
32 }
33 8
34 template<> 9 #include "GrFragmentProcessor.h"
35 SkTArray<GrProcessorTestFactory<GrXPFactory>*, true>* 10 #include "GrCoordTransform.h"
36 GrProcessorTestFactory<GrXPFactory>::GetFactories() { 11 #include "gl/GrGLFragmentProcessor.h"
37 static SkTArray<GrProcessorTestFactory<GrXPFactory>*, true> gFactories; 12 #include "effects/GrXfermodeFragmentProcessor.h"
38 return &gFactories;
39 }
40
41 template<>
42 SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true>*
43 GrProcessorTestFactory<GrGeometryProcessor>::GetFactories() {
44 static SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true> gFactori es;
45 return &gFactories;
46 }
47
48 /*
49 * To ensure we always have successful static initialization, before creating fr om the factories
50 * we verify the count is as expected. If a new factory is added, then these nu mbers must be
51 * manually adjusted.
52 */
53 static const int kFPFactoryCount = 38;
54 static const int kGPFactoryCount = 14;
55 static const int kXPFactoryCount = 5;
56
57 template<>
58 void GrProcessorTestFactory<GrFragmentProcessor>::VerifyFactoryCount() {
59 if (kFPFactoryCount != GetFactories()->count()) {
60 SkFAIL("Wrong number of fragment processor factories!");
61 }
62 }
63
64 template<>
65 void GrProcessorTestFactory<GrGeometryProcessor>::VerifyFactoryCount() {
66 if (kGPFactoryCount != GetFactories()->count()) {
67 SkFAIL("Wrong number of geometry processor factories!");
68 }
69 }
70
71 template<>
72 void GrProcessorTestFactory<GrXPFactory>::VerifyFactoryCount() {
73 if (kXPFactoryCount != GetFactories()->count()) {
74 SkFAIL("Wrong number of xp factory factories!");
75 }
76 }
77
78 #endif
79
80
81 // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
82 // different threads. The GrContext is not used concurrently on different thread s and there is a
83 // memory barrier between accesses of a context on different threads. Also, ther e may be multiple
84 // GrContexts and those contexts may be in use concurrently on different threads .
85 namespace {
86 SK_DECLARE_STATIC_SPINLOCK(gProcessorSpinlock);
87 class MemoryPoolAccessor {
88 public:
89 MemoryPoolAccessor() { gProcessorSpinlock.acquire(); }
90
91 ~MemoryPoolAccessor() { gProcessorSpinlock.release(); }
92
93 GrMemoryPool* pool() const {
94 static GrMemoryPool gPool(4096, 4096);
95 return &gPool;
96 }
97 };
98 }
99
100 int32_t GrProcessor::gCurrProcessorClassID = GrProcessor::kIllegalProcessorClass ID;
101
102 ///////////////////////////////////////////////////////////////////////////////
103
104 GrProcessor::~GrProcessor() {}
105
106 void GrProcessor::addTextureAccess(const GrTextureAccess* access) {
107 fTextureAccesses.push_back(access);
108 this->addGpuResource(access->getProgramTexture());
109 }
110
111 void* GrProcessor::operator new(size_t size) {
112 return MemoryPoolAccessor().pool()->allocate(size);
113 }
114
115 void GrProcessor::operator delete(void* target) {
116 return MemoryPoolAccessor().pool()->release(target);
117 }
118
119 bool GrProcessor::hasSameTextureAccesses(const GrProcessor& that) const {
120 if (this->numTextures() != that.numTextures()) {
121 return false;
122 }
123 for (int i = 0; i < this->numTextures(); ++i) {
124 if (this->textureAccess(i) != that.textureAccess(i)) {
125 return false;
126 }
127 }
128 return true;
129 }
130
131 //////////////////////////////////////////////////////////////////////////////// ///////////////////
132 13
133 GrFragmentProcessor::~GrFragmentProcessor() { 14 GrFragmentProcessor::~GrFragmentProcessor() {
134 // If we got here then our ref count must have reached zero, so we will have converted refs 15 // If we got here then our ref count must have reached zero, so we will have converted refs
135 // to pending executions for all children. 16 // to pending executions for all children.
136 for (int i = 0; i < fChildProcessors.count(); ++i) { 17 for (int i = 0; i < fChildProcessors.count(); ++i) {
137 fChildProcessors[i]->completedExecution(); 18 fChildProcessors[i]->completedExecution();
138 } 19 }
139 } 20 }
140 21
141 bool GrFragmentProcessor::isEqual(const GrFragmentProcessor& that, 22 bool GrFragmentProcessor::isEqual(const GrFragmentProcessor& that,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 115 }
235 int count = this->numTransforms(); 116 int count = this->numTransforms();
236 for (int i = 0; i < count; ++i) { 117 for (int i = 0; i < count; ++i) {
237 if (this->coordTransform(i) != that.coordTransform(i)) { 118 if (this->coordTransform(i) != that.coordTransform(i)) {
238 return false; 119 return false;
239 } 120 }
240 } 121 }
241 return true; 122 return true;
242 } 123 }
243 124
244 #include "effects/GrXfermodeFragmentProcessor.h"
245
246 const GrFragmentProcessor* GrFragmentProcessor::MulOuputByInputAlpha( 125 const GrFragmentProcessor* GrFragmentProcessor::MulOuputByInputAlpha(
247 const GrFragmentProcessor* fp) { 126 const GrFragmentProcessor* fp) {
248 return GrXfermodeFragmentProcessor::CreateFromDstProcessor(fp, SkXfermode::k DstIn_Mode); 127 return GrXfermodeFragmentProcessor::CreateFromDstProcessor(fp, SkXfermode::k DstIn_Mode);
249 } 128 }
250 129
251 //////////////////////////////////////////////////////////////////////////////// ///////////////////
252
253 // Initial static variable from GrXPFactory
254 int32_t GrXPFactory::gCurrXPFClassID =
255 GrXPFactory::kIllegalXPFClassID;
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698