gfx/skia/trunk/src/gpu/GrTexture.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.

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
michael@0 10 #include "GrTexture.h"
michael@0 11
michael@0 12 #include "GrContext.h"
michael@0 13 #include "GrDrawTargetCaps.h"
michael@0 14 #include "GrGpu.h"
michael@0 15 #include "GrRenderTarget.h"
michael@0 16 #include "GrResourceCache.h"
michael@0 17
michael@0 18 GrTexture::~GrTexture() {
michael@0 19 if (NULL != fRenderTarget.get()) {
michael@0 20 fRenderTarget.get()->owningTextureDestroyed();
michael@0 21 }
michael@0 22 }
michael@0 23
michael@0 24 /**
michael@0 25 * This method allows us to interrupt the normal deletion process and place
michael@0 26 * textures back in the texture cache when their ref count goes to zero.
michael@0 27 */
michael@0 28 void GrTexture::internal_dispose() const {
michael@0 29
michael@0 30 if (this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit) &&
michael@0 31 NULL != this->INHERITED::getContext()) {
michael@0 32 GrTexture* nonConstThis = const_cast<GrTexture *>(this);
michael@0 33 this->fRefCnt = 1; // restore ref count to initial setting
michael@0 34
michael@0 35 nonConstThis->resetFlag((GrTextureFlags) kReturnToCache_FlagBit);
michael@0 36 nonConstThis->INHERITED::getContext()->addExistingTextureToCache(nonConstThis);
michael@0 37
michael@0 38 // Note: "this" texture might be freed inside addExistingTextureToCache
michael@0 39 // if it is purged.
michael@0 40 return;
michael@0 41 }
michael@0 42
michael@0 43 SkASSERT(0 == this->getDeferredRefCount());
michael@0 44 this->INHERITED::internal_dispose();
michael@0 45 }
michael@0 46
michael@0 47 bool GrTexture::readPixels(int left, int top, int width, int height,
michael@0 48 GrPixelConfig config, void* buffer,
michael@0 49 size_t rowBytes, uint32_t pixelOpsFlags) {
michael@0 50 // go through context so that all necessary flushing occurs
michael@0 51 GrContext* context = this->getContext();
michael@0 52 if (NULL == context) {
michael@0 53 return false;
michael@0 54 }
michael@0 55 return context->readTexturePixels(this,
michael@0 56 left, top, width, height,
michael@0 57 config, buffer, rowBytes,
michael@0 58 pixelOpsFlags);
michael@0 59 }
michael@0 60
michael@0 61 void GrTexture::writePixels(int left, int top, int width, int height,
michael@0 62 GrPixelConfig config, const void* buffer,
michael@0 63 size_t rowBytes, uint32_t pixelOpsFlags) {
michael@0 64 // go through context so that all necessary flushing occurs
michael@0 65 GrContext* context = this->getContext();
michael@0 66 if (NULL == context) {
michael@0 67 return;
michael@0 68 }
michael@0 69 context->writeTexturePixels(this,
michael@0 70 left, top, width, height,
michael@0 71 config, buffer, rowBytes,
michael@0 72 pixelOpsFlags);
michael@0 73 }
michael@0 74
michael@0 75 void GrTexture::onRelease() {
michael@0 76 SkASSERT(!this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit));
michael@0 77 INHERITED::onRelease();
michael@0 78 }
michael@0 79
michael@0 80 void GrTexture::onAbandon() {
michael@0 81 if (NULL != fRenderTarget.get()) {
michael@0 82 fRenderTarget->abandon();
michael@0 83 }
michael@0 84 INHERITED::onAbandon();
michael@0 85 }
michael@0 86
michael@0 87 void GrTexture::validateDesc() const {
michael@0 88 if (NULL != this->asRenderTarget()) {
michael@0 89 // This texture has a render target
michael@0 90 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
michael@0 91
michael@0 92 if (NULL != this->asRenderTarget()->getStencilBuffer()) {
michael@0 93 SkASSERT(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
michael@0 94 } else {
michael@0 95 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
michael@0 96 }
michael@0 97
michael@0 98 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples());
michael@0 99 } else {
michael@0 100 SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
michael@0 101 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
michael@0 102 SkASSERT(0 == fDesc.fSampleCnt);
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 // These flags need to fit in a GrResourceKey::ResourceFlags so they can be folded into the texture
michael@0 107 // key
michael@0 108 enum TextureFlags {
michael@0 109 /**
michael@0 110 * The kStretchToPOT bit is set when the texture is NPOT and is being repeated but the
michael@0 111 * hardware doesn't support that feature.
michael@0 112 */
michael@0 113 kStretchToPOT_TextureFlag = 0x1,
michael@0 114 /**
michael@0 115 * The kBilerp bit can only be set when the kStretchToPOT flag is set and indicates whether the
michael@0 116 * stretched texture should be bilerped.
michael@0 117 */
michael@0 118 kBilerp_TextureFlag = 0x2,
michael@0 119 };
michael@0 120
michael@0 121 namespace {
michael@0 122 GrResourceKey::ResourceFlags get_texture_flags(const GrGpu* gpu,
michael@0 123 const GrTextureParams* params,
michael@0 124 const GrTextureDesc& desc) {
michael@0 125 GrResourceKey::ResourceFlags flags = 0;
michael@0 126 bool tiled = NULL != params && params->isTiled();
michael@0 127 if (tiled && !gpu->caps()->npotTextureTileSupport()) {
michael@0 128 if (!GrIsPow2(desc.fWidth) || !GrIsPow2(desc.fHeight)) {
michael@0 129 flags |= kStretchToPOT_TextureFlag;
michael@0 130 switch(params->filterMode()) {
michael@0 131 case GrTextureParams::kNone_FilterMode:
michael@0 132 break;
michael@0 133 case GrTextureParams::kBilerp_FilterMode:
michael@0 134 case GrTextureParams::kMipMap_FilterMode:
michael@0 135 flags |= kBilerp_TextureFlag;
michael@0 136 break;
michael@0 137 }
michael@0 138 }
michael@0 139 }
michael@0 140 return flags;
michael@0 141 }
michael@0 142
michael@0 143 GrResourceKey::ResourceType texture_resource_type() {
michael@0 144 static const GrResourceKey::ResourceType gType = GrResourceKey::GenerateResourceType();
michael@0 145 return gType;
michael@0 146 }
michael@0 147
michael@0 148 // FIXME: This should be refactored with the code in gl/GrGpuGL.cpp.
michael@0 149 GrSurfaceOrigin resolve_origin(const GrTextureDesc& desc) {
michael@0 150 // By default, GrRenderTargets are GL's normal orientation so that they
michael@0 151 // can be drawn to by the outside world without the client having
michael@0 152 // to render upside down.
michael@0 153 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit);
michael@0 154 if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
michael@0 155 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
michael@0 156 } else {
michael@0 157 return desc.fOrigin;
michael@0 158 }
michael@0 159 }
michael@0 160 }
michael@0 161
michael@0 162 GrResourceKey GrTexture::ComputeKey(const GrGpu* gpu,
michael@0 163 const GrTextureParams* params,
michael@0 164 const GrTextureDesc& desc,
michael@0 165 const GrCacheID& cacheID) {
michael@0 166 GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc);
michael@0 167 return GrResourceKey(cacheID, texture_resource_type(), flags);
michael@0 168 }
michael@0 169
michael@0 170 GrResourceKey GrTexture::ComputeScratchKey(const GrTextureDesc& desc) {
michael@0 171 GrCacheID::Key idKey;
michael@0 172 // Instead of a client-provided key of the texture contents we create a key from the
michael@0 173 // descriptor.
michael@0 174 GR_STATIC_ASSERT(sizeof(idKey) >= 16);
michael@0 175 SkASSERT(desc.fHeight < (1 << 16));
michael@0 176 SkASSERT(desc.fWidth < (1 << 16));
michael@0 177 idKey.fData32[0] = (desc.fWidth) | (desc.fHeight << 16);
michael@0 178 idKey.fData32[1] = desc.fConfig | desc.fSampleCnt << 16;
michael@0 179 idKey.fData32[2] = desc.fFlags;
michael@0 180 idKey.fData32[3] = resolve_origin(desc); // Only needs 2 bits actually
michael@0 181 static const int kPadSize = sizeof(idKey) - 16;
michael@0 182 GR_STATIC_ASSERT(kPadSize >= 0);
michael@0 183 memset(idKey.fData8 + 16, 0, kPadSize);
michael@0 184
michael@0 185 GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey);
michael@0 186 return GrResourceKey(cacheID, texture_resource_type(), 0);
michael@0 187 }
michael@0 188
michael@0 189 bool GrTexture::NeedsResizing(const GrResourceKey& key) {
michael@0 190 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag);
michael@0 191 }
michael@0 192
michael@0 193 bool GrTexture::NeedsBilerp(const GrResourceKey& key) {
michael@0 194 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag);
michael@0 195 }

mercurial