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

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

Issue 949263002: Improve tracking of bound FBOs in GrGLGpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months 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 8
9 #ifndef GrGLRenderTarget_DEFINED 9 #ifndef GrGLRenderTarget_DEFINED
10 #define GrGLRenderTarget_DEFINED 10 #define GrGLRenderTarget_DEFINED
11 11
12 #include "GrGLIRect.h" 12 #include "GrGLIRect.h"
13 #include "GrRenderTarget.h" 13 #include "GrRenderTarget.h"
14 #include "SkScalar.h" 14 #include "SkScalar.h"
15 15
16 class GrGLGpu; 16 class GrGLGpu;
17 17
18 class GrGLFBO : public SkRefCnt {
19 public:
20 SK_DECLARE_INST_COUNT(GrGLFBO);
21
22 GrGLFBO() : fGenID(SK_InvalidGenID) {}
23
24 GrGLFBO(GrGLint id) : fID(id), fGenID(NextGenID()) {}
25
26 GrGLFBO(const GrGLInterface* gl) : fGenID(NextGenID()) {
27 GR_GL_CALL(gl, GenFramebuffers(1, &fID));
28 }
29
30 ~GrGLFBO() SK_OVERRIDE { SkASSERT(!this->isValid()); }
31
32 void generateIfInvalid(const GrGLInterface* gl) {
33 if (!this->isValid()) {
34 GR_GL_CALL(gl, GenFramebuffers(1, &fID));
35 fGenID = NextGenID();
36 }
37 }
38
39 bool isValid() const { return SK_InvalidGenID != fGenID; }
40
41 uint32_t genID() const { return fGenID; }
42
43 GrGLint fboID() const { SkASSERT(this->isValid()); return fID; }
44
45 bool isDefaultFramebuffer() const { SkASSERT(this->isValid()); return 0 == f ID; }
46
47 void abandon(GrGLGpu* gpu);
48
49 void deleteIfValid(GrGLGpu* gpu);
50
51 private:
52 static uint32_t NextGenID() {
53 static int32_t gGenID = SK_InvalidGenID + 1;
54 return static_cast<uint32_t>(sk_atomic_inc(&gGenID));
55 }
56
57 GrGLuint fID;
58 uint32_t fGenID;
59
60 typedef SkRefCnt INHERITED;
61 };
62
63
18 class GrGLRenderTarget : public GrRenderTarget { 64 class GrGLRenderTarget : public GrRenderTarget {
19 public: 65 public:
20 // set fTexFBOID to this value to indicate that it is multisampled but
21 // Gr doesn't know how to resolve it.
22 enum { kUnresolvableFBOID = 0 };
23
24 struct IDDesc { 66 struct IDDesc {
25 GrGLuint fRTFBOID; 67 SkAutoTUnref<GrGLFBO> fRenderFBO;
26 GrGLuint fTexFBOID; 68 SkAutoTUnref<GrGLFBO> fTextureFBO;
27 GrGLuint fMSColorRenderbufferID; 69 GrGLuint fMSColorRenderbufferID;
28 GrGpuResource::LifeCycle fLifeCycle; 70 GrGpuResource::LifeCycle fLifeCycle; // Make this an ownership bool?
29 }; 71 };
30 72
31 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); 73 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
32 74
33 void setViewport(const GrGLIRect& rect) { fViewport = rect; } 75 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
34 const GrGLIRect& getViewport() const { return fViewport; } 76 const GrGLIRect& getViewport() const { return fViewport; }
35 77
36 // The following two functions return the same ID when a 78 // For multisampled renderbuffer render targets, these will return different GrGLFBO objects. If
37 // texture/render target is multisampled, and different IDs when 79 // the render target is not texturable, textureFBO() returns NULL. If the re nder target auto
38 // it is. 80 // resolves to a texture, the same object is returned.
39 // FBO ID used to render into 81
40 GrGLuint renderFBOID() const { return fRTFBOID; } 82 // FBO that should be rendered into. Always non-NULL.
41 // FBO ID that has texture ID attached. 83 const GrGLFBO* renderFBO() const {
42 GrGLuint textureFBOID() const { return fTexFBOID; } 84 SkASSERT(fRenderFBO && fRenderFBO->isValid());
85 return fRenderFBO;
86 }
87
88 // FBO that has the target's texture ID attached. The return value may be:
89 // * NULL when this render target is not a texture,
90 // * the same as renderFBO() when this surface is not multisampled or a uto-resolves,
91 // * or different than renderFBO() when it requires explicit resolving via
92 // glBlitFramebuffer.
93 const GrGLFBO* textureFBO() const {
94 SkASSERT(!fTextureFBO || fTextureFBO->isValid());
95 return fTextureFBO;
96 }
43 97
44 // override of GrRenderTarget 98 // override of GrRenderTarget
45 ResolveType getResolveType() const SK_OVERRIDE { 99 ResolveType getResolveType() const SK_OVERRIDE {
46 if (!this->isMultisampled() || 100 if (!this->isMultisampled() || this->renderFBO() == this->textureFBO()) {
47 fRTFBOID == fTexFBOID) {
48 // catches FBO 0 and non MSAA case 101 // catches FBO 0 and non MSAA case
49 return kAutoResolves_ResolveType; 102 return kAutoResolves_ResolveType;
50 } else if (kUnresolvableFBOID == fTexFBOID) { 103 } else if (!this->textureFBO()) {
51 return kCantResolve_ResolveType; 104 return kCantResolve_ResolveType;
52 } else { 105 } else {
53 return kCanResolve_ResolveType; 106 return kCanResolve_ResolveType;
54 } 107 }
55 } 108 }
56 109
57 /** When we don't own the FBO ID we don't attempt to modify its attachments. */ 110 /** When we don't own the FBO ID we don't attempt to modify its attachments. */
58 bool canAttemptStencilAttachment() const SK_OVERRIDE { return !fIsWrapped; } 111 bool canAttemptStencilAttachment() const SK_OVERRIDE { return !fIsWrapped; }
59 112
60 protected: 113 protected:
61 // The public constructor registers this object with the cache. However, onl y the most derived 114 // The public constructor registers this object with the cache. However, onl y the most derived
62 // class should register with the cache. This constructor does not do the re gistration and 115 // class should register with the cache. This constructor does not do the re gistration and
63 // rather moves that burden onto the derived class. 116 // rather moves that burden onto the derived class.
64 enum Derived { kDerived }; 117 enum Derived { kDerived };
65 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived); 118 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
66 119
67 void init(const GrSurfaceDesc&, const IDDesc&); 120 void init(const GrSurfaceDesc&, const IDDesc&);
68 121
69 void onAbandon() SK_OVERRIDE; 122 void onAbandon() SK_OVERRIDE;
70 void onRelease() SK_OVERRIDE; 123 void onRelease() SK_OVERRIDE;
71 124
72 // In protected because subclass GrGLTextureRenderTarget calls this version. 125 // In protected because subclass GrGLTextureRenderTarget calls this version.
73 size_t onGpuMemorySize() const SK_OVERRIDE; 126 size_t onGpuMemorySize() const SK_OVERRIDE;
74 127
75 private: 128 private:
76 GrGLuint fRTFBOID; 129 SkAutoTUnref<GrGLFBO> fRenderFBO;
77 GrGLuint fTexFBOID; 130 SkAutoTUnref<GrGLFBO> fTextureFBO;
78 GrGLuint fMSColorRenderbufferID; 131 GrGLuint fMSColorRenderbufferID;
79 132
80 // We track this separately from GrGpuResource because this may be both a te xture and a render 133 // We track this separately from GrGpuResource because this may be both a te xture and a render
81 // target, and the texture may be wrapped while the render target is not. 134 // target, and the texture may be wrapped while the render target is not.
82 bool fIsWrapped; 135 bool fIsWrapped;
83 136
84 // when we switch to this render target we want to set the viewport to 137 // when we switch to this render target we want to set the viewport to
85 // only render to content area (as opposed to the whole allocation) and 138 // only render to content area (as opposed to the whole allocation) and
86 // we want the rendering to be at top left (GL has origin in bottom left) 139 // we want the rendering to be at top left (GL has origin in bottom left)
87 GrGLIRect fViewport; 140 GrGLIRect fViewport;
88 141
89 // onGpuMemorySize() needs to know what how many color values are owned per pixel. However, 142 // onGpuMemorySize() needs to know what how many color values are owned per pixel. However,
90 // abandon and release zero out the IDs and the cache needs to know the size even after those 143 // abandon and release zero out the IDs and the cache needs to know the size even after those
91 // actions. 144 // actions.
92 uint8_t fColorValuesPerPixel; 145 uint8_t fColorValuesPerPixel;
93 146
94 typedef GrRenderTarget INHERITED; 147 typedef GrRenderTarget INHERITED;
95 }; 148 };
96 149
97 #endif 150 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698