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.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef GrGLSL_impl_DEFINED
michael@0 9 #define GrGLSL_impl_DEFINED
michael@0 10
michael@0 11 template<typename Self>
michael@0 12 template<typename T>
michael@0 13 inline Self GrGLSLExpr<Self>::VectorCastImpl(const T& expr) {
michael@0 14 if (expr.isZeros()) {
michael@0 15 return Self(0);
michael@0 16 }
michael@0 17 if (expr.isOnes()) {
michael@0 18 return Self(1);
michael@0 19 }
michael@0 20 return Self(Self::CastStr(), expr.c_str());
michael@0 21 }
michael@0 22
michael@0 23 template<typename Self>
michael@0 24 template<typename T0, typename T1>
michael@0 25 inline Self GrGLSLExpr<Self>::Mul(T0 in0, T1 in1) {
michael@0 26 if (in0.isZeros() || in1.isZeros()) {
michael@0 27 return Self(0);
michael@0 28 }
michael@0 29 if (in0.isOnes()) {
michael@0 30 return Self::VectorCast(in1);
michael@0 31 }
michael@0 32 if (in1.isOnes()) {
michael@0 33 return Self::VectorCast(in0);
michael@0 34 }
michael@0 35 return Self("(%s * %s)", in0.c_str(), in1.c_str());
michael@0 36 }
michael@0 37
michael@0 38 template<typename Self>
michael@0 39 template<typename T0, typename T1>
michael@0 40 inline Self GrGLSLExpr<Self>::Add(T0 in0, T1 in1) {
michael@0 41 if (in1.isZeros()) {
michael@0 42 return Self::VectorCast(in0);
michael@0 43 }
michael@0 44 if (in0.isZeros()) {
michael@0 45 return Self::VectorCast(in1);
michael@0 46 }
michael@0 47 if (in0.isOnes() && in1.isOnes()) {
michael@0 48 return Self(2);
michael@0 49 }
michael@0 50 return Self("(%s + %s)", in0.c_str(), in1.c_str());
michael@0 51 }
michael@0 52
michael@0 53 template<typename Self>
michael@0 54 template<typename T0, typename T1>
michael@0 55 inline Self GrGLSLExpr<Self>::Sub(T0 in0, T1 in1) {
michael@0 56 if (in1.isZeros()) {
michael@0 57 return Self::VectorCast(in0);
michael@0 58 }
michael@0 59 if (in1.isOnes()) {
michael@0 60 if (in0.isOnes()) {
michael@0 61 return Self(0);
michael@0 62 }
michael@0 63 }
michael@0 64
michael@0 65 return Self("(%s - %s)", in0.c_str(), in1.c_str());
michael@0 66 }
michael@0 67
michael@0 68 template <typename Self>
michael@0 69 template <typename T>
michael@0 70 T GrGLSLExpr<Self>::extractComponents(const char format[]) const {
michael@0 71 if (this->isZeros()) {
michael@0 72 return T(0);
michael@0 73 }
michael@0 74 if (this->isOnes()) {
michael@0 75 return T(1);
michael@0 76 }
michael@0 77 return T(format, this->c_str());
michael@0 78 }
michael@0 79
michael@0 80 inline GrGLSLExpr1 GrGLSLExpr1::VectorCast(const GrGLSLExpr1& expr) {
michael@0 81 return expr;
michael@0 82 }
michael@0 83
michael@0 84 inline const char* GrGLSLExpr1::ZerosStr() {
michael@0 85 return "0";
michael@0 86 }
michael@0 87
michael@0 88 inline const char* GrGLSLExpr1::OnesStr() {
michael@0 89 return "1.0";
michael@0 90 }
michael@0 91
michael@0 92 // GrGLSLExpr1::CastStr() is unimplemented because using them is likely an
michael@0 93 // error. This is now caught compile-time.
michael@0 94
michael@0 95 inline const char* GrGLSLExpr1::CastIntStr() {
michael@0 96 return "%d";
michael@0 97 }
michael@0 98
michael@0 99 inline GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
michael@0 100 return GrGLSLExpr1::Mul(in0, in1);
michael@0 101 }
michael@0 102
michael@0 103 inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
michael@0 104 return GrGLSLExpr1::Add(in0, in1);
michael@0 105 }
michael@0 106
michael@0 107 inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
michael@0 108 return GrGLSLExpr1::Sub(in0, in1);
michael@0 109 }
michael@0 110
michael@0 111 inline const char* GrGLSLExpr4::ZerosStr() {
michael@0 112 return "vec4(0)";
michael@0 113 }
michael@0 114
michael@0 115 inline const char* GrGLSLExpr4::OnesStr() {
michael@0 116 return "vec4(1)";
michael@0 117 }
michael@0 118
michael@0 119 inline const char* GrGLSLExpr4::CastStr() {
michael@0 120 return "vec4(%s)";
michael@0 121 }
michael@0 122
michael@0 123 inline const char* GrGLSLExpr4::CastIntStr() {
michael@0 124 return "vec4(%d)";
michael@0 125 }
michael@0 126
michael@0 127 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) {
michael@0 128 return INHERITED::VectorCastImpl(expr);
michael@0 129 }
michael@0 130
michael@0 131 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) {
michael@0 132 return expr;
michael@0 133 }
michael@0 134
michael@0 135 inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const {
michael@0 136 return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a");
michael@0 137 }
michael@0 138
michael@0 139 inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
michael@0 140 return GrGLSLExpr4::Mul(in0, in1);
michael@0 141 }
michael@0 142
michael@0 143 inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
michael@0 144 return GrGLSLExpr4::Add(in0, in1);
michael@0 145 }
michael@0 146
michael@0 147 inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
michael@0 148 return GrGLSLExpr4::Sub(in0, in1);
michael@0 149 }
michael@0 150
michael@0 151 inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
michael@0 152 return GrGLSLExpr4::Mul(in0, in1);
michael@0 153 }
michael@0 154
michael@0 155 inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
michael@0 156 return GrGLSLExpr4::Add(in0, in1);
michael@0 157 }
michael@0 158
michael@0 159 inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
michael@0 160 return GrGLSLExpr4::Sub(in0, in1);
michael@0 161 }
michael@0 162
michael@0 163 inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
michael@0 164 return GrGLSLExpr4::Mul(in0, in1);
michael@0 165 }
michael@0 166
michael@0 167 inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
michael@0 168 return GrGLSLExpr4::Add(in0, in1);
michael@0 169 }
michael@0 170
michael@0 171 inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
michael@0 172 return GrGLSLExpr4::Sub(in0, in1);
michael@0 173 }
michael@0 174
michael@0 175 #endif

mercurial