blob: 98813beb2cce1ba03ef574ee9c9939c6370b02a2 [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
bsalomon37dd3312014-11-03 08:47:23 -080012#define GPUGL static_cast<GrGpuGL*>(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.
16GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
17 : 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
bsalomon37dd3312014-11-03 08:47:23 -080023GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
24 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;
34
35 fViewport.fLeft = 0;
36 fViewport.fBottom = 0;
37 fViewport.fWidth = desc.fWidth;
38 fViewport.fHeight = desc.fHeight;
39
40 // We own one color value for each MSAA sample.
41 fColorValuesPerPixel = SkTMax(1, fDesc.fSampleCnt);
42 if (fTexFBOID != fRTFBOID) {
43 // If we own the resolve buffer then that is one more sample per pixel.
44 fColorValuesPerPixel += 1;
45 }
46}
47
bsalomon69ed47f2014-11-12 11:13:39 -080048size_t GrGLRenderTarget::onGpuMemorySize() const {
bsalomon37dd3312014-11-03 08:47:23 -080049 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig);
50 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig));
51 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig);
52 SkASSERT(colorBytes > 0);
53 return fColorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorBytes;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000054}
55
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000056void GrGLRenderTarget::onRelease() {
bsalomon@google.com72830222013-01-23 20:25:22 +000057 if (!this->isWrapped()) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000058 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000059 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000060 }
61 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000062 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000063 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000064 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000065 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000066 }
67 }
68 fRTFBOID = 0;
69 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000070 fMSColorRenderbufferID = 0;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000071 INHERITED::onRelease();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000072}
73
74void GrGLRenderTarget::onAbandon() {
75 fRTFBOID = 0;
76 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000077 fMSColorRenderbufferID = 0;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000078 INHERITED::onAbandon();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000079}