| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_SURFACES_EMBEDDED_SURFACE_TRACKER_H_ | |
| 6 #define CC_SURFACES_EMBEDDED_SURFACE_TRACKER_H_ | |
| 7 | |
| 8 #include <unordered_map> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "cc/surfaces/frame_sink_id.h" | |
| 13 #include "cc/surfaces/surface_id.h" | |
| 14 #include "cc/surfaces/surface_reference.h" | |
| 15 #include "cc/surfaces/surfaces_export.h" | |
| 16 | |
| 17 namespace cc { | |
| 18 | |
| 19 namespace test { | |
| 20 class EmbeddedSurfaceTrackerTest; | |
| 21 } | |
| 22 | |
| 23 // Tracks surface references from a client surface to embedded surfaces. Handles | |
| 24 // updating the references when the client surface resizes. | |
| 25 class CC_SURFACES_EXPORT EmbeddedSurfaceTracker { | |
| 26 public: | |
| 27 EmbeddedSurfaceTracker(); | |
| 28 ~EmbeddedSurfaceTracker(); | |
| 29 | |
| 30 const SurfaceId& current_surface_id() const { return current_surface_id_; } | |
| 31 | |
| 32 // Checks if the client has a valid SurfaceId. This will become true after | |
| 33 // SetCurrentSurfaceId() is called for the first time. No references will be | |
| 34 // added or removed until this is true. | |
| 35 bool HasValidSurfaceId() const { return current_surface_id_.is_valid(); } | |
| 36 | |
| 37 // Sets |current_surface_id_| when the client switches surfaces. Clears all | |
| 38 // references waiting to be added or removed, since no CompositorFrame will be | |
| 39 // submitted for the previous surface now. Generates new references from the | |
| 40 // new surface to all embedded surfaces. Does not send IPC. | |
| 41 void SetCurrentSurfaceId(const SurfaceId& surface_id); | |
| 42 | |
| 43 // Adds a reference from |current_surface_id_| to |embedded_id| and records | |
| 44 // |embedded_id|. If an existing surface with the same FrameSinkId is embedded | |
| 45 // removes the reference to it. Does not send IPC. Returns true for the first | |
| 46 // surface from a FrameSinkId and false for all subsequent surfaces. | |
| 47 bool EmbedSurface(const SurfaceId& embedded_id); | |
| 48 | |
| 49 // Removes reference from |current_surface_id_| to latest embedded surface for | |
| 50 // |frame_sink_id|. Does not send IPC. | |
| 51 void UnembedSurface(const FrameSinkId& frame_sink_id); | |
| 52 | |
| 53 // Returns |references_to_add_| and clears contents. It's expected this will | |
| 54 // be called immediately before submitting a CompositorFrame and caller will | |
| 55 // add references via IPC. | |
| 56 std::vector<SurfaceReference> GetReferencesToAdd(); | |
| 57 bool HasReferencesToAdd() const { return !references_to_add_.empty(); } | |
| 58 | |
| 59 // Returns |references_to_remove_| and clears contents. It's expected this | |
| 60 // will be called immediately after submitting a CompositorFrame and caller | |
| 61 // will remove references via IPC. | |
| 62 std::vector<SurfaceReference> GetReferencesToRemove(); | |
| 63 bool HasReferencesToRemove() const { return !references_to_remove_.empty(); } | |
| 64 | |
| 65 private: | |
| 66 friend class test::EmbeddedSurfaceTrackerTest; | |
| 67 | |
| 68 // Records adding a reference from |parent_id| to |child_id|. References are | |
| 69 // not actually added until SendAddSurfaceReferences() is called. | |
| 70 void AddReference(const SurfaceId& parent_id, const SurfaceId& child_id); | |
| 71 | |
| 72 // Records removing a reference from |parent_id| to |child_id|. References | |
| 73 // are not actually removed until SendRemoveSurfaceReferences() is called. | |
| 74 void RemoveReference(const SurfaceId& parent_id, const SurfaceId& child_id); | |
| 75 | |
| 76 // The id of the client surface that is embedding other surfaces. | |
| 77 SurfaceId current_surface_id_; | |
| 78 | |
| 79 // Surfaces that are embedded by the client surface. A reference from | |
| 80 // |current_surface_id_| will be added if it's valid. | |
| 81 std::unordered_map<FrameSinkId, SurfaceId, FrameSinkIdHash> | |
| 82 embedded_surfaces_; | |
| 83 | |
| 84 // References to surfaces that should be removed after the next | |
| 85 // CompositorFrame has been submitted and the surfaces are no longer embedded. | |
| 86 std::vector<SurfaceReference> references_to_remove_; | |
| 87 | |
| 88 // References that should be added before the next CompositorFrame is | |
| 89 // submitted. | |
| 90 std::vector<SurfaceReference> references_to_add_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(EmbeddedSurfaceTracker); | |
| 93 }; | |
| 94 | |
| 95 } // namespace cc | |
| 96 | |
| 97 #endif // CC_SURFACES_EMBEDDED_SURFACE_TRACKER_H_ | |
| OLD | NEW |