OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrGLRenderTarget.h" | 8 #include "GrGLRenderTarget.h" |
9 | 9 |
10 #include "GrGpuGL.h" | 10 #include "GrGpuGL.h" |
11 | 11 |
12 #define GPUGL static_cast<GrGpuGL*>(getGpu()) | 12 #define GPUGL static_cast<GrGpuGL*>(this->getGpu()) |
13 | |
14 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 13 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
15 | 14 |
16 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, | 15 GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, const GrSurfaceDesc& desc, cons t IDDesc& idDesc) |
17 const IDDesc& idDesc, | 16 : GrGLRenderTarget(gpu, desc, idDesc, kDerived) { |
18 const GrGLIRect& viewport, | 17 this->registerWithCache(); |
19 GrGLTexID* texID) { | 18 } |
19 | |
20 GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, const GrSurfaceDesc& desc, cons t IDDesc& idDesc, | |
21 Derived) | |
robertphillips
2014/11/03 13:58:54
move GrSurface ctor call to its own line ?
// GrR
bsalomon
2014/11/03 15:20:14
Done.
| |
22 : INHERITED(gpu, idDesc.fIsWrapped, desc), GrSurface(gpu, idDesc.fIsWrapped, desc) { | |
20 fRTFBOID = idDesc.fRTFBOID; | 23 fRTFBOID = idDesc.fRTFBOID; |
21 fTexFBOID = idDesc.fTexFBOID; | 24 fTexFBOID = idDesc.fTexFBOID; |
22 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; | 25 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; |
23 fViewport = viewport; | 26 |
24 fTexIDObj.reset(SkSafeRef(texID)); | 27 fViewport.fLeft = 0; |
25 this->registerWithCache(); | 28 fViewport.fBottom = 0; |
29 fViewport.fWidth = desc.fWidth; | |
30 fViewport.fHeight = desc.fHeight; | |
31 | |
32 // We own one color value for each MSAA sample. | |
33 fColorValuesPerPixel = SkTMax(1, fDesc.fSampleCnt); | |
34 if (fTexFBOID != fRTFBOID) { | |
35 // If we own the resolve buffer then that is one more sample per pixel. | |
36 fColorValuesPerPixel += 1; | |
37 } | |
26 } | 38 } |
27 | 39 |
28 GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, | 40 size_t GrGLRenderTarget::gpuMemorySize() const { |
29 const IDDesc& idDesc, | 41 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); |
30 const GrGLIRect& viewport, | 42 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); |
31 GrGLTexID* texID, | 43 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); |
32 GrGLTexture* texture) | 44 SkASSERT(colorBytes > 0); |
33 : INHERITED(gpu, idDesc.fIsWrapped, texture, texture->desc()) { | 45 return fColorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorBytes; |
34 SkASSERT(texID); | |
35 SkASSERT(texture); | |
36 // FBO 0 can't also be a texture, right? | |
37 SkASSERT(0 != idDesc.fRTFBOID); | |
38 SkASSERT(0 != idDesc.fTexFBOID); | |
39 | |
40 // we assume this is true, TODO: get rid of viewport as a param. | |
41 SkASSERT(viewport.fWidth == texture->width()); | |
42 SkASSERT(viewport.fHeight == texture->height()); | |
43 | |
44 this->init(texture->desc(), idDesc, viewport, texID); | |
45 } | |
46 | |
47 GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, | |
48 const GrSurfaceDesc& desc, | |
49 const IDDesc& idDesc, | |
50 const GrGLIRect& viewport) | |
51 : INHERITED(gpu, idDesc.fIsWrapped, NULL, desc) { | |
52 this->init(desc, idDesc, viewport, NULL); | |
53 } | 46 } |
54 | 47 |
55 void GrGLRenderTarget::onRelease() { | 48 void GrGLRenderTarget::onRelease() { |
56 if (!this->isWrapped()) { | 49 if (!this->isWrapped()) { |
57 if (fTexFBOID) { | 50 if (fTexFBOID) { |
58 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); | 51 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
59 } | 52 } |
60 if (fRTFBOID && fRTFBOID != fTexFBOID) { | 53 if (fRTFBOID && fRTFBOID != fTexFBOID) { |
61 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); | 54 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
62 } | 55 } |
63 if (fMSColorRenderbufferID) { | 56 if (fMSColorRenderbufferID) { |
64 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); | 57 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
65 } | 58 } |
66 } | 59 } |
67 fRTFBOID = 0; | 60 fRTFBOID = 0; |
68 fTexFBOID = 0; | 61 fTexFBOID = 0; |
69 fMSColorRenderbufferID = 0; | 62 fMSColorRenderbufferID = 0; |
70 fTexIDObj.reset(NULL); | |
71 INHERITED::onRelease(); | 63 INHERITED::onRelease(); |
72 } | 64 } |
73 | 65 |
74 void GrGLRenderTarget::onAbandon() { | 66 void GrGLRenderTarget::onAbandon() { |
75 fRTFBOID = 0; | 67 fRTFBOID = 0; |
76 fTexFBOID = 0; | 68 fTexFBOID = 0; |
77 fMSColorRenderbufferID = 0; | 69 fMSColorRenderbufferID = 0; |
78 if (fTexIDObj.get()) { | |
79 fTexIDObj->abandon(); | |
80 fTexIDObj.reset(NULL); | |
81 } | |
82 INHERITED::onAbandon(); | 70 INHERITED::onAbandon(); |
83 } | 71 } |
OLD | NEW |