blob: c513b65bf24738443b7a6a99cf87974de17010f7 [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
jvanverth39edf762014-12-22 11:44:19 -080010#include "GrGLGpu.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000011
bsalomon861e1032014-12-16 07:33:49 -080012#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
bsalomon@google.com0b77d682011-08-19 13:28:54 +000013#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
14
bsalomon37dd3312014-11-03 08:47:23 -080015// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
bsalomon861e1032014-12-16 07:33:49 -080016GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
bsalomon37dd3312014-11-03 08:47:23 -080017 : GrSurface(gpu, idDesc.fIsWrapped, desc)
18 , INHERITED(gpu, idDesc.fIsWrapped, desc) {
19 this->init(desc, idDesc);
bsalomon16961262014-08-26 14:01:07 -070020 this->registerWithCache();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000021}
22
bsalomon861e1032014-12-16 07:33:49 -080023GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
bsalomon37dd3312014-11-03 08:47:23 -080024 Derived)
25 : GrSurface(gpu, idDesc.fIsWrapped, desc)
26 , INHERITED(gpu, idDesc.fIsWrapped, desc) {
27 this->init(desc, idDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000028}
29
bsalomon37dd3312014-11-03 08:47:23 -080030void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
31 fRTFBOID = idDesc.fRTFBOID;
32 fTexFBOID = idDesc.fTexFBOID;
33 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
hendrikw9a0c7ab2014-12-09 14:26:47 -080034 fIsWrapped = idDesc.fIsWrapped;
bsalomon37dd3312014-11-03 08:47:23 -080035
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
bsalomon69ed47f2014-11-12 11:13:39 -080049size_t GrGLRenderTarget::onGpuMemorySize() const {
bsalomon37dd3312014-11-03 08:47:23 -080050 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.com5bfc2172011-07-29 20:29:05 +000055}
56
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000057void GrGLRenderTarget::onRelease() {
hendrikw9a0c7ab2014-12-09 14:26:47 -080058 if (!fIsWrapped) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000059 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000060 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000061 }
62 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000063 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000064 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000065 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000066 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000067 }
68 }
69 fRTFBOID = 0;
70 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000071 fMSColorRenderbufferID = 0;
hendrikw9a0c7ab2014-12-09 14:26:47 -080072 fIsWrapped = false;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000073 INHERITED::onRelease();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000074}
75
76void GrGLRenderTarget::onAbandon() {
77 fRTFBOID = 0;
78 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000079 fMSColorRenderbufferID = 0;
hendrikw9a0c7ab2014-12-09 14:26:47 -080080 fIsWrapped = false;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000081 INHERITED::onAbandon();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000082}