Commit 14be2cfe authored by yiyix's avatar yiyix Committed by Commit Bot

VizDevTools: Providing updates of a FrameSink tree

FrameSinkElement implements FrameSinkObserver interface and handles all
the events for updating the tree.

Bug: 816802
Change-Id: I6552281672cda18f611c65971aa56eea7aa13a00
Reviewed-on: https://chromium-review.googlesource.com/1113018
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584290}
parent 0d409001
......@@ -31,6 +31,7 @@ class UI_DEVTOOLS_EXPORT UIElement {
int node_id() const { return node_id_; };
std::string GetTypeName() const;
UIElement* parent() const { return parent_; };
void set_parent(UIElement* parent) { parent_ = parent; };
UIElementDelegate* delegate() const { return delegate_; };
UIElementType type() const { return type_; };
const std::vector<UIElement*>& children() const { return children_; };
......
......@@ -10,21 +10,37 @@
#include "components/ui_devtools/DOM.h"
#include "components/ui_devtools/dom_agent.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "components/viz/service/frame_sinks/frame_sink_observer.h"
namespace viz {
class FrameSinkManagerImpl;
}
namespace ui_devtools {
class FrameSinkElement;
class DOMAgentViz : public DOMAgent {
class DOMAgentViz : public viz::FrameSinkObserver, public DOMAgent {
public:
explicit DOMAgentViz(viz::FrameSinkManagerImpl* frame_sink_manager);
~DOMAgentViz() override;
// viz::FrameSinkObserver:
void OnRegisteredFrameSinkId(const viz::FrameSinkId& frame_sink_id) override;
void OnInvalidatedFrameSinkId(const viz::FrameSinkId& frame_sink_id) override;
void OnCreatedCompositorFrameSink(const viz::FrameSinkId& frame_sink_id,
bool is_root) override;
void OnDestroyedCompositorFrameSink(
const viz::FrameSinkId& frame_sink_id) override;
void OnRegisteredFrameSinkHierarchy(
const viz::FrameSinkId& parent_frame_sink_id,
const viz::FrameSinkId& child_frame_sink_id) override;
void OnUnregisteredFrameSinkHierarchy(
const viz::FrameSinkId& parent_frame_sink_id,
const viz::FrameSinkId& child_frame_sink_id) override;
private:
std::unique_ptr<protocol::DOM::Node> BuildTreeForFrameSink(
UIElement* frame_sink_element,
FrameSinkElement* frame_sink_element,
const viz::FrameSinkId& frame_sink_id);
// DOM::Backend:
......@@ -36,6 +52,10 @@ class DOMAgentViz : public DOMAgent {
std::unique_ptr<protocol::DOM::Node> BuildTreeForUIElement(
UIElement* ui_element) override;
// Removes the |child| subtree from the |parent| subtree and destroys every
// element in the |child| subtree.
void DestroyChildSubtree(UIElement* parent, UIElement* child);
// Every time the frontend disconnects we don't destroy DOMAgent so once we
// establish the connection again we need to clear the FrameSinkId sets
// because they may carry obsolete data. Then we initialize these with alive
......@@ -50,13 +70,33 @@ class DOMAgentViz : public DOMAgent {
// Mark a FrameSink that has |frame_sink_id| and all its subtree as attached.
void SetAttachedFrameSink(const viz::FrameSinkId& frame_sink_id);
// These sets are used to create and update the DOM tree.
base::flat_set<viz::FrameSinkId> registered_frame_sink_ids_;
base::flat_set<viz::FrameSinkId> client_connected_frame_sinks_;
// This is used to track created FrameSinkElements and will be used for
// updates in a FrameSink tree.
base::flat_map<viz::FrameSinkId, UIElement*> frame_sink_elements_;
// We delete the FrameSinkElements in the subtree rooted at |root| from
// |frame_sink_elements_| and attach all its children to the root_element().
void RemoveFrameSinkSubtree(UIElement* root);
// Remove FrameSinkElements for subtree rooted at |element| from the tree
// |frame_sink_elements_|.
void RemoveFrameSinkElement(UIElement* element);
// These sets are used to create and update the DOM tree. We add/remove
// registered FrameSinks to |registered_frame_sink_ids_to_is_connected_| when
// FrameSink is registered/invalidated and initialize the bool to false to
// indicate that the FrameSink is not created yet. Then when a |frame_sink| is
// created/destroyed, we update |registered_frame_sink_ids_to_is_connected_|
// of |frame_sink| true or false accordingly. When we get events
// registered/unregistered hierarchy we don't change these sets because we
// detach a subtree from one node and attach it to another node and the list
// of registered/created FrameSinkIds doesn't change.
// TODO(yiyix): Removes this map because it saves duplicated information as
// |frame_sink_elements_|.
base::flat_map<viz::FrameSinkId, bool>
registered_frame_sink_ids_to_is_connected_;
// This is used to track created FrameSinkElements in a FrameSink tree. Every
// time we register/invalidate a FrameSinkId, create/destroy a FrameSink,
// register/unregister hierarchy we change this set, because these actions
// involve deleting and adding elements.
base::flat_map<viz::FrameSinkId, FrameSinkElement*> frame_sink_elements_;
// This is used to denote attached FrameSinks.
base::flat_set<viz::FrameSinkId> attached_frame_sinks_;
......
......@@ -26,6 +26,17 @@ class FrameSinkElement : public UIElement {
bool is_client_connected);
~FrameSinkElement() override;
// Used by DOMAgentViz on updates when element is already present
// in a tree but its properties need to be changed.
void SetRegistered(bool is_registered) { is_registered_ = is_registered; }
void SetClientConnected(bool is_client_connected) {
is_client_connected_ = is_client_connected;
}
void SetRoot(bool is_root) { is_root_ = is_root; }
bool is_registered() const { return is_registered_; }
bool is_client_connected() const { return is_client_connected_; }
// UIElement:
std::vector<std::pair<std::string, std::string>> GetCustomProperties()
const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment