| 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_id_allocator.h" | 20 #include "cc/surfaces/surface_id_allocator.h" |
| 21 #include "components/exo/compositor_frame_sink.h" | 21 #include "components/exo/compositor_frame_sink.h" |
| 22 #include "components/exo/compositor_frame_sink_holder.h" | 22 #include "components/exo/compositor_frame_sink_holder.h" |
| 23 #include "third_party/skia/include/core/SkBlendMode.h" | 23 #include "third_party/skia/include/core/SkBlendMode.h" |
| 24 #include "third_party/skia/include/core/SkRegion.h" | 24 #include "third_party/skia/include/core/SkRegion.h" |
| 25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_observer.h" | 26 #include "ui/aura/window_observer.h" |
| 27 #include "ui/compositor/compositor_vsync_manager.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 namespace trace_event { | 31 namespace trace_event { |
| 31 class TracedValue; | 32 class TracedValue; |
| 32 } | 33 } |
| 33 } | 34 } |
| 34 | 35 |
| 35 namespace cc { | 36 namespace cc { |
| 36 class SurfaceIdAllocator; | 37 class SurfaceIdAllocator; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 53 namespace subtle { | 54 namespace subtle { |
| 54 class PropertyHelper; | 55 class PropertyHelper; |
| 55 } | 56 } |
| 56 | 57 |
| 57 // The pointer class is currently the only cursor provider class but this can | 58 // 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 // change in the future when better hardware cursor support is added. |
| 59 using CursorProvider = Pointer; | 60 using CursorProvider = Pointer; |
| 60 | 61 |
| 61 // This class represents a rectangular area that is displayed on the screen. | 62 // This class represents a rectangular area that is displayed on the screen. |
| 62 // It has a location, size and pixel contents. | 63 // It has a location, size and pixel contents. |
| 63 class Surface : public ui::ContextFactoryObserver, public aura::WindowObserver { | 64 class Surface : public ui::ContextFactoryObserver, |
| 65 public aura::WindowObserver, |
| 66 public ui::CompositorVSyncManager::Observer { |
| 64 public: | 67 public: |
| 65 using PropertyDeallocator = void (*)(int64_t value); | 68 using PropertyDeallocator = void (*)(int64_t value); |
| 66 | 69 |
| 67 Surface(); | 70 Surface(); |
| 68 ~Surface() override; | 71 ~Surface() override; |
| 69 | 72 |
| 70 // Type-checking downcast routine. | 73 // Type-checking downcast routine. |
| 71 static Surface* AsSurface(const aura::Window* window); | 74 static Surface* AsSurface(const aura::Window* window); |
| 72 | 75 |
| 73 aura::Window* window() { return window_.get(); } | 76 aura::Window* window() { return window_.get(); } |
| 74 | 77 |
| 75 cc::SurfaceId GetSurfaceId() const; | 78 cc::SurfaceId GetSurfaceId() const; |
| 76 | 79 |
| 77 CompositorFrameSinkHolder* compositor_frame_sink_holder() { | 80 CompositorFrameSinkHolder* compositor_frame_sink_holder() { |
| 78 return compositor_frame_sink_holder_.get(); | 81 return compositor_frame_sink_holder_.get(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 // Set a buffer as the content of this surface. A buffer can only be attached | 84 // Set a buffer as the content of this surface. A buffer can only be attached |
| 82 // to one surface at a time. | 85 // to one surface at a time. |
| 83 void Attach(Buffer* buffer); | 86 void Attach(Buffer* buffer); |
| 84 | 87 |
| 85 // Describe the regions where the pending buffer is different from the | 88 // Describe the regions where the pending buffer is different from the |
| 86 // current surface contents, and where the surface therefore needs to be | 89 // current surface contents, and where the surface therefore needs to be |
| 87 // repainted. | 90 // repainted. |
| 88 void Damage(const gfx::Rect& rect); | 91 void Damage(const gfx::Rect& rect); |
| 89 | 92 |
| 93 // Request notification when it's a good time to produce a new frame. Useful |
| 94 // for throttling redrawing operations, and driving animations. |
| 95 using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>; |
| 96 void RequestFrameCallback(const FrameCallback& callback); |
| 97 |
| 90 // Request notification when the next frame is displayed. Useful for | 98 // Request notification when the next frame is displayed. Useful for |
| 91 // throttling redrawing operations, and driving animations. | 99 // throttling redrawing operations, and driving animations. |
| 92 using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>; | 100 using PresentationCallback = |
| 93 void RequestFrameCallback(const FrameCallback& callback); | 101 base::Callback<void(base::TimeTicks presentation_time, |
| 102 base::TimeDelta refresh)>; |
| 103 void RequestPresentationCallback(const PresentationCallback& callback); |
| 94 | 104 |
| 95 // This sets the region of the surface that contains opaque content. | 105 // This sets the region of the surface that contains opaque content. |
| 96 void SetOpaqueRegion(const SkRegion& region); | 106 void SetOpaqueRegion(const SkRegion& region); |
| 97 | 107 |
| 98 // This sets the region of the surface that can receive pointer and touch | 108 // This sets the region of the surface that can receive pointer and touch |
| 99 // events. | 109 // events. |
| 100 void SetInputRegion(const SkRegion& region); | 110 void SetInputRegion(const SkRegion& region); |
| 101 | 111 |
| 102 // This sets the scaling factor used to interpret the contents of the buffer | 112 // This sets the scaling factor used to interpret the contents of the buffer |
| 103 // attached to the surface. Note that if the scale is larger than 1, then you | 113 // attached to the surface. Note that if the scale is larger than 1, then you |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 182 |
| 173 // Surface does not own observers. It is the responsibility of the observer | 183 // Surface does not own observers. It is the responsibility of the observer |
| 174 // to remove itself when it is done observing. | 184 // to remove itself when it is done observing. |
| 175 void AddSurfaceObserver(SurfaceObserver* observer); | 185 void AddSurfaceObserver(SurfaceObserver* observer); |
| 176 void RemoveSurfaceObserver(SurfaceObserver* observer); | 186 void RemoveSurfaceObserver(SurfaceObserver* observer); |
| 177 bool HasSurfaceObserver(const SurfaceObserver* observer) const; | 187 bool HasSurfaceObserver(const SurfaceObserver* observer) const; |
| 178 | 188 |
| 179 // Returns a trace value representing the state of the surface. | 189 // Returns a trace value representing the state of the surface. |
| 180 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; | 190 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; |
| 181 | 191 |
| 182 // Called when surface is being scheduled for a draw. | 192 // Call this to indicate that surface is being scheduled for a draw. |
| 183 void WillDraw(); | 193 void WillDraw(); |
| 184 | 194 |
| 185 // Called when the begin frame source has changed. | 195 // Returns true when there's an active frame callback that requires a |
| 186 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source); | 196 // BeginFrame() call. |
| 197 bool NeedsBeginFrame() const; |
| 198 |
| 199 // Call this to indicate that it's a good time to start producing a new frame. |
| 200 void BeginFrame(base::TimeTicks frame_time); |
| 187 | 201 |
| 188 // Check whether this Surface and its children need to create new cc::Surface | 202 // Check whether this Surface and its children need to create new cc::Surface |
| 189 // IDs for their contents next time they get new buffer contents. | 203 // IDs for their contents next time they get new buffer contents. |
| 190 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 204 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 191 | 205 |
| 192 // Returns the active contents size. | 206 // Returns the active contents size. |
| 193 gfx::Size content_size() const { return content_size_; } | 207 gfx::Size content_size() const { return content_size_; } |
| 194 | 208 |
| 195 // Overridden from ui::ContextFactoryObserver: | 209 // Overridden from ui::ContextFactoryObserver: |
| 196 void OnLostResources() override; | 210 void OnLostResources() override; |
| 197 | 211 |
| 198 // Overridden from aura::WindowObserver: | 212 // Overridden from aura::WindowObserver: |
| 199 void OnWindowAddedToRootWindow(aura::Window* window) override; | 213 void OnWindowAddedToRootWindow(aura::Window* window) override; |
| 200 void OnWindowRemovingFromRootWindow(aura::Window* window, | 214 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 201 aura::Window* new_root) override; | 215 aura::Window* new_root) override; |
| 202 | 216 |
| 217 // Overridden from ui::CompositorVSyncManager::Observer: |
| 218 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 219 base::TimeDelta interval) override; |
| 220 |
| 203 // Sets the |value| of the given surface |property|. Setting to the default | 221 // Sets the |value| of the given surface |property|. Setting to the default |
| 204 // value (e.g., NULL) removes the property. The caller is responsible for the | 222 // value (e.g., NULL) removes the property. The caller is responsible for the |
| 205 // lifetime of any object set as a property on the Surface. | 223 // lifetime of any object set as a property on the Surface. |
| 206 template <typename T> | 224 template <typename T> |
| 207 void SetProperty(const SurfaceProperty<T>* property, T value); | 225 void SetProperty(const SurfaceProperty<T>* property, T value); |
| 208 | 226 |
| 209 // Returns the value of the given surface |property|. Returns the | 227 // Returns the value of the given surface |property|. Returns the |
| 210 // property-specific default value if the property was not previously set. | 228 // property-specific default value if the property was not previously set. |
| 211 template <typename T> | 229 template <typename T> |
| 212 T GetProperty(const SurfaceProperty<T>* property) const; | 230 T GetProperty(const SurfaceProperty<T>* property) const; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 // The damage region to schedule paint for when Commit() is called. | 344 // The damage region to schedule paint for when Commit() is called. |
| 327 SkRegion pending_damage_; | 345 SkRegion pending_damage_; |
| 328 | 346 |
| 329 // These lists contains the callbacks to notify the client when it is a good | 347 // 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 | 348 // time to start producing a new frame. These callbacks move to |
| 331 // |frame_callbacks_| when Commit() is called. Later they are moved to | 349 // |frame_callbacks_| when Commit() is called. Later they are moved to |
| 332 // |active_frame_callbacks_| when the effect of the Commit() is scheduled to | 350 // |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. | 351 // be drawn. They fire at the first begin frame notification after this. |
| 334 std::list<FrameCallback> pending_frame_callbacks_; | 352 std::list<FrameCallback> pending_frame_callbacks_; |
| 335 std::list<FrameCallback> frame_callbacks_; | 353 std::list<FrameCallback> frame_callbacks_; |
| 354 std::list<FrameCallback> active_frame_callbacks_; |
| 355 |
| 356 // These lists contains the callbacks to notify the client when surface |
| 357 // contents have been presented. These callbacks move to |
| 358 // |presentation_callbacks_| when Commit() is called. Later they are moved to |
| 359 // |swapping_presentation_callbacks_| when the effect of the Commit() is |
| 360 // scheduled to be drawn and then moved to |swapped_presentation_callbacks_| |
| 361 // after receiving VSync parameters update for the previous frame. They fire |
| 362 // at the next VSync parameters update after that. |
| 363 std::list<PresentationCallback> pending_presentation_callbacks_; |
| 364 std::list<PresentationCallback> presentation_callbacks_; |
| 365 std::list<PresentationCallback> swapping_presentation_callbacks_; |
| 366 std::list<PresentationCallback> swapped_presentation_callbacks_; |
| 336 | 367 |
| 337 // This is the state that has yet to be committed. | 368 // This is the state that has yet to be committed. |
| 338 State pending_state_; | 369 State pending_state_; |
| 339 | 370 |
| 340 // This is the state that has been committed. | 371 // This is the state that has been committed. |
| 341 State state_; | 372 State state_; |
| 342 | 373 |
| 343 // The stack of sub-surfaces to take effect when Commit() is called. | 374 // The stack of sub-surfaces to take effect when Commit() is called. |
| 344 // Bottom-most sub-surface at the front of the list and top-most sub-surface | 375 // Bottom-most sub-surface at the front of the list and top-most sub-surface |
| 345 // at the back. | 376 // at the back. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 // ui::Layer::SetShowSurface because the layer needs to know how to add | 416 // ui::Layer::SetShowSurface because the layer needs to know how to add |
| 386 // references to surfaces. | 417 // references to surfaces. |
| 387 scoped_refptr<cc::SurfaceReferenceFactory> surface_reference_factory_; | 418 scoped_refptr<cc::SurfaceReferenceFactory> surface_reference_factory_; |
| 388 | 419 |
| 389 DISALLOW_COPY_AND_ASSIGN(Surface); | 420 DISALLOW_COPY_AND_ASSIGN(Surface); |
| 390 }; | 421 }; |
| 391 | 422 |
| 392 } // namespace exo | 423 } // namespace exo |
| 393 | 424 |
| 394 #endif // COMPONENTS_EXO_SURFACE_H_ | 425 #endif // COMPONENTS_EXO_SURFACE_H_ |
| OLD | NEW |