blob: 69d7b9ca580cf398da87dcb29a79a5b370db842a [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001/*
2 * 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.
6 */
7
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00008#include "GrGLRenderTarget.h"
9
10#include "GrGpuGL.h"
11
12#define GPUGL static_cast<GrGpuGL*>(getGpu())
13
bsalomon@google.com0b77d682011-08-19 13:28:54 +000014#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
15
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000016void GrGLRenderTarget::init(const Desc& desc,
17 const GrGLIRect& viewport,
18 GrGLTexID* texID) {
19 fRTFBOID = desc.fRTFBOID;
20 fTexFBOID = desc.fTexFBOID;
21 fMSColorRenderbufferID = desc.fMSColorRenderbufferID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000022 fViewport = viewport;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000023 fTexIDObj = texID;
24 GrSafeRef(fTexIDObj);
25}
26
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000027namespace {
28GrTextureDesc MakeDesc(GrTextureFlags flags,
29 int width, int height,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000030 GrPixelConfig config, int sampleCnt,
31 GrSurfaceOrigin origin) {
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000032 GrTextureDesc temp;
33 temp.fFlags = flags;
34 temp.fWidth = width;
35 temp.fHeight = height;
36 temp.fConfig = config;
37 temp.fSampleCnt = sampleCnt;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000038 temp.fOrigin = origin;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000039 return temp;
40}
41
42};
43
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000044GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
45 const Desc& desc,
46 const GrGLIRect& viewport,
47 GrGLTexID* texID,
48 GrGLTexture* texture)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000049 : INHERITED(gpu,
bsalomon@google.com72830222013-01-23 20:25:22 +000050 desc.fIsWrapped,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000051 texture,
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000052 MakeDesc(kNone_GrTextureFlags,
53 viewport.fWidth, viewport.fHeight,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000054 desc.fConfig, desc.fSampleCnt,
55 desc.fOrigin)) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000056 GrAssert(NULL != texID);
57 GrAssert(NULL != texture);
58 // FBO 0 can't also be a texture, right?
59 GrAssert(0 != desc.fRTFBOID);
60 GrAssert(0 != desc.fTexFBOID);
bsalomon@google.com99621082011-11-15 16:47:16 +000061
62 // we assume this is true, TODO: get rid of viewport as a param.
63 GrAssert(viewport.fWidth == texture->width());
64 GrAssert(viewport.fHeight == texture->height());
65
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000066 this->init(desc, viewport, texID);
67}
68
69GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
70 const Desc& desc,
71 const GrGLIRect& viewport)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000072 : INHERITED(gpu,
bsalomon@google.com72830222013-01-23 20:25:22 +000073 desc.fIsWrapped,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000074 NULL,
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000075 MakeDesc(kNone_GrTextureFlags,
76 viewport.fWidth, viewport.fHeight,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000077 desc.fConfig, desc.fSampleCnt,
78 desc.fOrigin)) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000079 this->init(desc, viewport, NULL);
80}
81
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000082void GrGLRenderTarget::onRelease() {
83 GPUGL->notifyRenderTargetDelete(this);
bsalomon@google.com72830222013-01-23 20:25:22 +000084 if (!this->isWrapped()) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000085 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000086 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000087 }
88 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000089 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000090 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000091 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000092 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000093 }
94 }
95 fRTFBOID = 0;
96 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000097 fMSColorRenderbufferID = 0;
98 GrSafeUnref(fTexIDObj);
99 fTexIDObj = NULL;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000100 INHERITED::onRelease();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000101}
102
103void GrGLRenderTarget::onAbandon() {
104 fRTFBOID = 0;
105 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000106 fMSColorRenderbufferID = 0;
107 if (NULL != fTexIDObj) {
108 fTexIDObj->abandon();
109 fTexIDObj = NULL;
110 }
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000111 INHERITED::onAbandon();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000112}