Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 CC_SURFACES_SURFACE_DEPENDENCY_TRACKER_H_ | |
| 6 #define CC_SURFACES_SURFACE_DEPENDENCY_TRACKER_H_ | |
| 7 | |
| 8 #include "cc/scheduler/begin_frame_source.h" | |
|
kylechar
2017/02/09 15:50:32
#include "base/macros.h"
| |
| 9 #include "cc/surfaces/pending_frame_observer.h" | |
| 10 #include "cc/surfaces/surface.h" | |
| 11 #include "cc/surfaces/surface_observer.h" | |
| 12 #include "cc/surfaces/surfaces_export.h" | |
| 13 | |
| 14 namespace cc { | |
| 15 | |
| 16 class SurfaceManager; | |
| 17 | |
| 18 // SurfaceDependencyTracker tracks unresolved dependencies blocking | |
| 19 // CompositorFrames from activating. This class maintains a map from | |
| 20 // a dependent surface ID to a set of Surfaces that have CompositorFrames | |
| 21 // blocked on that surface ID. SurfaceDependencyTracker observes when | |
| 22 // dependent frames activate, and informs blocked surfaces. | |
| 23 // | |
| 24 // When a blocking CompositorFrame is first submitted, SurfaceDependencyTracker | |
| 25 // will begin listening for BeginFrames, setting a deadline some number of | |
| 26 // BeginFrames in the future. If there are unresolved dependencies when the | |
| 27 // deadline hits, then SurfaceDependencyTracker will clear then and activate | |
| 28 // all pending CompositorFrames. Once there are no more remaining pending | |
| 29 // frames, then SurfaceDependencyTracker will stop observing BeginFrames. | |
| 30 // TODO(fsamuel): Deadlines should not be global. They should be scoped to a | |
| 31 // surface subtree. However, that will not be possible until SurfaceReference | |
| 32 // work is complete. | |
| 33 class CC_SURFACES_EXPORT SurfaceDependencyTracker : public BeginFrameObserver, | |
| 34 public PendingFrameObserver, | |
| 35 public SurfaceObserver { | |
| 36 public: | |
| 37 SurfaceDependencyTracker(SurfaceManager* surface_manager, | |
| 38 BeginFrameSource* begin_frame_source); | |
| 39 ~SurfaceDependencyTracker() override; | |
| 40 | |
| 41 // Called when |surface| has a pending CompositorFrame and it wishes to be | |
| 42 // informed when that surface's dependencies are resolved. | |
| 43 void RequestSurfaceResolution(Surface* surface); | |
| 44 | |
| 45 bool has_deadline() const { return frames_since_deadline_set_.has_value(); } | |
| 46 | |
| 47 // BeginFrameObserver implementation. | |
| 48 void OnBeginFrame(const BeginFrameArgs& args) override; | |
| 49 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; | |
| 50 void OnBeginFrameSourcePausedChanged(bool paused) override; | |
| 51 | |
| 52 // PendingFrameObserver implementation: | |
| 53 void OnSurfaceActivated(Surface* pending_frame) override; | |
| 54 void OnSurfaceDependenciesChanged( | |
| 55 Surface* pending_frame, | |
| 56 const SurfaceDependencies& added_dependencies, | |
| 57 const SurfaceDependencies& removed_dependencies) override; | |
| 58 void OnSurfaceDiscarded(Surface* pending_frame) override; | |
| 59 | |
| 60 // SurfaceObserver implementation: | |
| 61 void OnSurfaceCreated(const SurfaceInfo& surface_info) override; | |
| 62 void OnSurfaceDamaged(const SurfaceId& surface_id, bool* changed) override; | |
| 63 | |
| 64 private: | |
| 65 // Informs all Surfaces with pending frames blocked on the provided | |
| 66 // |surface_id| that there is now an active frame available in Surface | |
| 67 // corresponding to |surface_id|. | |
| 68 void NotifySurfaceIdAvailable(const SurfaceId& surface_id); | |
| 69 | |
| 70 SurfaceManager* const surface_manager_; | |
| 71 | |
| 72 // The last begin frame args generated by the begin frame source. | |
| 73 BeginFrameArgs last_begin_frame_args_; | |
| 74 | |
| 75 // The BeginFrameSource used to set deadlines. | |
| 76 BeginFrameSource* const begin_frame_source_; | |
| 77 | |
| 78 // The number of BeginFrames observed since a deadline was set. If | |
| 79 // base::nullopt_t then a deadline is not set. | |
| 80 base::Optional<uint32_t> frames_since_deadline_set_; | |
| 81 | |
| 82 // A map from a SurfaceId to the set of Surfaces blocked on that SurfaceId. | |
| 83 std::unordered_map<SurfaceId, PendingSurfaceSet, SurfaceIdHash> | |
| 84 blocked_surfaces_; | |
| 85 | |
| 86 PendingSurfaceSet pending_surfaces_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(SurfaceDependencyTracker); | |
| 89 }; | |
| 90 | |
| 91 } // namespace cc | |
| 92 | |
| 93 #endif // CC_SURFACES_SURFACE_DEPENDENCY_TRACKER_H_ | |
| OLD | NEW |