michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "GrGLTexture.h" michael@0: #include "GrGpuGL.h" michael@0: michael@0: #define GPUGL static_cast(getGpu()) michael@0: michael@0: #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) michael@0: michael@0: void GrGLTexture::init(GrGpuGL* gpu, michael@0: const Desc& textureDesc, michael@0: const GrGLRenderTarget::Desc* rtDesc) { michael@0: michael@0: SkASSERT(0 != textureDesc.fTextureID); michael@0: michael@0: fTexParams.invalidate(); michael@0: fTexParamsTimestamp = GrGpu::kExpiredTimestamp; michael@0: fTexIDObj.reset(SkNEW_ARGS(GrGLTexID, (GPUGL->glInterface(), michael@0: textureDesc.fTextureID, michael@0: textureDesc.fIsWrapped))); michael@0: michael@0: if (NULL != rtDesc) { michael@0: GrGLIRect vp; michael@0: vp.fLeft = 0; michael@0: vp.fWidth = textureDesc.fWidth; michael@0: vp.fBottom = 0; michael@0: vp.fHeight = textureDesc.fHeight; michael@0: michael@0: fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this))); michael@0: } michael@0: } michael@0: michael@0: GrGLTexture::GrGLTexture(GrGpuGL* gpu, michael@0: const Desc& textureDesc) michael@0: : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) { michael@0: this->init(gpu, textureDesc, NULL); michael@0: } michael@0: michael@0: GrGLTexture::GrGLTexture(GrGpuGL* gpu, michael@0: const Desc& textureDesc, michael@0: const GrGLRenderTarget::Desc& rtDesc) michael@0: : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) { michael@0: this->init(gpu, textureDesc, &rtDesc); michael@0: } michael@0: michael@0: void GrGLTexture::onRelease() { michael@0: GPUGL->notifyTextureDelete(this); michael@0: fTexIDObj.reset(NULL); michael@0: INHERITED::onRelease(); michael@0: } michael@0: michael@0: void GrGLTexture::onAbandon() { michael@0: if (NULL != fTexIDObj.get()) { michael@0: fTexIDObj->abandon(); michael@0: fTexIDObj.reset(NULL); michael@0: } michael@0: michael@0: INHERITED::onAbandon(); michael@0: } michael@0: michael@0: GrBackendObject GrGLTexture::getTextureHandle() const { michael@0: return static_cast(this->textureID()); michael@0: }