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

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

Issue 356513003: Step towards variable length effect keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update 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
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 GrTBackendEffectFactory_DEFINED 8 #ifndef GrTBackendEffectFactory_DEFINED
9 #define GrTBackendEffectFactory_DEFINED 9 #define GrTBackendEffectFactory_DEFINED
10 10
11 #include "GrBackendEffectFactory.h" 11 #include "GrBackendEffectFactory.h"
12 #include "GrDrawEffect.h" 12 #include "GrDrawEffect.h"
13 #include "gl/GrGLProgramEffects.h" 13 #include "gl/GrGLProgramEffects.h"
14 14
15 /** 15 /**
16 * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. 16 * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton.
17 */ 17 */
18 template <typename EffectClass> 18 template <typename EffectClass>
19 class GrTBackendEffectFactory : public GrBackendEffectFactory { 19 class GrTBackendEffectFactory : public GrBackendEffectFactory {
20 20
21 public: 21 public:
22 typedef typename EffectClass::GLEffect GLEffect; 22 typedef typename EffectClass::GLEffect GLEffect;
23 23
24 /** Returns a human-readable name that is accessible via GrEffect or 24 /** Returns a human-readable name that is accessible via GrEffect or
25 GrGLEffect and is consistent between the two of them. 25 GrGLEffect and is consistent between the two of them.
26 */ 26 */
27 virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } 27 virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); }
28 28
29 /** Returns a value that identifies the GLSL shader code generated by 29 /** Generates an effect's key. This enables caching of generated shaders. Pa rt of the
30 a GrEffect. This enables caching of generated shaders. Part of the 30 id identifies the GrEffect subclass. The remainder is based on the aspec ts of the
31 id identifies the GrEffect subclass. The remainder is based 31 GrEffect object's configuration that affect GLSL code generation. */
32 on the aspects of the GrEffect object's configuration that affect 32 virtual bool getGLEffectKey(const GrDrawEffect& drawEffect,
33 GLSL code generation. */ 33 const GrGLCaps& caps,
34 virtual EffectKey glEffectKey(const GrDrawEffect& drawEffect, 34 EffectKeyBuilder* b) const SK_OVERRIDE {
35 const GrGLCaps& caps) const SK_OVERRIDE {
36 SkASSERT(kIllegalEffectClassID != fEffectClassID); 35 SkASSERT(kIllegalEffectClassID != fEffectClassID);
37 EffectKey effectKey = GLEffect::GenKey(drawEffect, caps); 36 EffectKey effectKey = GLEffect::GenKey(drawEffect, caps);
38 EffectKey textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, cap s); 37 EffectKey textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, cap s);
39 EffectKey transformKey = GrGLProgramEffects::GenTransformKey(drawEffect) ; 38 EffectKey transformKey = GrGLProgramEffects::GenTransformKey(drawEffect) ;
40 EffectKey attribKey = GrGLProgramEffects::GenAttribKey(drawEffect); 39 EffectKey attribKey = GrGLProgramEffects::GenAttribKey(drawEffect);
41 #ifdef SK_DEBUG 40 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
42 static const EffectKey kIllegalEffectKeyMask = (uint16_t) (~((1U << kEff ectKeyBits) - 1)); 41 if ((textureKey | transformKey | attribKey | fEffectClassID) & kMetaKeyI nvalidMask) {
43 SkASSERT(!(kIllegalEffectKeyMask & effectKey)); 42 return false;
44 43 }
45 static const EffectKey kIllegalTextureKeyMask = (uint16_t) (~((1U << kTe xtureKeyBits) - 1)); 44 // effectKey must be first because it is what will be returned by
robertphillips 2014/07/10 12:15:50 pass -> passed ?
bsalomon 2014/07/10 17:24:34 Done.
46 SkASSERT(!(kIllegalTextureKeyMask & textureKey)); 45 // GrGLProgramDesc::EffectKeyProvider and pass to the GrGLEffect as its key.
47 46
48 static const EffectKey kIllegalTransformKeyMask = (uint16_t) (~((1U << k TransformKeyBits) - 1)); 47 b->add32(effectKey);
49 SkASSERT(!(kIllegalTransformKeyMask & transformKey)); 48 b->add32(textureKey << 16 | transformKey);
50 49 b->add32(fEffectClassID << 16 | attribKey);
51 static const EffectKey kIllegalAttribKeyMask = (uint16_t) (~((1U << kAtt ribKeyBits) - 1)); 50 return true;
52 SkASSERT(!(kIllegalAttribKeyMask & textureKey));
53
54 static const EffectKey kIllegalClassIDMask = (uint16_t) (~((1U << kClass IDBits) - 1));
55 SkASSERT(!(kIllegalClassIDMask & fEffectClassID));
56 #endif
57 return (fEffectClassID << (kEffectKeyBits+kTextureKeyBits+kTransformKeyB its+kAttribKeyBits)) |
58 (attribKey << (kEffectKeyBits+kTextureKeyBits+kTransformKeyBits)) |
59 (transformKey << (kEffectKeyBits+kTextureKeyBits)) |
60 (textureKey << kEffectKeyBits) |
61 (effectKey);
62 } 51 }
63 52
64 /** Returns a new instance of the appropriate *GL* implementation class 53 /** Returns a new instance of the appropriate *GL* implementation class
65 for the given GrEffect; caller is responsible for deleting 54 for the given GrEffect; caller is responsible for deleting
66 the object. */ 55 the object. */
67 virtual GrGLEffect* createGLInstance(const GrDrawEffect& drawEffect) const S K_OVERRIDE { 56 virtual GrGLEffect* createGLInstance(const GrDrawEffect& drawEffect) const S K_OVERRIDE {
68 return SkNEW_ARGS(GLEffect, (*this, drawEffect)); 57 return SkNEW_ARGS(GLEffect, (*this, drawEffect));
69 } 58 }
70 59
71 /** This class is a singleton. This function returns the single instance. 60 /** This class is a singleton. This function returns the single instance.
72 */ 61 */
73 static const GrBackendEffectFactory& getInstance() { 62 static const GrBackendEffectFactory& getInstance() {
74 static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem; 63 static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem;
75 static const GrTBackendEffectFactory* gInstance; 64 static const GrTBackendEffectFactory* gInstance;
76 if (!gInstance) { 65 if (!gInstance) {
77 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), 66 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
78 GrTBackendEffectFactory); 67 GrTBackendEffectFactory);
79 } 68 }
80 return *gInstance; 69 return *gInstance;
81 } 70 }
82 71
83 protected: 72 protected:
84 GrTBackendEffectFactory() { 73 GrTBackendEffectFactory() {
85 fEffectClassID = GenID(); 74 fEffectClassID = GenID();
86 } 75 }
87 }; 76 };
88 77
89 #endif 78 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698