| Index: services/ui/ws/embedded_surface_tracker.cc
|
| diff --git a/services/ui/ws/embedded_surface_tracker.cc b/services/ui/ws/embedded_surface_tracker.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f3cb91e49d663be6d2edba609b7c43d5adc03d50
|
| --- /dev/null
|
| +++ b/services/ui/ws/embedded_surface_tracker.cc
|
| @@ -0,0 +1,101 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "services/ui/ws/embedded_surface_tracker.h"
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace ui {
|
| +
|
| +EmbeddedSurfaceTracker::EmbeddedSurfaceTracker() {}
|
| +
|
| +EmbeddedSurfaceTracker::~EmbeddedSurfaceTracker() {}
|
| +
|
| +void EmbeddedSurfaceTracker::SetCurrentSurfaceId(
|
| + const cc::SurfaceId& surface_id) {
|
| + DCHECK(surface_id.is_valid());
|
| +
|
| + // The last submitted CompositorFrame for |current_surface_id_| still embeds
|
| + // the surfaces in |references_to_remove_| and hasn't embedded the surfaces in
|
| + // |references_to_add_| yet.
|
| + references_to_remove_.clear();
|
| + references_to_add_.clear();
|
| +
|
| + current_surface_id_ = surface_id;
|
| +
|
| + // Add references from updated |current_surface_id_| to all embedded surfaces.
|
| + for (auto& map_entry : embedded_surfaces_)
|
| + AddReference(current_surface_id_, map_entry.second);
|
| +}
|
| +
|
| +void EmbeddedSurfaceTracker::EmbedSurface(const cc::SurfaceId& embedded_id) {
|
| + auto iter = embedded_surfaces_.find(embedded_id.frame_sink_id());
|
| +
|
| + // This is the first surface for the FrameSinkId.
|
| + if (iter == embedded_surfaces_.end()) {
|
| + if (HasValidSurfaceId())
|
| + AddReference(current_surface_id_, embedded_id);
|
| +
|
| + embedded_surfaces_[embedded_id.frame_sink_id()] = embedded_id;
|
| + return;
|
| + }
|
| +
|
| + // This is not the first surface for the FrameSinkId, we are unembedding the
|
| + // old surface and embedding a new Surface.
|
| + cc::SurfaceId& stored_surface_id = iter->second;
|
| + DCHECK_NE(stored_surface_id, embedded_id);
|
| +
|
| + if (HasValidSurfaceId()) {
|
| + RemoveReference(current_surface_id_, stored_surface_id);
|
| + AddReference(current_surface_id_, embedded_id);
|
| + }
|
| +
|
| + stored_surface_id = embedded_id;
|
| +}
|
| +
|
| +void EmbeddedSurfaceTracker::UnembedSurface(
|
| + const cc::FrameSinkId& frame_sink_id) {
|
| + auto iter = embedded_surfaces_.find(frame_sink_id);
|
| + if (iter == embedded_surfaces_.end())
|
| + return;
|
| +
|
| + if (HasValidSurfaceId())
|
| + RemoveReference(current_surface_id_, iter->second);
|
| +
|
| + embedded_surfaces_.erase(iter);
|
| +}
|
| +
|
| +void EmbeddedSurfaceTracker::SendAddSurfaceReferences(
|
| + cc::mojom::MojoCompositorFrameSink* compositor_frame_sink) {
|
| + DCHECK(compositor_frame_sink);
|
| +
|
| + if (references_to_add_.empty())
|
| + return;
|
| +
|
| + compositor_frame_sink->AddSurfaceReferences(references_to_add_);
|
| + references_to_add_.clear();
|
| +}
|
| +
|
| +void EmbeddedSurfaceTracker::SendRemoveSurfaceReferences(
|
| + cc::mojom::MojoCompositorFrameSink* compositor_frame_sink) {
|
| + DCHECK(compositor_frame_sink);
|
| +
|
| + if (references_to_remove_.empty())
|
| + return;
|
| +
|
| + compositor_frame_sink->RemoveSurfaceReferences(references_to_remove_);
|
| + references_to_remove_.clear();
|
| +}
|
| +
|
| +void EmbeddedSurfaceTracker::AddReference(const cc::SurfaceId& parent_id,
|
| + const cc::SurfaceId& child_id) {
|
| + references_to_add_.push_back(cc::SurfaceReference(parent_id, child_id));
|
| +}
|
| +
|
| +void EmbeddedSurfaceTracker::RemoveReference(const cc::SurfaceId& parent_id,
|
| + const cc::SurfaceId& child_id) {
|
| + references_to_remove_.push_back(cc::SurfaceReference(parent_id, child_id));
|
| +}
|
| +
|
| +} // namespace ui
|
|
|