blob: d9db6ea2a2c652d0bab1a7c3e88c1ad39cd4086b [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;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000032 fTexIDObj.reset(SkNEW_ARGS(GrGLTexID, (GPUGL->glInterface(),
bsalomonb15b4c12014-10-29 12:41:57 -070033 idDesc.fTextureID,
34 idDesc.fIsWrapped)));
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000035}
36
bsalomon@google.com8fe72472011-03-30 21:26:44 +000037void GrGLTexture::onRelease() {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000038 fTexIDObj.reset(NULL);
robertphillips@google.comd3645542012-09-05 18:37:39 +000039 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000040}
41
bsalomon@google.com8fe72472011-03-30 21:26:44 +000042void GrGLTexture::onAbandon() {
bsalomon49f085d2014-09-05 13:34:00 -070043 if (fTexIDObj.get()) {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000044 fTexIDObj->abandon();
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000045 fTexIDObj.reset(NULL);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000046 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000047
48 INHERITED::onAbandon();
reed@google.comac10a2d2010-12-22 21:39:39 +000049}
50
bsalomon@google.com08afc842012-10-25 18:56:10 +000051GrBackendObject GrGLTexture::getTextureHandle() const {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000052 return static_cast<GrBackendObject>(this->textureID());
reed@google.comac10a2d2010-12-22 21:39:39 +000053}