blob: f798b31ea05e36681a66e3e3841faf13421a666a [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
21 GrAssert(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;
tomhudson@google.comc377baf2012-07-09 20:17:56 +000025 fTexIDObj = SkNEW_ARGS(GrGLTexID,
26 (GPUGL->glInterface(),
27 textureDesc.fTextureID,
bsalomon@google.com72830222013-01-23 20:25:22 +000028 textureDesc.fIsWrapped));
skia.committer@gmail.come862d162012-10-31 02:01:18 +000029
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000030 if (NULL != rtDesc) {
robertphillips@google.comcf9faf62013-02-05 14:05:06 +000031 GrAssert(kBottomLeft_GrSurfaceOrigin == textureDesc.fOrigin);
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000032 GrGLIRect vp;
reed@google.comac10a2d2010-12-22 21:39:39 +000033 vp.fLeft = 0;
bsalomon@google.com99621082011-11-15 16:47:16 +000034 vp.fWidth = textureDesc.fWidth;
35 vp.fBottom = 0;
36 vp.fHeight = textureDesc.fHeight;
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000037
tomhudson@google.comc377baf2012-07-09 20:17:56 +000038 fRenderTarget = SkNEW_ARGS(GrGLRenderTarget,
39 (gpu, *rtDesc, vp, fTexIDObj, this));
reed@google.comac10a2d2010-12-22 21:39:39 +000040 }
reed@google.comac10a2d2010-12-22 21:39:39 +000041}
42
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000043GrGLTexture::GrGLTexture(GrGpuGL* gpu,
rmistry@google.comfbfcd562012-08-23 18:09:54 +000044 const Desc& textureDesc)
robertphillips@google.comcf9faf62013-02-05 14:05:06 +000045 : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc, textureDesc.fOrigin) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000046 this->init(gpu, textureDesc, NULL);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000047}
48
49GrGLTexture::GrGLTexture(GrGpuGL* gpu,
50 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000051 const GrGLRenderTarget::Desc& rtDesc)
robertphillips@google.comcf9faf62013-02-05 14:05:06 +000052 : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc, textureDesc.fOrigin) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000053 this->init(gpu, textureDesc, &rtDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000054}
55
bsalomon@google.com8fe72472011-03-30 21:26:44 +000056void GrGLTexture::onRelease() {
Scroggoc29d7cd2011-06-16 13:14:21 +000057 GPUGL->notifyTextureDelete(this);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000058 if (NULL != fTexIDObj) {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000059 fTexIDObj->unref();
60 fTexIDObj = NULL;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000061 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000062
63 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000064}
65
bsalomon@google.com8fe72472011-03-30 21:26:44 +000066void GrGLTexture::onAbandon() {
67 if (NULL != fTexIDObj) {
68 fTexIDObj->abandon();
69 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000070
71 INHERITED::onAbandon();
reed@google.comac10a2d2010-12-22 21:39:39 +000072}
73
bsalomon@google.com08afc842012-10-25 18:56:10 +000074GrBackendObject GrGLTexture::getTextureHandle() const {
bsalomon@google.com1da07462011-03-10 14:51:57 +000075 return fTexIDObj->id();
reed@google.comac10a2d2010-12-22 21:39:39 +000076}