blob: f2a0cdced30989a7dff09cea482e1bf32f5ba2bc [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;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000023 fTexIDObj.reset(SkSafeRef(texID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000024}
25
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000026namespace {
27GrTextureDesc MakeDesc(GrTextureFlags flags,
28 int width, int height,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000029 GrPixelConfig config, int sampleCnt,
30 GrSurfaceOrigin origin) {
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000031 GrTextureDesc temp;
32 temp.fFlags = flags;
33 temp.fWidth = width;
34 temp.fHeight = height;
35 temp.fConfig = config;
36 temp.fSampleCnt = sampleCnt;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000037 temp.fOrigin = origin;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000038 return temp;
39}
40
41};
42
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000043GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
44 const Desc& desc,
45 const GrGLIRect& viewport,
46 GrGLTexID* texID,
47 GrGLTexture* texture)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000048 : INHERITED(gpu,
bsalomon@google.com72830222013-01-23 20:25:22 +000049 desc.fIsWrapped,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000050 texture,
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000051 MakeDesc(kNone_GrTextureFlags,
52 viewport.fWidth, viewport.fHeight,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000053 desc.fConfig, desc.fSampleCnt,
54 desc.fOrigin)) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000055 SkASSERT(NULL != texID);
56 SkASSERT(NULL != texture);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000057 // FBO 0 can't also be a texture, right?
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000058 SkASSERT(0 != desc.fRTFBOID);
59 SkASSERT(0 != desc.fTexFBOID);
bsalomon@google.com99621082011-11-15 16:47:16 +000060
61 // we assume this is true, TODO: get rid of viewport as a param.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000062 SkASSERT(viewport.fWidth == texture->width());
63 SkASSERT(viewport.fHeight == texture->height());
bsalomon@google.com99621082011-11-15 16:47:16 +000064
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000065 this->init(desc, viewport, texID);
66}
67
68GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
69 const Desc& desc,
70 const GrGLIRect& viewport)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000071 : INHERITED(gpu,
bsalomon@google.com72830222013-01-23 20:25:22 +000072 desc.fIsWrapped,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000073 NULL,
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000074 MakeDesc(kNone_GrTextureFlags,
75 viewport.fWidth, viewport.fHeight,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000076 desc.fConfig, desc.fSampleCnt,
77 desc.fOrigin)) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000078 this->init(desc, viewport, NULL);
79}
80
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000081void GrGLRenderTarget::onRelease() {
82 GPUGL->notifyRenderTargetDelete(this);
bsalomon@google.com72830222013-01-23 20:25:22 +000083 if (!this->isWrapped()) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000084 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000085 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000086 }
87 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000088 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000089 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000090 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000091 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000092 }
93 }
94 fRTFBOID = 0;
95 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000096 fMSColorRenderbufferID = 0;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000097 fTexIDObj.reset(NULL);
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000098 INHERITED::onRelease();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000099}
100
101void GrGLRenderTarget::onAbandon() {
102 fRTFBOID = 0;
103 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000104 fMSColorRenderbufferID = 0;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +0000105 if (NULL != fTexIDObj.get()) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000106 fTexIDObj->abandon();
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +0000107 fTexIDObj.reset(NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000108 }
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000109 INHERITED::onAbandon();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000110}