gfx/skia/trunk/src/gpu/GrEffect.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 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 #include "GrEffect.h"
     9 #include "GrBackendEffectFactory.h"
    10 #include "GrContext.h"
    11 #include "GrCoordTransform.h"
    12 #include "GrMemoryPool.h"
    13 #include "SkTLS.h"
    15 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
    16 SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() {
    17     static SkTArray<GrEffectTestFactory*, true> gFactories;
    18     return &gFactories;
    19 }
    20 #endif
    22 namespace GrEffectUnitTest {
    23 const SkMatrix& TestMatrix(SkRandom* random) {
    24     static SkMatrix gMatrices[5];
    25     static bool gOnce;
    26     if (!gOnce) {
    27         gMatrices[0].reset();
    28         gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
    29         gMatrices[2].setRotate(SkIntToScalar(17));
    30         gMatrices[3].setRotate(SkIntToScalar(185));
    31         gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
    32         gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf);
    33         gMatrices[4].setRotate(SkIntToScalar(215));
    34         gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
    35         gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
    36         gOnce = true;
    37     }
    38     return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
    39 }
    40 }
    42 class GrEffect_Globals {
    43 public:
    44     static GrMemoryPool* GetTLS() {
    45         return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
    46     }
    48 private:
    49     static void* CreateTLS() {
    50         return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
    51     }
    53     static void DeleteTLS(void* pool) {
    54         SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
    55     }
    56 };
    58 int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID;
    60 ///////////////////////////////////////////////////////////////////////////////
    62 GrEffectRef::~GrEffectRef() {
    63     SkASSERT(this->unique());
    64     fEffect->EffectRefDestroyed();
    65     fEffect->unref();
    66 }
    68 void* GrEffectRef::operator new(size_t size) {
    69     return GrEffect_Globals::GetTLS()->allocate(size);
    70 }
    72 void GrEffectRef::operator delete(void* target) {
    73     GrEffect_Globals::GetTLS()->release(target);
    74 }
    76 ///////////////////////////////////////////////////////////////////////////////
    78 GrEffect::~GrEffect() {
    79     SkASSERT(NULL == fEffectRef);
    80 }
    82 const char* GrEffect::name() const {
    83     return this->getFactory().name();
    84 }
    86 void GrEffect::addCoordTransform(const GrCoordTransform* transform) {
    87     fCoordTransforms.push_back(transform);
    88     SkDEBUGCODE(transform->setInEffect();)
    89 }
    91 void GrEffect::addTextureAccess(const GrTextureAccess* access) {
    92     fTextureAccesses.push_back(access);
    93 }
    95 void* GrEffect::operator new(size_t size) {
    96     return GrEffect_Globals::GetTLS()->allocate(size);
    97 }
    99 void GrEffect::operator delete(void* target) {
   100     GrEffect_Globals::GetTLS()->release(target);
   101 }
   103 #ifdef SK_DEBUG
   104 void GrEffect::assertEquality(const GrEffect& other) const {
   105     SkASSERT(this->numTransforms() == other.numTransforms());
   106     for (int i = 0; i < this->numTransforms(); ++i) {
   107         SkASSERT(this->coordTransform(i) == other.coordTransform(i));
   108     }
   109     SkASSERT(this->numTextures() == other.numTextures());
   110     for (int i = 0; i < this->numTextures(); ++i) {
   111         SkASSERT(this->textureAccess(i) == other.textureAccess(i));
   112     }
   113 }
   114 #endif

mercurial