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