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

Side by Side Diff: cc/output/compositor_frame_sink.h

Issue 2349743004: cc: Remove things from OutputSurface and CompositorFrameSink. (Closed)
Patch Set: delete-stuff-cfs: . Created 4 years, 3 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
« no previous file with comments | « cc/BUILD.gn ('k') | cc/output/compositor_frame_sink.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ 5 #ifndef CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_
6 #define CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ 6 #define CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "base/trace_event/memory_dump_provider.h" 15 #include "base/trace_event/memory_dump_provider.h"
16 #include "cc/base/cc_export.h" 16 #include "cc/base/cc_export.h"
17 #include "cc/output/context_provider.h" 17 #include "cc/output/context_provider.h"
18 #include "cc/output/overlay_candidate_validator.h" 18 #include "cc/output/overlay_candidate_validator.h"
19 #include "cc/output/software_output_device.h"
20 #include "cc/output/vulkan_context_provider.h" 19 #include "cc/output/vulkan_context_provider.h"
21 #include "cc/resources/returned_resource.h" 20 #include "cc/resources/returned_resource.h"
22 #include "gpu/command_buffer/common/texture_in_use_response.h" 21 #include "gpu/command_buffer/common/texture_in_use_response.h"
23 #include "ui/gfx/color_space.h" 22 #include "ui/gfx/color_space.h"
24 23
25 namespace ui { 24 namespace ui {
26 class LatencyInfo; 25 class LatencyInfo;
27 } 26 }
28 27
29 namespace gfx { 28 namespace gfx {
(...skipping 12 matching lines...) Expand all
42 // Represents the output surface for a compositor. The compositor owns 41 // Represents the output surface for a compositor. The compositor owns
43 // and manages its destruction. Its lifetime is: 42 // and manages its destruction. Its lifetime is:
44 // 1. Created on the main thread by the LayerTreeHost through its client. 43 // 1. Created on the main thread by the LayerTreeHost through its client.
45 // 2. Passed to the compositor thread and bound to a client via BindToClient. 44 // 2. Passed to the compositor thread and bound to a client via BindToClient.
46 // From here on, it will only be used on the compositor thread. 45 // From here on, it will only be used on the compositor thread.
47 // 3. If the 3D context is lost, then the compositor will delete the output 46 // 3. If the 3D context is lost, then the compositor will delete the output
48 // surface (on the compositor thread) and go back to step 1. 47 // surface (on the compositor thread) and go back to step 1.
49 class CC_EXPORT CompositorFrameSink 48 class CC_EXPORT CompositorFrameSink
50 : public base::trace_event::MemoryDumpProvider { 49 : public base::trace_event::MemoryDumpProvider {
51 public: 50 public:
51 struct Capabilities {
52 Capabilities() = default;
53
54 // TODO(enne): Remove this since everything uses begin frames now, but it
55 // causes some racey unit tests to fail.
56 bool adjust_deadline_for_parent = true;
danakj 2016/09/17 01:29:37 So ok the story with this one is I left it as true
57
58 // Whether ForceReclaimResources can be called to reclaim all resources
59 // from the CompositorFrameSink.
60 bool can_force_reclaim_resources = false;
61 // True if sync points for resources are needed when swapping delegated
62 // frames.
63 bool delegated_sync_points_required = true;
64 };
65
52 // Constructor for GL-based and/or software compositing. 66 // Constructor for GL-based and/or software compositing.
53 explicit CompositorFrameSink( 67 explicit CompositorFrameSink(
54 scoped_refptr<ContextProvider> context_provider, 68 scoped_refptr<ContextProvider> context_provider,
55 scoped_refptr<ContextProvider> worker_context_provider, 69 scoped_refptr<ContextProvider> worker_context_provider);
56 std::unique_ptr<SoftwareOutputDevice> software_device);
57 70
58 // Constructor for Vulkan-based compositing. 71 // Constructor for Vulkan-based compositing.
59 explicit CompositorFrameSink( 72 explicit CompositorFrameSink(
60 scoped_refptr<VulkanContextProvider> vulkan_context_provider); 73 scoped_refptr<VulkanContextProvider> vulkan_context_provider);
61 74
62 ~CompositorFrameSink() override; 75 ~CompositorFrameSink() override;
63 76
64 struct Capabilities {
65 Capabilities()
66 : delegated_rendering(false),
67 max_frames_pending(1),
68 adjust_deadline_for_parent(true),
69 uses_default_gl_framebuffer(true),
70 flipped_compositor_frame_sink(false),
71 can_force_reclaim_resources(false),
72 delegated_sync_points_required(true) {}
73 bool delegated_rendering;
74 int max_frames_pending;
75 // This doesn't handle the <webview> case, but once BeginFrame is
76 // supported natively, we shouldn't need adjust_deadline_for_parent.
77 bool adjust_deadline_for_parent;
78 // Whether this output surface renders to the default OpenGL zero
79 // framebuffer or to an offscreen framebuffer.
80 bool uses_default_gl_framebuffer;
81 // Whether this CompositorFrameSink is flipped or not.
82 bool flipped_compositor_frame_sink;
83 // Whether ForceReclaimResources can be called to reclaim all resources
84 // from the CompositorFrameSink.
85 bool can_force_reclaim_resources;
86 // True if sync points for resources are needed when swapping delegated
87 // frames.
88 bool delegated_sync_points_required;
89 };
90
91 // ============== DISPLAY COMPOSITOR ONLY =======================
92
93 virtual void EnsureBackbuffer();
94 virtual void DiscardBackbuffer();
95
96 const gfx::ColorSpace& device_color_space() const {
97 return device_color_space_;
98 }
99
100 // Called by subclasses after receiving a response from the gpu process to a
101 // query about whether a given set of textures is still in use by the OS
102 // compositor.
103 void DidReceiveTextureInUseResponses(
104 const gpu::TextureInUseResponses& responses);
105
106 // Get the class capable of informing cc of hardware overlay capability.
107 virtual OverlayCandidateValidator* GetOverlayCandidateValidator() const;
108
109 // Returns true if a main image overlay plane should be scheduled.
110 virtual bool IsDisplayedAsOverlayPlane() const;
111
112 // Get the texture for the main image's overlay.
113 virtual unsigned GetOverlayTextureId() const;
114
115 // If this returns true, then the surface will not attempt to draw.
116 virtual bool SurfaceIsSuspendForRecycle() const;
117
118 virtual void Reshape(const gfx::Size& size,
119 float scale_factor,
120 const gfx::ColorSpace& color_space,
121 bool alpha);
122 gfx::Size SurfaceSize() const { return surface_size_; }
123
124 virtual bool HasExternalStencilTest() const;
125 virtual void ApplyExternalStencil();
126
127 // ============== LAYER TREE COMPOSITOR ONLY ===================
128
129 // If supported, this causes a ReclaimResources for all resources that are
130 // currently in use.
131 virtual void ForceReclaimResources() {}
132
133 virtual void BindFramebuffer();
134 // Gives the GL internal format that should be used for calling CopyTexImage2D
135 // when the framebuffer is bound via BindFramebuffer().
136 virtual uint32_t GetFramebufferCopyTextureFormat() = 0;
137
138 // Support for a pull-model where draws are requested by the output surface.
139 //
140 // CompositorFrameSink::Invalidate is called by the compositor to notify that
141 // there's new content.
142 virtual void Invalidate() {}
143
144 // ============== BOTH TYPES OF COMPOSITOR ======================
145
146 // Called by the compositor on the compositor thread. This is a place where 77 // Called by the compositor on the compositor thread. This is a place where
147 // thread-specific data for the output surface can be initialized, since from 78 // thread-specific data for the output surface can be initialized, since from
148 // this point to when DetachFromClient() is called the output surface will 79 // this point to when DetachFromClient() is called the output surface will
149 // only be used on the compositor thread. 80 // only be used on the compositor thread.
150 // The caller should call DetachFromClient() on the same thread before 81 // The caller should call DetachFromClient() on the same thread before
151 // destroying the CompositorFrameSink, even if this fails. And BindToClient 82 // destroying the CompositorFrameSink, even if this fails. And BindToClient
152 // should not be called twice for a given CompositorFrameSink. 83 // should not be called twice for a given CompositorFrameSink.
153 virtual bool BindToClient(CompositorFrameSinkClient* client); 84 virtual bool BindToClient(CompositorFrameSinkClient* client);
154 85
155 // Called by the compositor on the compositor thread. This is a place where 86 // Called by the compositor on the compositor thread. This is a place where
156 // thread-specific data for the output surface can be uninitialized. 87 // thread-specific data for the output surface can be uninitialized.
157 virtual void DetachFromClient(); 88 virtual void DetachFromClient();
158 89
159 bool HasClient() { return !!client_; } 90 bool HasClient() { return !!client_; }
160 91
161 const Capabilities& capabilities() const { return capabilities_; } 92 const Capabilities& capabilities() const { return capabilities_; }
162 93
163 // Obtain the 3d context or the software device associated with this output 94 // Obtain the 3d context or the software device associated with this output
164 // surface. Either of these may return a null pointer, but not both. 95 // surface. Either of these may return a null pointer, but not both.
165 // In the event of a lost context, the entire output surface should be 96 // In the event of a lost context, the entire output surface should be
166 // recreated. 97 // recreated.
167 ContextProvider* context_provider() const { return context_provider_.get(); } 98 ContextProvider* context_provider() const { return context_provider_.get(); }
168 ContextProvider* worker_context_provider() const { 99 ContextProvider* worker_context_provider() const {
169 return worker_context_provider_.get(); 100 return worker_context_provider_.get();
170 } 101 }
171 VulkanContextProvider* vulkan_context_provider() const { 102 VulkanContextProvider* vulkan_context_provider() const {
172 return vulkan_context_provider_.get(); 103 return vulkan_context_provider_.get();
173 } 104 }
174 SoftwareOutputDevice* software_device() const {
175 return software_device_.get();
176 }
177 105
178 // The implementation may destroy or steal the contents of the CompositorFrame 106 // If supported, this causes a ReclaimResources for all resources that are
179 // passed in (though it will not take ownership of the CompositorFrame 107 // currently in use.
180 // itself). For successful swaps, the implementation must call 108 virtual void ForceReclaimResources() {}
181 // DidSwapBuffersComplete() (via OnSwapBuffersComplete()) eventually. 109
110 // Support for a pull-model where draws are requested by the output surface.
111 //
112 // CompositorFrameSink::Invalidate is called by the compositor to notify that
113 // there's new content.
114 virtual void Invalidate() {}
115
116 // For successful swaps, the implementation must call DidSwapBuffersComplete()
117 // (via OnSwapBuffersComplete()) eventually.
182 virtual void SwapBuffers(CompositorFrame frame) = 0; 118 virtual void SwapBuffers(CompositorFrame frame) = 0;
183 virtual void OnSwapBuffersComplete(); 119 virtual void OnSwapBuffersComplete();
184 120
185 // base::trace_event::MemoryDumpProvider implementation. 121 // base::trace_event::MemoryDumpProvider implementation.
186 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 122 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
187 base::trace_event::ProcessMemoryDump* pmd) override; 123 base::trace_event::ProcessMemoryDump* pmd) override;
188 124
189 protected: 125 protected:
190 // This is used by both display and delegating implementations. 126 // This is used by both display and delegating implementations.
191 void PostSwapBuffersComplete(); 127 void PostSwapBuffersComplete();
192 128
193 // This is how LayerTreeHostImpl hears about context loss when the Display 129 // Bound to the ContextProvider to hear about when it is lost and inform the
194 // is the one listening for context loss. Also used internally for the 130 // |client_|.
195 // context provider to inform the LayerTreeHostImpl or Display about loss. 131 void DidLoseCompositorFrameSink();
196 // It would become display-compositor-only when LayerTreeHostImpl receives
197 // its contexts independently from the "CompositorFrameSink".
198 virtual void DidLoseCompositorFrameSink();
199 132
200 CompositorFrameSinkClient* client_ = nullptr; 133 CompositorFrameSinkClient* client_ = nullptr;
201 134
202 struct CompositorFrameSink::Capabilities capabilities_; 135 struct CompositorFrameSink::Capabilities capabilities_;
203 scoped_refptr<ContextProvider> context_provider_; 136 scoped_refptr<ContextProvider> context_provider_;
204 scoped_refptr<ContextProvider> worker_context_provider_; 137 scoped_refptr<ContextProvider> worker_context_provider_;
205 scoped_refptr<VulkanContextProvider> vulkan_context_provider_; 138 scoped_refptr<VulkanContextProvider> vulkan_context_provider_;
206 std::unique_ptr<SoftwareOutputDevice> software_device_;
207 gfx::Size surface_size_;
208 float device_scale_factor_ = -1;
209 gfx::ColorSpace device_color_space_;
210 bool has_alpha_ = true;
211 gfx::ColorSpace color_space_;
212 base::ThreadChecker client_thread_checker_; 139 base::ThreadChecker client_thread_checker_;
213 140
214 private: 141 private:
215 void DetachFromClientInternal(); 142 void DetachFromClientInternal();
216 143
217 base::WeakPtrFactory<CompositorFrameSink> weak_ptr_factory_; 144 base::WeakPtrFactory<CompositorFrameSink> weak_ptr_factory_;
218 145
219 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSink); 146 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSink);
220 }; 147 };
221 148
222 } // namespace cc 149 } // namespace cc
223 150
224 #endif // CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ 151 #endif // CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_
OLDNEW
« no previous file with comments | « cc/BUILD.gn ('k') | cc/output/compositor_frame_sink.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698