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