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

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

Issue 2562263002: [ABANDONED] Revert of Change exo::SurfaceFactoryOwner to exo::ExoCompositorFrameSink (Closed)
Patch Set: Created 4 years 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 | « components/exo/compositor_frame_sink_holder.cc ('k') | 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/scheduler/begin_frame_source.h"
20 #include "cc/surfaces/surface_id_allocator.h" 20 #include "cc/surfaces/surface_factory_client.h"
21 #include "components/exo/compositor_frame_sink.h"
22 #include "components/exo/compositor_frame_sink_holder.h"
23 #include "third_party/skia/include/core/SkBlendMode.h" 21 #include "third_party/skia/include/core/SkBlendMode.h"
24 #include "third_party/skia/include/core/SkRegion.h" 22 #include "third_party/skia/include/core/SkRegion.h"
25 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
26 #include "ui/aura/window_observer.h" 24 #include "ui/aura/window_observer.h"
27 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
28 26
29 namespace base { 27 namespace base {
30 namespace trace_event { 28 namespace trace_event {
31 class TracedValue; 29 class TracedValue;
32 } 30 }
33 } 31 }
34 32
35 namespace cc { 33 namespace cc {
34 class SurfaceFactory;
36 class SurfaceIdAllocator; 35 class SurfaceIdAllocator;
37 } 36 }
38 37
39 namespace gfx { 38 namespace gfx {
40 class Path; 39 class Path;
41 } 40 }
42 41
43 namespace exo { 42 namespace exo {
44 class Buffer; 43 class Buffer;
45 class Pointer; 44 class Pointer;
46 class SurfaceDelegate; 45 class SurfaceDelegate;
47 class SurfaceObserver; 46 class SurfaceObserver;
48 class Surface; 47 class Surface;
49 48
50 template <typename T> 49 template <typename T>
51 struct SurfaceProperty; 50 struct SurfaceProperty;
52 51
53 namespace subtle { 52 namespace subtle {
54 class PropertyHelper; 53 class PropertyHelper;
55 } 54 }
56 55
57 // The pointer class is currently the only cursor provider class but this can 56 // The pointer class is currently the only cursor provider class but this can
58 // change in the future when better hardware cursor support is added. 57 // change in the future when better hardware cursor support is added.
59 using CursorProvider = Pointer; 58 using CursorProvider = Pointer;
60 59
60 // This class owns the SurfaceFactory and keeps track of references to the
61 // contents of Buffers. It's keeped alive by references from
62 // release_callbacks_. It's destroyed when its owning Surface is destroyed and
63 // the last outstanding release callback is called.
64 class SurfaceFactoryOwner : public base::RefCounted<SurfaceFactoryOwner>,
65 public cc::SurfaceFactoryClient {
66 public:
67 SurfaceFactoryOwner();
68
69 // Overridden from cc::SurfaceFactoryClient:
70 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
71 void WillDrawSurface(const cc::LocalFrameId& id,
72 const gfx::Rect& damage_rect) override;
73 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override;
74
75 private:
76 friend class base::RefCounted<SurfaceFactoryOwner>;
77 friend class Surface;
78
79 ~SurfaceFactoryOwner() override;
80
81 std::map<int,
82 std::pair<scoped_refptr<SurfaceFactoryOwner>,
83 std::unique_ptr<cc::SingleReleaseCallback>>>
84 release_callbacks_;
85 cc::FrameSinkId frame_sink_id_;
86 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_;
87 std::unique_ptr<cc::SurfaceFactory> surface_factory_;
88 Surface* surface_ = nullptr;
89 };
90
61 // This class represents a rectangular area that is displayed on the screen. 91 // This class represents a rectangular area that is displayed on the screen.
62 // It has a location, size and pixel contents. 92 // It has a location, size and pixel contents.
63 class Surface : public ui::ContextFactoryObserver, public aura::WindowObserver { 93 class Surface : public ui::ContextFactoryObserver,
94 public aura::WindowObserver,
95 public cc::BeginFrameObserver {
64 public: 96 public:
65 using PropertyDeallocator = void (*)(int64_t value); 97 using PropertyDeallocator = void (*)(int64_t value);
66 98
67 Surface(); 99 Surface();
68 ~Surface() override; 100 ~Surface() override;
69 101
70 // Type-checking downcast routine. 102 // Type-checking downcast routine.
71 static Surface* AsSurface(const aura::Window* window); 103 static Surface* AsSurface(const aura::Window* window);
72 104
73 aura::Window* window() { return window_.get(); } 105 aura::Window* window() { return window_.get(); }
74 106
107 const cc::LocalFrameId& local_frame_id() const { return local_frame_id_; }
75 cc::SurfaceId GetSurfaceId() const; 108 cc::SurfaceId GetSurfaceId() const;
76 109
77 CompositorFrameSinkHolder* compositor_frame_sink_holder() {
78 return compositor_frame_sink_holder_.get();
79 }
80
81 // Set a buffer as the content of this surface. A buffer can only be attached 110 // Set a buffer as the content of this surface. A buffer can only be attached
82 // to one surface at a time. 111 // to one surface at a time.
83 void Attach(Buffer* buffer); 112 void Attach(Buffer* buffer);
84 113
85 // Describe the regions where the pending buffer is different from the 114 // Describe the regions where the pending buffer is different from the
86 // current surface contents, and where the surface therefore needs to be 115 // current surface contents, and where the surface therefore needs to be
87 // repainted. 116 // repainted.
88 void Damage(const gfx::Rect& rect); 117 void Damage(const gfx::Rect& rect);
89 118
90 // Request notification when the next frame is displayed. Useful for 119 // Request notification when the next frame is displayed. Useful for
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 gfx::Size content_size() const { return content_size_; } 222 gfx::Size content_size() const { return content_size_; }
194 223
195 // Overridden from ui::ContextFactoryObserver: 224 // Overridden from ui::ContextFactoryObserver:
196 void OnLostResources() override; 225 void OnLostResources() override;
197 226
198 // Overridden from aura::WindowObserver: 227 // Overridden from aura::WindowObserver:
199 void OnWindowAddedToRootWindow(aura::Window* window) override; 228 void OnWindowAddedToRootWindow(aura::Window* window) override;
200 void OnWindowRemovingFromRootWindow(aura::Window* window, 229 void OnWindowRemovingFromRootWindow(aura::Window* window,
201 aura::Window* new_root) override; 230 aura::Window* new_root) override;
202 231
232 // Overridden from cc::BeginFrameObserver:
233 void OnBeginFrame(const cc::BeginFrameArgs& args) override;
234 const cc::BeginFrameArgs& LastUsedBeginFrameArgs() const override;
235 void OnBeginFrameSourcePausedChanged(bool paused) override {}
236
203 // Sets the |value| of the given surface |property|. Setting to the default 237 // Sets the |value| of the given surface |property|. Setting to the default
204 // value (e.g., NULL) removes the property. The caller is responsible for the 238 // value (e.g., NULL) removes the property. The caller is responsible for the
205 // lifetime of any object set as a property on the Surface. 239 // lifetime of any object set as a property on the Surface.
206 template <typename T> 240 template <typename T>
207 void SetProperty(const SurfaceProperty<T>* property, T value); 241 void SetProperty(const SurfaceProperty<T>* property, T value);
208 242
209 // Returns the value of the given surface |property|. Returns the 243 // Returns the value of the given surface |property|. Returns the
210 // property-specific default value if the property was not previously set. 244 // property-specific default value if the property was not previously set.
211 template <typename T> 245 template <typename T>
212 T GetProperty(const SurfaceProperty<T>* property) const; 246 T GetProperty(const SurfaceProperty<T>* property) const;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // Updates current_resource_ with a new resource id corresponding to the 307 // Updates current_resource_ with a new resource id corresponding to the
274 // contents of the attached buffer (or id 0, if no buffer is attached). 308 // contents of the attached buffer (or id 0, if no buffer is attached).
275 // UpdateSurface must be called afterwards to ensure the release callback 309 // UpdateSurface must be called afterwards to ensure the release callback
276 // will be called. 310 // will be called.
277 void UpdateResource(bool client_usage); 311 void UpdateResource(bool client_usage);
278 312
279 // Updates the current Surface with a new frame referring to the resource in 313 // Updates the current Surface with a new frame referring to the resource in
280 // current_resource_. 314 // current_resource_.
281 void UpdateSurface(bool full_damage); 315 void UpdateSurface(bool full_damage);
282 316
317 // Adds/Removes begin frame observer based on state.
318 void UpdateNeedsBeginFrame();
319
283 int64_t SetPropertyInternal(const void* key, 320 int64_t SetPropertyInternal(const void* key,
284 const char* name, 321 const char* name,
285 PropertyDeallocator deallocator, 322 PropertyDeallocator deallocator,
286 int64_t value, 323 int64_t value,
287 int64_t default_value); 324 int64_t default_value);
288 int64_t GetPropertyInternal(const void* key, int64_t default_value) const; 325 int64_t GetPropertyInternal(const void* key, int64_t default_value) const;
289 326
290 // This returns true when the surface has some contents assigned to it. 327 // This returns true when the surface has some contents assigned to it.
291 bool has_contents() const { return !!current_buffer_.buffer(); } 328 bool has_contents() const { return !!current_buffer_.buffer(); }
292 329
(...skipping 13 matching lines...) Expand all
306 // This is the size of the last committed contents. 343 // This is the size of the last committed contents.
307 gfx::Size content_size_; 344 gfx::Size content_size_;
308 345
309 // This is true when Attach() has been called and new contents should take 346 // This is true when Attach() has been called and new contents should take
310 // effect next time Commit() is called. 347 // effect next time Commit() is called.
311 bool has_pending_contents_ = false; 348 bool has_pending_contents_ = false;
312 349
313 // The buffer that will become the content of surface when Commit() is called. 350 // The buffer that will become the content of surface when Commit() is called.
314 BufferAttachment pending_buffer_; 351 BufferAttachment pending_buffer_;
315 352
316 const cc::FrameSinkId frame_sink_id_; 353 cc::SurfaceManager* surface_manager_;
354
355 scoped_refptr<SurfaceFactoryOwner> factory_owner_;
356
357 // The Surface Id currently attached to the window.
317 cc::LocalFrameId local_frame_id_; 358 cc::LocalFrameId local_frame_id_;
318 359
319 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder_;
320
321 cc::SurfaceIdAllocator id_allocator_;
322
323 // The next resource id the buffer will be attached to. 360 // The next resource id the buffer will be attached to.
324 int next_resource_id_ = 1; 361 int next_resource_id_ = 1;
325 362
326 // The damage region to schedule paint for when Commit() is called. 363 // The damage region to schedule paint for when Commit() is called.
327 SkRegion pending_damage_; 364 SkRegion pending_damage_;
328 365
329 // These lists contains the callbacks to notify the client when it is a good 366 // These lists contains the callbacks to notify the client when it is a good
330 // time to start producing a new frame. These callbacks move to 367 // time to start producing a new frame. These callbacks move to
331 // |frame_callbacks_| when Commit() is called. Later they are moved to 368 // |frame_callbacks_| when Commit() is called. Later they are moved to
332 // |active_frame_callbacks_| when the effect of the Commit() is scheduled to 369 // |active_frame_callbacks_| when the effect of the Commit() is scheduled to
333 // be drawn. They fire at the first begin frame notification after this. 370 // be drawn. They fire at the first begin frame notification after this.
334 std::list<FrameCallback> pending_frame_callbacks_; 371 std::list<FrameCallback> pending_frame_callbacks_;
335 std::list<FrameCallback> frame_callbacks_; 372 std::list<FrameCallback> frame_callbacks_;
373 std::list<FrameCallback> active_frame_callbacks_;
336 374
337 // This is the state that has yet to be committed. 375 // This is the state that has yet to be committed.
338 State pending_state_; 376 State pending_state_;
339 377
340 // This is the state that has been committed. 378 // This is the state that has been committed.
341 State state_; 379 State state_;
342 380
343 // The stack of sub-surfaces to take effect when Commit() is called. 381 // The stack of sub-surfaces to take effect when Commit() is called.
344 // Bottom-most sub-surface at the front of the list and top-most sub-surface 382 // Bottom-most sub-surface at the front of the list and top-most sub-surface
345 // at the back. 383 // at the back.
(...skipping 16 matching lines...) Expand all
362 base::TimeTicks last_compositing_start_time_; 400 base::TimeTicks last_compositing_start_time_;
363 401
364 // Cursor providers. Surface does not own the cursor providers. 402 // Cursor providers. Surface does not own the cursor providers.
365 std::set<CursorProvider*> cursor_providers_; 403 std::set<CursorProvider*> cursor_providers_;
366 404
367 // This can be set to have some functions delegated. E.g. ShellSurface class 405 // This can be set to have some functions delegated. E.g. ShellSurface class
368 // can set this to handle Commit() and apply any double buffered state it 406 // can set this to handle Commit() and apply any double buffered state it
369 // maintains. 407 // maintains.
370 SurfaceDelegate* delegate_ = nullptr; 408 SurfaceDelegate* delegate_ = nullptr;
371 409
410 // The begin frame source being observed.
411 cc::BeginFrameSource* begin_frame_source_ = nullptr;
412 cc::BeginFrameArgs last_begin_frame_args_;
413 bool needs_begin_frame_ = false;
414
372 struct Value { 415 struct Value {
373 const char* name; 416 const char* name;
374 int64_t value; 417 int64_t value;
375 PropertyDeallocator deallocator; 418 PropertyDeallocator deallocator;
376 }; 419 };
377 420
378 std::map<const void*, Value> prop_map_; 421 std::map<const void*, Value> prop_map_;
379 422
380 // Surface observer list. Surface does not own the observers. 423 // Surface observer list. Surface does not own the observers.
381 base::ObserverList<SurfaceObserver, true> observers_; 424 base::ObserverList<SurfaceObserver, true> observers_;
382 425
383 DISALLOW_COPY_AND_ASSIGN(Surface); 426 DISALLOW_COPY_AND_ASSIGN(Surface);
384 }; 427 };
385 428
386 } // namespace exo 429 } // namespace exo
387 430
388 #endif // COMPONENTS_EXO_SURFACE_H_ 431 #endif // COMPONENTS_EXO_SURFACE_H_
OLDNEW
« no previous file with comments | « components/exo/compositor_frame_sink_holder.cc ('k') | components/exo/surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698