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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "cc/trees/layer_tree_host_client.h" | 15 #include "cc/trees/layer_tree_host_client.h" |
16 #include "cc/trees/layer_tree_host_single_thread_client.h" | 16 #include "cc/trees/layer_tree_host_single_thread_client.h" |
17 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
18 #include "ui/compositor/compositor_export.h" | 18 #include "ui/compositor/compositor_export.h" |
19 #include "ui/compositor/compositor_observer.h" | 19 #include "ui/compositor/compositor_observer.h" |
20 #include "ui/compositor/layer_animator_collection.h" | 20 #include "ui/compositor/layer_animator_collection.h" |
21 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
22 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
23 #include "ui/gfx/vector2d.h" | 23 #include "ui/gfx/vector2d.h" |
24 | 24 |
25 class SkBitmap; | |
26 | |
27 namespace base { | 25 namespace base { |
28 class MessageLoopProxy; | 26 class MessageLoopProxy; |
29 class RunLoop; | 27 class RunLoop; |
30 } | 28 } |
31 | 29 |
32 namespace cc { | 30 namespace cc { |
33 class ContextProvider; | 31 class ContextProvider; |
34 class Layer; | 32 class Layer; |
35 class LayerTreeDebugState; | 33 class LayerTreeDebugState; |
36 class LayerTreeHost; | 34 class LayerTreeHost; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 148 |
151 // Called when we need the compositor to preserve the alpha channel in the | 149 // Called when we need the compositor to preserve the alpha channel in the |
152 // output for situations when we want to render transparently atop something | 150 // output for situations when we want to render transparently atop something |
153 // else, e.g. Aero glass. | 151 // else, e.g. Aero glass. |
154 void SetHostHasTransparentBackground(bool host_has_transparent_background); | 152 void SetHostHasTransparentBackground(bool host_has_transparent_background); |
155 | 153 |
156 // The scale factor of the device that this compositor is | 154 // The scale factor of the device that this compositor is |
157 // compositing layers on. | 155 // compositing layers on. |
158 float device_scale_factor() const { return device_scale_factor_; } | 156 float device_scale_factor() const { return device_scale_factor_; } |
159 | 157 |
160 // Draws the scene created by the layer tree and any visual effects. | |
161 void Draw(); | |
162 | |
163 // Where possible, draws are scissored to a damage region calculated from | 158 // Where possible, draws are scissored to a damage region calculated from |
164 // changes to layer properties. This bypasses that and indicates that | 159 // changes to layer properties. This bypasses that and indicates that |
165 // the whole frame needs to be drawn. | 160 // the whole frame needs to be drawn. |
166 void ScheduleFullRedraw(); | 161 void ScheduleFullRedraw(); |
167 | 162 |
168 // Schedule redraw and append damage_rect to the damage region calculated | 163 // Schedule redraw and append damage_rect to the damage region calculated |
169 // from changes to layer properties. | 164 // from changes to layer properties. |
170 void ScheduleRedrawRect(const gfx::Rect& damage_rect); | 165 void ScheduleRedrawRect(const gfx::Rect& damage_rect); |
171 | 166 |
172 // Finishes all outstanding rendering on the GPU. | 167 // Finishes all outstanding rendering on the GPU. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 float page_scale) OVERRIDE {} | 216 float page_scale) OVERRIDE {} |
222 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) | 217 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) |
223 OVERRIDE; | 218 OVERRIDE; |
224 virtual void DidInitializeOutputSurface() OVERRIDE {} | 219 virtual void DidInitializeOutputSurface() OVERRIDE {} |
225 virtual void WillCommit() OVERRIDE {} | 220 virtual void WillCommit() OVERRIDE {} |
226 virtual void DidCommit() OVERRIDE; | 221 virtual void DidCommit() OVERRIDE; |
227 virtual void DidCommitAndDrawFrame() OVERRIDE; | 222 virtual void DidCommitAndDrawFrame() OVERRIDE; |
228 virtual void DidCompleteSwapBuffers() OVERRIDE; | 223 virtual void DidCompleteSwapBuffers() OVERRIDE; |
229 | 224 |
230 // cc::LayerTreeHostSingleThreadClient implementation. | 225 // cc::LayerTreeHostSingleThreadClient implementation. |
231 virtual void ScheduleComposite() OVERRIDE; | |
232 virtual void ScheduleAnimation() OVERRIDE; | |
233 virtual void DidPostSwapBuffers() OVERRIDE; | 226 virtual void DidPostSwapBuffers() OVERRIDE; |
234 virtual void DidAbortSwapBuffers() OVERRIDE; | 227 virtual void DidAbortSwapBuffers() OVERRIDE; |
235 | 228 |
236 // LayerAnimatorCollectionDelegate implementation. | 229 // LayerAnimatorCollectionDelegate implementation. |
237 virtual void ScheduleAnimationForLayerCollection() OVERRIDE; | 230 virtual void ScheduleAnimationForLayerCollection() OVERRIDE; |
238 | 231 |
239 int last_started_frame() { return last_started_frame_; } | |
240 int last_ended_frame() { return last_ended_frame_; } | |
241 | |
242 bool IsLocked() { return compositor_lock_ != NULL; } | 232 bool IsLocked() { return compositor_lock_ != NULL; } |
243 | 233 |
244 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; | 234 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; |
245 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); | 235 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); |
246 | 236 |
247 LayerAnimatorCollection* layer_animator_collection() { | 237 LayerAnimatorCollection* layer_animator_collection() { |
248 return &layer_animator_collection_; | 238 return &layer_animator_collection_; |
249 } | 239 } |
250 | 240 |
251 private: | 241 private: |
252 friend class base::RefCounted<Compositor>; | 242 friend class base::RefCounted<Compositor>; |
253 friend class CompositorLock; | 243 friend class CompositorLock; |
254 | 244 |
255 // Called by CompositorLock. | 245 // Called by CompositorLock. |
256 void UnlockCompositor(); | 246 void UnlockCompositor(); |
257 | 247 |
258 // Called to release any pending CompositorLock | 248 // Called to release any pending CompositorLock |
259 void CancelCompositorLock(); | 249 void CancelCompositorLock(); |
260 | 250 |
261 // Notifies the compositor that compositing is complete. | |
262 void NotifyEnd(); | |
263 | |
264 gfx::Size size_; | 251 gfx::Size size_; |
265 | 252 |
266 ui::ContextFactory* context_factory_; | 253 ui::ContextFactory* context_factory_; |
267 | 254 |
268 // The root of the Layer tree drawn by this compositor. | 255 // The root of the Layer tree drawn by this compositor. |
269 Layer* root_layer_; | 256 Layer* root_layer_; |
270 | 257 |
271 ObserverList<CompositorObserver> observer_list_; | 258 ObserverList<CompositorObserver> observer_list_; |
272 | 259 |
273 gfx::AcceleratedWidget widget_; | 260 gfx::AcceleratedWidget widget_; |
274 scoped_refptr<cc::Layer> root_web_layer_; | 261 scoped_refptr<cc::Layer> root_web_layer_; |
275 scoped_ptr<cc::LayerTreeHost> host_; | 262 scoped_ptr<cc::LayerTreeHost> host_; |
276 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; | 263 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; |
277 | 264 |
278 // The manager of vsync parameters for this compositor. | 265 // The manager of vsync parameters for this compositor. |
279 scoped_refptr<CompositorVSyncManager> vsync_manager_; | 266 scoped_refptr<CompositorVSyncManager> vsync_manager_; |
280 | 267 |
281 // The device scale factor of the monitor that this compositor is compositing | 268 // The device scale factor of the monitor that this compositor is compositing |
282 // layers on. | 269 // layers on. |
283 float device_scale_factor_; | 270 float device_scale_factor_; |
284 | 271 |
285 int last_started_frame_; | 272 int last_started_frame_; |
286 int last_ended_frame_; | 273 int last_ended_frame_; |
287 | 274 |
288 bool disable_schedule_composite_; | 275 bool disable_schedule_composite_; |
289 | 276 |
290 CompositorLock* compositor_lock_; | 277 CompositorLock* compositor_lock_; |
291 | 278 |
292 // Prevent more than one draw from being scheduled. | |
293 bool defer_draw_scheduling_; | |
294 | |
295 // Used to prevent Draw()s while a composite is in progress. | |
296 bool waiting_on_compositing_end_; | |
297 bool draw_on_compositing_end_; | |
298 enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED }; | |
299 SwapState swap_state_; | |
300 | |
301 LayerAnimatorCollection layer_animator_collection_; | 279 LayerAnimatorCollection layer_animator_collection_; |
302 | 280 |
303 base::WeakPtrFactory<Compositor> schedule_draw_factory_; | |
304 | |
305 DISALLOW_COPY_AND_ASSIGN(Compositor); | 281 DISALLOW_COPY_AND_ASSIGN(Compositor); |
306 }; | 282 }; |
307 | 283 |
308 } // namespace ui | 284 } // namespace ui |
309 | 285 |
310 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 286 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |