blob: 977212255f34852aa8baeea0b1bda04a95aabdf2 [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
reed@google.comfa35e3d2012-06-26 20:16:17 +000011SK_DEFINE_INST_COUNT(GrGLTexID)
12
bsalomon@google.com8fe72472011-03-30 21:26:44 +000013#define GPUGL static_cast<GrGpuGL*>(getGpu())
14
bsalomon@google.com0b77d682011-08-19 13:28:54 +000015#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
16
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000017void GrGLTexture::init(GrGpuGL* gpu,
18 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000019 const GrGLRenderTarget::Desc* rtDesc) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000020
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000021 SkASSERT(0 != textureDesc.fTextureID);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000022
bsalomon@google.com80d09b92011-11-05 21:21:13 +000023 fTexParams.invalidate();
24 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000025 fTexIDObj.reset(SkNEW_ARGS(GrGLTexID, (GPUGL->glInterface(),
26 textureDesc.fTextureID,
27 textureDesc.fIsWrapped)));
skia.committer@gmail.come862d162012-10-31 02:01:18 +000028
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000029 if (NULL != rtDesc) {
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000030 GrGLIRect vp;
reed@google.comac10a2d2010-12-22 21:39:39 +000031 vp.fLeft = 0;
bsalomon@google.com99621082011-11-15 16:47:16 +000032 vp.fWidth = textureDesc.fWidth;
33 vp.fBottom = 0;
34 vp.fHeight = textureDesc.fHeight;
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000035
bsalomon@google.com686bcb82013-04-09 15:04:12 +000036 fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this)));
reed@google.comac10a2d2010-12-22 21:39:39 +000037 }
reed@google.comac10a2d2010-12-22 21:39:39 +000038}
39
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000040GrGLTexture::GrGLTexture(GrGpuGL* gpu,
rmistry@google.comfbfcd562012-08-23 18:09:54 +000041 const Desc& textureDesc)
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000042 : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000043 this->init(gpu, textureDesc, NULL);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000044}
45
46GrGLTexture::GrGLTexture(GrGpuGL* gpu,
47 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000048 const GrGLRenderTarget::Desc& rtDesc)
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000049 : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000050 this->init(gpu, textureDesc, &rtDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000051}
52
bsalomon@google.com8fe72472011-03-30 21:26:44 +000053void GrGLTexture::onRelease() {
Scroggoc29d7cd2011-06-16 13:14:21 +000054 GPUGL->notifyTextureDelete(this);
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000055 fTexIDObj.reset(NULL);
robertphillips@google.comd3645542012-09-05 18:37:39 +000056 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000057}
58
bsalomon@google.com8fe72472011-03-30 21:26:44 +000059void GrGLTexture::onAbandon() {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000060 if (NULL != fTexIDObj.get()) {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000061 fTexIDObj->abandon();
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000062 fTexIDObj.reset(NULL);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000063 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000064
65 INHERITED::onAbandon();
reed@google.comac10a2d2010-12-22 21:39:39 +000066}
67
bsalomon@google.com08afc842012-10-25 18:56:10 +000068GrBackendObject GrGLTexture::getTextureHandle() const {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000069 return static_cast<GrBackendObject>(this->textureID());
reed@google.comac10a2d2010-12-22 21:39:39 +000070}