gfx/skia/trunk/src/gpu/gl/GrGLSL_impl.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 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 #ifndef GrGLSL_impl_DEFINED
     9 #define GrGLSL_impl_DEFINED
    11 template<typename Self>
    12 template<typename T>
    13 inline Self GrGLSLExpr<Self>::VectorCastImpl(const T& expr) {
    14     if (expr.isZeros()) {
    15         return Self(0);
    16     }
    17     if (expr.isOnes()) {
    18         return Self(1);
    19     }
    20     return Self(Self::CastStr(), expr.c_str());
    21 }
    23 template<typename Self>
    24 template<typename T0, typename T1>
    25 inline Self GrGLSLExpr<Self>::Mul(T0 in0, T1 in1) {
    26     if (in0.isZeros() || in1.isZeros()) {
    27         return Self(0);
    28     }
    29     if (in0.isOnes()) {
    30         return Self::VectorCast(in1);
    31     }
    32     if (in1.isOnes()) {
    33         return Self::VectorCast(in0);
    34     }
    35     return Self("(%s * %s)", in0.c_str(), in1.c_str());
    36 }
    38 template<typename Self>
    39 template<typename T0, typename T1>
    40 inline Self GrGLSLExpr<Self>::Add(T0 in0, T1 in1) {
    41     if (in1.isZeros()) {
    42         return Self::VectorCast(in0);
    43     }
    44     if (in0.isZeros()) {
    45         return Self::VectorCast(in1);
    46     }
    47     if (in0.isOnes() && in1.isOnes()) {
    48         return Self(2);
    49     }
    50     return Self("(%s + %s)", in0.c_str(), in1.c_str());
    51 }
    53 template<typename Self>
    54 template<typename T0, typename T1>
    55 inline Self GrGLSLExpr<Self>::Sub(T0 in0, T1 in1) {
    56     if (in1.isZeros()) {
    57         return Self::VectorCast(in0);
    58     }
    59     if (in1.isOnes()) {
    60         if (in0.isOnes()) {
    61             return Self(0);
    62         }
    63     }
    65     return Self("(%s - %s)", in0.c_str(), in1.c_str());
    66 }
    68 template <typename Self>
    69 template <typename T>
    70 T GrGLSLExpr<Self>::extractComponents(const char format[]) const {
    71     if (this->isZeros()) {
    72         return T(0);
    73     }
    74     if (this->isOnes()) {
    75         return T(1);
    76     }
    77     return T(format, this->c_str());
    78 }
    80 inline GrGLSLExpr1 GrGLSLExpr1::VectorCast(const GrGLSLExpr1& expr) {
    81     return expr;
    82 }
    84 inline const char* GrGLSLExpr1::ZerosStr() {
    85     return "0";
    86 }
    88 inline const char* GrGLSLExpr1::OnesStr() {
    89     return "1.0";
    90 }
    92 // GrGLSLExpr1::CastStr() is unimplemented because using them is likely an
    93 // error. This is now caught compile-time.
    95 inline const char* GrGLSLExpr1::CastIntStr() {
    96     return "%d";
    97 }
    99 inline GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
   100     return GrGLSLExpr1::Mul(in0, in1);
   101 }
   103 inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
   104     return GrGLSLExpr1::Add(in0, in1);
   105 }
   107 inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
   108     return GrGLSLExpr1::Sub(in0, in1);
   109 }
   111 inline const char* GrGLSLExpr4::ZerosStr() {
   112     return "vec4(0)";
   113 }
   115 inline const char* GrGLSLExpr4::OnesStr() {
   116     return "vec4(1)";
   117 }
   119 inline const char* GrGLSLExpr4::CastStr() {
   120     return "vec4(%s)";
   121 }
   123 inline const char* GrGLSLExpr4::CastIntStr() {
   124     return "vec4(%d)";
   125 }
   127 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) {
   128     return INHERITED::VectorCastImpl(expr);
   129 }
   131 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) {
   132     return expr;
   133 }
   135 inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const {
   136     return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a");
   137 }
   139 inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
   140     return GrGLSLExpr4::Mul(in0, in1);
   141 }
   143 inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
   144     return GrGLSLExpr4::Add(in0, in1);
   145 }
   147 inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
   148     return GrGLSLExpr4::Sub(in0, in1);
   149 }
   151 inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
   152     return GrGLSLExpr4::Mul(in0, in1);
   153 }
   155 inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
   156     return GrGLSLExpr4::Add(in0, in1);
   157 }
   159 inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
   160     return GrGLSLExpr4::Sub(in0, in1);
   161 }
   163 inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
   164     return GrGLSLExpr4::Mul(in0, in1);
   165 }
   167 inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
   168     return GrGLSLExpr4::Add(in0, in1);
   169 }
   171 inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
   172     return GrGLSLExpr4::Sub(in0, in1);
   173 }
   175 #endif

mercurial