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