Chromium Code Reviews| Index: services/ui/ws/embedded_surface_tracker.h |
| diff --git a/services/ui/ws/embedded_surface_tracker.h b/services/ui/ws/embedded_surface_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..24403f9fc58dea38006fa63036f45d6d36deebd5 |
| --- /dev/null |
| +++ b/services/ui/ws/embedded_surface_tracker.h |
| @@ -0,0 +1,102 @@ |
| +// 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. |
| + |
| +#ifndef SERVICES_UI_WS_EMBEDDED_SURFACE_TRACKER_H_ |
| +#define SERVICES_UI_WS_EMBEDDED_SURFACE_TRACKER_H_ |
| + |
| +#include <unordered_map> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "cc/ipc/mojo_compositor_frame_sink.mojom.h" |
| +#include "cc/surfaces/frame_sink_id.h" |
| +#include "cc/surfaces/surface_id.h" |
| +#include "cc/surfaces/surface_reference.h" |
| + |
| +namespace ui { |
| + |
| +namespace test { |
| +class EmbeddedSurfaceTrackerTest; |
| +} |
| + |
| +// Tracks surface references from a client surface to all surfaces embedded in |
| +// the client surface. Handles updating the references when the client surface |
| +// resizes. |
| +// TODO(kylechar): This class should move somewhere else, cc/surfaces maybe? |
| +class EmbeddedSurfaceTracker { |
|
Fady Samuel
2017/01/05 19:36:19
Can we move this to cc/surfaces.
kylechar
2017/01/06 17:58:40
Done.
|
| + public: |
| + EmbeddedSurfaceTracker(); |
| + ~EmbeddedSurfaceTracker(); |
| + |
| + const cc::SurfaceId& current_surface_id() const { |
| + return current_surface_id_; |
| + } |
| + |
| + // Checks if the client has a valid SurfaceId. This will become true after |
| + // SetCurrentSurfaceId() is called for the first time. No references will be |
| + // added or removed until this is true. |
| + bool HasValidSurfaceId() const { return current_surface_id_.is_valid(); } |
| + |
| + // Sets |current_surface_id_| when the client switches surfaces. Clears all |
| + // references waiting to be added or removed, since no CompositorFrame will be |
| + // submitted for the previous surface now. Generates new references from the |
| + // new surface to all embedded surfaces. Does not send IPC. |
| + void SetCurrentSurfaceId(const cc::SurfaceId& surface_id); |
| + |
| + // Adds a reference from |current_surface_id_| to |embedded_id| and records |
| + // |embedded_id|. If an existing surface with the same FrameSinkId is embedded |
| + // removes the reference to it. Does not send IPC. |
| + void EmbedSurface(const cc::SurfaceId& embedded_id); |
| + |
| + // Removes reference from |current_surface_id_| to latest embedded surface for |
| + // |frame_sink_id|. Does not send IPC. |
| + void UnembedSurface(const cc::FrameSinkId& frame_sink_id); |
| + |
| + // Sends IPC to add references in |references_to_add_|. This should be called |
| + // *before* the next CompositorFrame is submitted. Does nothing if there are |
| + // no references to add. |
| + void SendAddSurfaceReferences( |
| + cc::mojom::MojoCompositorFrameSink* compositor_frame_sink); |
|
Fady Samuel
2017/01/05 19:36:19
Don't depend on mojo.
kylechar
2017/01/06 17:58:40
Done.
|
| + |
| + // Sends IPC to remove all references in |references_to_remove_|. This should |
| + // be called *after* the next CompositorFrame is submitted. Does nothing if |
| + // there are no references to remove. |
| + void SendRemoveSurfaceReferences( |
| + cc::mojom::MojoCompositorFrameSink* compositor_frame_sink); |
| + |
| + private: |
| + friend class test::EmbeddedSurfaceTrackerTest; |
| + |
| + // Records adding a reference from |parent_id| to |child_id|. References are |
| + // not actually added until SendAddSurfaceReferences() is called. |
| + void AddReference(const cc::SurfaceId& parent_id, |
| + const cc::SurfaceId& child_id); |
| + |
| + // Records removing a reference from |parent_id| to |child_id|. References |
| + // are not actually removed until SendRemoveSurfaceReferences() is called. |
| + void RemoveReference(const cc::SurfaceId& parent_id, |
| + const cc::SurfaceId& child_id); |
| + |
| + // The SurfaceId of the client surface that is embedding other surfaces. |
| + cc::SurfaceId current_surface_id_; |
| + |
| + // Surfaces that are embedded by the client surface. A reference from |
| + // |current_surface_id_| will be added if it's valid. |
| + std::unordered_map<cc::FrameSinkId, cc::SurfaceId, cc::FrameSinkIdHash> |
| + embedded_surfaces_; |
| + |
| + // References to surfaces that should be removed after the next |
| + // CompositorFrame has been submitted and the surfaces are no longer embedded. |
| + std::vector<cc::SurfaceReference> references_to_remove_; |
| + |
| + // References that should be added before the next CompositorFrame is |
| + // submitted. |
| + std::vector<cc::SurfaceReference> references_to_add_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(EmbeddedSurfaceTracker); |
| +}; |
| + |
| +} // namespace ui |
| + |
| +#endif // SERVICES_UI_WS_EMBEDDED_SURFACE_TRACKER_H_ |