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 | |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 10 | #include "GrGLGpu.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 11 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 12 | #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 13 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 14 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 15 | // Because this class is virtually derived from GrSurface we must explicitly call its constructor. |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 16 | GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc) |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 17 | : GrSurface(gpu, idDesc.fIsWrapped, desc) |
| 18 | , INHERITED(gpu, idDesc.fIsWrapped, desc) { |
| 19 | this->init(desc, idDesc); |
bsalomon | 1696126 | 2014-08-26 14:01:07 -0700 | [diff] [blame] | 20 | this->registerWithCache(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 21 | } |
| 22 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 23 | GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 24 | Derived) |
| 25 | : GrSurface(gpu, idDesc.fIsWrapped, desc) |
| 26 | , INHERITED(gpu, idDesc.fIsWrapped, desc) { |
| 27 | this->init(desc, idDesc); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 28 | } |
| 29 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 30 | void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { |
| 31 | fRTFBOID = idDesc.fRTFBOID; |
| 32 | fTexFBOID = idDesc.fTexFBOID; |
| 33 | fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 34 | fIsWrapped = idDesc.fIsWrapped; |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 35 | |
| 36 | fViewport.fLeft = 0; |
| 37 | fViewport.fBottom = 0; |
| 38 | fViewport.fWidth = desc.fWidth; |
| 39 | fViewport.fHeight = desc.fHeight; |
| 40 | |
| 41 | // We own one color value for each MSAA sample. |
| 42 | fColorValuesPerPixel = SkTMax(1, fDesc.fSampleCnt); |
| 43 | if (fTexFBOID != fRTFBOID) { |
| 44 | // If we own the resolve buffer then that is one more sample per pixel. |
| 45 | fColorValuesPerPixel += 1; |
| 46 | } |
| 47 | } |
| 48 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 49 | size_t GrGLRenderTarget::onGpuMemorySize() const { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 50 | SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); |
| 51 | SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); |
| 52 | size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); |
| 53 | SkASSERT(colorBytes > 0); |
| 54 | return fColorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorBytes; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 55 | } |
| 56 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 57 | void GrGLRenderTarget::onRelease() { |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 58 | if (!fIsWrapped) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 59 | if (fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 60 | GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 61 | } |
| 62 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 63 | GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 64 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 65 | if (fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 66 | GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | fRTFBOID = 0; |
| 70 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 71 | fMSColorRenderbufferID = 0; |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 72 | fIsWrapped = false; |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 73 | INHERITED::onRelease(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void GrGLRenderTarget::onAbandon() { |
| 77 | fRTFBOID = 0; |
| 78 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 79 | fMSColorRenderbufferID = 0; |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 80 | fIsWrapped = false; |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 81 | INHERITED::onAbandon(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 82 | } |