reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_EXO_SURFACE_H_ |
| 6 | #define COMPONENTS_EXO_SURFACE_H_ |
| 7 | |
| 8 | #include <list> |
dcheng | 31759da | 2016-04-21 01:26:31 | [diff] [blame] | 9 | #include <memory> |
reveman | 70baca1 | 2016-05-31 20:35:30 | [diff] [blame] | 10 | #include <set> |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 11 | #include <utility> |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 12 | |
| 13 | #include "base/callback.h" |
| 14 | #include "base/macros.h" |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 17 | #include "base/observer_list.h" |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame^] | 18 | #include "cc/output/begin_frame_args.h" |
jbauman | 2fdc073 | 2016-06-07 00:55:36 | [diff] [blame] | 19 | #include "cc/resources/transferable_resource.h" |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 20 | #include "cc/scheduler/begin_frame_source.h" |
xing.xu | 1a9aa94c | 2017-02-23 21:04:32 | [diff] [blame] | 21 | #include "cc/surfaces/local_surface_id_allocator.h" |
staraz | d8f4f64 | 2016-12-10 23:49:20 | [diff] [blame] | 22 | #include "components/exo/compositor_frame_sink.h" |
| 23 | #include "components/exo/compositor_frame_sink_holder.h" |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 24 | #include "third_party/skia/include/core/SkBlendMode.h" |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 25 | #include "third_party/skia/include/core/SkRegion.h" |
reveman | 4c94cf96 | 2015-12-03 06:49:43 | [diff] [blame] | 26 | #include "ui/aura/window.h" |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 27 | #include "ui/aura/window_observer.h" |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 28 | #include "ui/compositor/compositor_vsync_manager.h" |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 29 | #include "ui/gfx/geometry/rect.h" |
reveman | e295c66 | 2017-01-30 23:01:21 | [diff] [blame] | 30 | #include "ui/gfx/native_widget_types.h" |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 31 | |
| 32 | namespace base { |
| 33 | namespace trace_event { |
| 34 | class TracedValue; |
| 35 | } |
| 36 | } |
| 37 | |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 38 | namespace cc { |
xing.xu | 1a9aa94c | 2017-02-23 21:04:32 | [diff] [blame] | 39 | class LocalSurfaceIdAllocator; |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 40 | } |
| 41 | |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 42 | namespace gfx { |
| 43 | class Path; |
| 44 | } |
| 45 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 46 | namespace exo { |
| 47 | class Buffer; |
reveman | 70baca1 | 2016-05-31 20:35:30 | [diff] [blame] | 48 | class Pointer; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 49 | class SurfaceDelegate; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 50 | class SurfaceObserver; |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 51 | class Surface; |
| 52 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 53 | namespace subtle { |
| 54 | class PropertyHelper; |
| 55 | } |
| 56 | |
reveman | 70baca1 | 2016-05-31 20:35:30 | [diff] [blame] | 57 | // 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. |
| 59 | using CursorProvider = Pointer; |
| 60 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 61 | // This class represents a rectangular area that is displayed on the screen. |
| 62 | // It has a location, size and pixel contents. |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 63 | class Surface : public ui::ContextFactoryObserver, |
| 64 | public aura::WindowObserver, |
kylixrd | f81b1e4 | 2017-01-31 14:05:41 | [diff] [blame] | 65 | public ui::PropertyHandler, |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame^] | 66 | public ui::CompositorVSyncManager::Observer, |
| 67 | public cc::BeginFrameObserverBase { |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 68 | public: |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 69 | using PropertyDeallocator = void (*)(int64_t value); |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 70 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 71 | Surface(); |
| 72 | ~Surface() override; |
| 73 | |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 74 | // Type-checking downcast routine. |
kinaba | d14ca03e | 2016-02-23 04:43:35 | [diff] [blame] | 75 | static Surface* AsSurface(const aura::Window* window); |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 76 | |
jbauman | e352625 | 2016-06-09 18:43:05 | [diff] [blame] | 77 | aura::Window* window() { return window_.get(); } |
| 78 | |
fsamuel | 01f3620 | 2016-10-06 01:08:28 | [diff] [blame] | 79 | cc::SurfaceId GetSurfaceId() const; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 80 | |
staraz | d8f4f64 | 2016-12-10 23:49:20 | [diff] [blame] | 81 | CompositorFrameSinkHolder* compositor_frame_sink_holder() { |
| 82 | return compositor_frame_sink_holder_.get(); |
| 83 | } |
| 84 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 85 | // Set a buffer as the content of this surface. A buffer can only be attached |
| 86 | // to one surface at a time. |
| 87 | void Attach(Buffer* buffer); |
| 88 | |
| 89 | // Describe the regions where the pending buffer is different from the |
| 90 | // current surface contents, and where the surface therefore needs to be |
| 91 | // repainted. |
| 92 | void Damage(const gfx::Rect& rect); |
| 93 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 94 | // Request notification when it's a good time to produce a new frame. Useful |
| 95 | // for throttling redrawing operations, and driving animations. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 96 | using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>; |
| 97 | void RequestFrameCallback(const FrameCallback& callback); |
| 98 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 99 | // Request notification when the next frame is displayed. Useful for |
| 100 | // throttling redrawing operations, and driving animations. |
| 101 | using PresentationCallback = |
| 102 | base::Callback<void(base::TimeTicks presentation_time, |
| 103 | base::TimeDelta refresh)>; |
| 104 | void RequestPresentationCallback(const PresentationCallback& callback); |
| 105 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 106 | // This sets the region of the surface that contains opaque content. |
| 107 | void SetOpaqueRegion(const SkRegion& region); |
| 108 | |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 109 | // This sets the region of the surface that can receive pointer and touch |
| 110 | // events. |
| 111 | void SetInputRegion(const SkRegion& region); |
| 112 | |
reveman | 7efa4b0 | 2016-01-06 08:29:54 | [diff] [blame] | 113 | // This sets the scaling factor used to interpret the contents of the buffer |
| 114 | // attached to the surface. Note that if the scale is larger than 1, then you |
| 115 | // have to attach a buffer that is larger (by a factor of scale in each |
| 116 | // dimension) than the desired surface size. |
| 117 | void SetBufferScale(float scale); |
| 118 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 119 | // Functions that control sub-surface state. All sub-surface state is |
| 120 | // double-buffered and will be applied when Commit() is called. |
| 121 | void AddSubSurface(Surface* sub_surface); |
| 122 | void RemoveSubSurface(Surface* sub_surface); |
| 123 | void SetSubSurfacePosition(Surface* sub_surface, const gfx::Point& position); |
| 124 | void PlaceSubSurfaceAbove(Surface* sub_surface, Surface* reference); |
| 125 | void PlaceSubSurfaceBelow(Surface* sub_surface, Surface* sibling); |
| 126 | |
reveman | 642d8c33 | 2016-02-19 19:55:44 | [diff] [blame] | 127 | // This sets the surface viewport for scaling. |
| 128 | void SetViewport(const gfx::Size& viewport); |
| 129 | |
reveman | 8e32390 | 2016-05-23 21:55:36 | [diff] [blame] | 130 | // This sets the surface crop rectangle. |
| 131 | void SetCrop(const gfx::RectF& crop); |
| 132 | |
reveman | 85b7a56 | 2016-03-17 23:27:32 | [diff] [blame] | 133 | // This sets the only visible on secure output flag, preventing it from |
| 134 | // appearing in screenshots or from being viewed on non-secure displays. |
| 135 | void SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output); |
| 136 | |
reveman | fca687e | 2016-05-10 21:44:48 | [diff] [blame] | 137 | // This sets the blend mode that will be used when drawing the surface. |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 138 | void SetBlendMode(SkBlendMode blend_mode); |
reveman | fca687e | 2016-05-10 21:44:48 | [diff] [blame] | 139 | |
| 140 | // This sets the alpha value that will be applied to the whole surface. |
| 141 | void SetAlpha(float alpha); |
| 142 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 143 | // Surface state (damage regions, attached buffers, etc.) is double-buffered. |
| 144 | // A Commit() call atomically applies all pending state, replacing the |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 145 | // current state. Commit() is not guaranteed to be synchronous. See |
| 146 | // CommitSurfaceHierarchy() below. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 147 | void Commit(); |
| 148 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 149 | // This will synchronously commit all pending state of the surface and its |
| 150 | // descendants by recursively calling CommitSurfaceHierarchy() for each |
| 151 | // sub-surface with pending state. |
| 152 | void CommitSurfaceHierarchy(); |
| 153 | |
| 154 | // Returns true if surface is in synchronized mode. |
| 155 | bool IsSynchronized() const; |
| 156 | |
reveman | b947076 | 2016-04-10 03:49:24 | [diff] [blame] | 157 | // Returns the bounds of the current input region of surface. |
| 158 | gfx::Rect GetHitTestBounds() const; |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 159 | |
| 160 | // Returns true if |rect| intersects this surface's bounds. |
| 161 | bool HitTestRect(const gfx::Rect& rect) const; |
| 162 | |
| 163 | // Returns true if the current input region is different than the surface |
| 164 | // bounds. |
| 165 | bool HasHitTestMask() const; |
| 166 | |
| 167 | // Returns the current input region of surface in the form of a hit-test mask. |
| 168 | void GetHitTestMask(gfx::Path* mask) const; |
reveman | 4c94cf96 | 2015-12-03 06:49:43 | [diff] [blame] | 169 | |
reveman | 70baca1 | 2016-05-31 20:35:30 | [diff] [blame] | 170 | // Surface does not own cursor providers. It is the responsibility of the |
| 171 | // caller to remove the cursor provider before it is destroyed. |
| 172 | void RegisterCursorProvider(CursorProvider* provider); |
| 173 | void UnregisterCursorProvider(CursorProvider* provider); |
| 174 | |
reveman | e295c66 | 2017-01-30 23:01:21 | [diff] [blame] | 175 | // Returns the cursor for the surface. If no cursor provider is registered |
| 176 | // then kCursorNull is returned. |
| 177 | gfx::NativeCursor GetCursor(); |
reveman | 70baca1 | 2016-05-31 20:35:30 | [diff] [blame] | 178 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 179 | // Set the surface delegate. |
| 180 | void SetSurfaceDelegate(SurfaceDelegate* delegate); |
| 181 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 182 | // Returns true if surface has been assigned a surface delegate. |
| 183 | bool HasSurfaceDelegate() const; |
| 184 | |
| 185 | // Surface does not own observers. It is the responsibility of the observer |
| 186 | // to remove itself when it is done observing. |
| 187 | void AddSurfaceObserver(SurfaceObserver* observer); |
| 188 | void RemoveSurfaceObserver(SurfaceObserver* observer); |
| 189 | bool HasSurfaceObserver(const SurfaceObserver* observer) const; |
| 190 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 191 | // Returns a trace value representing the state of the surface. |
dcheng | 31759da | 2016-04-21 01:26:31 | [diff] [blame] | 192 | std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 193 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 194 | // Call this to indicate that surface is being scheduled for a draw. |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 195 | void WillDraw(); |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 196 | |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame^] | 197 | // Called when the begin frame source has changed. |
| 198 | void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source); |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 199 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 200 | // Check whether this Surface and its children need to create new cc::Surface |
| 201 | // IDs for their contents next time they get new buffer contents. |
| 202 | void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 203 | |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 204 | // Returns the active contents size. |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 205 | gfx::Size content_size() const { return content_size_; } |
| 206 | |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 207 | // Overridden from ui::ContextFactoryObserver: |
| 208 | void OnLostResources() override; |
| 209 | |
| 210 | // Overridden from aura::WindowObserver: |
| 211 | void OnWindowAddedToRootWindow(aura::Window* window) override; |
| 212 | void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 213 | aura::Window* new_root) override; |
| 214 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 215 | // Overridden from ui::CompositorVSyncManager::Observer: |
| 216 | void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 217 | base::TimeDelta interval) override; |
| 218 | |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 219 | bool HasPendingDamageForTesting(const gfx::Rect& damage) const { |
| 220 | return pending_damage_.contains(gfx::RectToSkIRect(damage)); |
| 221 | } |
| 222 | |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame^] | 223 | // Overridden from cc::BeginFrameObserverBase: |
| 224 | bool OnBeginFrameDerivedImpl(const cc::BeginFrameArgs& args) override; |
| 225 | void OnBeginFrameSourcePausedChanged(bool paused) override {} |
| 226 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 227 | private: |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 228 | struct State { |
| 229 | State(); |
| 230 | ~State(); |
| 231 | |
| 232 | bool operator==(const State& other); |
| 233 | bool operator!=(const State& other) { return !(*this == other); } |
| 234 | |
| 235 | SkRegion opaque_region; |
| 236 | SkRegion input_region; |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 237 | float buffer_scale = 1.0f; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 238 | gfx::Size viewport; |
| 239 | gfx::RectF crop; |
| 240 | bool only_visible_on_secure_output = false; |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 241 | SkBlendMode blend_mode = SkBlendMode::kSrcOver; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 242 | float alpha = 1.0f; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 243 | }; |
| 244 | class BufferAttachment { |
| 245 | public: |
| 246 | BufferAttachment(); |
| 247 | ~BufferAttachment(); |
| 248 | |
| 249 | BufferAttachment& operator=(BufferAttachment&& buffer); |
| 250 | |
| 251 | base::WeakPtr<Buffer>& buffer(); |
| 252 | const base::WeakPtr<Buffer>& buffer() const; |
| 253 | void Reset(base::WeakPtr<Buffer> buffer); |
| 254 | |
| 255 | private: |
| 256 | base::WeakPtr<Buffer> buffer_; |
| 257 | |
| 258 | DISALLOW_COPY_AND_ASSIGN(BufferAttachment); |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 259 | }; |
| 260 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 261 | friend class subtle::PropertyHelper; |
| 262 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 263 | bool needs_commit_surface_hierarchy() const { |
| 264 | return needs_commit_surface_hierarchy_; |
| 265 | } |
| 266 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 267 | // Returns true if this surface or any child surface needs a commit and has |
| 268 | // has_pending_layer_changes_ true. |
| 269 | bool HasLayerHierarchyChanged() const; |
| 270 | |
| 271 | // Sets that all children must create new cc::SurfaceIds for their contents. |
| 272 | void SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 273 | |
reveman | 56f34590 | 2016-06-06 03:58:28 | [diff] [blame] | 274 | // Set SurfaceLayer contents to the current buffer. |
| 275 | void SetSurfaceLayerContents(ui::Layer* layer); |
| 276 | |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 277 | // Updates current_resource_ with a new resource id corresponding to the |
| 278 | // contents of the attached buffer (or id 0, if no buffer is attached). |
| 279 | // UpdateSurface must be called afterwards to ensure the release callback |
| 280 | // will be called. |
| 281 | void UpdateResource(bool client_usage); |
| 282 | |
| 283 | // Updates the current Surface with a new frame referring to the resource in |
| 284 | // current_resource_. |
| 285 | void UpdateSurface(bool full_damage); |
| 286 | |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame^] | 287 | // Adds/Removes begin frame observer based on state. |
| 288 | void UpdateNeedsBeginFrame(); |
| 289 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 290 | // This returns true when the surface has some contents assigned to it. |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 291 | bool has_contents() const { return !!current_buffer_.buffer(); } |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 292 | |
jbauman | e352625 | 2016-06-09 18:43:05 | [diff] [blame] | 293 | // This window has the layer which contains the Surface contents. |
| 294 | std::unique_ptr<aura::Window> window_; |
| 295 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 296 | // This is true if it's possible that the layer properties (size, opacity, |
| 297 | // etc.) may have been modified since the last commit. Attaching a new |
| 298 | // buffer with the same size as the old shouldn't set this to true. |
| 299 | bool has_pending_layer_changes_ = true; |
| 300 | |
| 301 | // This is true if the next commit to this surface should put its contents |
| 302 | // into a new cc::SurfaceId. This allows for synchronization between Surface |
| 303 | // and layer changes. |
| 304 | bool needs_commit_to_new_surface_ = true; |
| 305 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 306 | // This is the size of the last committed contents. |
| 307 | gfx::Size content_size_; |
| 308 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 309 | // This is true when Attach() has been called and new contents should take |
| 310 | // effect next time Commit() is called. |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 311 | bool has_pending_contents_ = false; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 312 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 313 | // The buffer that will become the content of surface when Commit() is called. |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 314 | BufferAttachment pending_buffer_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 315 | |
staraz | d8f4f64 | 2016-12-10 23:49:20 | [diff] [blame] | 316 | const cc::FrameSinkId frame_sink_id_; |
samans | 5258bfb | 2017-01-27 21:16:26 | [diff] [blame] | 317 | cc::LocalSurfaceId local_surface_id_; |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 318 | |
staraz | d8f4f64 | 2016-12-10 23:49:20 | [diff] [blame] | 319 | scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder_; |
| 320 | |
xing.xu | 1a9aa94c | 2017-02-23 21:04:32 | [diff] [blame] | 321 | cc::LocalSurfaceIdAllocator id_allocator_; |
staraz | d8f4f64 | 2016-12-10 23:49:20 | [diff] [blame] | 322 | |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 323 | // The next resource id the buffer will be attached to. |
jbauman | 2fdc073 | 2016-06-07 00:55:36 | [diff] [blame] | 324 | int next_resource_id_ = 1; |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 325 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 326 | // The damage region to schedule paint for when Commit() is called. |
reveman | 5c353d5 | 2016-02-11 21:28:56 | [diff] [blame] | 327 | SkRegion pending_damage_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 328 | |
| 329 | // 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 |
| 331 | // |frame_callbacks_| when Commit() is called. Later they are moved to |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 332 | // |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. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 334 | std::list<FrameCallback> pending_frame_callbacks_; |
| 335 | std::list<FrameCallback> frame_callbacks_; |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 336 | std::list<FrameCallback> active_frame_callbacks_; |
| 337 | |
| 338 | // These lists contains the callbacks to notify the client when surface |
| 339 | // contents have been presented. These callbacks move to |
| 340 | // |presentation_callbacks_| when Commit() is called. Later they are moved to |
| 341 | // |swapping_presentation_callbacks_| when the effect of the Commit() is |
| 342 | // scheduled to be drawn and then moved to |swapped_presentation_callbacks_| |
| 343 | // after receiving VSync parameters update for the previous frame. They fire |
| 344 | // at the next VSync parameters update after that. |
| 345 | std::list<PresentationCallback> pending_presentation_callbacks_; |
| 346 | std::list<PresentationCallback> presentation_callbacks_; |
| 347 | std::list<PresentationCallback> swapping_presentation_callbacks_; |
| 348 | std::list<PresentationCallback> swapped_presentation_callbacks_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 349 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 350 | // This is the state that has yet to be committed. |
| 351 | State pending_state_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 352 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 353 | // This is the state that has been committed. |
| 354 | State state_; |
reveman | 7efa4b0 | 2016-01-06 08:29:54 | [diff] [blame] | 355 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 356 | // The stack of sub-surfaces to take effect when Commit() is called. |
| 357 | // Bottom-most sub-surface at the front of the list and top-most sub-surface |
| 358 | // at the back. |
| 359 | using SubSurfaceEntry = std::pair<Surface*, gfx::Point>; |
| 360 | using SubSurfaceEntryList = std::list<SubSurfaceEntry>; |
| 361 | SubSurfaceEntryList pending_sub_surfaces_; |
| 362 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 363 | // The buffer that is currently set as content of surface. |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 364 | BufferAttachment current_buffer_; |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 365 | |
jbauman | 2fdc073 | 2016-06-07 00:55:36 | [diff] [blame] | 366 | // The last resource that was sent to a surface. |
| 367 | cc::TransferableResource current_resource_; |
| 368 | |
reveman | ca132dc | 2017-01-31 22:35:54 | [diff] [blame] | 369 | // Whether the last resource that was sent to a surface has an alpha channel. |
| 370 | bool current_resource_has_alpha_ = false; |
| 371 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 372 | // This is true if a call to Commit() as been made but |
| 373 | // CommitSurfaceHierarchy() has not yet been called. |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 374 | bool needs_commit_surface_hierarchy_ = false; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 375 | |
reveman | 7cadea4 | 2016-02-05 20:14:38 | [diff] [blame] | 376 | // This is set when the compositing starts and passed to active frame |
| 377 | // callbacks when compositing successfully ends. |
| 378 | base::TimeTicks last_compositing_start_time_; |
| 379 | |
reveman | 70baca1 | 2016-05-31 20:35:30 | [diff] [blame] | 380 | // Cursor providers. Surface does not own the cursor providers. |
| 381 | std::set<CursorProvider*> cursor_providers_; |
| 382 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 383 | // This can be set to have some functions delegated. E.g. ShellSurface class |
| 384 | // can set this to handle Commit() and apply any double buffered state it |
| 385 | // maintains. |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 386 | SurfaceDelegate* delegate_ = nullptr; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 387 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 388 | // Surface observer list. Surface does not own the observers. |
| 389 | base::ObserverList<SurfaceObserver, true> observers_; |
| 390 | |
samans | 72b2a28 | 2016-12-17 02:44:15 | [diff] [blame] | 391 | // A reference factory that uses the compositor frame sink holder provided |
| 392 | // to this class to construct surface references. This object is passed to |
| 393 | // ui::Layer::SetShowSurface because the layer needs to know how to add |
| 394 | // references to surfaces. |
| 395 | scoped_refptr<cc::SurfaceReferenceFactory> surface_reference_factory_; |
| 396 | |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame^] | 397 | // The begin frame source being observed. |
| 398 | cc::BeginFrameSource* begin_frame_source_ = nullptr; |
| 399 | bool needs_begin_frame_ = false; |
| 400 | cc::BeginFrameAck current_begin_frame_ack_; |
| 401 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 402 | DISALLOW_COPY_AND_ASSIGN(Surface); |
| 403 | }; |
| 404 | |
| 405 | } // namespace exo |
| 406 | |
| 407 | #endif // COMPONENTS_EXO_SURFACE_H_ |