blob: 2f4f49b0ce08f947230a1ad837ca8243c1ead28d [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"
jvanverth39edf762014-12-22 11:44:19 -08009#include "GrGLGpu.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000010
bsalomon861e1032014-12-16 07:33:49 -080011#define GPUGL static_cast<GrGLGpu*>(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.
bsalomon861e1032014-12-16 07:33:49 -080015GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
bsalomon37dd3312014-11-03 08:47:23 -080016 : 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
bsalomon861e1032014-12-16 07:33:49 -080022GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived)
bsalomon37dd3312014-11-03 08:47:23 -080023 : 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;
hendrikw9a0c7ab2014-12-09 14:26:47 -080033 fIsWrapped = idDesc.fIsWrapped;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000034}
35
bsalomon@google.com8fe72472011-03-30 21:26:44 +000036void GrGLTexture::onRelease() {
bsalomonbcaefb02014-11-03 11:07:12 -080037 if (fTextureID) {
hendrikw9a0c7ab2014-12-09 14:26:47 -080038 if (!fIsWrapped) {
bsalomonbcaefb02014-11-03 11:07:12 -080039 GL_CALL(DeleteTextures(1, &fTextureID));
40 }
41 fTextureID = 0;
hendrikw9a0c7ab2014-12-09 14:26:47 -080042 fIsWrapped = false;
bsalomonbcaefb02014-11-03 11:07:12 -080043 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000044 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000045}
46
bsalomon@google.com8fe72472011-03-30 21:26:44 +000047void GrGLTexture::onAbandon() {
bsalomonbcaefb02014-11-03 11:07:12 -080048 fTextureID = 0;
hendrikw9a0c7ab2014-12-09 14:26:47 -080049 fIsWrapped = false;
robertphillips@google.comd3645542012-09-05 18:37:39 +000050 INHERITED::onAbandon();
reed@google.comac10a2d2010-12-22 21:39:39 +000051}
52
bsalomon@google.com08afc842012-10-25 18:56:10 +000053GrBackendObject GrGLTexture::getTextureHandle() const {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000054 return static_cast<GrBackendObject>(this->textureID());
reed@google.comac10a2d2010-12-22 21:39:39 +000055}