| 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 "base/hash_tables.h" | 8 #include "base/hash_tables.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // An interface to allow the compositor to communicate with its owner. | 120 // An interface to allow the compositor to communicate with its owner. |
| 121 class COMPOSITOR_EXPORT CompositorDelegate { | 121 class COMPOSITOR_EXPORT CompositorDelegate { |
| 122 public: | 122 public: |
| 123 // Requests the owner to schedule a redraw of the layer tree. | 123 // Requests the owner to schedule a redraw of the layer tree. |
| 124 virtual void ScheduleDraw() = 0; | 124 virtual void ScheduleDraw() = 0; |
| 125 | 125 |
| 126 protected: | 126 protected: |
| 127 virtual ~CompositorDelegate() {} | 127 virtual ~CompositorDelegate() {} |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 // This class represents a lock on the compositor, that can be used to prevent |
| 131 // commits to the compositor tree while we're waiting for an asynchronous |
| 132 // event. The typical use case is when waiting for a renderer to produce a frame |
| 133 // at the right size. The caller keeps a reference on this object, and drops the |
| 134 // reference once it desires to release the lock. |
| 135 // Note however that the lock is cancelled after a short timeout to ensure |
| 136 // responsiveness of the UI, so the compositor tree should be kept in a |
| 137 // "reasonable" state while the lock is held. |
| 138 // Don't instantiate this class directly, use Compositor::GetCompositorLock. |
| 139 class COMPOSITOR_EXPORT CompositorLock |
| 140 : public base::RefCounted<CompositorLock>, |
| 141 public base::SupportsWeakPtr<CompositorLock> { |
| 142 private: |
| 143 friend class base::RefCounted<CompositorLock>; |
| 144 friend class Compositor; |
| 145 |
| 146 explicit CompositorLock(Compositor* compositor); |
| 147 ~CompositorLock(); |
| 148 |
| 149 void CancelLock(); |
| 150 |
| 151 Compositor* compositor_; |
| 152 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
| 153 }; |
| 154 |
| 155 |
| 130 // Compositor object to take care of GPU painting. | 156 // Compositor object to take care of GPU painting. |
| 131 // A Browser compositor object is responsible for generating the final | 157 // A Browser compositor object is responsible for generating the final |
| 132 // displayable form of pixels comprising a single widget's contents. It draws an | 158 // displayable form of pixels comprising a single widget's contents. It draws an |
| 133 // appropriately transformed texture for each transformed view in the widget's | 159 // appropriately transformed texture for each transformed view in the widget's |
| 134 // view hierarchy. | 160 // view hierarchy. |
| 135 class COMPOSITOR_EXPORT Compositor | 161 class COMPOSITOR_EXPORT Compositor |
| 136 : NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) { | 162 : NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) { |
| 137 public: | 163 public: |
| 138 Compositor(CompositorDelegate* delegate, | 164 Compositor(CompositorDelegate* delegate, |
| 139 gfx::AcceleratedWidget widget); | 165 gfx::AcceleratedWidget widget); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // Compositor does not own observers. It is the responsibility of the | 216 // Compositor does not own observers. It is the responsibility of the |
| 191 // observer to remove itself when it is done observing. | 217 // observer to remove itself when it is done observing. |
| 192 void AddObserver(CompositorObserver* observer); | 218 void AddObserver(CompositorObserver* observer); |
| 193 void RemoveObserver(CompositorObserver* observer); | 219 void RemoveObserver(CompositorObserver* observer); |
| 194 bool HasObserver(CompositorObserver* observer); | 220 bool HasObserver(CompositorObserver* observer); |
| 195 | 221 |
| 196 // Returns whether a draw is pending, that is, if we're between the Draw call | 222 // Returns whether a draw is pending, that is, if we're between the Draw call |
| 197 // and the OnCompositingEnded. | 223 // and the OnCompositingEnded. |
| 198 bool DrawPending() const { return swap_posted_; } | 224 bool DrawPending() const { return swap_posted_; } |
| 199 | 225 |
| 200 // Returns whether the drawing is issued from a separate thread | 226 // Creates a compositor lock. Returns NULL if it is not possible to lock at |
| 201 // (i.e. |Compositor::Initialize(true)| was called). | 227 // this time (i.e. we're waiting to complete a previous unlock). |
| 202 bool IsThreaded() const; | 228 scoped_refptr<CompositorLock> GetCompositorLock(); |
| 203 | 229 |
| 204 // Internal functions, called back by command-buffer contexts on swap buffer | 230 // Internal functions, called back by command-buffer contexts on swap buffer |
| 205 // events. | 231 // events. |
| 206 | 232 |
| 207 // Signals swap has been posted. | 233 // Signals swap has been posted. |
| 208 void OnSwapBuffersPosted(); | 234 void OnSwapBuffersPosted(); |
| 209 | 235 |
| 210 // Signals swap has completed. | 236 // Signals swap has completed. |
| 211 void OnSwapBuffersComplete(); | 237 void OnSwapBuffersComplete(); |
| 212 | 238 |
| 213 // Signals swap has aborted (e.g. lost context). | 239 // Signals swap has aborted (e.g. lost context). |
| 214 void OnSwapBuffersAborted(); | 240 void OnSwapBuffersAborted(); |
| 215 | 241 |
| 216 // WebLayerTreeViewClient implementation. | 242 // WebLayerTreeViewClient implementation. |
| 217 virtual void updateAnimations(double frameBeginTime); | 243 virtual void updateAnimations(double frameBeginTime); |
| 218 virtual void layout(); | 244 virtual void layout(); |
| 219 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 245 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
| 220 float scaleFactor); | 246 float scaleFactor); |
| 221 virtual WebKit::WebCompositorOutputSurface* createOutputSurface(); | 247 virtual WebKit::WebCompositorOutputSurface* createOutputSurface(); |
| 222 virtual void didRecreateOutputSurface(bool success); | 248 virtual void didRecreateOutputSurface(bool success); |
| 223 virtual void didCommit(); | 249 virtual void didCommit(); |
| 224 virtual void didCommitAndDrawFrame(); | 250 virtual void didCommitAndDrawFrame(); |
| 225 virtual void didCompleteSwapBuffers(); | 251 virtual void didCompleteSwapBuffers(); |
| 226 virtual void scheduleComposite(); | 252 virtual void scheduleComposite(); |
| 227 | 253 |
| 228 int last_started_frame() { return last_started_frame_; } | 254 int last_started_frame() { return last_started_frame_; } |
| 229 int last_ended_frame() { return last_ended_frame_; } | 255 int last_ended_frame() { return last_ended_frame_; } |
| 230 | 256 |
| 257 bool IsLocked() { return compositor_lock_; } |
| 258 |
| 231 private: | 259 private: |
| 232 friend class base::RefCounted<Compositor>; | 260 friend class base::RefCounted<Compositor>; |
| 261 friend class CompositorLock; |
| 262 |
| 263 // Called by CompositorLock. |
| 264 void Unlock(); |
| 233 | 265 |
| 234 // Notifies the compositor that compositing is complete. | 266 // Notifies the compositor that compositing is complete. |
| 235 void NotifyEnd(); | 267 void NotifyEnd(); |
| 236 | 268 |
| 237 CompositorDelegate* delegate_; | 269 CompositorDelegate* delegate_; |
| 238 gfx::Size size_; | 270 gfx::Size size_; |
| 239 | 271 |
| 240 // The root of the Layer tree drawn by this compositor. | 272 // The root of the Layer tree drawn by this compositor. |
| 241 Layer* root_layer_; | 273 Layer* root_layer_; |
| 242 | 274 |
| 243 ObserverList<CompositorObserver> observer_list_; | 275 ObserverList<CompositorObserver> observer_list_; |
| 244 | 276 |
| 245 gfx::AcceleratedWidget widget_; | 277 gfx::AcceleratedWidget widget_; |
| 246 scoped_ptr<WebKit::WebLayer> root_web_layer_; | 278 scoped_ptr<WebKit::WebLayer> root_web_layer_; |
| 247 scoped_ptr<WebKit::WebLayerTreeView> host_; | 279 scoped_ptr<WebKit::WebLayerTreeView> host_; |
| 248 | 280 |
| 249 // This is set to true when the swap buffers has been posted and we're waiting | 281 // This is set to true when the swap buffers has been posted and we're waiting |
| 250 // for completion. | 282 // for completion. |
| 251 bool swap_posted_; | 283 bool swap_posted_; |
| 252 | 284 |
| 253 // The device scale factor of the monitor that this compositor is compositing | 285 // The device scale factor of the monitor that this compositor is compositing |
| 254 // layers on. | 286 // layers on. |
| 255 float device_scale_factor_; | 287 float device_scale_factor_; |
| 256 | 288 |
| 257 int last_started_frame_; | 289 int last_started_frame_; |
| 258 int last_ended_frame_; | 290 int last_ended_frame_; |
| 259 | 291 |
| 260 bool disable_schedule_composite_; | 292 bool disable_schedule_composite_; |
| 261 | 293 |
| 294 CompositorLock* compositor_lock_; |
| 295 |
| 262 DISALLOW_COPY_AND_ASSIGN(Compositor); | 296 DISALLOW_COPY_AND_ASSIGN(Compositor); |
| 263 }; | 297 }; |
| 264 | 298 |
| 265 } // namespace ui | 299 } // namespace ui |
| 266 | 300 |
| 267 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 301 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
| OLD | NEW |