1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "GrGLTexture.h" 9 #include "GrGpuGL.h" 10 11 SK_DEFINE_INST_COUNT(GrGLTexID) 12 13 #define GPUGL static_cast<GrGpuGL*>(getGpu()) 14 15 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) 16 17 void GrGLTexture::init(GrGpuGL* gpu, 18 const Desc& textureDesc, 19 const GrGLRenderTarget::Desc* rtDesc) { 20 21 GrAssert(0 != textureDesc.fTextureID); 22 23 fTexParams.invalidate(); 24 fTexParamsTimestamp = GrGpu::kExpiredTimestamp; 25 fTexIDObj.reset(SkNEW_ARGS(GrGLTexID, (GPUGL->glInterface(), 26 textureDesc.fTextureID, 27 textureDesc.fIsWrapped))); 28 29 if (NULL != rtDesc) { 30 GrGLIRect vp; 31 vp.fLeft = 0; 32 vp.fWidth = textureDesc.fWidth; 33 vp.fBottom = 0; 34 vp.fHeight = textureDesc.fHeight; 35 36 fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this))); 37 } 38 } 39 40 GrGLTexture::GrGLTexture(GrGpuGL* gpu, 41 const Desc& textureDesc) 42 : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) { 43 this->init(gpu, textureDesc, NULL); 44 } 45 46 GrGLTexture::GrGLTexture(GrGpuGL* gpu, 47 const Desc& textureDesc, 48 const GrGLRenderTarget::Desc& rtDesc) 49 : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) { 50 this->init(gpu, textureDesc, &rtDesc); 51 } 52 53 void GrGLTexture::onRelease() { 54 GPUGL->notifyTextureDelete(this); 55 fTexIDObj.reset(NULL); 56 INHERITED::onRelease(); 57 } 58 59 void GrGLTexture::onAbandon() { 60 if (NULL != fTexIDObj.get()) { 61 fTexIDObj->abandon(); 62 fTexIDObj.reset(NULL); 63 } 64 65 INHERITED::onAbandon(); 66 } 67 68 GrBackendObject GrGLTexture::getTextureHandle() const { 69 return static_cast<GrBackendObject>(this->textureID()); 70 } 71