Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Unified Diff: services/ui/surfaces/display_compositor.cc

Issue 2638833002: Moving temporary reference logic to SurfaceManager (Closed)
Patch Set: c Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/surfaces/display_compositor.h ('k') | services/ui/surfaces/display_compositor_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/surfaces/display_compositor.cc
diff --git a/services/ui/surfaces/display_compositor.cc b/services/ui/surfaces/display_compositor.cc
index 35c92cd31db5df72c58eea5c23a44c971aeff84a..8f30e7fb6ef8fc6536e73a7725325439497aa550 100644
--- a/services/ui/surfaces/display_compositor.cc
+++ b/services/ui/surfaces/display_compositor.cc
@@ -24,7 +24,7 @@
#include "services/ui/surfaces/display_output_surface_ozone.h"
#endif
- namespace ui {
+namespace ui {
DisplayCompositor::DisplayCompositor(
scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service,
@@ -48,8 +48,10 @@ DisplayCompositor::DisplayCompositor(
void DisplayCompositor::AddSurfaceReferences(
const std::vector<cc::SurfaceReference>& references) {
DCHECK(thread_checker_.CalledOnValidThread());
- for (auto& reference : references)
- AddSurfaceReference(reference);
+ for (const auto& reference : references) {
+ reference_manager_->AddSurfaceReference(reference.parent_id(),
+ reference.child_id());
+ }
}
void DisplayCompositor::RemoveSurfaceReferences(
@@ -58,20 +60,14 @@ void DisplayCompositor::RemoveSurfaceReferences(
// TODO(kylechar): Each remove reference can trigger GC, it would be better if
// we GC only once if removing multiple references.
- for (auto& reference : references)
- RemoveSurfaceReference(reference);
+ for (const auto& reference : references) {
+ reference_manager_->RemoveSurfaceReference(reference.parent_id(),
+ reference.child_id());
+ }
}
DisplayCompositor::~DisplayCompositor() {
DCHECK(thread_checker_.CalledOnValidThread());
- // Remove all temporary references on shutdown.
- for (auto& map_entry : temp_references_) {
- const cc::FrameSinkId& frame_sink_id = map_entry.first;
- for (auto& local_frame_id : map_entry.second) {
- reference_manager_->RemoveSurfaceReference(
- GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id));
- }
- }
manager_.RemoveObserver(this);
}
@@ -126,63 +122,6 @@ void DisplayCompositor::CreateOffscreenCompositorFrameSink(
std::move(client), nullptr);
}
-void DisplayCompositor::AddSurfaceReference(const cc::SurfaceReference& ref) {
- const cc::SurfaceId& parent_id = ref.parent_id();
- const cc::SurfaceId& child_id = ref.child_id();
-
- auto vector_iter = temp_references_.find(child_id.frame_sink_id());
-
- // If there are no temporary references for the FrameSinkId then we can just
- // add reference and return.
- if (vector_iter == temp_references_.end()) {
- reference_manager_->AddSurfaceReference(parent_id, child_id);
- return;
- }
-
- // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for
- // |child_id.local_frame_id| in that vector. If found, there is a temporary
- // reference to |child_id|.
- std::vector<cc::LocalFrameId>& refs = vector_iter->second;
- auto temp_ref_iter =
- std::find(refs.begin(), refs.end(), child_id.local_frame_id());
-
- if (temp_ref_iter == refs.end()) {
- reference_manager_->AddSurfaceReference(parent_id, child_id);
- return;
- }
-
- // All surfaces get a temporary reference to the top level root. If the parent
- // wants to add a reference to the top level root then we do nothing.
- // Otherwise remove the temporary reference and add the reference.
- if (parent_id != GetRootSurfaceId()) {
- reference_manager_->AddSurfaceReference(parent_id, child_id);
- reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(), child_id);
- }
-
- // Remove temporary references for surfaces with the same FrameSinkId that
- // were created before |child_id|. The earlier surfaces were never embedded in
- // the parent and the parent is embedding a later surface, so we know the
- // parent doesn't need them anymore.
- for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) {
- cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter);
- reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(), id);
- }
-
- // Remove markers for temporary references up to |child_id|, as the temporary
- // references they correspond to were removed above. If |temp_ref_iter| points
- // at the last element in |refs| then we are removing all temporary references
- // for the FrameSinkId and can remove the map entry entirely.
- if (++temp_ref_iter == refs.end())
- temp_references_.erase(child_id.frame_sink_id());
- else
- refs.erase(refs.begin(), temp_ref_iter);
-}
-
-void DisplayCompositor::RemoveSurfaceReference(
- const cc::SurfaceReference& ref) {
- reference_manager_->RemoveSurfaceReference(ref.parent_id(), ref.child_id());
-}
-
std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay(
const cc::FrameSinkId& frame_sink_id,
gpu::SurfaceHandle surface_handle,
@@ -254,16 +193,6 @@ const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const {
void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceInfo& surface_info) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_GT(surface_info.device_scale_factor(), 0.0f);
- // We can get into a situation where multiple CompositorFrames arrive for a
- // CompositorFrameSink before the DisplayCompositorClient can add any
- // references for the frame. When the second frame with a new size arrives,
- // the first will be destroyed and then if there are no references it will be
- // deleted during surface GC. A temporary reference, removed when a real
- // reference is received, is added to prevent this from happening.
- reference_manager_->AddSurfaceReference(GetRootSurfaceId(),
- surface_info.id());
- temp_references_[surface_info.id().frame_sink_id()].push_back(
- surface_info.id().local_frame_id());
if (client_)
client_->OnSurfaceCreated(surface_info);
« no previous file with comments | « services/ui/surfaces/display_compositor.h ('k') | services/ui/surfaces/display_compositor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698