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

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

Issue 1810323002: Cache render targets that render to wrapped textures Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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 class GrGLStencilAttachment; 17 class GrGLStencilAttachment;
18 18
19 class GrGLRenderTarget : public GrRenderTarget { 19 class GrGLRenderTarget : public GrRenderTarget {
20 public: 20 public:
21 // set fTexFBOID to this value to indicate that it is multisampled but 21 // set fTexFBOID to this value to indicate that it is multisampled but
22 // Gr doesn't know how to resolve it. 22 // Gr doesn't know how to resolve it.
23 enum { kUnresolvableFBOID = 0 }; 23 enum { kUnresolvableFBOID = 0 };
24 24
25 struct IDDesc { 25 struct IDDesc {
26 IDDesc() : fRTFBOID(0), fRTFBOLifeCycle(GrBackendObjectLifeCycle::kInter nal),
27 fTexID(0), fTexLifeCycle(GrBackendObjectLifeCycle::kInternal) ,
28 fTexFBOID(kUnresolvableFBOID), fMSColorRenderbufferID(0),
29 fSampleConfig(GrRenderTarget::kUnified_SampleConfig) {}
26 GrGLuint fRTFBOID; 30 GrGLuint fRTFBOID;
31 GrBackendObjectLifeCycle fRTFBOLifeCycle;
32 GrGLuint fTexID; // ID of an adopted texture as rt.
33 GrBackendObjectLifeCycle fTexLifeCycle;
27 GrGLuint fTexFBOID; 34 GrGLuint fTexFBOID;
28 GrGLuint fMSColorRenderbufferID; 35 GrGLuint fMSColorRenderbufferID;
29 GrGpuResource::LifeCycle fLifeCycle;
30 GrRenderTarget::SampleConfig fSampleConfig; 36 GrRenderTarget::SampleConfig fSampleConfig;
31 }; 37 };
32 38
33 static GrGLRenderTarget* CreateWrapped(GrGLGpu*, 39 static GrGLRenderTarget* CreateWrapped(GrGLGpu*,
40 SkBudgeted,
34 const GrSurfaceDesc&, 41 const GrSurfaceDesc&,
35 const IDDesc&, 42 const IDDesc&,
36 int stencilBits); 43 int stencilBits);
37 44
38 void setViewport(const GrGLIRect& rect) { fViewport = rect; } 45 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
39 const GrGLIRect& getViewport() const { return fViewport; } 46 const GrGLIRect& getViewport() const { return fViewport; }
40 47
41 // The following two functions return the same ID when a 48 // The following two functions return the same ID when a
42 // texture/render target is multisampled, and different IDs when 49 // texture/render target is multisampled, and different IDs when
43 // it is. 50 // it is.
44 // FBO ID used to render into 51 // FBO ID used to render into
45 GrGLuint renderFBOID() const { return fRTFBOID; } 52 GrGLuint renderFBOID() const { return fIDDesc.fRTFBOID; }
46 // FBO ID that has texture ID attached. 53 // FBO ID that has texture ID attached.
47 GrGLuint textureFBOID() const { return fTexFBOID; } 54 GrGLuint textureFBOID() const { return fIDDesc.fTexFBOID; }
48 55
49 // override of GrRenderTarget 56 // override of GrRenderTarget
50 ResolveType getResolveType() const override { 57 ResolveType getResolveType() const override {
51 if (!this->isUnifiedMultisampled() || 58 if (!this->isUnifiedMultisampled() ||
52 fRTFBOID == fTexFBOID) { 59 fIDDesc.fRTFBOID == fIDDesc.fTexFBOID) {
53 // catches FBO 0 and non MSAA case 60 // catches FBO 0 and non MSAA case
54 return kAutoResolves_ResolveType; 61 return kAutoResolves_ResolveType;
55 } else if (kUnresolvableFBOID == fTexFBOID) { 62 } else if (kUnresolvableFBOID == fIDDesc.fTexFBOID) {
56 return kCantResolve_ResolveType; 63 return kCantResolve_ResolveType;
57 } else { 64 } else {
58 return kCanResolve_ResolveType; 65 return kCanResolve_ResolveType;
59 } 66 }
60 } 67 }
61 68
62 GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; } 69 GrBackendObject getRenderTargetHandle() const override { return fIDDesc.fRTF BOID; }
63 70
64 /** When we don't own the FBO ID we don't attempt to modify its attachments. */ 71 /** When we don't own the FBO ID we don't attempt to modify its attachments. */
65 bool canAttemptStencilAttachment() const override { 72 bool canAttemptStencilAttachment() const override {
66 return kCached_LifeCycle == fRTLifecycle || kUncached_LifeCycle == fRTLi fecycle; 73 return GrBackendObjectLifeCycle::kInternal == fIDDesc.fRTFBOLifeCycle;
67 } 74 }
68 75
69 // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer 76 // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
70 // components seperately. 77 // components seperately.
71 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override ; 78 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override ;
72
73 protected: 79 protected:
74 // The public constructor registers this object with the cache. However, onl y the most derived 80 // The public constructor registers this object with the cache. However, onl y the most derived
75 // class should register with the cache. This constructor does not do the re gistration and 81 // class should register with the cache. This constructor does not do the re gistration and
76 // rather moves that burden onto the derived class. 82 // rather moves that burden onto the derived class.
77 enum Derived { kDerived }; 83 enum Derived { kDerived };
78 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived); 84 GrGLRenderTarget(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, Derived);
79 85
80 void init(const GrSurfaceDesc&, const IDDesc&); 86 void init(const GrSurfaceDesc&);
81 87
82 void onAbandon() override; 88 void onAbandon() override;
83 void onRelease() override; 89 void onRelease() override;
84 90
91 bool refsWrappedResources() const override;
92
85 // In protected because subclass GrGLTextureRenderTarget calls this version. 93 // In protected because subclass GrGLTextureRenderTarget calls this version.
86 size_t onGpuMemorySize() const override; 94 size_t onGpuMemorySize() const override;
87 95
88 private: 96 private:
89 // This ctor is used only for creating wrapped render targets and is only ca lled for the static 97 // This ctor is used only for creating wrapped render targets and is only ca lled for the static
90 // create function CreateWrapped(...). 98 // create function CreateWrapped(...).
91 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilA ttachment*); 99 GrGLRenderTarget(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*);
92 100
93 GrGLGpu* getGLGpu() const; 101 GrGLGpu* getGLGpu() const;
94 bool completeStencilAttachment() override; 102 bool completeStencilAttachment() override;
95 103
96 // The total size of the resource (including all pixels) for a single sample . 104 // The total size of the resource (including all pixels) for a single sample .
97 size_t totalBytesPerSample() const; 105 size_t totalBytesPerSample() const;
98 int msaaSamples() const;
99 // The number total number of samples, including both MSAA and resolve textu re samples. 106 // The number total number of samples, including both MSAA and resolve textu re samples.
100 int totalSamples() const; 107 int totalSamples() const;
101 108
102 GrGLuint fRTFBOID; 109 IDDesc fIDDesc;
103 GrGLuint fTexFBOID;
104 GrGLuint fMSColorRenderbufferID;
105
106 // We track this separately from GrGpuResource because this may be both a te xture and a render
107 // target, and the texture may be wrapped while the render target is not.
108 LifeCycle fRTLifecycle;
109
110 // when we switch to this render target we want to set the viewport to 110 // when we switch to this render target we want to set the viewport to
111 // only render to content area (as opposed to the whole allocation) and 111 // only render to content area (as opposed to the whole allocation) and
112 // we want the rendering to be at top left (GL has origin in bottom left) 112 // we want the rendering to be at top left (GL has origin in bottom left)
113 GrGLIRect fViewport; 113 GrGLIRect fViewport;
114 114
115 // onGpuMemorySize() needs to know the VRAM footprint of the FBO(s). However , abandon and 115 // onGpuMemorySize() needs to know the VRAM footprint of the FBO(s). However , abandon and
116 // release zero out the IDs and the cache needs to know the size even after those actions. 116 // release zero out the IDs and the cache needs to know the size even after those actions.
117 size_t fGpuMemorySize; 117 size_t fGpuMemorySize;
118 118
119 typedef GrRenderTarget INHERITED; 119 typedef GrRenderTarget INHERITED;
120 }; 120 };
121 121
122 #endif 122 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698