Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: src/gpu/gl/GrGLRenderTarget.cpp

Issue 695813003: Add class GrGLTextureRenderTarget for GL texture/rendertarget objects (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: forgot to save file Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Because this class is virtually derived from GrSurface we must explicitly cal l its constructor.
17 const IDDesc& idDesc, 16 GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, const GrSurfaceDesc& desc, cons t IDDesc& idDesc)
18 const GrGLIRect& viewport, 17 : GrSurface(gpu, idDesc.fIsWrapped, desc)
19 GrGLTexID* texID) { 18 , INHERITED(gpu, idDesc.fIsWrapped, desc) {
19 this->init(desc, idDesc);
20 this->registerWithCache();
21 }
22
23 GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, const GrSurfaceDesc& desc, cons t IDDesc& idDesc,
24 Derived)
25 : GrSurface(gpu, idDesc.fIsWrapped, desc)
26 , INHERITED(gpu, idDesc.fIsWrapped, desc) {
27 this->init(desc, idDesc);
28 }
29
30 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
20 fRTFBOID = idDesc.fRTFBOID; 31 fRTFBOID = idDesc.fRTFBOID;
21 fTexFBOID = idDesc.fTexFBOID; 32 fTexFBOID = idDesc.fTexFBOID;
22 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; 33 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
23 fViewport = viewport; 34
24 fTexIDObj.reset(SkSafeRef(texID)); 35 fViewport.fLeft = 0;
25 this->registerWithCache(); 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 }
26 } 46 }
27 47
28 GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, 48 size_t GrGLRenderTarget::gpuMemorySize() const {
29 const IDDesc& idDesc, 49 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig);
30 const GrGLIRect& viewport, 50 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig));
31 GrGLTexID* texID, 51 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig);
32 GrGLTexture* texture) 52 SkASSERT(colorBytes > 0);
33 : INHERITED(gpu, idDesc.fIsWrapped, texture, texture->desc()) { 53 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 } 54 }
54 55
55 void GrGLRenderTarget::onRelease() { 56 void GrGLRenderTarget::onRelease() {
56 if (!this->isWrapped()) { 57 if (!this->isWrapped()) {
57 if (fTexFBOID) { 58 if (fTexFBOID) {
58 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); 59 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
59 } 60 }
60 if (fRTFBOID && fRTFBOID != fTexFBOID) { 61 if (fRTFBOID && fRTFBOID != fTexFBOID) {
61 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); 62 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
62 } 63 }
63 if (fMSColorRenderbufferID) { 64 if (fMSColorRenderbufferID) {
64 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); 65 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
65 } 66 }
66 } 67 }
67 fRTFBOID = 0; 68 fRTFBOID = 0;
68 fTexFBOID = 0; 69 fTexFBOID = 0;
69 fMSColorRenderbufferID = 0; 70 fMSColorRenderbufferID = 0;
70 fTexIDObj.reset(NULL);
71 INHERITED::onRelease(); 71 INHERITED::onRelease();
72 } 72 }
73 73
74 void GrGLRenderTarget::onAbandon() { 74 void GrGLRenderTarget::onAbandon() {
75 fRTFBOID = 0; 75 fRTFBOID = 0;
76 fTexFBOID = 0; 76 fTexFBOID = 0;
77 fMSColorRenderbufferID = 0; 77 fMSColorRenderbufferID = 0;
78 if (fTexIDObj.get()) {
79 fTexIDObj->abandon();
80 fTexIDObj.reset(NULL);
81 }
82 INHERITED::onAbandon(); 78 INHERITED::onAbandon();
83 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698