gfx/skia/trunk/include/gpu/GrBackendEffectFactory.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/gpu/GrBackendEffectFactory.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrBackendEffectFactory_DEFINED
    1.12 +#define GrBackendEffectFactory_DEFINED
    1.13 +
    1.14 +#include "GrTypes.h"
    1.15 +#include "SkTemplates.h"
    1.16 +#include "SkThread.h"
    1.17 +#include "SkTypes.h"
    1.18 +
    1.19 +/** Given a GrEffect of a particular type, creates the corresponding graphics-backend-specific
    1.20 +    effect object. Also tracks equivalence of shaders generated via a key. Each factory instance
    1.21 +    is assigned a generation ID at construction. The ID of the return of GrEffect::getFactory()
    1.22 +    is used as a type identifier. Thus a GrEffect subclass must return a singleton from
    1.23 +    getFactory(). GrEffect subclasses should use the derived class GrTBackendEffectFactory that is
    1.24 +    templated on the GrEffect subclass as their factory object. It requires that the GrEffect
    1.25 +    subclass has a nested class (or typedef) GLEffect which is its GL implementation and a subclass
    1.26 +    of GrGLEffect.
    1.27 + */
    1.28 +
    1.29 +class GrEffectRef;
    1.30 +class GrGLEffect;
    1.31 +class GrGLCaps;
    1.32 +class GrDrawEffect;
    1.33 +
    1.34 +class GrBackendEffectFactory : public SkNoncopyable {
    1.35 +public:
    1.36 +    typedef uint32_t EffectKey;
    1.37 +    enum {
    1.38 +        kNoEffectKey = 0,
    1.39 +        kEffectKeyBits = 10,
    1.40 +        /**
    1.41 +         * The framework automatically includes coord transforms and texture accesses in their
    1.42 +         * effect's EffectKey, so effects don't need to account for them in GenKey().
    1.43 +         */
    1.44 +        kTextureKeyBits = 4,
    1.45 +        kTransformKeyBits = 6,
    1.46 +        kAttribKeyBits = 6,
    1.47 +        kClassIDBits = 6
    1.48 +    };
    1.49 +
    1.50 +    virtual EffectKey glEffectKey(const GrDrawEffect&, const GrGLCaps&) const = 0;
    1.51 +    virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0;
    1.52 +
    1.53 +    bool operator ==(const GrBackendEffectFactory& b) const {
    1.54 +        return fEffectClassID == b.fEffectClassID;
    1.55 +    }
    1.56 +    bool operator !=(const GrBackendEffectFactory& b) const {
    1.57 +        return !(*this == b);
    1.58 +    }
    1.59 +
    1.60 +    virtual const char* name() const = 0;
    1.61 +
    1.62 +    static EffectKey GetTransformKey(EffectKey key) {
    1.63 +        return key >> (kEffectKeyBits + kTextureKeyBits) & ((1U << kTransformKeyBits) - 1);
    1.64 +    }
    1.65 +
    1.66 +protected:
    1.67 +    enum {
    1.68 +        kIllegalEffectClassID = 0,
    1.69 +    };
    1.70 +
    1.71 +    GrBackendEffectFactory() {
    1.72 +        fEffectClassID = kIllegalEffectClassID;
    1.73 +    }
    1.74 +    virtual ~GrBackendEffectFactory() {}
    1.75 +
    1.76 +    static EffectKey GenID() {
    1.77 +        SkDEBUGCODE(static const int32_t kClassIDBits = 8 * sizeof(EffectKey) -
    1.78 +                           kTextureKeyBits - kEffectKeyBits - kAttribKeyBits);
    1.79 +        // fCurrEffectClassID has been initialized to kIllegalEffectClassID. The
    1.80 +        // atomic inc returns the old value not the incremented value. So we add
    1.81 +        // 1 to the returned value.
    1.82 +        int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1;
    1.83 +        SkASSERT(id < (1 << kClassIDBits));
    1.84 +        return static_cast<EffectKey>(id);
    1.85 +    }
    1.86 +
    1.87 +    EffectKey fEffectClassID;
    1.88 +
    1.89 +private:
    1.90 +    static int32_t fCurrEffectClassID;
    1.91 +};
    1.92 +
    1.93 +#endif

mercurial