OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 UI_COMPOSITOR_COMPOSITOR_H_ | 5 #ifndef UI_COMPOSITOR_COMPOSITOR_H_ |
6 #define UI_COMPOSITOR_COMPOSITOR_H_ | 6 #define UI_COMPOSITOR_COMPOSITOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Notifies that the ContextProvider returned from | 79 // Notifies that the ContextProvider returned from |
80 // ui::ContextFactory::SharedMainThreadContextProvider was lost. When this | 80 // ui::ContextFactory::SharedMainThreadContextProvider was lost. When this |
81 // is called, the old resources (e.g. shared context, GL helper) still | 81 // is called, the old resources (e.g. shared context, GL helper) still |
82 // exist, but are about to be destroyed. Getting a reference to those | 82 // exist, but are about to be destroyed. Getting a reference to those |
83 // resources from the ContextFactory (e.g. through | 83 // resources from the ContextFactory (e.g. through |
84 // SharedMainThreadContextProvider()) will return newly recreated, valid | 84 // SharedMainThreadContextProvider()) will return newly recreated, valid |
85 // resources. | 85 // resources. |
86 virtual void OnLostResources() = 0; | 86 virtual void OnLostResources() = 0; |
87 }; | 87 }; |
88 | 88 |
89 // This class abstracts the creation of the 3D context for the compositor. It is | 89 // This is privileged interface to the compositor. It is a global object. |
90 // a global object. | 90 class COMPOSITOR_EXPORT ContextFactoryPrivate { |
91 class COMPOSITOR_EXPORT ContextFactory { | |
92 public: | 91 public: |
93 virtual ~ContextFactory() {} | |
94 | |
95 // Creates an output surface for the given compositor. The factory may keep | |
96 // per-compositor data (e.g. a shared context), that needs to be cleaned up | |
97 // by calling RemoveCompositor when the compositor gets destroyed. | |
98 virtual void CreateCompositorFrameSink( | |
99 base::WeakPtr<Compositor> compositor) = 0; | |
100 | |
101 // Creates a reflector that copies the content of the |mirrored_compositor| | 92 // Creates a reflector that copies the content of the |mirrored_compositor| |
102 // onto |mirroring_layer|. | 93 // onto |mirroring_layer|. |
103 virtual std::unique_ptr<Reflector> CreateReflector( | 94 virtual std::unique_ptr<Reflector> CreateReflector( |
104 Compositor* mirrored_compositor, | 95 Compositor* mirrored_compositor, |
105 Layer* mirroring_layer) = 0; | 96 Layer* mirroring_layer) = 0; |
| 97 |
106 // Removes the reflector, which stops the mirroring. | 98 // Removes the reflector, which stops the mirroring. |
107 virtual void RemoveReflector(Reflector* reflector) = 0; | 99 virtual void RemoveReflector(Reflector* reflector) = 0; |
108 | 100 |
109 // Return a reference to a shared offscreen context provider usable from the | |
110 // main thread. | |
111 virtual scoped_refptr<cc::ContextProvider> | |
112 SharedMainThreadContextProvider() = 0; | |
113 | |
114 // Destroys per-compositor data. | |
115 virtual void RemoveCompositor(Compositor* compositor) = 0; | |
116 | |
117 // When true, the factory uses test contexts that do not do real GL | |
118 // operations. | |
119 virtual bool DoesCreateTestContexts() = 0; | |
120 | |
121 // Returns the OpenGL target to use for image textures. | |
122 virtual uint32_t GetImageTextureTarget(gfx::BufferFormat format, | |
123 gfx::BufferUsage usage) = 0; | |
124 | |
125 // Gets the GPU memory buffer manager. | |
126 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; | |
127 | |
128 // Gets the task graph runner. | |
129 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; | |
130 | |
131 // Allocate a new client ID for the display compositor. | 101 // Allocate a new client ID for the display compositor. |
132 virtual cc::FrameSinkId AllocateFrameSinkId() = 0; | 102 virtual cc::FrameSinkId AllocateFrameSinkId() = 0; |
133 | 103 |
134 // Gets the surface manager. | 104 // Gets the surface manager. |
135 virtual cc::SurfaceManager* GetSurfaceManager() = 0; | 105 virtual cc::SurfaceManager* GetSurfaceManager() = 0; |
136 | 106 |
137 // Inform the display corresponding to this compositor if it is visible. When | 107 // Inform the display corresponding to this compositor if it is visible. When |
138 // false it does not need to produce any frames. Visibility is reset for each | 108 // false it does not need to produce any frames. Visibility is reset for each |
139 // call to CreateCompositorFrameSink. | 109 // call to CreateCompositorFrameSink. |
140 virtual void SetDisplayVisible(ui::Compositor* compositor, bool visible) = 0; | 110 virtual void SetDisplayVisible(ui::Compositor* compositor, bool visible) = 0; |
141 | 111 |
142 // Resize the display corresponding to this compositor to a particular size. | 112 // Resize the display corresponding to this compositor to a particular size. |
143 virtual void ResizeDisplay(ui::Compositor* compositor, | 113 virtual void ResizeDisplay(ui::Compositor* compositor, |
144 const gfx::Size& size) = 0; | 114 const gfx::Size& size) = 0; |
145 | 115 |
146 // Set the output color profile into which this compositor should render. | 116 // Set the output color profile into which this compositor should render. |
147 virtual void SetDisplayColorSpace(ui::Compositor* compositor, | 117 virtual void SetDisplayColorSpace(ui::Compositor* compositor, |
148 const gfx::ColorSpace& color_space) = 0; | 118 const gfx::ColorSpace& color_space) = 0; |
149 | 119 |
150 virtual void SetAuthoritativeVSyncInterval(ui::Compositor* compositor, | 120 virtual void SetAuthoritativeVSyncInterval(ui::Compositor* compositor, |
151 base::TimeDelta interval) = 0; | 121 base::TimeDelta interval) = 0; |
152 // Mac path for transporting vsync parameters to the display. Other platforms | 122 // Mac path for transporting vsync parameters to the display. Other platforms |
153 // update it via the BrowserCompositorCompositorFrameSink directly. | 123 // update it via the BrowserCompositorCompositorFrameSink directly. |
154 virtual void SetDisplayVSyncParameters(ui::Compositor* compositor, | 124 virtual void SetDisplayVSyncParameters(ui::Compositor* compositor, |
155 base::TimeTicks timebase, | 125 base::TimeTicks timebase, |
156 base::TimeDelta interval) = 0; | 126 base::TimeDelta interval) = 0; |
157 | 127 |
158 virtual void SetOutputIsSecure(Compositor* compositor, bool secure) = 0; | 128 virtual void SetOutputIsSecure(Compositor* compositor, bool secure) = 0; |
| 129 }; |
| 130 |
| 131 // This class abstracts the creation of the 3D context for the compositor. It is |
| 132 // a global object. |
| 133 class COMPOSITOR_EXPORT ContextFactory { |
| 134 public: |
| 135 virtual ~ContextFactory() {} |
| 136 |
| 137 // Creates an output surface for the given compositor. The factory may keep |
| 138 // per-compositor data (e.g. a shared context), that needs to be cleaned up |
| 139 // by calling RemoveCompositor when the compositor gets destroyed. |
| 140 virtual void CreateCompositorFrameSink( |
| 141 base::WeakPtr<Compositor> compositor) = 0; |
| 142 |
| 143 // Return a reference to a shared offscreen context provider usable from the |
| 144 // main thread. |
| 145 virtual scoped_refptr<cc::ContextProvider> |
| 146 SharedMainThreadContextProvider() = 0; |
| 147 |
| 148 // Destroys per-compositor data. |
| 149 virtual void RemoveCompositor(Compositor* compositor) = 0; |
| 150 |
| 151 // When true, the factory uses test contexts that do not do real GL |
| 152 // operations. |
| 153 virtual bool DoesCreateTestContexts() = 0; |
| 154 |
| 155 // Returns the OpenGL target to use for image textures. |
| 156 virtual uint32_t GetImageTextureTarget(gfx::BufferFormat format, |
| 157 gfx::BufferUsage usage) = 0; |
| 158 |
| 159 // Gets the GPU memory buffer manager. |
| 160 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; |
| 161 |
| 162 // Gets the task graph runner. |
| 163 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; |
159 | 164 |
160 virtual void AddObserver(ContextFactoryObserver* observer) = 0; | 165 virtual void AddObserver(ContextFactoryObserver* observer) = 0; |
161 | 166 |
162 virtual void RemoveObserver(ContextFactoryObserver* observer) = 0; | 167 virtual void RemoveObserver(ContextFactoryObserver* observer) = 0; |
163 }; | 168 }; |
164 | 169 |
165 // This class represents a lock on the compositor, that can be used to prevent | 170 // This class represents a lock on the compositor, that can be used to prevent |
166 // commits to the compositor tree while we're waiting for an asynchronous | 171 // commits to the compositor tree while we're waiting for an asynchronous |
167 // event. The typical use case is when waiting for a renderer to produce a frame | 172 // event. The typical use case is when waiting for a renderer to produce a frame |
168 // at the right size. The caller keeps a reference on this object, and drops the | 173 // at the right size. The caller keeps a reference on this object, and drops the |
(...skipping 22 matching lines...) Expand all Loading... |
191 // Compositor object to take care of GPU painting. | 196 // Compositor object to take care of GPU painting. |
192 // A Browser compositor object is responsible for generating the final | 197 // A Browser compositor object is responsible for generating the final |
193 // displayable form of pixels comprising a single widget's contents. It draws an | 198 // displayable form of pixels comprising a single widget's contents. It draws an |
194 // appropriately transformed texture for each transformed view in the widget's | 199 // appropriately transformed texture for each transformed view in the widget's |
195 // view hierarchy. | 200 // view hierarchy. |
196 class COMPOSITOR_EXPORT Compositor | 201 class COMPOSITOR_EXPORT Compositor |
197 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), | 202 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), |
198 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { | 203 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { |
199 public: | 204 public: |
200 Compositor(ui::ContextFactory* context_factory, | 205 Compositor(ui::ContextFactory* context_factory, |
| 206 ui::ContextFactoryPrivate* context_factory_private, |
201 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 207 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
202 ~Compositor() override; | 208 ~Compositor() override; |
203 | 209 |
204 ui::ContextFactory* context_factory() { return context_factory_; } | 210 ui::ContextFactory* context_factory() { return context_factory_; } |
205 | 211 |
| 212 ui::ContextFactoryPrivate* context_factory_private() { |
| 213 return context_factory_private_; |
| 214 } |
| 215 |
206 void AddFrameSink(const cc::FrameSinkId& frame_sink_id); | 216 void AddFrameSink(const cc::FrameSinkId& frame_sink_id); |
207 void RemoveFrameSink(const cc::FrameSinkId& frame_sink_id); | 217 void RemoveFrameSink(const cc::FrameSinkId& frame_sink_id); |
208 | 218 |
209 void SetCompositorFrameSink(std::unique_ptr<cc::CompositorFrameSink> surface); | 219 void SetCompositorFrameSink(std::unique_ptr<cc::CompositorFrameSink> surface); |
210 | 220 |
211 // Schedules a redraw of the layer tree associated with this compositor. | 221 // Schedules a redraw of the layer tree associated with this compositor. |
212 void ScheduleDraw(); | 222 void ScheduleDraw(); |
213 | 223 |
214 // Sets the root of the layer tree drawn by this Compositor. The root layer | 224 // Sets the root of the layer tree drawn by this Compositor. The root layer |
215 // must have no parent. The compositor's root layer is reset if the root layer | 225 // must have no parent. The compositor's root layer is reset if the root layer |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 395 |
386 // Called by CompositorLock. | 396 // Called by CompositorLock. |
387 void UnlockCompositor(); | 397 void UnlockCompositor(); |
388 | 398 |
389 // Called to release any pending CompositorLock | 399 // Called to release any pending CompositorLock |
390 void CancelCompositorLock(); | 400 void CancelCompositorLock(); |
391 | 401 |
392 gfx::Size size_; | 402 gfx::Size size_; |
393 | 403 |
394 ui::ContextFactory* context_factory_; | 404 ui::ContextFactory* context_factory_; |
| 405 ui::ContextFactoryPrivate* context_factory_private_; |
395 | 406 |
396 // The root of the Layer tree drawn by this compositor. | 407 // The root of the Layer tree drawn by this compositor. |
397 Layer* root_layer_; | 408 Layer* root_layer_; |
398 | 409 |
399 base::ObserverList<CompositorObserver, true> observer_list_; | 410 base::ObserverList<CompositorObserver, true> observer_list_; |
400 base::ObserverList<CompositorAnimationObserver> animation_observer_list_; | 411 base::ObserverList<CompositorAnimationObserver> animation_observer_list_; |
401 | 412 |
402 gfx::AcceleratedWidget widget_; | 413 gfx::AcceleratedWidget widget_; |
403 #if defined(USE_AURA) | 414 #if defined(USE_AURA) |
404 ui::Window* window_; | 415 ui::Window* window_; |
(...skipping 24 matching lines...) Expand all Loading... |
429 gfx::ColorSpace color_space_; | 440 gfx::ColorSpace color_space_; |
430 | 441 |
431 base::WeakPtrFactory<Compositor> weak_ptr_factory_; | 442 base::WeakPtrFactory<Compositor> weak_ptr_factory_; |
432 | 443 |
433 DISALLOW_COPY_AND_ASSIGN(Compositor); | 444 DISALLOW_COPY_AND_ASSIGN(Compositor); |
434 }; | 445 }; |
435 | 446 |
436 } // namespace ui | 447 } // namespace ui |
437 | 448 |
438 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 449 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |