gfx/skia/trunk/src/gpu/effects/GrCustomCoordsTextureEffect.cpp

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 2013 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 #include "GrCustomCoordsTextureEffect.h"
     9 #include "gl/GrGLEffect.h"
    10 #include "gl/GrGLSL.h"
    11 #include "gl/GrGLTexture.h"
    12 #include "gl/GrGLVertexEffect.h"
    13 #include "GrTBackendEffectFactory.h"
    14 #include "GrTexture.h"
    16 class GrGLCustomCoordsTextureEffect : public GrGLVertexEffect {
    17 public:
    18     GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect)
    19         : INHERITED (factory) {}
    21     virtual void emitCode(GrGLFullShaderBuilder* builder,
    22                           const GrDrawEffect& drawEffect,
    23                           EffectKey key,
    24                           const char* outputColor,
    25                           const char* inputColor,
    26                           const TransformedCoordsArray&,
    27                           const TextureSamplerArray& samplers) SK_OVERRIDE {
    28         SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVertexAttribs());
    30         SkString fsCoordName;
    31         const char* vsVaryingName;
    32         const char* fsVaryingNamePtr;
    33         builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &fsVaryingNamePtr);
    34         fsCoordName = fsVaryingNamePtr;
    36         const char* attrName =
    37             builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0])->c_str();
    38         builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName);
    40         builder->fsCodeAppendf("\t%s = ", outputColor);
    41         builder->fsAppendTextureLookupAndModulate(inputColor,
    42                                                   samplers[0],
    43                                                   fsCoordName.c_str(),
    44                                                   kVec2f_GrSLType);
    45         builder->fsCodeAppend(";\n");
    46     }
    48     virtual void setData(const GrGLUniformManager& uman,
    49                          const GrDrawEffect& drawEffect) SK_OVERRIDE {}
    51 private:
    52     typedef GrGLVertexEffect INHERITED;
    53 };
    55 ///////////////////////////////////////////////////////////////////////////////
    57 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture,
    58                                                          const GrTextureParams& params)
    59     : fTextureAccess(texture, params) {
    60     this->addTextureAccess(&fTextureAccess);
    61     this->addVertexAttrib(kVec2f_GrSLType);
    62 }
    64 bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const {
    65     const GrCustomCoordsTextureEffect& cte = CastEffect<GrCustomCoordsTextureEffect>(other);
    66     return fTextureAccess == cte.fTextureAccess;
    67 }
    69 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color,
    70                                                              uint32_t* validFlags) const {
    71     if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
    72         GrPixelConfigIsOpaque(this->texture(0)->config())) {
    73         *validFlags = kA_GrColorComponentFlag;
    74     } else {
    75         *validFlags = 0;
    76     }
    77 }
    79 const GrBackendEffectFactory& GrCustomCoordsTextureEffect::getFactory() const {
    80     return GrTBackendEffectFactory<GrCustomCoordsTextureEffect>::getInstance();
    81 }
    83 ///////////////////////////////////////////////////////////////////////////////
    85 GR_DEFINE_EFFECT_TEST(GrCustomCoordsTextureEffect);
    87 GrEffectRef* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random,
    88                                                      GrContext*,
    89                                                      const GrDrawTargetCaps&,
    90                                                      GrTexture* textures[]) {
    91     int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
    92                                       GrEffectUnitTest::kAlphaTextureIdx;
    93     static const SkShader::TileMode kTileModes[] = {
    94         SkShader::kClamp_TileMode,
    95         SkShader::kRepeat_TileMode,
    96         SkShader::kMirror_TileMode,
    97     };
    98     SkShader::TileMode tileModes[] = {
    99         kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
   100         kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
   101     };
   102     GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
   103                                                            GrTextureParams::kNone_FilterMode);
   105     return GrCustomCoordsTextureEffect::Create(textures[texIdx], params);
   106 }

mercurial