Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: ui/compositor/compositor.h

Issue 10690168: Aura: Resize locks with --ui-enable-threaded-compositing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New approach. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 a
130 // updates 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Compositor does not own observers. It is the responsibility of the 210 // Compositor does not own observers. It is the responsibility of the
185 // observer to remove itself when it is done observing. 211 // observer to remove itself when it is done observing.
186 void AddObserver(CompositorObserver* observer); 212 void AddObserver(CompositorObserver* observer);
187 void RemoveObserver(CompositorObserver* observer); 213 void RemoveObserver(CompositorObserver* observer);
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 // Creates a compositor lock.
195 // (i.e. |Compositor::Initialize(true)| was called). 221 scoped_refptr<CompositorLock> GetCompositorLock();
196 bool IsThreaded() const;
197 222
198 // Internal functions, called back by command-buffer contexts on swap buffer 223 // Internal functions, called back by command-buffer contexts on swap buffer
199 // events. 224 // events.
200 225
201 // Signals swap has been posted. 226 // Signals swap has been posted.
202 void OnSwapBuffersPosted(); 227 void OnSwapBuffersPosted();
203 228
204 // Signals swap has completed. 229 // Signals swap has completed.
205 void OnSwapBuffersComplete(); 230 void OnSwapBuffersComplete();
206 231
207 // Signals swap has aborted (e.g. lost context). 232 // Signals swap has aborted (e.g. lost context).
208 void OnSwapBuffersAborted(); 233 void OnSwapBuffersAborted();
209 234
210 // WebLayerTreeViewClient implementation. 235 // WebLayerTreeViewClient implementation.
211 virtual void updateAnimations(double frameBeginTime); 236 virtual void updateAnimations(double frameBeginTime);
212 virtual void layout(); 237 virtual void layout();
213 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta, 238 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta,
214 float scaleFactor); 239 float scaleFactor);
215 virtual WebKit::WebGraphicsContext3D* createContext3D(); 240 virtual WebKit::WebGraphicsContext3D* createContext3D();
216 virtual void didRebindGraphicsContext(bool success); 241 virtual void didRebindGraphicsContext(bool success);
217 virtual void didCommit(); 242 virtual void didCommit();
218 virtual void didCommitAndDrawFrame(); 243 virtual void didCommitAndDrawFrame();
219 virtual void didCompleteSwapBuffers(); 244 virtual void didCompleteSwapBuffers();
220 virtual void scheduleComposite(); 245 virtual void scheduleComposite();
221 246
222 int last_started_frame() { return last_started_frame_; } 247 int last_started_frame() { return last_started_frame_; }
223 int last_ended_frame() { return last_ended_frame_; } 248 int last_ended_frame() { return last_ended_frame_; }
249 int last_commit_id() { return last_commit_id_; }
224 250
225 private: 251 private:
226 friend class base::RefCounted<Compositor>; 252 friend class base::RefCounted<Compositor>;
253 friend class CompositorLock;
254
255 // Called by CompositorLock.
256 void Unlock();
227 257
228 // When reading back pixel data we often get RGBA rather than BGRA pixels and 258 // When reading back pixel data we often get RGBA rather than BGRA pixels and
229 // and the image often needs to be flipped vertically. 259 // and the image often needs to be flipped vertically.
230 static void SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, 260 static void SwizzleRGBAToBGRAAndFlip(unsigned char* pixels,
231 const gfx::Size& image_size); 261 const gfx::Size& image_size);
232 262
233 // Notifies the compositor that compositing is complete. 263 // Notifies the compositor that compositing is complete.
234 void NotifyEnd(); 264 void NotifyEnd();
235 265
236 CompositorDelegate* delegate_; 266 CompositorDelegate* delegate_;
(...skipping 12 matching lines...) Expand all
249 // for completion. 279 // for completion.
250 bool swap_posted_; 280 bool swap_posted_;
251 281
252 // The device scale factor of the monitor that this compositor is compositing 282 // The device scale factor of the monitor that this compositor is compositing
253 // layers on. 283 // layers on.
254 float device_scale_factor_; 284 float device_scale_factor_;
255 285
256 int last_started_frame_; 286 int last_started_frame_;
257 int last_ended_frame_; 287 int last_ended_frame_;
258 288
289 int last_commit_id_;
290
259 bool disable_schedule_composite_; 291 bool disable_schedule_composite_;
260 292
293 enum UpdatesAllowedState {
294 // We've told |root_layer_| to enable updates, but no update has cleared.
piman 2012/07/31 23:42:17 "update" is a very overloaded term... Should we us
jonathan.backer 2012/08/01 17:22:43 Done.
295 ENABLED_NEEDS_UPDATE,
296 // We've updated since being enabled.
297 ENABLED_DID_UPDATE,
298 // We will tell |root_layer_| to defer updates once an update clears.
299 DISABLED_PENDING_UPDATE,
300 // We told |root_layer_| to disable updates.
301 DISABLED,
302 };
303
304 int updates_allowed_;
piman 2012/07/31 23:42:17 UpdatesAllowedState instead of int?
jonathan.backer 2012/08/01 17:22:43 Done.
305
306 CompositorLock* compositor_lock_;
307
261 DISALLOW_COPY_AND_ASSIGN(Compositor); 308 DISALLOW_COPY_AND_ASSIGN(Compositor);
262 }; 309 };
263 310
264 } // namespace ui 311 } // namespace ui
265 312
266 #endif // UI_COMPOSITOR_COMPOSITOR_H_ 313 #endif // UI_COMPOSITOR_COMPOSITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698