1 // Copyright 2018 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 #include "components/ui_devtools/viz/surface_element.h"
6 
7 #include "components/ui_devtools/Protocol.h"
8 #include "components/ui_devtools/ui_element_delegate.h"
9 #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
10 #include "components/viz/service/surfaces/surface.h"
11 #include "components/viz/service/surfaces/surface_manager.h"
12 
13 namespace ui_devtools {
14 
SurfaceElement(const viz::SurfaceId & surface_id,viz::FrameSinkManagerImpl * frame_sink_manager,UIElementDelegate * ui_element_delegate,UIElement * parent)15 SurfaceElement::SurfaceElement(const viz::SurfaceId& surface_id,
16                                viz::FrameSinkManagerImpl* frame_sink_manager,
17                                UIElementDelegate* ui_element_delegate,
18                                UIElement* parent)
19     : VizElement(UIElementType::SURFACE, ui_element_delegate, parent),
20       surface_id_(surface_id),
21       frame_sink_manager_(frame_sink_manager) {
22   viz::Surface* surface =
23       frame_sink_manager_->surface_manager()->GetSurfaceForId(surface_id_);
24   if (surface) {
25     surface_bounds_ = gfx::Rect(surface->size_in_pixels());
26   } else {
27     // The root surface id doesn't have an associated surface.
28     DCHECK_EQ(surface_id_,
29               frame_sink_manager_->surface_manager()->GetRootSurfaceId());
30   }
31   // DOMAgentViz handles all of the Surface events, so it owns all of the
32   // SurfaceElements.
33   set_owns_children(false);
34 }
35 
36 SurfaceElement::~SurfaceElement() = default;
37 
GetBounds(gfx::Rect * bounds) const38 void SurfaceElement::GetBounds(gfx::Rect* bounds) const {
39   // We cannot really know real bounds on the surface unless we do
40   // aggregation. Here we just return size of the surface.
41   *bounds = surface_bounds_;
42 }
43 
SetBounds(const gfx::Rect & bounds)44 void SurfaceElement::SetBounds(const gfx::Rect& bounds) {
45   NOTREACHED();
46 }
47 
GetVisible(bool * visible) const48 void SurfaceElement::GetVisible(bool* visible) const {
49   // Currently not real data.
50   *visible = true;
51 }
52 
SetVisible(bool visible)53 void SurfaceElement::SetVisible(bool visible) {}
54 
GetAttributes() const55 std::vector<std::string> SurfaceElement::GetAttributes() const {
56   return {
57       "SurfaceId", surface_id_.ToString(), "FrameSink Debug Label",
58       frame_sink_manager_->GetFrameSinkDebugLabel(surface_id_.frame_sink_id())
59           .as_string()};
60 }
61 
62 std::pair<gfx::NativeWindow, gfx::Rect>
GetNodeWindowAndScreenBounds() const63 SurfaceElement::GetNodeWindowAndScreenBounds() const {
64   return {};
65 }
66 
67 // static
From(const UIElement * element)68 const viz::SurfaceId& SurfaceElement::From(const UIElement* element) {
69   DCHECK_EQ(UIElementType::SURFACE, element->type());
70   return static_cast<const SurfaceElement*>(element)->surface_id_;
71 }
72 
73 }  // namespace ui_devtools
74