1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10 #include "GrGLTexture.h"
11
12 #include "GrGpuGL.h"
13
14 #define GPUGL static_cast<GrGpuGL*>(getGpu())
15
16 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
17
WrapMode2GLWrap()18 const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
19 static const GrGLenum repeatModes[] = {
20 GR_GL_CLAMP_TO_EDGE,
21 GR_GL_REPEAT,
22 GR_GL_MIRRORED_REPEAT
23 };
24 return repeatModes;
25 };
26
init(GrGpuGL * gpu,const Desc & textureDesc,const GrGLRenderTarget::Desc * rtDesc)27 void GrGLTexture::init(GrGpuGL* gpu,
28 const Desc& textureDesc,
29 const GrGLRenderTarget::Desc* rtDesc) {
30
31 GrAssert(0 != textureDesc.fTextureID);
32
33 fTexParams.invalidate();
34 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
35 fTexIDObj = new GrGLTexID(GPUGL->glInterface(),
36 textureDesc.fTextureID,
37 textureDesc.fOwnsID);
38 fOrientation = textureDesc.fOrientation;
39
40 if (NULL != rtDesc) {
41 // we render to the top left
42 GrGLIRect vp;
43 vp.fLeft = 0;
44 vp.fWidth = textureDesc.fWidth;
45 vp.fBottom = 0;
46 vp.fHeight = textureDesc.fHeight;
47
48 fRenderTarget = new GrGLRenderTarget(gpu, *rtDesc, vp, fTexIDObj, this);
49 }
50 }
51
GrGLTexture(GrGpuGL * gpu,const Desc & textureDesc)52 GrGLTexture::GrGLTexture(GrGpuGL* gpu,
53 const Desc& textureDesc)
54 : INHERITED(gpu,
55 textureDesc.fWidth,
56 textureDesc.fHeight,
57 textureDesc.fConfig) {
58 this->init(gpu, textureDesc, NULL);
59 }
60
GrGLTexture(GrGpuGL * gpu,const Desc & textureDesc,const GrGLRenderTarget::Desc & rtDesc)61 GrGLTexture::GrGLTexture(GrGpuGL* gpu,
62 const Desc& textureDesc,
63 const GrGLRenderTarget::Desc& rtDesc)
64 : INHERITED(gpu,
65 textureDesc.fWidth,
66 textureDesc.fHeight,
67 textureDesc.fConfig) {
68 this->init(gpu, textureDesc, &rtDesc);
69 }
70
onRelease()71 void GrGLTexture::onRelease() {
72 INHERITED::onRelease();
73 GPUGL->notifyTextureDelete(this);
74 if (NULL != fTexIDObj) {
75 fTexIDObj->unref();
76 fTexIDObj = NULL;
77 }
78 }
79
onAbandon()80 void GrGLTexture::onAbandon() {
81 INHERITED::onAbandon();
82 if (NULL != fTexIDObj) {
83 fTexIDObj->abandon();
84 }
85 }
86
getTextureHandle() const87 intptr_t GrGLTexture::getTextureHandle() const {
88 return fTexIDObj->id();
89 }
90
91