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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /*
     2  * Copyright 2012 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #ifndef GrTBackendEffectFactory_DEFINED
     9 #define GrTBackendEffectFactory_DEFINED
    11 #include "GrBackendEffectFactory.h"
    12 #include "GrDrawEffect.h"
    13 #include "gl/GrGLProgramEffects.h"
    15 /**
    16  * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton.
    17  */
    18 template <typename EffectClass>
    19 class GrTBackendEffectFactory : public GrBackendEffectFactory {
    21 public:
    22     typedef typename EffectClass::GLEffect GLEffect;
    24     /** Returns a human-readable name that is accessible via GrEffect or
    25         GrGLEffect and is consistent between the two of them.
    26      */
    27     virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); }
    29     /** Returns a value that identifies the GLSL shader code generated by
    30         a GrEffect. This enables caching of generated shaders. Part of the
    31         id identifies the GrEffect subclass. The remainder is based
    32         on the aspects of the GrEffect object's configuration that affect
    33         GLSL code generation. */
    34     virtual EffectKey glEffectKey(const GrDrawEffect& drawEffect,
    35                                   const GrGLCaps& caps) const SK_OVERRIDE {
    36         SkASSERT(kIllegalEffectClassID != fEffectClassID);
    37         EffectKey effectKey = GLEffect::GenKey(drawEffect, caps);
    38         EffectKey textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps);
    39         EffectKey transformKey = GrGLProgramEffects::GenTransformKey(drawEffect);
    40         EffectKey attribKey = GrGLProgramEffects::GenAttribKey(drawEffect);
    41 #ifdef SK_DEBUG
    42         static const EffectKey kIllegalEffectKeyMask = (uint16_t) (~((1U << kEffectKeyBits) - 1));
    43         SkASSERT(!(kIllegalEffectKeyMask & effectKey));
    45         static const EffectKey kIllegalTextureKeyMask = (uint16_t) (~((1U << kTextureKeyBits) - 1));
    46         SkASSERT(!(kIllegalTextureKeyMask & textureKey));
    48         static const EffectKey kIllegalTransformKeyMask = (uint16_t) (~((1U << kTransformKeyBits) - 1));
    49         SkASSERT(!(kIllegalTransformKeyMask & transformKey));
    51         static const EffectKey kIllegalAttribKeyMask = (uint16_t) (~((1U << kAttribKeyBits) - 1));
    52         SkASSERT(!(kIllegalAttribKeyMask & textureKey));
    54         static const EffectKey kIllegalClassIDMask = (uint16_t) (~((1U << kClassIDBits) - 1));
    55         SkASSERT(!(kIllegalClassIDMask & fEffectClassID));
    56 #endif
    57         return (fEffectClassID << (kEffectKeyBits+kTextureKeyBits+kTransformKeyBits+kAttribKeyBits)) |
    58                (attribKey << (kEffectKeyBits+kTextureKeyBits+kTransformKeyBits)) |
    59                (transformKey << (kEffectKeyBits+kTextureKeyBits)) |
    60                (textureKey << kEffectKeyBits) |
    61                (effectKey);
    62     }
    64     /** Returns a new instance of the appropriate *GL* implementation class
    65         for the given GrEffect; caller is responsible for deleting
    66         the object. */
    67     virtual GrGLEffect* createGLInstance(const GrDrawEffect& drawEffect) const SK_OVERRIDE {
    68         return SkNEW_ARGS(GLEffect, (*this, drawEffect));
    69     }
    71     /** This class is a singleton. This function returns the single instance.
    72      */
    73     static const GrBackendEffectFactory& getInstance() {
    74         static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem;
    75         static const GrTBackendEffectFactory* gInstance;
    76         if (!gInstance) {
    77             gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
    78                                         GrTBackendEffectFactory);
    79         }
    80         return *gInstance;
    81     }
    83 protected:
    84     GrTBackendEffectFactory() {
    85         fEffectClassID = GenID();
    86     }
    87 };
    89 #endif

mercurial