* found in the LICENSE file.
*/
-
-#include "GrTexture.h"
-
#include "GrContext.h"
#include "GrDrawTargetCaps.h"
#include "GrGpu.h"
-#include "GrRenderTarget.h"
#include "GrResourceCache.h"
+#include "GrTexture.h"
+#include "GrTexturePriv.h"
-GrTexture::~GrTexture() {
- if (fRenderTarget.get()) {
- fRenderTarget.get()->owningTextureDestroyed();
- }
-}
-
-/**
- * This method allows us to interrupt the normal deletion process and place
- * textures back in the texture cache when their ref count goes to zero.
- */
-void GrTexture::internal_dispose() const {
- if (this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit) &&
- this->INHERITED::getContext()) {
- GrTexture* nonConstThis = const_cast<GrTexture *>(this);
- this->ref(); // restore ref count to initial setting
-
- nonConstThis->impl()->resetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit);
- nonConstThis->INHERITED::getContext()->addExistingTextureToCache(nonConstThis);
-
- // Note: "this" texture might be freed inside addExistingTextureToCache
- // if it is purged.
- return;
- }
-
- this->INHERITED::internal_dispose();
-}
-
-void GrTextureImpl::dirtyMipMaps(bool mipMapsDirty) {
+void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
if (mipMapsDirty) {
if (kValid_MipMapsStatus == fMipMapsStatus) {
- fMipMapsStatus = kAllocated_MipMapsStatus;
+ fMipMapsStatus = kAllocated_MipMapsStatus;
}
} else {
const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus;
textureSize = (size_t) fDesc.fWidth * fDesc.fHeight * GrBytesPerPixel(fDesc.fConfig);
}
- if (this->impl()->hasMipMaps()) {
+ if (this->texturePriv().hasMipMaps()) {
// We don't have to worry about the mipmaps being a different size than
// we'd expect because we never change fDesc.fWidth/fHeight.
textureSize *= 2;
return textureSize;
}
-bool GrTexture::readPixels(int left, int top, int width, int height,
- GrPixelConfig config, void* buffer,
- size_t rowBytes, uint32_t pixelOpsFlags) {
- // go through context so that all necessary flushing occurs
- GrContext* context = this->getContext();
- if (NULL == context) {
- return false;
- }
- return context->readTexturePixels(this,
- left, top, width, height,
- config, buffer, rowBytes,
- pixelOpsFlags);
-}
-
-void GrTexture::writePixels(int left, int top, int width, int height,
- GrPixelConfig config, const void* buffer,
- size_t rowBytes, uint32_t pixelOpsFlags) {
- // go through context so that all necessary flushing occurs
- GrContext* context = this->getContext();
- if (NULL == context) {
- return;
- }
- context->writeTexturePixels(this,
- left, top, width, height,
- config, buffer, rowBytes,
- pixelOpsFlags);
-}
-
-void GrTexture::abandonReleaseCommon() {
- // In debug builds the resource cache tracks removed/exclusive textures and has an unref'ed ptr.
- // After abandon() or release() the resource cache will be unreachable (getContext() == NULL).
- // So we readd the texture to the cache here so that it is removed from the exclusive list and
- // there is no longer an unref'ed ptr to the texture in the cache.
- if (this->impl()->isSetFlag((GrTextureFlags)GrTextureImpl::kReturnToCache_FlagBit)) {
- SkASSERT(!this->wasDestroyed());
- this->ref(); // restores the ref the resource cache gave up when it marked this exclusive.
- this->impl()->resetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit);
- this->getContext()->addExistingTextureToCache(this);
- }
-}
-
-void GrTexture::onRelease() {
- this->abandonReleaseCommon();
- SkASSERT(!this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit));
- INHERITED::onRelease();
-}
-
-void GrTexture::onAbandon() {
- this->abandonReleaseCommon();
- if (fRenderTarget.get()) {
- fRenderTarget->abandon();
- }
- INHERITED::onAbandon();
-}
-
void GrTexture::validateDesc() const {
if (this->asRenderTarget()) {
// This texture has a render target
- SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
+ SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrSurfaceFlag));
if (this->asRenderTarget()->getStencilBuffer()) {
- SkASSERT(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
+ SkASSERT(0 != (fDesc.fFlags & kNoStencil_GrSurfaceFlag));
} else {
- SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
+ SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrSurfaceFlag));
}
SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples());
} else {
- SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
- SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
+ SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrSurfaceFlag));
+ SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrSurfaceFlag));
SkASSERT(0 == fDesc.fSampleCnt);
}
}
namespace {
GrResourceKey::ResourceFlags get_texture_flags(const GrGpu* gpu,
const GrTextureParams* params,
- const GrTextureDesc& desc) {
+ const GrSurfaceDesc& desc) {
GrResourceKey::ResourceFlags flags = 0;
bool tiled = params && params->isTiled();
if (tiled && !gpu->caps()->npotTextureTileSupport()) {
return flags;
}
-GrResourceKey::ResourceType texture_resource_type() {
- static const GrResourceKey::ResourceType gType = GrResourceKey::GenerateResourceType();
- return gType;
-}
-
// FIXME: This should be refactored with the code in gl/GrGpuGL.cpp.
-GrSurfaceOrigin resolve_origin(const GrTextureDesc& desc) {
+GrSurfaceOrigin resolve_origin(const GrSurfaceDesc& desc) {
// By default, GrRenderTargets are GL's normal orientation so that they
// can be drawn to by the outside world without the client having
// to render upside down.
- bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit);
+ bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag);
if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
} else {
}
//////////////////////////////////////////////////////////////////////////////
-GrTextureImpl::GrTextureImpl(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc)
+GrTexture::GrTexture(GrGpu* gpu, bool isWrapped, const GrSurfaceDesc& desc)
: INHERITED(gpu, isWrapped, desc)
, fMipMapsStatus(kNotAllocated_MipMapsStatus) {
- this->setScratchKey(ComputeScratchKey(desc));
+ this->setScratchKey(GrTexturePriv::ComputeScratchKey(desc));
+ // only make sense if alloc size is pow2
+ fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
+ fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
}
-GrResourceKey GrTextureImpl::ComputeKey(const GrGpu* gpu,
+GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu,
const GrTextureParams* params,
- const GrTextureDesc& desc,
+ const GrSurfaceDesc& desc,
const GrCacheID& cacheID) {
GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc);
- return GrResourceKey(cacheID, texture_resource_type(), flags);
+ return GrResourceKey(cacheID, ResourceType(), flags);
}
-GrResourceKey GrTextureImpl::ComputeScratchKey(const GrTextureDesc& desc) {
+GrResourceKey GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc) {
GrCacheID::Key idKey;
// Instead of a client-provided key of the texture contents we create a key from the
// descriptor.
memset(idKey.fData8 + 16, 0, kPadSize);
GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey);
- return GrResourceKey(cacheID, texture_resource_type(), 0);
+ return GrResourceKey(cacheID, ResourceType(), 0);
}
-bool GrTextureImpl::NeedsResizing(const GrResourceKey& key) {
+bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) {
return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag);
}
-bool GrTextureImpl::NeedsBilerp(const GrResourceKey& key) {
+bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) {
return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag);
}