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/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // An interface to allow the compositor to communicate with its owner. | 119 // An interface to allow the compositor to communicate with its owner. |
120 class COMPOSITOR_EXPORT CompositorDelegate { | 120 class COMPOSITOR_EXPORT CompositorDelegate { |
121 public: | 121 public: |
122 // Requests the owner to schedule a redraw of the layer tree. | 122 // Requests the owner to schedule a redraw of the layer tree. |
123 virtual void ScheduleDraw() = 0; | 123 virtual void ScheduleDraw() = 0; |
124 | 124 |
125 protected: | 125 protected: |
126 virtual ~CompositorDelegate() {} | 126 virtual ~CompositorDelegate() {} |
127 }; | 127 }; |
128 | 128 |
| 129 // This class represents a lock on the compositor, that can be used to prevent |
| 130 // commits to the compositor tree while we're waiting for an asynchronous |
| 131 // event. The typical use case is when waiting for a renderer to produce a frame |
| 132 // at the right size. The caller keeps a reference on this object, and drops the |
| 133 // reference once it desires to release the lock. |
| 134 // Note however that the lock is canceled after a short timeout to ensure |
| 135 // responsiveness of the UI, so the compositor tree should be kept in a |
| 136 // "reasonable" state while the lock is held. |
| 137 // Don't instantiate this class directly, use Compositor::GetCompositorLock. |
| 138 class COMPOSITOR_EXPORT CompositorLock |
| 139 : public base::RefCounted<CompositorLock>, |
| 140 public base::SupportsWeakPtr<CompositorLock> { |
| 141 private: |
| 142 friend class base::RefCounted<CompositorLock>; |
| 143 friend class Compositor; |
| 144 |
| 145 explicit CompositorLock(Compositor* compositor); |
| 146 ~CompositorLock(); |
| 147 |
| 148 void CancelLock(); |
| 149 |
| 150 Compositor* compositor_; |
| 151 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
| 152 }; |
| 153 |
| 154 |
129 // Compositor object to take care of GPU painting. | 155 // Compositor object to take care of GPU painting. |
130 // A Browser compositor object is responsible for generating the final | 156 // A Browser compositor object is responsible for generating the final |
131 // displayable form of pixels comprising a single widget's contents. It draws an | 157 // displayable form of pixels comprising a single widget's contents. It draws an |
132 // appropriately transformed texture for each transformed view in the widget's | 158 // appropriately transformed texture for each transformed view in the widget's |
133 // view hierarchy. | 159 // view hierarchy. |
134 class COMPOSITOR_EXPORT Compositor | 160 class COMPOSITOR_EXPORT Compositor |
135 : NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) { | 161 : NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) { |
136 public: | 162 public: |
137 Compositor(CompositorDelegate* delegate, | 163 Compositor(CompositorDelegate* delegate, |
138 gfx::AcceleratedWidget widget); | 164 gfx::AcceleratedWidget widget); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bool HasObserver(CompositorObserver* observer); | 214 bool HasObserver(CompositorObserver* observer); |
189 | 215 |
190 // Returns whether a draw is pending, that is, if we're between the Draw call | 216 // Returns whether a draw is pending, that is, if we're between the Draw call |
191 // and the OnCompositingEnded. | 217 // and the OnCompositingEnded. |
192 bool DrawPending() const { return swap_posted_; } | 218 bool DrawPending() const { return swap_posted_; } |
193 | 219 |
194 // Returns whether the drawing is issued from a separate thread | 220 // Returns whether the drawing is issued from a separate thread |
195 // (i.e. |Compositor::Initialize(true)| was called). | 221 // (i.e. |Compositor::Initialize(true)| was called). |
196 bool IsThreaded() const; | 222 bool IsThreaded() const; |
197 | 223 |
| 224 // Creates a compositor lock. |
| 225 scoped_refptr<CompositorLock> GetCompositorLock(); |
| 226 |
198 // Internal functions, called back by command-buffer contexts on swap buffer | 227 // Internal functions, called back by command-buffer contexts on swap buffer |
199 // events. | 228 // events. |
200 | 229 |
201 // Signals swap has been posted. | 230 // Signals swap has been posted. |
202 void OnSwapBuffersPosted(); | 231 void OnSwapBuffersPosted(); |
203 | 232 |
204 // Signals swap has completed. | 233 // Signals swap has completed. |
205 void OnSwapBuffersComplete(); | 234 void OnSwapBuffersComplete(); |
206 | 235 |
207 // Signals swap has aborted (e.g. lost context). | 236 // Signals swap has aborted (e.g. lost context). |
208 void OnSwapBuffersAborted(); | 237 void OnSwapBuffersAborted(); |
209 | 238 |
210 // WebLayerTreeViewClient implementation. | 239 // WebLayerTreeViewClient implementation. |
211 virtual void updateAnimations(double frameBeginTime); | 240 virtual void updateAnimations(double frameBeginTime); |
212 virtual void layout(); | 241 virtual void layout(); |
213 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 242 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
214 float scaleFactor); | 243 float scaleFactor); |
215 virtual WebKit::WebGraphicsContext3D* createContext3D(); | 244 virtual WebKit::WebGraphicsContext3D* createContext3D(); |
216 virtual void didRebindGraphicsContext(bool success); | 245 virtual void didRebindGraphicsContext(bool success); |
217 virtual void didCommit(); | 246 virtual void didCommit(); |
218 virtual void didCommitAndDrawFrame(); | 247 virtual void didCommitAndDrawFrame(); |
219 virtual void didCompleteSwapBuffers(); | 248 virtual void didCompleteSwapBuffers(); |
220 virtual void scheduleComposite(); | 249 virtual void scheduleComposite(); |
221 | 250 |
222 int last_started_frame() { return last_started_frame_; } | 251 int last_started_frame() { return last_started_frame_; } |
223 int last_ended_frame() { return last_ended_frame_; } | 252 int last_ended_frame() { return last_ended_frame_; } |
224 | 253 |
225 private: | 254 private: |
226 friend class base::RefCounted<Compositor>; | 255 friend class base::RefCounted<Compositor>; |
| 256 friend class CompositorLock; |
| 257 |
| 258 // Called by CompositorLock. |
| 259 void Unlock(); |
227 | 260 |
228 // When reading back pixel data we often get RGBA rather than BGRA pixels and | 261 // When reading back pixel data we often get RGBA rather than BGRA pixels and |
229 // and the image often needs to be flipped vertically. | 262 // and the image often needs to be flipped vertically. |
230 static void SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, | 263 static void SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, |
231 const gfx::Size& image_size); | 264 const gfx::Size& image_size); |
232 | 265 |
233 // Notifies the compositor that compositing is complete. | 266 // Notifies the compositor that compositing is complete. |
234 void NotifyEnd(); | 267 void NotifyEnd(); |
235 | 268 |
236 CompositorDelegate* delegate_; | 269 CompositorDelegate* delegate_; |
(...skipping 14 matching lines...) Expand all Loading... |
251 | 284 |
252 // 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 |
253 // layers on. | 286 // layers on. |
254 float device_scale_factor_; | 287 float device_scale_factor_; |
255 | 288 |
256 int last_started_frame_; | 289 int last_started_frame_; |
257 int last_ended_frame_; | 290 int last_ended_frame_; |
258 | 291 |
259 bool disable_schedule_composite_; | 292 bool disable_schedule_composite_; |
260 | 293 |
| 294 enum CommitsAllowedState { |
| 295 // We've told |root_layer_| to enable commits, but no commit has cleared. |
| 296 ENABLED_NEEDS_COMMIT, |
| 297 // We've committed since being enabled. |
| 298 ENABLED_DID_COMMIT, |
| 299 // We will tell |root_layer_| to defer commits once an commit clears. |
| 300 DISABLED_PENDING_COMMIT, |
| 301 // We told |root_layer_| to disable commits. |
| 302 DISABLED, |
| 303 }; |
| 304 |
| 305 CommitsAllowedState commits_allowed_; |
| 306 |
| 307 CompositorLock* compositor_lock_; |
| 308 |
261 DISALLOW_COPY_AND_ASSIGN(Compositor); | 309 DISALLOW_COPY_AND_ASSIGN(Compositor); |
262 }; | 310 }; |
263 | 311 |
264 } // namespace ui | 312 } // namespace ui |
265 | 313 |
266 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 314 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |