blob: 8cf574ba15bb2d15bce3ce5e49d7534e4bab892c [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,
bsalomonb15b4c12014-10-29 12:41:57 -070016 const GrSurfaceDesc& desc,
17 const IDDesc& idDesc,
18 const GrGLRenderTarget::IDDesc* rtIDDesc) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000019
bsalomonb15b4c12014-10-29 12:41:57 -070020 SkASSERT(0 != idDesc.fTextureID);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000021
bsalomon@google.com80d09b92011-11-05 21:21:13 +000022 fTexParams.invalidate();
23 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000024 fTexIDObj.reset(SkNEW_ARGS(GrGLTexID, (GPUGL->glInterface(),
bsalomonb15b4c12014-10-29 12:41:57 -070025 idDesc.fTextureID,
26 idDesc.fIsWrapped)));
skia.committer@gmail.come862d162012-10-31 02:01:18 +000027
bsalomonb15b4c12014-10-29 12:41:57 -070028 if (rtIDDesc) {
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000029 GrGLIRect vp;
reed@google.comac10a2d2010-12-22 21:39:39 +000030 vp.fLeft = 0;
bsalomonb15b4c12014-10-29 12:41:57 -070031 vp.fWidth = desc.fWidth;
bsalomon@google.com99621082011-11-15 16:47:16 +000032 vp.fBottom = 0;
bsalomonb15b4c12014-10-29 12:41:57 -070033 vp.fHeight = desc.fHeight;
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000034
bsalomonb15b4c12014-10-29 12:41:57 -070035 fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtIDDesc, vp, fTexIDObj, this)));
reed@google.comac10a2d2010-12-22 21:39:39 +000036 }
bsalomon16961262014-08-26 14:01:07 -070037 this->registerWithCache();
reed@google.comac10a2d2010-12-22 21:39:39 +000038}
39
bsalomonb15b4c12014-10-29 12:41:57 -070040GrGLTexture::GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
41 : INHERITED(gpu, idDesc.fIsWrapped, desc) {
42 this->init(gpu, desc, idDesc, NULL);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000043}
44
45GrGLTexture::GrGLTexture(GrGpuGL* gpu,
bsalomonb15b4c12014-10-29 12:41:57 -070046 const GrSurfaceDesc& desc,
47 const IDDesc& idDesc,
48 const GrGLRenderTarget::IDDesc& rtIDDesc)
49 : INHERITED(gpu, idDesc.fIsWrapped, desc) {
50 this->init(gpu, desc, idDesc, &rtIDDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000051}
52
bsalomon@google.com8fe72472011-03-30 21:26:44 +000053void GrGLTexture::onRelease() {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000054 fTexIDObj.reset(NULL);
robertphillips@google.comd3645542012-09-05 18:37:39 +000055 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000056}
57
bsalomon@google.com8fe72472011-03-30 21:26:44 +000058void GrGLTexture::onAbandon() {
bsalomon49f085d2014-09-05 13:34:00 -070059 if (fTexIDObj.get()) {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000060 fTexIDObj->abandon();
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000061 fTexIDObj.reset(NULL);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000062 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000063
64 INHERITED::onAbandon();
reed@google.comac10a2d2010-12-22 21:39:39 +000065}
66
bsalomon@google.com08afc842012-10-25 18:56:10 +000067GrBackendObject GrGLTexture::getTextureHandle() const {
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000068 return static_cast<GrBackendObject>(this->textureID());
reed@google.comac10a2d2010-12-22 21:39:39 +000069}