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