bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | /* |
| 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.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 8 | #include "GrGLRenderTarget.h" |
| 9 | |
| 10 | #include "GrGpuGL.h" |
| 11 | |
| 12 | #define GPUGL static_cast<GrGpuGL*>(getGpu()) |
| 13 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 14 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 15 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 16 | void 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.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 22 | fViewport = viewport; |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 23 | fTexIDObj.reset(SkSafeRef(texID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 24 | } |
| 25 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 26 | namespace { |
| 27 | GrTextureDesc MakeDesc(GrTextureFlags flags, |
| 28 | int width, int height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 29 | GrPixelConfig config, int sampleCnt, |
| 30 | GrSurfaceOrigin origin) { |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 31 | GrTextureDesc temp; |
| 32 | temp.fFlags = flags; |
| 33 | temp.fWidth = width; |
| 34 | temp.fHeight = height; |
| 35 | temp.fConfig = config; |
| 36 | temp.fSampleCnt = sampleCnt; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 37 | temp.fOrigin = origin; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 38 | return temp; |
| 39 | } |
| 40 | |
| 41 | }; |
| 42 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 43 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 44 | const Desc& desc, |
| 45 | const GrGLIRect& viewport, |
| 46 | GrGLTexID* texID, |
| 47 | GrGLTexture* texture) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 48 | : INHERITED(gpu, |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 49 | desc.fIsWrapped, |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 50 | texture, |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 51 | MakeDesc(kNone_GrTextureFlags, |
| 52 | viewport.fWidth, viewport.fHeight, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 53 | desc.fConfig, desc.fSampleCnt, |
| 54 | desc.fOrigin)) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 55 | SkASSERT(NULL != texID); |
| 56 | SkASSERT(NULL != texture); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 57 | // FBO 0 can't also be a texture, right? |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 58 | SkASSERT(0 != desc.fRTFBOID); |
| 59 | SkASSERT(0 != desc.fTexFBOID); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 60 | |
| 61 | // we assume this is true, TODO: get rid of viewport as a param. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 62 | SkASSERT(viewport.fWidth == texture->width()); |
| 63 | SkASSERT(viewport.fHeight == texture->height()); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 64 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 65 | this->init(desc, viewport, texID); |
| 66 | } |
| 67 | |
| 68 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 69 | const Desc& desc, |
| 70 | const GrGLIRect& viewport) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 71 | : INHERITED(gpu, |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 72 | desc.fIsWrapped, |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 73 | NULL, |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 74 | MakeDesc(kNone_GrTextureFlags, |
| 75 | viewport.fWidth, viewport.fHeight, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 76 | desc.fConfig, desc.fSampleCnt, |
| 77 | desc.fOrigin)) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 78 | this->init(desc, viewport, NULL); |
| 79 | } |
| 80 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 81 | void GrGLRenderTarget::onRelease() { |
| 82 | GPUGL->notifyRenderTargetDelete(this); |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 83 | if (!this->isWrapped()) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 84 | if (fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 85 | GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 86 | } |
| 87 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 88 | GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 89 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 90 | if (fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 91 | GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | fRTFBOID = 0; |
| 95 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 96 | fMSColorRenderbufferID = 0; |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 97 | fTexIDObj.reset(NULL); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 98 | INHERITED::onRelease(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void GrGLRenderTarget::onAbandon() { |
| 102 | fRTFBOID = 0; |
| 103 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 104 | fMSColorRenderbufferID = 0; |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 105 | if (NULL != fTexIDObj.get()) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 106 | fTexIDObj->abandon(); |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 107 | fTexIDObj.reset(NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 108 | } |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 109 | INHERITED::onAbandon(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 110 | } |