gfx/skia/trunk/include/gpu/GrTexture.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 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9 #ifndef GrTexture_DEFINED
michael@0 10 #define GrTexture_DEFINED
michael@0 11
michael@0 12 #include "GrSurface.h"
michael@0 13 #include "SkPoint.h"
michael@0 14 #include "GrRenderTarget.h"
michael@0 15
michael@0 16 class GrResourceKey;
michael@0 17 class GrTextureParams;
michael@0 18
michael@0 19 class GrTexture : public GrSurface {
michael@0 20
michael@0 21 public:
michael@0 22 SK_DECLARE_INST_COUNT(GrTexture)
michael@0 23 // from GrResource
michael@0 24 /**
michael@0 25 * Informational texture flags
michael@0 26 */
michael@0 27 enum FlagBits {
michael@0 28 kFirstBit = (kLastPublic_GrTextureFlagBit << 1),
michael@0 29
michael@0 30 /**
michael@0 31 * This texture should be returned to the texture cache when
michael@0 32 * it is no longer reffed
michael@0 33 */
michael@0 34 kReturnToCache_FlagBit = kFirstBit,
michael@0 35 };
michael@0 36
michael@0 37 void setFlag(GrTextureFlags flags) {
michael@0 38 fDesc.fFlags = fDesc.fFlags | flags;
michael@0 39 }
michael@0 40 void resetFlag(GrTextureFlags flags) {
michael@0 41 fDesc.fFlags = fDesc.fFlags & ~flags;
michael@0 42 }
michael@0 43 bool isSetFlag(GrTextureFlags flags) const {
michael@0 44 return 0 != (fDesc.fFlags & flags);
michael@0 45 }
michael@0 46
michael@0 47 void dirtyMipMaps(bool mipMapsDirty) {
michael@0 48 fMipMapsDirty = mipMapsDirty;
michael@0 49 }
michael@0 50
michael@0 51 bool mipMapsAreDirty() const {
michael@0 52 return fMipMapsDirty;
michael@0 53 }
michael@0 54
michael@0 55 /**
michael@0 56 * Approximate number of bytes used by the texture
michael@0 57 */
michael@0 58 virtual size_t sizeInBytes() const SK_OVERRIDE {
michael@0 59 return (size_t) fDesc.fWidth *
michael@0 60 fDesc.fHeight *
michael@0 61 GrBytesPerPixel(fDesc.fConfig);
michael@0 62 }
michael@0 63
michael@0 64 // GrSurface overrides
michael@0 65 virtual bool readPixels(int left, int top, int width, int height,
michael@0 66 GrPixelConfig config,
michael@0 67 void* buffer,
michael@0 68 size_t rowBytes = 0,
michael@0 69 uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
michael@0 70
michael@0 71 virtual void writePixels(int left, int top, int width, int height,
michael@0 72 GrPixelConfig config,
michael@0 73 const void* buffer,
michael@0 74 size_t rowBytes = 0,
michael@0 75 uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
michael@0 76
michael@0 77 /**
michael@0 78 * @return this texture
michael@0 79 */
michael@0 80 virtual GrTexture* asTexture() SK_OVERRIDE { return this; }
michael@0 81 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; }
michael@0 82
michael@0 83 /**
michael@0 84 * Retrieves the render target underlying this texture that can be passed to
michael@0 85 * GrGpu::setRenderTarget().
michael@0 86 *
michael@0 87 * @return handle to render target or NULL if the texture is not a
michael@0 88 * render target
michael@0 89 */
michael@0 90 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE {
michael@0 91 return fRenderTarget.get();
michael@0 92 }
michael@0 93 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE {
michael@0 94 return fRenderTarget.get();
michael@0 95 }
michael@0 96
michael@0 97 // GrTexture
michael@0 98 /**
michael@0 99 * Convert from texels to normalized texture coords for POT textures
michael@0 100 * only.
michael@0 101 */
michael@0 102 GrFixed normalizeFixedX(GrFixed x) const {
michael@0 103 SkASSERT(GrIsPow2(fDesc.fWidth));
michael@0 104 return x >> fShiftFixedX;
michael@0 105 }
michael@0 106 GrFixed normalizeFixedY(GrFixed y) const {
michael@0 107 SkASSERT(GrIsPow2(fDesc.fHeight));
michael@0 108 return y >> fShiftFixedY;
michael@0 109 }
michael@0 110
michael@0 111 /**
michael@0 112 * Return the native ID or handle to the texture, depending on the
michael@0 113 * platform. e.g. on OpenGL, return the texture ID.
michael@0 114 */
michael@0 115 virtual GrBackendObject getTextureHandle() const = 0;
michael@0 116
michael@0 117 /**
michael@0 118 * Call this when the state of the native API texture object is
michael@0 119 * altered directly, without being tracked by skia.
michael@0 120 */
michael@0 121 virtual void invalidateCachedState() = 0;
michael@0 122
michael@0 123 #ifdef SK_DEBUG
michael@0 124 void validate() const {
michael@0 125 this->INHERITED::validate();
michael@0 126
michael@0 127 this->validateDesc();
michael@0 128 }
michael@0 129 #endif
michael@0 130
michael@0 131 static GrResourceKey ComputeKey(const GrGpu* gpu,
michael@0 132 const GrTextureParams* params,
michael@0 133 const GrTextureDesc& desc,
michael@0 134 const GrCacheID& cacheID);
michael@0 135 static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc);
michael@0 136 static bool NeedsResizing(const GrResourceKey& key);
michael@0 137 static bool NeedsBilerp(const GrResourceKey& key);
michael@0 138
michael@0 139 protected:
michael@0 140 // A texture refs its rt representation but not vice-versa. It is up to
michael@0 141 // the subclass constructor to initialize this pointer.
michael@0 142 SkAutoTUnref<GrRenderTarget> fRenderTarget;
michael@0 143
michael@0 144 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc)
michael@0 145 : INHERITED(gpu, isWrapped, desc)
michael@0 146 , fRenderTarget(NULL)
michael@0 147 , fMipMapsDirty(true) {
michael@0 148
michael@0 149 // only make sense if alloc size is pow2
michael@0 150 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
michael@0 151 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
michael@0 152 }
michael@0 153 virtual ~GrTexture();
michael@0 154
michael@0 155 // GrResource overrides
michael@0 156 virtual void onRelease() SK_OVERRIDE;
michael@0 157 virtual void onAbandon() SK_OVERRIDE;
michael@0 158
michael@0 159 void validateDesc() const;
michael@0 160
michael@0 161 private:
michael@0 162 // these two shift a fixed-point value into normalized coordinates
michael@0 163 // for this texture if the texture is power of two sized.
michael@0 164 int fShiftFixedX;
michael@0 165 int fShiftFixedY;
michael@0 166
michael@0 167 bool fMipMapsDirty;
michael@0 168
michael@0 169 virtual void internal_dispose() const SK_OVERRIDE;
michael@0 170
michael@0 171 typedef GrSurface INHERITED;
michael@0 172 };
michael@0 173
michael@0 174 /**
michael@0 175 * Represents a texture that is intended to be accessed in device coords with an offset.
michael@0 176 */
michael@0 177 class GrDeviceCoordTexture {
michael@0 178 public:
michael@0 179 GrDeviceCoordTexture() { fOffset.set(0, 0); }
michael@0 180
michael@0 181 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) {
michael@0 182 *this = other;
michael@0 183 }
michael@0 184
michael@0 185 GrDeviceCoordTexture(GrTexture* texture, const SkIPoint& offset)
michael@0 186 : fTexture(SkSafeRef(texture))
michael@0 187 , fOffset(offset) {
michael@0 188 }
michael@0 189
michael@0 190 GrDeviceCoordTexture& operator=(const GrDeviceCoordTexture& other) {
michael@0 191 fTexture.reset(SkSafeRef(other.fTexture.get()));
michael@0 192 fOffset = other.fOffset;
michael@0 193 return *this;
michael@0 194 }
michael@0 195
michael@0 196 const SkIPoint& offset() const { return fOffset; }
michael@0 197
michael@0 198 void setOffset(const SkIPoint& offset) { fOffset = offset; }
michael@0 199 void setOffset(int ox, int oy) { fOffset.set(ox, oy); }
michael@0 200
michael@0 201 GrTexture* texture() const { return fTexture.get(); }
michael@0 202
michael@0 203 GrTexture* setTexture(GrTexture* texture) {
michael@0 204 fTexture.reset(SkSafeRef(texture));
michael@0 205 return texture;
michael@0 206 }
michael@0 207 private:
michael@0 208 SkAutoTUnref<GrTexture> fTexture;
michael@0 209 SkIPoint fOffset;
michael@0 210 };
michael@0 211
michael@0 212 #endif

mercurial