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

Side by Side Diff: components/exo/surface.h

Issue 2480783002: exo: Connect frame callbacks with UI compositor begin frames. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | components/exo/surface.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_EXO_SURFACE_H_ 5 #ifndef COMPONENTS_EXO_SURFACE_H_
6 #define COMPONENTS_EXO_SURFACE_H_ 6 #define COMPONENTS_EXO_SURFACE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "cc/resources/transferable_resource.h" 18 #include "cc/resources/transferable_resource.h"
19 #include "cc/scheduler/begin_frame_source.h"
19 #include "cc/surfaces/surface_factory_client.h" 20 #include "cc/surfaces/surface_factory_client.h"
20 #include "third_party/skia/include/core/SkRegion.h" 21 #include "third_party/skia/include/core/SkRegion.h"
21 #include "third_party/skia/include/core/SkXfermode.h" 22 #include "third_party/skia/include/core/SkXfermode.h"
22 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
23 #include "ui/compositor/compositor.h" 24 #include "ui/aura/window_observer.h"
24 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
25 26
26 namespace base { 27 namespace base {
27 namespace trace_event { 28 namespace trace_event {
28 class TracedValue; 29 class TracedValue;
29 } 30 }
30 } 31 }
31 32
32 namespace cc { 33 namespace cc {
33 class SurfaceFactory; 34 class SurfaceFactory;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 std::unique_ptr<cc::SingleReleaseCallback>>> 82 std::unique_ptr<cc::SingleReleaseCallback>>>
82 release_callbacks_; 83 release_callbacks_;
83 cc::FrameSinkId frame_sink_id_; 84 cc::FrameSinkId frame_sink_id_;
84 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_; 85 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_;
85 std::unique_ptr<cc::SurfaceFactory> surface_factory_; 86 std::unique_ptr<cc::SurfaceFactory> surface_factory_;
86 Surface* surface_ = nullptr; 87 Surface* surface_ = nullptr;
87 }; 88 };
88 89
89 // This class represents a rectangular area that is displayed on the screen. 90 // This class represents a rectangular area that is displayed on the screen.
90 // It has a location, size and pixel contents. 91 // It has a location, size and pixel contents.
91 class Surface : public ui::ContextFactoryObserver { 92 class Surface : public ui::ContextFactoryObserver,
93 public aura::WindowObserver,
94 public cc::BeginFrameObserver {
92 public: 95 public:
93 using PropertyDeallocator = void (*)(int64_t value); 96 using PropertyDeallocator = void (*)(int64_t value);
94 97
95 Surface(); 98 Surface();
96 ~Surface() override; 99 ~Surface() override;
97 100
98 // Type-checking downcast routine. 101 // Type-checking downcast routine.
99 static Surface* AsSurface(const aura::Window* window); 102 static Surface* AsSurface(const aura::Window* window);
100 103
101 aura::Window* window() { return window_.get(); } 104 aura::Window* window() { return window_.get(); }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 200
198 // Surface does not own observers. It is the responsibility of the observer 201 // Surface does not own observers. It is the responsibility of the observer
199 // to remove itself when it is done observing. 202 // to remove itself when it is done observing.
200 void AddSurfaceObserver(SurfaceObserver* observer); 203 void AddSurfaceObserver(SurfaceObserver* observer);
201 void RemoveSurfaceObserver(SurfaceObserver* observer); 204 void RemoveSurfaceObserver(SurfaceObserver* observer);
202 bool HasSurfaceObserver(const SurfaceObserver* observer) const; 205 bool HasSurfaceObserver(const SurfaceObserver* observer) const;
203 206
204 // Returns a trace value representing the state of the surface. 207 // Returns a trace value representing the state of the surface.
205 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; 208 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const;
206 209
207 bool HasPendingDamageForTesting(const gfx::Rect& damage) const { 210 // Called when surface is being scheduled for a draw.
208 return pending_damage_.contains(gfx::RectToSkIRect(damage)); 211 void WillDraw();
209 }
210 212
211 // Overridden from ui::ContextFactoryObserver. 213 // Called when the begin frame source has changed.
212 void OnLostResources() override; 214 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source);
213
214 void WillDraw(const cc::LocalFrameId& local_frame_id);
215 215
216 // Check whether this Surface and its children need to create new cc::Surface 216 // Check whether this Surface and its children need to create new cc::Surface
217 // IDs for their contents next time they get new buffer contents. 217 // IDs for their contents next time they get new buffer contents.
218 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); 218 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
219 219
220 // Returns the active contents size.
220 gfx::Size content_size() const { return content_size_; } 221 gfx::Size content_size() const { return content_size_; }
221 222
223 // Overridden from ui::ContextFactoryObserver:
224 void OnLostResources() override;
225
226 // Overridden from aura::WindowObserver:
227 void OnWindowAddedToRootWindow(aura::Window* window) override;
228 void OnWindowRemovingFromRootWindow(aura::Window* window,
229 aura::Window* new_root) override;
230
231 // Overridden from cc::BeginFrameObserver:
232 void OnBeginFrame(const cc::BeginFrameArgs& args) override;
233 const cc::BeginFrameArgs& LastUsedBeginFrameArgs() const override;
234 void OnBeginFrameSourcePausedChanged(bool paused) override {}
235
222 // Sets the |value| of the given surface |property|. Setting to the default 236 // Sets the |value| of the given surface |property|. Setting to the default
223 // value (e.g., NULL) removes the property. The caller is responsible for the 237 // value (e.g., NULL) removes the property. The caller is responsible for the
224 // lifetime of any object set as a property on the Surface. 238 // lifetime of any object set as a property on the Surface.
225 template <typename T> 239 template <typename T>
226 void SetProperty(const SurfaceProperty<T>* property, T value); 240 void SetProperty(const SurfaceProperty<T>* property, T value);
227 241
228 // Returns the value of the given surface |property|. Returns the 242 // Returns the value of the given surface |property|. Returns the
229 // property-specific default value if the property was not previously set. 243 // property-specific default value if the property was not previously set.
230 template <typename T> 244 template <typename T>
231 T GetProperty(const SurfaceProperty<T>* property) const; 245 T GetProperty(const SurfaceProperty<T>* property) const;
232 246
233 // Sets the |property| to its default value. Useful for avoiding a cast when 247 // Sets the |property| to its default value. Useful for avoiding a cast when
234 // setting to NULL. 248 // setting to NULL.
235 template <typename T> 249 template <typename T>
236 void ClearProperty(const SurfaceProperty<T>* property); 250 void ClearProperty(const SurfaceProperty<T>* property);
237 251
252 bool HasPendingDamageForTesting(const gfx::Rect& damage) const {
253 return pending_damage_.contains(gfx::RectToSkIRect(damage));
254 }
255
238 private: 256 private:
239 struct State { 257 struct State {
240 State(); 258 State();
241 ~State(); 259 ~State();
242 260
243 bool operator==(const State& other); 261 bool operator==(const State& other);
244 bool operator!=(const State& other) { return !(*this == other); } 262 bool operator!=(const State& other) { return !(*this == other); }
245 263
246 SkRegion opaque_region; 264 SkRegion opaque_region;
247 SkRegion input_region; 265 SkRegion input_region;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // Updates current_resource_ with a new resource id corresponding to the 306 // Updates current_resource_ with a new resource id corresponding to the
289 // contents of the attached buffer (or id 0, if no buffer is attached). 307 // contents of the attached buffer (or id 0, if no buffer is attached).
290 // UpdateSurface must be called afterwards to ensure the release callback 308 // UpdateSurface must be called afterwards to ensure the release callback
291 // will be called. 309 // will be called.
292 void UpdateResource(bool client_usage); 310 void UpdateResource(bool client_usage);
293 311
294 // Updates the current Surface with a new frame referring to the resource in 312 // Updates the current Surface with a new frame referring to the resource in
295 // current_resource_. 313 // current_resource_.
296 void UpdateSurface(bool full_damage); 314 void UpdateSurface(bool full_damage);
297 315
316 // Adds/Removes begin frame observer based on state.
317 void UpdateNeedsBeginFrame();
318
298 int64_t SetPropertyInternal(const void* key, 319 int64_t SetPropertyInternal(const void* key,
299 const char* name, 320 const char* name,
300 PropertyDeallocator deallocator, 321 PropertyDeallocator deallocator,
301 int64_t value, 322 int64_t value,
302 int64_t default_value); 323 int64_t default_value);
303 int64_t GetPropertyInternal(const void* key, int64_t default_value) const; 324 int64_t GetPropertyInternal(const void* key, int64_t default_value) const;
304 325
305 // This returns true when the surface has some contents assigned to it. 326 // This returns true when the surface has some contents assigned to it.
306 bool has_contents() const { return !!current_buffer_.buffer(); } 327 bool has_contents() const { return !!current_buffer_.buffer(); }
307 328
(...skipping 29 matching lines...) Expand all
337 358
338 // The next resource id the buffer will be attached to. 359 // The next resource id the buffer will be attached to.
339 int next_resource_id_ = 1; 360 int next_resource_id_ = 1;
340 361
341 // The damage region to schedule paint for when Commit() is called. 362 // The damage region to schedule paint for when Commit() is called.
342 SkRegion pending_damage_; 363 SkRegion pending_damage_;
343 364
344 // These lists contains the callbacks to notify the client when it is a good 365 // These lists contains the callbacks to notify the client when it is a good
345 // time to start producing a new frame. These callbacks move to 366 // time to start producing a new frame. These callbacks move to
346 // |frame_callbacks_| when Commit() is called. Later they are moved to 367 // |frame_callbacks_| when Commit() is called. Later they are moved to
347 // |active_frame_callbacks_| when the effect of the Commit() is reflected in 368 // |active_frame_callbacks_| when the effect of the Commit() is scheduled to
348 // the compositor's active layer tree. The callbacks fire once we're notified 369 // be drawn. They fire at the first begin frame notification after this.
349 // that the compositor started drawing that active layer tree.
350 std::list<FrameCallback> pending_frame_callbacks_; 370 std::list<FrameCallback> pending_frame_callbacks_;
351 std::list<FrameCallback> frame_callbacks_; 371 std::list<FrameCallback> frame_callbacks_;
352 std::list<FrameCallback> active_frame_callbacks_; 372 std::list<FrameCallback> active_frame_callbacks_;
353 373
354 // This is the state that has yet to be committed. 374 // This is the state that has yet to be committed.
355 State pending_state_; 375 State pending_state_;
356 376
357 // This is the state that has been committed. 377 // This is the state that has been committed.
358 State state_; 378 State state_;
359 379
(...skipping 19 matching lines...) Expand all
379 base::TimeTicks last_compositing_start_time_; 399 base::TimeTicks last_compositing_start_time_;
380 400
381 // Cursor providers. Surface does not own the cursor providers. 401 // Cursor providers. Surface does not own the cursor providers.
382 std::set<CursorProvider*> cursor_providers_; 402 std::set<CursorProvider*> cursor_providers_;
383 403
384 // This can be set to have some functions delegated. E.g. ShellSurface class 404 // This can be set to have some functions delegated. E.g. ShellSurface class
385 // can set this to handle Commit() and apply any double buffered state it 405 // can set this to handle Commit() and apply any double buffered state it
386 // maintains. 406 // maintains.
387 SurfaceDelegate* delegate_ = nullptr; 407 SurfaceDelegate* delegate_ = nullptr;
388 408
409 // The begin frame source being observed.
410 cc::BeginFrameSource* begin_frame_source_ = nullptr;
411 cc::BeginFrameArgs last_begin_frame_args_;
412 bool needs_begin_frame_ = false;
413
389 struct Value { 414 struct Value {
390 const char* name; 415 const char* name;
391 int64_t value; 416 int64_t value;
392 PropertyDeallocator deallocator; 417 PropertyDeallocator deallocator;
393 }; 418 };
394 419
395 std::map<const void*, Value> prop_map_; 420 std::map<const void*, Value> prop_map_;
396 421
397 // Surface observer list. Surface does not own the observers. 422 // Surface observer list. Surface does not own the observers.
398 base::ObserverList<SurfaceObserver, true> observers_; 423 base::ObserverList<SurfaceObserver, true> observers_;
399 424
400 DISALLOW_COPY_AND_ASSIGN(Surface); 425 DISALLOW_COPY_AND_ASSIGN(Surface);
401 }; 426 };
402 427
403 } // namespace exo 428 } // namespace exo
404 429
405 #endif // COMPONENTS_EXO_SURFACE_H_ 430 #endif // COMPONENTS_EXO_SURFACE_H_
OLDNEW
« no previous file with comments | « no previous file | components/exo/surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698