blob: 8777d1b75559765f7117d9359d32911b71ca9c96 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#include "GrGLTexture.h"
9#include "GrGpuGL.h"
10
bsalomon37dd3312014-11-03 08:47:23 -080011#define GPUGL static_cast<GrGpuGL*>(this->getGpu())
bsalomon@google.com0b77d682011-08-19 13:28:54 +000012#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
13
bsalomon37dd3312014-11-03 08:47:23 -080014// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
15GrGLTexture::GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
16 : GrSurface(gpu, idDesc.fIsWrapped, desc)
17 , INHERITED(gpu, idDesc.fIsWrapped, desc) {
18 this->init(desc, idDesc);
19 this->registerWithCache();
20}
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000021
bsalomon37dd3312014-11-03 08:47:23 -080022GrGLTexture::GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived)
23 : GrSurface(gpu, idDesc.fIsWrapped, desc)
24 , INHERITED(gpu, idDesc.fIsWrapped, desc) {
25 this->init(desc, idDesc);
26}
27
28void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
bsalomonb15b4c12014-10-29 12:41:57 -070029 SkASSERT(0 != idDesc.fTextureID);
bsalomon@google.com80d09b92011-11-05 21:21:13 +000030 fTexParams.invalidate();
31 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
bsalomonbcaefb02014-11-03 11:07:12 -080032 fTextureID = idDesc.fTextureID;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000033}
34
bsalomon@google.com8fe72472011-03-30 21:26:44 +000035void GrGLTexture::onRelease() {
bsalomonbcaefb02014-11-03 11:07:12 -080036 if (fTextureID) {
37 if (!this->isWrapped()) {
38 GL_CALL(DeleteTextures(1, &fTextureID));
39 }
40 fTextureID = 0;
41 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000042 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000043}
44
bsalomon@google.com8fe72472011-03-30 21:26:44 +000045void GrGLTexture::onAbandon() {
bsalomonbcaefb02014-11-03 11:07:12 -080046 fTextureID = 0;
robertphillips@google.comd3645542012-09-05 18:37:39 +000047 INHERITED::onAbandon();
reed@google.comac10a2d2010-12-22 21:39:39 +000048}
49
bsalomon@google.com08afc842012-10-25 18:56:10 +000050GrBackendObject GrGLTexture::getTextureHandle() const {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000051 return static_cast<GrBackendObject>(this->textureID());
reed@google.comac10a2d2010-12-22 21:39:39 +000052}