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