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

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

Issue 385713005: Allow GrGLEffects to produce variable length keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@key
Patch Set: rebase Created 6 years, 5 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 | « no previous file | include/gpu/GrEffect.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 GrBackendEffectFactory_DEFINED 8 #ifndef GrBackendEffectFactory_DEFINED
9 #define GrBackendEffectFactory_DEFINED 9 #define GrBackendEffectFactory_DEFINED
10 10
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 size_t size() const { return sizeof(uint32_t) * fCount; } 43 size_t size() const { return sizeof(uint32_t) * fCount; }
44 44
45 private: 45 private:
46 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. 46 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
47 int fCount; // number of uint32_ts added to fData by the effect. 47 int fCount; // number of uint32_ts added to fData by the effect.
48 }; 48 };
49 49
50 /** 50 /**
51 * This class is used to pass the key that was created for a GrGLEffect back to it
52 * when it emits code. It may allow the emit step to skip calculations that were
53 * performed when computing the key.
54 */
55 class GrEffectKey {
56 public:
57 GrEffectKey(const uint32_t* key, int count) : fKey(key), fCount(count) {
58 SkASSERT(0 == reinterpret_cast<intptr_t>(key) % sizeof(uint32_t));
59 }
60
61 /** Gets the uint32_t values that the effect inserted into the key. */
62 uint32_t get32(int index) const {
63 SkASSERT(index >=0 && index < fCount);
64 return fKey[index];
65 }
66
67 /** Gets the number of uint32_t values that the effect inserted into the key . */
68 int count32() const { return fCount; }
69
70 private:
71 const uint32_t* fKey; // unowned ptr into the larger key.
72 int fCount; // number of uint32_ts inserted by the effec t into its key.
73 };
74
75 /**
51 * Given a GrEffect of a particular type, creates the corresponding graphics-bac kend-specific 76 * Given a GrEffect of a particular type, creates the corresponding graphics-bac kend-specific
52 * effect object. It also tracks equivalence of shaders generated via a key. The factory for an 77 * effect object. It also tracks equivalence of shaders generated via a key. The factory for an
53 * effect is accessed via GrEffect::getFactory(). Each factory instance is assig ned an ID at 78 * effect is accessed via GrEffect::getFactory(). Each factory instance is assig ned an ID at
54 * construction. The ID of GrEffect::getFactory() is used as a type identifier. Thus, a GrEffect 79 * construction. The ID of GrEffect::getFactory() is used as a type identifier. Thus, a GrEffect
55 * subclass must always return the same object from getFactory() and that factor y object must be 80 * subclass must always return the same object from getFactory() and that factor y object must be
56 * unique to the GrEffect subclass (and unique from any further derived subclass es). 81 * unique to the GrEffect subclass (and unique from any further derived subclass es).
57 * 82 *
58 * Rather than subclassing this class themselves, it is recommended that GrEffec t authors use 83 * Rather than subclassing this class themselves, it is recommended that GrEffec t authors use
59 * the templated subclass GrTBackendEffectFactory by writing their getFactory() method as: 84 * the templated subclass GrTBackendEffectFactory by writing their getFactory() method as:
60 * 85 *
61 * const GrBackendEffectFactory& MyEffect::getFactory() const { 86 * const GrBackendEffectFactory& MyEffect::getFactory() const {
62 * return GrTBackendEffectFactory<MyEffect>::getInstance(); 87 * return GrTBackendEffectFactory<MyEffect>::getInstance();
63 * } 88 * }
64 * 89 *
65 * Using GrTBackendEffectFactory places a few constraints on the effect. See tha t class's comments. 90 * Using GrTBackendEffectFactory places a few constraints on the effect. See tha t class's comments.
66 */ 91 */
67 class GrBackendEffectFactory : SkNoncopyable { 92 class GrBackendEffectFactory : SkNoncopyable {
68 public: 93 public:
69 typedef uint32_t EffectKey;
70
71 /** 94 /**
72 * Generates an effect's key. The key is based on the aspects of the GrEffec t object's 95 * Generates an effect's key. The key is based on the aspects of the GrEffec t object's
73 * configuration that affect GLSL code generation. Two GrEffect instances th at would cause 96 * configuration that affect GLSL code generation. Two GrEffect instances th at would cause
74 * this->createGLInstance()->emitCode() to produce different code must produ ce different keys. 97 * this->createGLInstance()->emitCode() to produce different code must produ ce different keys.
75 */ 98 */
76 virtual void getGLEffectKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKe yBuilder*) const = 0; 99 virtual void getGLEffectKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKe yBuilder*) const = 0;
77 100
78 /** 101 /**
79 * Creates a GrGLEffect instance that is used both to generate code for the GrEffect in a GLSL 102 * Creates a GrGLEffect instance that is used both to generate code for the GrEffect in a GLSL
80 * program and to manage updating uniforms for the program when it is used. 103 * program and to manage updating uniforms for the program when it is used.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 "subclass."); 135 "subclass.");
113 } 136 }
114 return id; 137 return id;
115 } 138 }
116 139
117 const uint32_t fEffectClassID; 140 const uint32_t fEffectClassID;
118 static int32_t fCurrEffectClassID; 141 static int32_t fCurrEffectClassID;
119 }; 142 };
120 143
121 #endif 144 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698