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

Side by Side Diff: include/gpu/GrProcessor.h

Issue 778453002: Remove backend factories (Closed) Base URL: https://skia.googlesource.com/skia.git@unichoice
Patch Set: more clang warnings Created 6 years 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 | « include/gpu/GrFragmentProcessor.h ('k') | include/gpu/GrTBackendProcessorFactory.h » ('j') | 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 #ifndef GrProcessor_DEFINED 8 #ifndef GrProcessor_DEFINED
9 #define GrProcessor_DEFINED 9 #define GrProcessor_DEFINED
10 10
11 #include "GrBackendProcessorFactory.h"
12 #include "GrColor.h" 11 #include "GrColor.h"
13 #include "GrProcessorUnitTest.h" 12 #include "GrProcessorUnitTest.h"
14 #include "GrProgramElement.h" 13 #include "GrProgramElement.h"
15 #include "GrTextureAccess.h" 14 #include "GrTextureAccess.h"
16 #include "SkMath.h" 15 #include "SkMath.h"
17 16
18 class GrContext; 17 class GrContext;
19 class GrCoordTransform; 18 class GrCoordTransform;
20 class GrInvariantOutput; 19 class GrInvariantOutput;
21 20
21 /**
22 * Used by processors to build their keys. It incorporates each per-processor ke y into a larger
23 * shader key.
24 */
25 class GrProcessorKeyBuilder {
26 public:
27 GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fC ount(0) {
28 SkASSERT(0 == fData->count() % sizeof(uint32_t));
29 }
30
31 void add32(uint32_t v) {
32 ++fCount;
33 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v));
34 }
35
36 /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next
37 add*() call. */
38 uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) {
39 SkASSERT(count > 0);
40 fCount += count;
41 return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count));
42 }
43
44 size_t size() const { return sizeof(uint32_t) * fCount; }
45
46 private:
47 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
48 int fCount; // number of uint32_ts added to fData by the processor.
49 };
50
22 /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor obje cts *must* be 51 /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor obje cts *must* be
23 immutable: after being constructed, their fields may not change. 52 immutable: after being constructed, their fields may not change.
24 53
25 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an 54 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
26 processor must reach 0 before the thread terminates and the pool is destroye d. To create a 55 processor must reach 0 before the thread terminates and the pool is destroye d. To create a
27 static processor use the helper macro GR_CREATE_STATIC_PROCESSOR declared be low. 56 static processor use the helper macro GR_CREATE_STATIC_PROCESSOR declared be low.
28 */ 57 */
29 class GrProcessor : public GrProgramElement { 58 class GrProcessor : public GrProgramElement {
30 public: 59 public:
31 SK_DECLARE_INST_COUNT(GrProcessor) 60 SK_DECLARE_INST_COUNT(GrProcessor)
32 61
33 virtual ~GrProcessor(); 62 virtual ~GrProcessor();
34 63
35 /** 64 /**
36 * This function is used to perform optimizations. When called the invarient Ouput param 65 * This function is used to perform optimizations. When called the invarient Ouput param
37 * indicate whether the input components to this processor in the FS will ha ve known values. 66 * indicate whether the input components to this processor in the FS will ha ve known values.
38 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th e isSingleComponent 67 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th e isSingleComponent
39 * member indicates whether the input will be 1 or 4 bytes. The function upd ates the members of 68 * member indicates whether the input will be 1 or 4 bytes. The function upd ates the members of
40 * inout to indicate known values of its output. A component of the color me mber only has 69 * inout to indicate known values of its output. A component of the color me mber only has
41 * meaning if the corresponding bit in validFlags is set. 70 * meaning if the corresponding bit in validFlags is set.
42 */ 71 */
43 void computeInvariantOutput(GrInvariantOutput* inout) const; 72 void computeInvariantOutput(GrInvariantOutput* inout) const;
44 73
45 /** This object, besides creating back-end-specific helper objects, is used for run-time-type-
46 identification. The factory should be an instance of templated class,
47 GrTBackendProcessorFactory. It is templated on the subclass of GrProcess or. The subclass
48 must have a nested type (or typedef) named GLProcessor which will be the subclass of
49 GrGLProcessor created by the factory.
50
51 Example:
52 class MyCustomProcessor : public GrProcessor {
53 ...
54 virtual const GrBackendProcessorFactory& getFactory() const SK_OVERR IDE {
55 return GrTBackendProcessorFactory<MyCustomProcessor>::getInstanc e();
56 }
57 ...
58 };
59 */
60 virtual const GrBackendProcessorFactory& getFactory() const = 0;
61
62 /** Human-meaningful string to identify this prcoessor; may be embedded 74 /** Human-meaningful string to identify this prcoessor; may be embedded
63 in generated shader code. */ 75 in generated shader code. */
64 const char* name() const; 76 virtual const char* name() const = 0;
65 77
66 int numTextures() const { return fTextureAccesses.count(); } 78 int numTextures() const { return fTextureAccesses.count(); }
67 79
68 /** Returns the access pattern for the texture at index. index must be valid according to 80 /** Returns the access pattern for the texture at index. index must be valid according to
69 numTextures(). */ 81 numTextures(). */
70 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } 82 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; }
71 83
72 /** Shortcut for textureAccess(index).texture(); */ 84 /** Shortcut for textureAccess(index).texture(); */
73 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } 85 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); }
74 86
75 /** Will this processor read the fragment position? */ 87 /** Will this processor read the fragment position? */
76 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } 88 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; }
77 89
78 void* operator new(size_t size); 90 void* operator new(size_t size);
79 void operator delete(void* target); 91 void operator delete(void* target);
80 92
81 void* operator new(size_t size, void* placement) { 93 void* operator new(size_t size, void* placement) {
82 return ::operator new(size, placement); 94 return ::operator new(size, placement);
83 } 95 }
84 void operator delete(void* target, void* placement) { 96 void operator delete(void* target, void* placement) {
85 ::operator delete(target, placement); 97 ::operator delete(target, placement);
86 } 98 }
87 99
88 /** 100 /**
89 * Helper for down-casting to a GrProcessor subclass 101 * Helper for down-casting to a GrProcessor subclass
90 */ 102 */
91 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 103 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
92 104
105 uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); r eturn fClassID; }
106
93 protected: 107 protected:
94 GrProcessor() : fWillReadFragmentPosition(false) {} 108 GrProcessor() : fClassID(kIllegalProcessorClassID), fWillReadFragmentPositio n(false) {}
95 109
96 /** 110 /**
97 * Subclasses call this from their constructor to register GrTextureAccesses . The processor 111 * Subclasses call this from their constructor to register GrTextureAccesses . The processor
98 * subclass manages the lifetime of the accesses (this function only stores a pointer). The 112 * subclass manages the lifetime of the accesses (this function only stores a pointer). The
99 * GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be 113 * GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be
100 * called from the constructor because GrProcessors are immutable. 114 * called from the constructor because GrProcessors are immutable.
101 */ 115 */
102 void addTextureAccess(const GrTextureAccess* textureAccess); 116 void addTextureAccess(const GrTextureAccess* textureAccess);
103 117
104 bool hasSameTextureAccesses(const GrProcessor&) const; 118 bool hasSameTextureAccesses(const GrProcessor&) const;
105 119
106 /** 120 /**
107 * If the prcoessor will generate a backend-specific processor that will rea d the fragment 121 * If the prcoessor will generate a backend-specific processor that will rea d the fragment
108 * position in the FS then it must call this method from its constructor. Ot herwise, the 122 * position in the FS then it must call this method from its constructor. Ot herwise, the
109 * request to access the fragment position will be denied. 123 * request to access the fragment position will be denied.
110 */ 124 */
111 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } 125 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; }
112 126
127 template <typename PROC_SUBCLASS> void initClassID() {
128 static uint32_t kClassID = GenClassID();
129 fClassID = kClassID;
130 }
131
132 uint32_t fClassID;
133
113 private: 134 private:
114 /** 135 /**
115 * Subclass implements this to support getConstantColorComponents(...). 136 * Subclass implements this to support getConstantColorComponents(...).
116 */ 137 */
117 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; 138 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0;
139
140 static uint32_t GenClassID() {
141 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The
142 // atomic inc returns the old value not the incremented value. So we add
143 // 1 to the returned value.
144 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID )) + 1;
145 if (!id) {
146 SkFAIL("This should never wrap as it should only be called once for each GrProcessor "
147 "subclass.");
148 }
149 return id;
150 }
151
152 enum {
153 kIllegalProcessorClassID = 0,
154 };
155 static int32_t gCurrProcessorClassID;
118 156
119 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 157 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
120 bool fWillReadFragmentPosition; 158 bool fWillReadFragmentPosition;
121 159
122 typedef GrProgramElement INHERITED; 160 typedef GrProgramElement INHERITED;
123 }; 161 };
124 162
125
126 /** 163 /**
127 * This creates a processor outside of the memory pool. The processor's destruct or will be called 164 * This creates a processor outside of the memory pool. The processor's destruct or will be called
128 * at global destruction time. NAME will be the name of the created instance. 165 * at global destruction time. NAME will be the name of the created instance.
129 */ 166 */
130 #define GR_CREATE_STATIC_PROCESSOR(NAME, PROC_CLASS, ARGS) \ 167 #define GR_CREATE_STATIC_PROCESSOR(NAME, PROC_CLASS, ARGS) \
131 static SkAlignedSStorage<sizeof(PROC_CLASS)> g_##NAME##_Storage; \ 168 static SkAlignedSStorage<sizeof(PROC_CLASS)> g_##NAME##_Storage; \
132 static PROC_CLASS* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), PROC_CLAS S, ARGS); \ 169 static PROC_CLASS* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), PROC_CLAS S, ARGS); \
133 static SkAutoTDestroy<GrProcessor> NAME##_ad(NAME); 170 static SkAutoTDestroy<GrProcessor> NAME##_ad(NAME);
134 171
135 #endif 172 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrFragmentProcessor.h ('k') | include/gpu/GrTBackendProcessorFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698