gfx/skia/trunk/include/gpu/GrTextureAccess.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 2012 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 GrTextureAccess_DEFINED
michael@0 9 #define GrTextureAccess_DEFINED
michael@0 10
michael@0 11 #include "SkRefCnt.h"
michael@0 12 #include "SkShader.h"
michael@0 13 #include "SkTypes.h"
michael@0 14
michael@0 15 class GrTexture;
michael@0 16
michael@0 17 /**
michael@0 18 * Represents the filtering and tile modes used to access a texture. It is mostly used with
michael@0 19 * GrTextureAccess (defined below). Also, some of the texture cache methods require knowledge about
michael@0 20 * filtering and tiling to perform a cache lookup. If it wasn't for this latter usage this would
michael@0 21 * be folded into GrTextureAccess. The default is clamp tile modes and no filtering.
michael@0 22 */
michael@0 23 class GrTextureParams {
michael@0 24 public:
michael@0 25 GrTextureParams() {
michael@0 26 this->reset();
michael@0 27 }
michael@0 28
michael@0 29 enum FilterMode {
michael@0 30 kNone_FilterMode,
michael@0 31 kBilerp_FilterMode,
michael@0 32 kMipMap_FilterMode
michael@0 33 };
michael@0 34
michael@0 35 GrTextureParams(SkShader::TileMode tileXAndY, FilterMode filterMode) {
michael@0 36 this->reset(tileXAndY, filterMode);
michael@0 37 }
michael@0 38
michael@0 39 GrTextureParams(const SkShader::TileMode tileModes[2], FilterMode filterMode) {
michael@0 40 this->reset(tileModes, filterMode);
michael@0 41 }
michael@0 42
michael@0 43 GrTextureParams(const GrTextureParams& params) {
michael@0 44 *this = params;
michael@0 45 }
michael@0 46
michael@0 47 GrTextureParams& operator= (const GrTextureParams& params) {
michael@0 48 fTileModes[0] = params.fTileModes[0];
michael@0 49 fTileModes[1] = params.fTileModes[1];
michael@0 50 fFilterMode = params.fFilterMode;
michael@0 51 return *this;
michael@0 52 }
michael@0 53
michael@0 54 void reset() {
michael@0 55 this->reset(SkShader::kClamp_TileMode, kNone_FilterMode);
michael@0 56 }
michael@0 57
michael@0 58 void reset(SkShader::TileMode tileXAndY, FilterMode filterMode) {
michael@0 59 fTileModes[0] = fTileModes[1] = tileXAndY;
michael@0 60 fFilterMode = filterMode;
michael@0 61 }
michael@0 62
michael@0 63 void reset(const SkShader::TileMode tileModes[2], FilterMode filterMode) {
michael@0 64 fTileModes[0] = tileModes[0];
michael@0 65 fTileModes[1] = tileModes[1];
michael@0 66 fFilterMode = filterMode;
michael@0 67 }
michael@0 68
michael@0 69 void setClampNoFilter() {
michael@0 70 fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode;
michael@0 71 fFilterMode = kNone_FilterMode;
michael@0 72 }
michael@0 73
michael@0 74 void setClamp() {
michael@0 75 fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode;
michael@0 76 }
michael@0 77
michael@0 78 void setFilterMode(FilterMode filterMode) { fFilterMode = filterMode; }
michael@0 79
michael@0 80 void setTileModeX(const SkShader::TileMode tm) { fTileModes[0] = tm; }
michael@0 81 void setTileModeY(const SkShader::TileMode tm) { fTileModes[1] = tm; }
michael@0 82 void setTileModeXAndY(const SkShader::TileMode tm) { fTileModes[0] = fTileModes[1] = tm; }
michael@0 83
michael@0 84 SkShader::TileMode getTileModeX() const { return fTileModes[0]; }
michael@0 85
michael@0 86 SkShader::TileMode getTileModeY() const { return fTileModes[1]; }
michael@0 87
michael@0 88 bool isTiled() const {
michael@0 89 return SkShader::kClamp_TileMode != fTileModes[0] ||
michael@0 90 SkShader::kClamp_TileMode != fTileModes[1];
michael@0 91 }
michael@0 92
michael@0 93 FilterMode filterMode() const { return fFilterMode; }
michael@0 94
michael@0 95 bool operator== (const GrTextureParams& other) const {
michael@0 96 return fTileModes[0] == other.fTileModes[0] &&
michael@0 97 fTileModes[1] == other.fTileModes[1] &&
michael@0 98 fFilterMode == other.fFilterMode;
michael@0 99 }
michael@0 100
michael@0 101 bool operator!= (const GrTextureParams& other) const { return !(*this == other); }
michael@0 102
michael@0 103 private:
michael@0 104
michael@0 105 SkShader::TileMode fTileModes[2];
michael@0 106 FilterMode fFilterMode;
michael@0 107 };
michael@0 108
michael@0 109 /** A class representing the swizzle access pattern for a texture. Note that if the texture is
michael@0 110 * an alpha-only texture then the alpha channel is substituted for other components. Any mangling
michael@0 111 * to handle the r,g,b->a conversions for alpha textures is automatically included in the stage
michael@0 112 * key. However, if a GrEffect uses different swizzles based on its input then it must
michael@0 113 * consider that variation in its key-generation.
michael@0 114 */
michael@0 115 class GrTextureAccess : public SkNoncopyable {
michael@0 116 public:
michael@0 117 /**
michael@0 118 * A default GrTextureAccess must have reset() called on it in a GrEffect subclass's
michael@0 119 * constructor if it will be accessible via GrEffect::textureAccess().
michael@0 120 */
michael@0 121 GrTextureAccess();
michael@0 122
michael@0 123 /**
michael@0 124 * Uses the default swizzle, "rgba".
michael@0 125 */
michael@0 126 GrTextureAccess(GrTexture*, const GrTextureParams&);
michael@0 127 explicit GrTextureAccess(GrTexture*,
michael@0 128 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
michael@0 129 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
michael@0 130
michael@0 131 /**
michael@0 132 * swizzle must be a string between one and four (inclusive) characters containing only 'r',
michael@0 133 * 'g', 'b', and/or 'a'.
michael@0 134 */
michael@0 135 GrTextureAccess(GrTexture*, const char* swizzle, const GrTextureParams&);
michael@0 136 GrTextureAccess(GrTexture*,
michael@0 137 const char* swizzle,
michael@0 138 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
michael@0 139 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
michael@0 140
michael@0 141 void reset(GrTexture*, const GrTextureParams&);
michael@0 142 void reset(GrTexture*,
michael@0 143 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
michael@0 144 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
michael@0 145 void reset(GrTexture*, const char* swizzle, const GrTextureParams&);
michael@0 146 void reset(GrTexture*,
michael@0 147 const char* swizzle,
michael@0 148 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
michael@0 149 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
michael@0 150
michael@0 151 bool operator== (const GrTextureAccess& other) const {
michael@0 152 #ifdef SK_DEBUG
michael@0 153 // below assumes all chars in fSwizzle are initialized even if string is < 4 chars long.
michael@0 154 SkASSERT(memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1) ==
michael@0 155 strcmp(fSwizzle, other.fSwizzle));
michael@0 156 #endif
michael@0 157 return fParams == other.fParams &&
michael@0 158 (fTexture.get() == other.fTexture.get()) &&
michael@0 159 (0 == memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1));
michael@0 160 }
michael@0 161
michael@0 162 bool operator!= (const GrTextureAccess& other) const { return !(*this == other); }
michael@0 163
michael@0 164 GrTexture* getTexture() const { return fTexture.get(); }
michael@0 165
michael@0 166 /**
michael@0 167 * Returns a string representing the swizzle. The string is is null-terminated.
michael@0 168 */
michael@0 169 const char* getSwizzle() const { return fSwizzle; }
michael@0 170
michael@0 171 /** Returns a mask indicating which components are referenced in the swizzle. The return
michael@0 172 is a bitfield of GrColorComponentFlags. */
michael@0 173 uint32_t swizzleMask() const { return fSwizzleMask; }
michael@0 174
michael@0 175 const GrTextureParams& getParams() const { return fParams; }
michael@0 176
michael@0 177 private:
michael@0 178 void setSwizzle(const char*);
michael@0 179
michael@0 180 GrTextureParams fParams;
michael@0 181 SkAutoTUnref<GrTexture> fTexture;
michael@0 182 uint32_t fSwizzleMask;
michael@0 183 char fSwizzle[5];
michael@0 184
michael@0 185 typedef SkNoncopyable INHERITED;
michael@0 186 };
michael@0 187
michael@0 188 #endif

mercurial