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

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

Issue 356513003: Step towards variable length effect keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak comment 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 GrBackendEffectFactory_DEFINED 8 #ifndef GrBackendEffectFactory_DEFINED
9 #define GrBackendEffectFactory_DEFINED 9 #define GrBackendEffectFactory_DEFINED
10 10
11 #include "GrTypes.h" 11 #include "GrTypes.h"
12 #include "SkTemplates.h" 12 #include "SkTemplates.h"
13 #include "SkThread.h" 13 #include "SkThread.h"
14 #include "SkTypes.h" 14 #include "SkTypes.h"
15 #include "SkTArray.h"
15 16
16 /** Given a GrEffect of a particular type, creates the corresponding graphics-ba ckend-specific 17 /** Given a GrEffect of a particular type, creates the corresponding graphics-ba ckend-specific
17 effect object. Also tracks equivalence of shaders generated via a key. Each factory instance 18 effect object. Also tracks equivalence of shaders generated via a key. Each factory instance
18 is assigned a generation ID at construction. The ID of the return of GrEffec t::getFactory() 19 is assigned a generation ID at construction. The ID of the return of GrEffec t::getFactory()
19 is used as a type identifier. Thus a GrEffect subclass must return a singlet on from 20 is used as a type identifier. Thus a GrEffect subclass must return a singlet on from
20 getFactory(). GrEffect subclasses should use the derived class GrTBackendEff ectFactory that is 21 getFactory(). GrEffect subclasses should use the derived class GrTBackendEff ectFactory that is
21 templated on the GrEffect subclass as their factory object. It requires that the GrEffect 22 templated on the GrEffect subclass as their factory object. It requires that the GrEffect
22 subclass has a nested class (or typedef) GLEffect which is its GL implementa tion and a subclass 23 subclass has a nested class (or typedef) GLEffect which is its GL implementa tion and a subclass
23 of GrGLEffect. 24 of GrGLEffect.
24 */ 25 */
25 26
26 class GrGLEffect; 27 class GrGLEffect;
27 class GrGLCaps; 28 class GrGLCaps;
28 class GrDrawEffect; 29 class GrDrawEffect;
29 30
31 /**
32 * Used by effects to build their keys. It incorpates each per-effect key into a larger shader key.
jvanverth1 2014/07/11 15:33:12 Typo: incorporates
33 */
34 class GrEffectKeyBuilder {
35 public:
36 GrEffectKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCoun t(0) {
37 SkASSERT(0 == fData->count() % sizeof(uint32_t));
38 }
39
40 void add32(uint32_t v) {
41 ++fCount;
42 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v));
43 }
44
45 size_t size() const { return sizeof(uint32_t) * fCount; }
46
47 private:
48 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
49 int fCount; // number of uint32_ts added to fData by the effect.
50 };
51
30 class GrBackendEffectFactory : SkNoncopyable { 52 class GrBackendEffectFactory : SkNoncopyable {
31 public: 53 public:
32 typedef uint32_t EffectKey; 54 typedef uint32_t EffectKey;
33 enum {
34 kNoEffectKey = 0,
35 kEffectKeyBits = 10,
36 /**
37 * The framework automatically includes coord transforms and texture acc esses in their
38 * effect's EffectKey, so effects don't need to account for them in GenK ey().
39 */
40 kTextureKeyBits = 4,
41 kTransformKeyBits = 6,
42 kAttribKeyBits = 6,
43 kClassIDBits = 6
44 };
45 55
46 virtual EffectKey glEffectKey(const GrDrawEffect&, const GrGLCaps&) const = 0; 56 virtual bool getGLEffectKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKe yBuilder*) const = 0;
47 virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0; 57 virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0;
48 58
49 bool operator ==(const GrBackendEffectFactory& b) const { 59 bool operator ==(const GrBackendEffectFactory& b) const {
50 return fEffectClassID == b.fEffectClassID; 60 return fEffectClassID == b.fEffectClassID;
51 } 61 }
52 bool operator !=(const GrBackendEffectFactory& b) const { 62 bool operator !=(const GrBackendEffectFactory& b) const {
53 return !(*this == b); 63 return !(*this == b);
54 } 64 }
55 65
56 virtual const char* name() const = 0; 66 virtual const char* name() const = 0;
57 67
58 static EffectKey GetTransformKey(EffectKey key) {
59 return key >> (kEffectKeyBits + kTextureKeyBits) & ((1U << kTransformKey Bits) - 1);
60 }
61
62 protected: 68 protected:
63 enum { 69 enum {
64 kIllegalEffectClassID = 0, 70 kIllegalEffectClassID = 0,
65 }; 71 };
66 72
67 GrBackendEffectFactory() { 73 GrBackendEffectFactory() {
68 fEffectClassID = kIllegalEffectClassID; 74 fEffectClassID = kIllegalEffectClassID;
69 } 75 }
70 virtual ~GrBackendEffectFactory() {} 76 virtual ~GrBackendEffectFactory() {}
71 77
72 static EffectKey GenID() { 78 static int32_t GenID() {
73 SkDEBUGCODE(static const int32_t kClassIDBits = 8 * sizeof(EffectKey) -
74 kTextureKeyBits - kEffectKeyBits - kAttribKeyBits);
75 // fCurrEffectClassID has been initialized to kIllegalEffectClassID. The 79 // fCurrEffectClassID has been initialized to kIllegalEffectClassID. The
76 // atomic inc returns the old value not the incremented value. So we add 80 // atomic inc returns the old value not the incremented value. So we add
77 // 1 to the returned value. 81 // 1 to the returned value.
78 int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1; 82 int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1;
79 SkASSERT(id < (1 << kClassIDBits)); 83 return id;
80 return static_cast<EffectKey>(id);
81 } 84 }
82 85
83 EffectKey fEffectClassID; 86 int32_t fEffectClassID;
84 87
85 private: 88 private:
86 static int32_t fCurrEffectClassID; 89 static int32_t fCurrEffectClassID;
87 }; 90 };
88 91
89 #endif 92 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrTBackendEffectFactory.h » ('j') | include/gpu/GrTBackendEffectFactory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698