Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
vmpstr
2017/02/07 22:46:19
nit: 2017
Fady Samuel
2017/02/08 00:52:50
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/surfaces/surface_dependency_tracker.h" | |
| 6 | |
| 7 #include "cc/surfaces/surface.h" | |
| 8 #include "cc/surfaces/surface_info.h" | |
| 9 #include "cc/surfaces/surface_manager.h" | |
| 10 | |
| 11 namespace cc { | |
| 12 | |
| 13 namespace { | |
| 14 static constexpr uint32_t MAX_BEGIN_FRAME_COUNT = 4; | |
|
vmpstr
2017/02/07 22:46:19
nit: no need for static or no need for namespace {
Fady Samuel
2017/02/08 00:52:49
Done.
| |
| 15 } | |
| 16 | |
| 17 SurfaceDependencyTracker::SurfaceDependencyTracker( | |
| 18 SurfaceManager* surface_manager, | |
| 19 BeginFrameSource* begin_frame_source) | |
| 20 : surface_manager_(surface_manager), | |
| 21 begin_frame_source_(begin_frame_source) { | |
| 22 surface_manager_->AddObserver(this); | |
| 23 } | |
| 24 | |
| 25 SurfaceDependencyTracker::~SurfaceDependencyTracker() { | |
| 26 surface_manager_->RemoveObserver(this); | |
| 27 } | |
| 28 | |
| 29 void SurfaceDependencyTracker::RequestSurfaceResolution( | |
| 30 Surface* pending_surface) { | |
| 31 if (!pending_surface->HasPendingFrame()) | |
|
vmpstr
2017/02/07 22:46:20
From reading the header comment, it seems that the
Fady Samuel
2017/02/08 00:52:49
Yes, this should be a DCHECK. Also renamed instanc
| |
| 32 return; | |
| 33 const CompositorFrame& pending_frame = pending_surface->GetPendingFrame(); | |
| 34 bool needs_begin_frame = pending_frame.metadata.respect_deadline; | |
| 35 | |
| 36 // Referenced surface IDs that aren't currently known to the surface manager | |
|
vmpstr
2017/02/07 22:46:19
I guess I'm misunderstanding a bit, but is
"known
Fady Samuel
2017/02/08 00:52:50
Yes, I've added an extra bit to clarify. Thanks!
| |
| 37 // block this frame. | |
| 38 for (const SurfaceId& surface_id : | |
| 39 pending_frame.metadata.referenced_surfaces) { | |
| 40 Surface* surface = surface_manager_->GetSurfaceForId(surface_id); | |
| 41 if (!surface || !surface->HasActiveFrame()) | |
| 42 blocking_surfaces_[surface_id].insert(pending_surface); | |
| 43 } | |
| 44 | |
| 45 if (!pending_surfaces_.count(pending_surface)) { | |
| 46 pending_surface->AddObserver(this); | |
| 47 pending_surfaces_.insert(pending_surface); | |
| 48 } | |
| 49 | |
| 50 if (needs_begin_frame && !has_deadline_) { | |
| 51 begin_frame_source_->AddObserver(this); | |
| 52 has_deadline_ = true; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void SurfaceDependencyTracker::OnBeginFrame(const BeginFrameArgs& args) { | |
| 57 // TODO(fsamuel, kylechar): We have a single global deadline here. We should | |
| 58 // scope deadlines to surface subtrees. We cannot do that until | |
|
vmpstr
2017/02/07 22:46:19
Can you file a bug for this and reference it here,
Fady Samuel
2017/02/08 00:52:50
Done.
| |
| 59 // SurfaceReferences have been fully implemented. | |
| 60 last_begin_frame_args_ = args; | |
| 61 // Nothing to do if we haven't hit a deadline yet. | |
| 62 if (++begin_frame_count_ != MAX_BEGIN_FRAME_COUNT) | |
| 63 return; | |
| 64 | |
| 65 // Activate all surfaces that respect the deadline. | |
| 66 PendingSurfaceSet pending_surfaces(pending_surfaces_); | |
| 67 for (Surface* pending_surface : pending_surfaces) | |
| 68 pending_surface->ActivatePendingFrameForDeadline(); | |
| 69 | |
| 70 if (has_deadline_) { | |
|
vmpstr
2017/02/07 22:46:19
Instead of adding/removing |this| from the observe
Fady Samuel
2017/02/08 00:52:49
I agree, that's easier. Also, eww, this looks like
| |
| 71 begin_frame_source_->RemoveObserver(this); | |
| 72 has_deadline_ = false; | |
| 73 } | |
| 74 begin_frame_count_ = 0; | |
| 75 } | |
| 76 | |
| 77 const BeginFrameArgs& SurfaceDependencyTracker::LastUsedBeginFrameArgs() const { | |
| 78 return last_begin_frame_args_; | |
| 79 } | |
| 80 | |
| 81 void SurfaceDependencyTracker::OnBeginFrameSourcePausedChanged(bool paused) {} | |
| 82 | |
| 83 void SurfaceDependencyTracker::OnSurfaceDiscarded(Surface* pending_surface) { | |
| 84 if (!pending_surface->HasPendingFrame()) | |
|
vmpstr
2017/02/07 22:46:20
Comment please
Fady Samuel
2017/02/08 00:52:49
Done.
| |
| 85 return; | |
| 86 | |
| 87 const CompositorFrame& pending_frame = pending_surface->GetPendingFrame(); | |
| 88 | |
| 89 DCHECK(!pending_frame.metadata.referenced_surfaces.empty()); | |
| 90 | |
| 91 for (const SurfaceId& surface_id : | |
| 92 pending_frame.metadata.referenced_surfaces) { | |
| 93 auto it = blocking_surfaces_.find(surface_id); | |
| 94 if (it != blocking_surfaces_.end()) { | |
|
vmpstr
2017/02/07 22:46:19
if (it == blocking_surface_.end())
continue;
...
Fady Samuel
2017/02/08 00:52:49
Done.
| |
| 95 auto& pending_surface_set = it->second; | |
| 96 auto pending_surface_it = pending_surface_set.find(pending_surface); | |
| 97 if (pending_surface_it != pending_surface_set.end()) { | |
| 98 pending_surface_set.erase(pending_surface); | |
| 99 if (pending_surface_set.empty()) | |
| 100 blocking_surfaces_.erase(surface_id); | |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 if (has_deadline_ && blocking_surfaces_.empty()) { | |
| 106 begin_frame_source_->RemoveObserver(this); | |
| 107 has_deadline_ = false; | |
| 108 } | |
| 109 | |
| 110 pending_surfaces_.erase(pending_surface); | |
| 111 pending_surface->RemoveObserver(this); | |
| 112 | |
| 113 // TODO(fsamuel): We should consider removing this surface as a dependency on | |
|
vmpstr
2017/02/07 22:46:19
File a bug for this please and reference here (I k
Fady Samuel
2017/02/08 00:52:49
Done.
| |
| 114 // other surfaces. This dependency will be removed when the deadline hits | |
| 115 // anyway but maybe we should try to actiate these frames early. | |
| 116 } | |
| 117 | |
| 118 void SurfaceDependencyTracker::OnSurfaceActivated(Surface* pending_surface) { | |
| 119 pending_surface->RemoveObserver(this); | |
| 120 pending_surfaces_.erase(pending_surface); | |
| 121 ReportSurfaceIdAvailable(pending_surface->surface_id()); | |
| 122 } | |
| 123 | |
| 124 void SurfaceDependencyTracker::OnSurfaceChanged( | |
| 125 Surface* pending_surface, | |
| 126 const SurfaceDependencies& added_dependencies, | |
| 127 const SurfaceDependencies& removed_dependencies) { | |
| 128 // Update the |blocking_surfaces_| map with the changes in dependencies. | |
| 129 for (const SurfaceId& surface_id : added_dependencies) | |
| 130 blocking_surfaces_[surface_id].insert(pending_surface); | |
| 131 | |
| 132 for (const SurfaceId& surface_id : removed_dependencies) { | |
| 133 blocking_surfaces_[surface_id].erase(pending_surface); | |
|
vmpstr
2017/02/07 22:46:19
Do a find and use the iterator for both erase and
Fady Samuel
2017/02/08 00:52:49
Done.
| |
| 134 if (blocking_surfaces_[surface_id].empty()) | |
| 135 blocking_surfaces_.erase(surface_id); | |
| 136 } | |
| 137 | |
| 138 // If there are no more dependencies to resolve then we don't need to listen | |
| 139 // to BeginFrames. | |
| 140 if (blocking_surfaces_.empty() && has_deadline_) { | |
| 141 begin_frame_source_->RemoveObserver(this); | |
| 142 has_deadline_ = false; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 // SurfaceObserver implementation: | |
| 147 void SurfaceDependencyTracker::OnSurfaceCreated( | |
| 148 const SurfaceInfo& surface_info) { | |
| 149 // This is called when a Surface has an activated frame for the first time. | |
| 150 // SurfaceDependencyTracker only observes Surfaces that contain pending | |
| 151 // frames. SurfaceDependencyTracker becomes aware of CompositorFrames that | |
| 152 // activate immediately go through here. | |
| 153 ReportSurfaceIdAvailable(surface_info.id()); | |
| 154 } | |
| 155 | |
| 156 void SurfaceDependencyTracker::OnSurfaceDamaged(const SurfaceId& surface_id, | |
| 157 bool* changed) {} | |
| 158 | |
| 159 void SurfaceDependencyTracker::ReportSurfaceIdAvailable( | |
| 160 const SurfaceId& surface_id) { | |
| 161 auto it = blocking_surfaces_.find(surface_id); | |
| 162 if (it == blocking_surfaces_.end()) | |
| 163 return; | |
| 164 | |
| 165 // Unblock surfaces that depend on this pending surface. | |
| 166 PendingSurfaceSet blocked_pending_surface_set(it->second); | |
| 167 blocking_surfaces_.erase(it); | |
| 168 // If there are no more blockers in the system, then we no longer need to | |
| 169 // listen to BeginFrames. | |
| 170 if (has_deadline_ && blocking_surfaces_.empty()) { | |
| 171 begin_frame_source_->RemoveObserver(this); | |
| 172 has_deadline_ = false; | |
| 173 } | |
| 174 // Tell each surface about the availability of its blocker. | |
| 175 for (Surface* blocked_pending_surface : blocked_pending_surface_set) | |
| 176 blocked_pending_surface->ReportSurfaceIdAvailable(surface_id); | |
| 177 } | |
| 178 | |
| 179 } // namespace cc | |
| OLD | NEW |