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