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 "GrGLGpu.h"
10
11 #define GPUGL static_cast<GrGLGpu*>(this->getGpu())
12 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
13
14 // Because this class is virtually derived from GrSurface we must explicitly call its constructor.
GrGLTexture(GrGLGpu * gpu,const GrSurfaceDesc & desc,const IDDesc & idDesc)15 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
16 : GrSurface(gpu, idDesc.fLifeCycle, desc)
17 , INHERITED(gpu, idDesc.fLifeCycle, desc) {
18 this->init(desc, idDesc);
19 this->registerWithCache();
20 }
21
GrGLTexture(GrGLGpu * gpu,const GrSurfaceDesc & desc,const IDDesc & idDesc,Derived)22 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived)
23 : GrSurface(gpu, idDesc.fLifeCycle, desc)
24 , INHERITED(gpu, idDesc.fLifeCycle, desc) {
25 this->init(desc, idDesc);
26 }
27
init(const GrSurfaceDesc & desc,const IDDesc & idDesc)28 void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
29 SkASSERT(0 != idDesc.fTextureID);
30 fTexParams.invalidate();
31 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
32 fTextureID = idDesc.fTextureID;
33 fIsWrapped = kWrapped_LifeCycle == idDesc.fLifeCycle;
34 }
35
onRelease()36 void GrGLTexture::onRelease() {
37 if (fTextureID) {
38 if (!fIsWrapped) {
39 GL_CALL(DeleteTextures(1, &fTextureID));
40 }
41 fTextureID = 0;
42 fIsWrapped = false;
43 }
44 INHERITED::onRelease();
45 }
46
onAbandon()47 void GrGLTexture::onAbandon() {
48 fTextureID = 0;
49 fIsWrapped = false;
50 INHERITED::onAbandon();
51 }
52
getTextureHandle() const53 GrBackendObject GrGLTexture::getTextureHandle() const {
54 return static_cast<GrBackendObject>(this->textureID());
55 }
56