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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/gpu/GrTBackendEffectFactory.h » ('j') | include/gpu/GrTBackendEffectFactory.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/gpu/GrBackendEffectFactory.h
diff --git a/include/gpu/GrBackendEffectFactory.h b/include/gpu/GrBackendEffectFactory.h
index af8d5c76c577b9bfb3034c602ab82bf2e329e160..32f14f27460955a0f99939faaaef27a4d87ec9b3 100644
--- a/include/gpu/GrBackendEffectFactory.h
+++ b/include/gpu/GrBackendEffectFactory.h
@@ -12,6 +12,7 @@
#include "SkTemplates.h"
#include "SkThread.h"
#include "SkTypes.h"
+#include "SkTArray.h"
/** Given a GrEffect of a particular type, creates the corresponding graphics-backend-specific
effect object. Also tracks equivalence of shaders generated via a key. Each factory instance
@@ -27,23 +28,32 @@ class GrGLEffect;
class GrGLCaps;
class GrDrawEffect;
+/**
+ * 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
+ */
+class GrEffectKeyBuilder {
+public:
+ GrEffectKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) {
+ SkASSERT(0 == fData->count() % sizeof(uint32_t));
+ }
+
+ void add32(uint32_t v) {
+ ++fCount;
+ fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v));
+ }
+
+ size_t size() const { return sizeof(uint32_t) * fCount; }
+
+private:
+ SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
+ int fCount; // number of uint32_ts added to fData by the effect.
+};
+
class GrBackendEffectFactory : SkNoncopyable {
public:
typedef uint32_t EffectKey;
- enum {
- kNoEffectKey = 0,
- kEffectKeyBits = 10,
- /**
- * The framework automatically includes coord transforms and texture accesses in their
- * effect's EffectKey, so effects don't need to account for them in GenKey().
- */
- kTextureKeyBits = 4,
- kTransformKeyBits = 6,
- kAttribKeyBits = 6,
- kClassIDBits = 6
- };
- virtual EffectKey glEffectKey(const GrDrawEffect&, const GrGLCaps&) const = 0;
+ virtual bool getGLEffectKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*) const = 0;
virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0;
bool operator ==(const GrBackendEffectFactory& b) const {
@@ -55,10 +65,6 @@ public:
virtual const char* name() const = 0;
- static EffectKey GetTransformKey(EffectKey key) {
- return key >> (kEffectKeyBits + kTextureKeyBits) & ((1U << kTransformKeyBits) - 1);
- }
-
protected:
enum {
kIllegalEffectClassID = 0,
@@ -69,18 +75,15 @@ protected:
}
virtual ~GrBackendEffectFactory() {}
- static EffectKey GenID() {
- SkDEBUGCODE(static const int32_t kClassIDBits = 8 * sizeof(EffectKey) -
- kTextureKeyBits - kEffectKeyBits - kAttribKeyBits);
+ static int32_t GenID() {
// fCurrEffectClassID has been initialized to kIllegalEffectClassID. The
// atomic inc returns the old value not the incremented value. So we add
// 1 to the returned value.
int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1;
- SkASSERT(id < (1 << kClassIDBits));
- return static_cast<EffectKey>(id);
+ return id;
}
- EffectKey fEffectClassID;
+ int32_t fEffectClassID;
private:
static int32_t fCurrEffectClassID;
« 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