OLD | NEW |
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 <utility> |
9 | 10 |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" |
13 #include "cc/base/region.h" | 15 #include "cc/base/region.h" |
14 #include "third_party/skia/include/core/SkRegion.h" | 16 #include "third_party/skia/include/core/SkRegion.h" |
15 #include "ui/compositor/compositor_observer.h" | 17 #include "ui/compositor/compositor_observer.h" |
16 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
18 | 20 |
19 namespace base { | 21 namespace base { |
20 namespace trace_event { | 22 namespace trace_event { |
21 class TracedValue; | 23 class TracedValue; |
22 } | 24 } |
23 } | 25 } |
24 | 26 |
25 namespace exo { | 27 namespace exo { |
26 class Buffer; | 28 class Buffer; |
27 class SurfaceDelegate; | 29 class SurfaceDelegate; |
| 30 class SurfaceObserver; |
28 | 31 |
29 // This class represents a rectangular area that is displayed on the screen. | 32 // This class represents a rectangular area that is displayed on the screen. |
30 // It has a location, size and pixel contents. | 33 // It has a location, size and pixel contents. |
31 class Surface : public views::View, public ui::CompositorObserver { | 34 class Surface : public views::View, public ui::CompositorObserver { |
32 public: | 35 public: |
33 Surface(); | 36 Surface(); |
34 ~Surface() override; | 37 ~Surface() override; |
35 | 38 |
36 // Set a buffer as the content of this surface. A buffer can only be attached | 39 // Set a buffer as the content of this surface. A buffer can only be attached |
37 // to one surface at a time. | 40 // to one surface at a time. |
38 void Attach(Buffer* buffer); | 41 void Attach(Buffer* buffer); |
39 | 42 |
40 // Describe the regions where the pending buffer is different from the | 43 // Describe the regions where the pending buffer is different from the |
41 // current surface contents, and where the surface therefore needs to be | 44 // current surface contents, and where the surface therefore needs to be |
42 // repainted. | 45 // repainted. |
43 void Damage(const gfx::Rect& rect); | 46 void Damage(const gfx::Rect& rect); |
44 | 47 |
45 // Request notification when the next frame is displayed. Useful for | 48 // Request notification when the next frame is displayed. Useful for |
46 // throttling redrawing operations, and driving animations. | 49 // throttling redrawing operations, and driving animations. |
47 using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>; | 50 using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>; |
48 void RequestFrameCallback(const FrameCallback& callback); | 51 void RequestFrameCallback(const FrameCallback& callback); |
49 | 52 |
50 // This sets the region of the surface that contains opaque content. | 53 // This sets the region of the surface that contains opaque content. |
51 void SetOpaqueRegion(const SkRegion& region); | 54 void SetOpaqueRegion(const SkRegion& region); |
52 | 55 |
| 56 // Functions that control sub-surface state. All sub-surface state is |
| 57 // double-buffered and will be applied when Commit() is called. |
| 58 void AddSubSurface(Surface* sub_surface); |
| 59 void RemoveSubSurface(Surface* sub_surface); |
| 60 void SetSubSurfacePosition(Surface* sub_surface, const gfx::Point& position); |
| 61 void PlaceSubSurfaceAbove(Surface* sub_surface, Surface* reference); |
| 62 void PlaceSubSurfaceBelow(Surface* sub_surface, Surface* sibling); |
| 63 |
53 // Surface state (damage regions, attached buffers, etc.) is double-buffered. | 64 // Surface state (damage regions, attached buffers, etc.) is double-buffered. |
54 // A Commit() call atomically applies all pending state, replacing the | 65 // A Commit() call atomically applies all pending state, replacing the |
55 // current state. | 66 // current state. Commit() is not guaranteed to be synchronous. See |
| 67 // CommitSurfaceHierarchy() below. |
56 void Commit(); | 68 void Commit(); |
57 | 69 |
| 70 // This will synchronously commit all pending state of the surface and its |
| 71 // descendants by recursively calling CommitSurfaceHierarchy() for each |
| 72 // sub-surface with pending state. |
| 73 void CommitSurfaceHierarchy(); |
| 74 |
| 75 // Returns true if surface is in synchronized mode. |
| 76 bool IsSynchronized() const; |
| 77 |
58 // Set the surface delegate. | 78 // Set the surface delegate. |
59 void SetSurfaceDelegate(SurfaceDelegate* delegate); | 79 void SetSurfaceDelegate(SurfaceDelegate* delegate); |
60 | 80 |
| 81 // Returns true if surface has been assigned a surface delegate. |
| 82 bool HasSurfaceDelegate() const; |
| 83 |
| 84 // Surface does not own observers. It is the responsibility of the observer |
| 85 // to remove itself when it is done observing. |
| 86 void AddSurfaceObserver(SurfaceObserver* observer); |
| 87 void RemoveSurfaceObserver(SurfaceObserver* observer); |
| 88 bool HasSurfaceObserver(const SurfaceObserver* observer) const; |
| 89 |
61 // Returns a trace value representing the state of the surface. | 90 // Returns a trace value representing the state of the surface. |
62 scoped_refptr<base::trace_event::TracedValue> AsTracedValue() const; | 91 scoped_refptr<base::trace_event::TracedValue> AsTracedValue() const; |
63 | 92 |
64 bool HasPendingDamageForTesting() const { return !pending_damage_.IsEmpty(); } | 93 bool HasPendingDamageForTesting() const { return !pending_damage_.IsEmpty(); } |
65 | 94 |
66 // Overridden from views::View: | 95 // Overridden from views::View: |
67 gfx::Size GetPreferredSize() const override; | 96 gfx::Size GetPreferredSize() const override; |
68 | 97 |
69 // Overridden from ui::CompositorObserver: | 98 // Overridden from ui::CompositorObserver: |
70 void OnCompositingDidCommit(ui::Compositor* compositor) override; | 99 void OnCompositingDidCommit(ui::Compositor* compositor) override; |
71 void OnCompositingStarted(ui::Compositor* compositor, | 100 void OnCompositingStarted(ui::Compositor* compositor, |
72 base::TimeTicks start_time) override; | 101 base::TimeTicks start_time) override; |
73 void OnCompositingEnded(ui::Compositor* compositor) override {} | 102 void OnCompositingEnded(ui::Compositor* compositor) override {} |
74 void OnCompositingAborted(ui::Compositor* compositor) override {} | 103 void OnCompositingAborted(ui::Compositor* compositor) override {} |
75 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} | 104 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} |
76 void OnCompositingShuttingDown(ui::Compositor* compositor) override; | 105 void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
77 | 106 |
78 private: | 107 private: |
| 108 bool needs_commit_surface_hierarchy() const { |
| 109 return needs_commit_surface_hierarchy_; |
| 110 } |
| 111 |
| 112 bool has_contents() const { return has_contents_; } |
| 113 |
79 // The buffer that will become the content of surface when Commit() is called. | 114 // The buffer that will become the content of surface when Commit() is called. |
80 base::WeakPtr<Buffer> pending_buffer_; | 115 base::WeakPtr<Buffer> pending_buffer_; |
81 | 116 |
82 // The damage region to schedule paint for when Commit() is called. | 117 // The damage region to schedule paint for when Commit() is called. |
83 // TODO(reveman): Use cc::Region here after adding a version of | 118 // TODO(reveman): Use cc::Region here after adding a version of |
84 // ui::Layer::SchedulePaint that takes a cc::Region. | 119 // ui::Layer::SchedulePaint that takes a cc::Region. |
85 gfx::Rect pending_damage_; | 120 gfx::Rect pending_damage_; |
86 | 121 |
87 // These lists contains the callbacks to notify the client when it is a good | 122 // These lists contains the callbacks to notify the client when it is a good |
88 // time to start producing a new frame. These callbacks move to | 123 // time to start producing a new frame. These callbacks move to |
89 // |frame_callbacks_| when Commit() is called. Later they are moved to | 124 // |frame_callbacks_| when Commit() is called. Later they are moved to |
90 // |active_frame_callbacks_| when the effect of the Commit() is reflected in | 125 // |active_frame_callbacks_| when the effect of the Commit() is reflected in |
91 // the compositor's active layer tree. The callbacks fire once we're notified | 126 // the compositor's active layer tree. The callbacks fire once we're notified |
92 // that the compositor started drawing that active layer tree. | 127 // that the compositor started drawing that active layer tree. |
93 std::list<FrameCallback> pending_frame_callbacks_; | 128 std::list<FrameCallback> pending_frame_callbacks_; |
94 std::list<FrameCallback> frame_callbacks_; | 129 std::list<FrameCallback> frame_callbacks_; |
95 std::list<FrameCallback> active_frame_callbacks_; | 130 std::list<FrameCallback> active_frame_callbacks_; |
96 | 131 |
97 // The opaque region to take effect when Commit() is called. | 132 // The opaque region to take effect when Commit() is called. |
98 SkRegion pending_opaque_region_; | 133 SkRegion pending_opaque_region_; |
99 | 134 |
| 135 // The stack of sub-surfaces to take effect when Commit() is called. |
| 136 // Bottom-most sub-surface at the front of the list and top-most sub-surface |
| 137 // at the back. |
| 138 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>; |
| 139 using SubSurfaceEntryList = std::list<SubSurfaceEntry>; |
| 140 SubSurfaceEntryList pending_sub_surfaces_; |
| 141 |
| 142 // This is true if a call to Commit() as been made but |
| 143 // CommitSurfaceHierarchy() has not yet been called. |
| 144 bool needs_commit_surface_hierarchy_; |
| 145 |
| 146 // This is true when surface has some contents assigned to it. |
| 147 bool has_contents_; |
| 148 |
100 // The compsitor being observer or null if not observing a compositor. | 149 // The compsitor being observer or null if not observing a compositor. |
101 ui::Compositor* compositor_; | 150 ui::Compositor* compositor_; |
102 | 151 |
103 // This can be set to have some functions delegated. E.g. ShellSurface class | 152 // This can be set to have some functions delegated. E.g. ShellSurface class |
104 // can set this to handle Commit() and apply any double buffered state it | 153 // can set this to handle Commit() and apply any double buffered state it |
105 // maintains. | 154 // maintains. |
106 SurfaceDelegate* delegate_; | 155 SurfaceDelegate* delegate_; |
107 | 156 |
| 157 // Surface observer list. Surface does not own the observers. |
| 158 base::ObserverList<SurfaceObserver, true> observers_; |
| 159 |
108 DISALLOW_COPY_AND_ASSIGN(Surface); | 160 DISALLOW_COPY_AND_ASSIGN(Surface); |
109 }; | 161 }; |
110 | 162 |
111 } // namespace exo | 163 } // namespace exo |
112 | 164 |
113 #endif // COMPONENTS_EXO_SURFACE_H_ | 165 #endif // COMPONENTS_EXO_SURFACE_H_ |
OLD | NEW |