| OLD | NEW |
| 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 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 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. |
| 57 */ | 57 */ |
| 58 class GrProcessor : public GrProgramElement { | 58 class GrProcessor : public GrProgramElement { |
| 59 public: | 59 public: |
| 60 virtual ~GrProcessor(); | 60 virtual ~GrProcessor(); |
| 61 | 61 |
| 62 /** Human-meaningful string to identify this prcoessor; may be embedded | 62 /** Human-meaningful string to identify this prcoessor; may be embedded |
| 63 in generated shader code. */ | 63 in generated shader code. */ |
| 64 virtual const char* name() const = 0; | 64 virtual const char* name() const = 0; |
| 65 | 65 |
| 66 int numTextures() const { return fTextureAccesses.count(); } | 66 virtual int numTextures() const { return fTextureAccesses.count(); } |
| 67 | 67 |
| 68 /** Returns the access pattern for the texture at index. index must be valid
according to | 68 /** Returns the access pattern for the texture at index. index must be valid
according to |
| 69 numTextures(). */ | 69 numTextures(). */ |
| 70 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } | 70 virtual const GrTextureAccess& textureAccess(int index) const { |
| 71 return *fTextureAccesses[index]; |
| 72 } |
| 71 | 73 |
| 72 /** Shortcut for textureAccess(index).texture(); */ | 74 /** Shortcut for textureAccess(index).texture(); */ |
| 73 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } | 75 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } |
| 74 | 76 |
| 75 /** Will this processor read the fragment position? */ | 77 /** Will this processor read the fragment position? */ |
| 76 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } | 78 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } |
| 77 | 79 |
| 78 void* operator new(size_t size); | 80 void* operator new(size_t size); |
| 79 void operator delete(void* target); | 81 void operator delete(void* target); |
| 80 | 82 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 111 * request to access the fragment position will be denied. | 113 * request to access the fragment position will be denied. |
| 112 */ | 114 */ |
| 113 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } | 115 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } |
| 114 | 116 |
| 115 template <typename PROC_SUBCLASS> void initClassID() { | 117 template <typename PROC_SUBCLASS> void initClassID() { |
| 116 static uint32_t kClassID = GenClassID(); | 118 static uint32_t kClassID = GenClassID(); |
| 117 fClassID = kClassID; | 119 fClassID = kClassID; |
| 118 } | 120 } |
| 119 | 121 |
| 120 uint32_t fClassID; | 122 uint32_t fClassID; |
| 123 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
| 121 | 124 |
| 122 private: | 125 private: |
| 123 static uint32_t GenClassID() { | 126 static uint32_t GenClassID() { |
| 124 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The | 127 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The |
| 125 // atomic inc returns the old value not the incremented value. So we add | 128 // atomic inc returns the old value not the incremented value. So we add |
| 126 // 1 to the returned value. | 129 // 1 to the returned value. |
| 127 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID
)) + 1; | 130 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID
)) + 1; |
| 128 if (!id) { | 131 if (!id) { |
| 129 SkFAIL("This should never wrap as it should only be called once for
each GrProcessor " | 132 SkFAIL("This should never wrap as it should only be called once for
each GrProcessor " |
| 130 "subclass."); | 133 "subclass."); |
| 131 } | 134 } |
| 132 return id; | 135 return id; |
| 133 } | 136 } |
| 134 | 137 |
| 135 enum { | 138 enum { |
| 136 kIllegalProcessorClassID = 0, | 139 kIllegalProcessorClassID = 0, |
| 137 }; | 140 }; |
| 138 static int32_t gCurrProcessorClassID; | 141 static int32_t gCurrProcessorClassID; |
| 139 | 142 |
| 140 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | |
| 141 bool fWillReadFragmentPosition; | 143 bool fWillReadFragmentPosition; |
| 142 | 144 |
| 143 typedef GrProgramElement INHERITED; | 145 typedef GrProgramElement INHERITED; |
| 144 }; | 146 }; |
| 145 | 147 |
| 146 /** | 148 /** |
| 147 * This creates a processor outside of the memory pool. The processor's destruct
or will be called | 149 * This creates a processor outside of the memory pool. The processor's destruct
or will be called |
| 148 * at global destruction time. NAME will be the name of the created instance. | 150 * at global destruction time. NAME will be the name of the created instance. |
| 149 */ | 151 */ |
| 150 #define GR_CREATE_STATIC_PROCESSOR(NAME, PROC_CLASS, ARGS)
\ | 152 #define GR_CREATE_STATIC_PROCESSOR(NAME, PROC_CLASS, ARGS)
\ |
| 151 static SkAlignedSStorage<sizeof(PROC_CLASS)> g_##NAME##_Storage;
\ | 153 static SkAlignedSStorage<sizeof(PROC_CLASS)> g_##NAME##_Storage;
\ |
| 152 static PROC_CLASS* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), PROC_CLAS
S, ARGS); \ | 154 static PROC_CLASS* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), PROC_CLAS
S, ARGS); \ |
| 153 static SkAutoTDestroy<GrProcessor> NAME##_ad(NAME); | 155 static SkAutoTDestroy<GrProcessor> NAME##_ad(NAME); |
| 154 | 156 |
| 155 #endif | 157 #endif |
| OLD | NEW |