Chromium Code Reviews| 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/output/begin_frame_args.h" | |
| 18 #include "cc/resources/transferable_resource.h" | 19 #include "cc/resources/transferable_resource.h" |
| 19 #include "cc/scheduler/begin_frame_source.h" | 20 #include "cc/scheduler/begin_frame_source.h" |
| 20 #include "cc/surfaces/local_surface_id_allocator.h" | 21 #include "cc/surfaces/local_surface_id_allocator.h" |
| 21 #include "components/exo/compositor_frame_sink.h" | 22 #include "components/exo/compositor_frame_sink.h" |
| 22 #include "components/exo/compositor_frame_sink_holder.h" | 23 #include "components/exo/compositor_frame_sink_holder.h" |
| 23 #include "third_party/skia/include/core/SkBlendMode.h" | 24 #include "third_party/skia/include/core/SkBlendMode.h" |
| 24 #include "third_party/skia/include/core/SkRegion.h" | 25 #include "third_party/skia/include/core/SkRegion.h" |
| 25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
| 27 #include "ui/compositor/compositor_vsync_manager.h" | 28 #include "ui/compositor/compositor_vsync_manager.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 55 | 56 |
| 56 // The pointer class is currently the only cursor provider class but this can | 57 // 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. | 58 // change in the future when better hardware cursor support is added. |
| 58 using CursorProvider = Pointer; | 59 using CursorProvider = Pointer; |
| 59 | 60 |
| 60 // This class represents a rectangular area that is displayed on the screen. | 61 // This class represents a rectangular area that is displayed on the screen. |
| 61 // It has a location, size and pixel contents. | 62 // It has a location, size and pixel contents. |
| 62 class Surface : public ui::ContextFactoryObserver, | 63 class Surface : public ui::ContextFactoryObserver, |
| 63 public aura::WindowObserver, | 64 public aura::WindowObserver, |
| 64 public ui::PropertyHandler, | 65 public ui::PropertyHandler, |
| 65 public ui::CompositorVSyncManager::Observer { | 66 public ui::CompositorVSyncManager::Observer, |
| 67 public cc::BeginFrameObserverBase { | |
| 66 public: | 68 public: |
| 67 using PropertyDeallocator = void (*)(int64_t value); | 69 using PropertyDeallocator = void (*)(int64_t value); |
| 68 | 70 |
| 69 Surface(); | 71 Surface(); |
| 70 ~Surface() override; | 72 ~Surface() override; |
| 71 | 73 |
| 72 // Type-checking downcast routine. | 74 // Type-checking downcast routine. |
| 73 static Surface* AsSurface(const aura::Window* window); | 75 static Surface* AsSurface(const aura::Window* window); |
| 74 | 76 |
| 75 aura::Window* window() { return window_.get(); } | 77 aura::Window* window() { return window_.get(); } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 void AddSurfaceObserver(SurfaceObserver* observer); | 187 void AddSurfaceObserver(SurfaceObserver* observer); |
| 186 void RemoveSurfaceObserver(SurfaceObserver* observer); | 188 void RemoveSurfaceObserver(SurfaceObserver* observer); |
| 187 bool HasSurfaceObserver(const SurfaceObserver* observer) const; | 189 bool HasSurfaceObserver(const SurfaceObserver* observer) const; |
| 188 | 190 |
| 189 // Returns a trace value representing the state of the surface. | 191 // Returns a trace value representing the state of the surface. |
| 190 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; | 192 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; |
| 191 | 193 |
| 192 // Call this to indicate that surface is being scheduled for a draw. | 194 // Call this to indicate that surface is being scheduled for a draw. |
| 193 void WillDraw(); | 195 void WillDraw(); |
| 194 | 196 |
| 195 // Returns true when there's an active frame callback that requires a | 197 // Called when the begin frame source has changed. |
| 196 // BeginFrame() call. | 198 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source); |
| 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); | |
| 201 | 199 |
| 202 // Check whether this Surface and its children need to create new cc::Surface | 200 // Check whether this Surface and its children need to create new cc::Surface |
| 203 // IDs for their contents next time they get new buffer contents. | 201 // IDs for their contents next time they get new buffer contents. |
| 204 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 202 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 205 | 203 |
| 206 // Returns the active contents size. | 204 // Returns the active contents size. |
| 207 gfx::Size content_size() const { return content_size_; } | 205 gfx::Size content_size() const { return content_size_; } |
| 208 | 206 |
| 209 // Overridden from ui::ContextFactoryObserver: | 207 // Overridden from ui::ContextFactoryObserver: |
| 210 void OnLostResources() override; | 208 void OnLostResources() override; |
| 211 | 209 |
| 212 // Overridden from aura::WindowObserver: | 210 // Overridden from aura::WindowObserver: |
| 213 void OnWindowAddedToRootWindow(aura::Window* window) override; | 211 void OnWindowAddedToRootWindow(aura::Window* window) override; |
| 214 void OnWindowRemovingFromRootWindow(aura::Window* window, | 212 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 215 aura::Window* new_root) override; | 213 aura::Window* new_root) override; |
| 216 | 214 |
| 217 // Overridden from ui::CompositorVSyncManager::Observer: | 215 // Overridden from ui::CompositorVSyncManager::Observer: |
| 218 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 216 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 219 base::TimeDelta interval) override; | 217 base::TimeDelta interval) override; |
| 220 | 218 |
| 221 bool HasPendingDamageForTesting(const gfx::Rect& damage) const { | 219 bool HasPendingDamageForTesting(const gfx::Rect& damage) const { |
| 222 return pending_damage_.contains(gfx::RectToSkIRect(damage)); | 220 return pending_damage_.contains(gfx::RectToSkIRect(damage)); |
| 223 } | 221 } |
| 224 | 222 |
| 223 // Overridden from cc::BeginFrameObserverBase: | |
| 224 bool OnBeginFrameDerivedImpl(const cc::BeginFrameArgs& args) override; | |
| 225 void OnBeginFrameSourcePausedChanged(bool paused) override {} | |
| 226 | |
| 225 private: | 227 private: |
| 226 struct State { | 228 struct State { |
| 227 State(); | 229 State(); |
| 228 ~State(); | 230 ~State(); |
| 229 | 231 |
| 230 bool operator==(const State& other); | 232 bool operator==(const State& other); |
| 231 bool operator!=(const State& other) { return !(*this == other); } | 233 bool operator!=(const State& other) { return !(*this == other); } |
| 232 | 234 |
| 233 SkRegion opaque_region; | 235 SkRegion opaque_region; |
| 234 SkRegion input_region; | 236 SkRegion input_region; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 // Updates current_resource_ with a new resource id corresponding to the | 277 // Updates current_resource_ with a new resource id corresponding to the |
| 276 // contents of the attached buffer (or id 0, if no buffer is attached). | 278 // contents of the attached buffer (or id 0, if no buffer is attached). |
| 277 // UpdateSurface must be called afterwards to ensure the release callback | 279 // UpdateSurface must be called afterwards to ensure the release callback |
| 278 // will be called. | 280 // will be called. |
| 279 void UpdateResource(bool client_usage); | 281 void UpdateResource(bool client_usage); |
| 280 | 282 |
| 281 // Updates the current Surface with a new frame referring to the resource in | 283 // Updates the current Surface with a new frame referring to the resource in |
| 282 // current_resource_. | 284 // current_resource_. |
| 283 void UpdateSurface(bool full_damage); | 285 void UpdateSurface(bool full_damage); |
| 284 | 286 |
| 287 // Adds/Removes begin frame observer based on state. | |
| 288 void UpdateNeedsBeginFrame(); | |
| 289 | |
| 285 // This returns true when the surface has some contents assigned to it. | 290 // This returns true when the surface has some contents assigned to it. |
| 286 bool has_contents() const { return !!current_buffer_.buffer(); } | 291 bool has_contents() const { return !!current_buffer_.buffer(); } |
| 287 | 292 |
| 288 // This window has the layer which contains the Surface contents. | 293 // This window has the layer which contains the Surface contents. |
| 289 std::unique_ptr<aura::Window> window_; | 294 std::unique_ptr<aura::Window> window_; |
| 290 | 295 |
| 291 // This is true if it's possible that the layer properties (size, opacity, | 296 // This is true if it's possible that the layer properties (size, opacity, |
| 292 // etc.) may have been modified since the last commit. Attaching a new | 297 // etc.) may have been modified since the last commit. Attaching a new |
| 293 // buffer with the same size as the old shouldn't set this to true. | 298 // buffer with the same size as the old shouldn't set this to true. |
| 294 bool has_pending_layer_changes_ = true; | 299 bool has_pending_layer_changes_ = true; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 387 |
| 383 // Surface observer list. Surface does not own the observers. | 388 // Surface observer list. Surface does not own the observers. |
| 384 base::ObserverList<SurfaceObserver, true> observers_; | 389 base::ObserverList<SurfaceObserver, true> observers_; |
| 385 | 390 |
| 386 // A reference factory that uses the compositor frame sink holder provided | 391 // A reference factory that uses the compositor frame sink holder provided |
| 387 // to this class to construct surface references. This object is passed to | 392 // to this class to construct surface references. This object is passed to |
| 388 // ui::Layer::SetShowSurface because the layer needs to know how to add | 393 // ui::Layer::SetShowSurface because the layer needs to know how to add |
| 389 // references to surfaces. | 394 // references to surfaces. |
| 390 scoped_refptr<cc::SurfaceReferenceFactory> surface_reference_factory_; | 395 scoped_refptr<cc::SurfaceReferenceFactory> surface_reference_factory_; |
| 391 | 396 |
| 397 // The begin frame source being observed. | |
| 398 cc::BeginFrameSource* begin_frame_source_ = nullptr; | |
| 399 bool begin_frame_observer_added_ = false; | |
|
reveman
2017/03/13 12:13:35
nit: s/begin_frame_observer_added_/needs_begin_fra
Eric Seckler
2017/03/14 09:27:14
Done.
| |
| 400 cc::BeginFrameAck current_begin_frame_ack_; | |
| 401 | |
| 392 DISALLOW_COPY_AND_ASSIGN(Surface); | 402 DISALLOW_COPY_AND_ASSIGN(Surface); |
| 393 }; | 403 }; |
| 394 | 404 |
| 395 } // namespace exo | 405 } // namespace exo |
| 396 | 406 |
| 397 #endif // COMPONENTS_EXO_SURFACE_H_ | 407 #endif // COMPONENTS_EXO_SURFACE_H_ |
| OLD | NEW |