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

Unified Diff: cc/surfaces/compositor_frame_sink_support.cc

Issue 2687433002: Move surface reference code to CompositorFrameSinkSupport. (Closed)
Patch Set: Revert to patch 2 to reland. Created 3 years, 10 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 | « cc/surfaces/compositor_frame_sink_support.h ('k') | cc/surfaces/referenced_surface_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/surfaces/compositor_frame_sink_support.cc
diff --git a/cc/surfaces/compositor_frame_sink_support.cc b/cc/surfaces/compositor_frame_sink_support.cc
index 95222ed1defc2354e69faf20ac12300a4b439b61..e7848f8021f16e3d3cadc78723a0076d505d2e9f 100644
--- a/cc/surfaces/compositor_frame_sink_support.cc
+++ b/cc/surfaces/compositor_frame_sink_support.cc
@@ -4,12 +4,17 @@
#include "cc/surfaces/compositor_frame_sink_support.h"
+#include <algorithm>
+#include <utility>
+#include <vector>
+
#include "cc/output/compositor_frame.h"
#include "cc/scheduler/begin_frame_source.h"
#include "cc/surfaces/compositor_frame_sink_support_client.h"
#include "cc/surfaces/display.h"
#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_manager.h"
+#include "cc/surfaces/surface_reference.h"
namespace cc {
@@ -25,6 +30,7 @@ CompositorFrameSinkSupport::CompositorFrameSinkSupport(
display_begin_frame_source_(std::move(display_begin_frame_source)),
display_(std::move(display)),
surface_factory_(frame_sink_id_, surface_manager_, this),
+ reference_tracker_(frame_sink_id),
weak_factory_(this) {
surface_manager_->RegisterFrameSinkId(frame_sink_id_);
surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
@@ -36,6 +42,12 @@ CompositorFrameSinkSupport::CompositorFrameSinkSupport(
}
CompositorFrameSinkSupport::~CompositorFrameSinkSupport() {
+ // For display root surfaces, the surface is no longer going to be visible
+ // so make it unreachable from the top-level root.
+ if (surface_manager_->using_surface_references() && display_ &&
+ reference_tracker_.current_surface_id().is_valid())
+ RemoveTopLevelRootReference(reference_tracker_.current_surface_id());
+
for (auto& child_frame_sink_id : child_frame_sinks_) {
DCHECK(child_frame_sink_id.is_valid());
surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_,
@@ -62,14 +74,31 @@ void CompositorFrameSinkSupport::SubmitCompositorFrame(
const LocalSurfaceId& local_surface_id,
CompositorFrame frame) {
++ack_pending_count_;
- surface_factory_.SubmitCompositorFrame(
- local_surface_id, std::move(frame),
- base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
- weak_factory_.GetWeakPtr()));
- if (display_) {
- display_->SetLocalSurfaceId(local_surface_id,
- frame.metadata.device_scale_factor);
+ float device_scale_factor = frame.metadata.device_scale_factor;
+
+ if (surface_manager_->using_surface_references()) {
+ SurfaceId last_surface_id = reference_tracker_.current_surface_id();
+
+ // Populate list of surface references to add and remove based on reference
+ // surfaces in current frame compared with the last frame.
+ reference_tracker_.UpdateReferences(local_surface_id,
+ frame.metadata.referenced_surfaces);
+
+ surface_factory_.SubmitCompositorFrame(
+ local_surface_id, std::move(frame),
+ base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
+ weak_factory_.GetWeakPtr()));
+
+ UpdateSurfaceReferences(last_surface_id, local_surface_id);
+ } else {
+ surface_factory_.SubmitCompositorFrame(
+ local_surface_id, std::move(frame),
+ base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
+ weak_factory_.GetWeakPtr()));
}
+
+ if (display_)
+ display_->SetLocalSurfaceId(local_surface_id, device_scale_factor);
}
void CompositorFrameSinkSupport::Require(const LocalSurfaceId& local_surface_id,
@@ -82,6 +111,51 @@ void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) {
surface_manager_->SatisfySequence(sequence);
}
+void CompositorFrameSinkSupport::UpdateSurfaceReferences(
+ const SurfaceId& last_surface_id,
+ const LocalSurfaceId& local_surface_id) {
+ const bool surface_id_changed =
+ last_surface_id.local_surface_id() != local_surface_id;
+
+ // If this is a display root surface and the SurfaceId is changing, make the
+ // new SurfaceId reachable from the top-level root.
+ if (display_ && surface_id_changed)
+ AddTopLevelRootReference(reference_tracker_.current_surface_id());
+
+ // Add references based on CompositorFrame referenced surfaces. If the
+ // SurfaceId has changed all referenced surfaces will be in this list.
+ if (!reference_tracker_.references_to_add().empty()) {
+ surface_manager_->AddSurfaceReferences(
+ reference_tracker_.references_to_add());
+ }
+
+ // If this is a display root surface and the SurfaceId is changing, make the
+ // old SurfaceId unreachable from the top-level root. This needs to happen
+ // after adding all references for the new SurfaceId.
+ if (display_ && surface_id_changed && last_surface_id.is_valid())
+ RemoveTopLevelRootReference(last_surface_id);
+
+ // Remove references based on CompositorFrame referenced surfaces. If the
+ // SurfaceId has changed this list will be empty.
+ if (!reference_tracker_.references_to_remove().empty()) {
+ DCHECK(!surface_id_changed);
+ surface_manager_->RemoveSurfaceReferences(
+ reference_tracker_.references_to_remove());
+ }
+}
+
+void CompositorFrameSinkSupport::AddTopLevelRootReference(
+ const SurfaceId& surface_id) {
+ SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
+ surface_manager_->AddSurfaceReferences({reference});
+}
+
+void CompositorFrameSinkSupport::RemoveTopLevelRootReference(
+ const SurfaceId& surface_id) {
+ SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
+ surface_manager_->RemoveSurfaceReferences({reference});
+}
+
void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() {
DCHECK_GT(ack_pending_count_, 0);
ack_pending_count_--;
« no previous file with comments | « cc/surfaces/compositor_frame_sink_support.h ('k') | cc/surfaces/referenced_surface_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698