Skip to content

Commit

Permalink
Let cc verbose log use TracedValue
Browse files Browse the repository at this point in the history
To avoid two copies of internal data dump.

Change-Id: Ia177193ee81964ce64ac04147c43a1afe98ab951
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2042284
Reviewed-by: Robert Flack <flackr@chromium.org>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739671}
  • Loading branch information
wangxianzhu authored and Commit Bot committed Feb 8, 2020
1 parent 2e635d8 commit 61ace67
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 188 deletions.
23 changes: 0 additions & 23 deletions cc/base/math_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,22 +625,6 @@ gfx::Vector2dF MathUtil::ProjectVector(const gfx::Vector2dF& source,
projected_length * destination.y());
}

std::unique_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) {
std::unique_ptr<base::DictionaryValue> res(new base::DictionaryValue());
res->SetDouble("width", s.width());
res->SetDouble("height", s.height());
return std::move(res);
}

std::unique_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) {
std::unique_ptr<base::ListValue> res(new base::ListValue());
res->AppendInteger(r.x());
res->AppendInteger(r.y());
res->AppendInteger(r.width());
res->AppendInteger(r.height());
return std::move(res);
}

bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) {
const base::ListValue* value = nullptr;
if (!raw_value->GetAsList(&value))
Expand All @@ -662,13 +646,6 @@ bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) {
return true;
}

std::unique_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) {
std::unique_ptr<base::ListValue> res(new base::ListValue());
res->AppendDouble(pt.x());
res->AppendDouble(pt.y());
return std::move(res);
}

void MathUtil::AddToTracedValue(const char* name,
const gfx::Size& s,
base::trace_event::TracedValue* res) {
Expand Down
4 changes: 0 additions & 4 deletions cc/base/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ class CC_BASE_EXPORT MathUtil {
static gfx::Vector2dF ProjectVector(const gfx::Vector2dF& source,
const gfx::Vector2dF& destination);

// Conversion to value.
static std::unique_ptr<base::Value> AsValue(const gfx::Size& s);
static std::unique_ptr<base::Value> AsValue(const gfx::Rect& r);
static bool FromValue(const base::Value*, gfx::Rect* out_rect);
static std::unique_ptr<base::Value> AsValue(const gfx::PointF& q);

static void AddToTracedValue(const char* name,
const gfx::Size& s,
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ void Layer::SetElementId(ElementId id) {
if (inputs_.element_id == id)
return;
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "Layer::SetElementId",
"element", id.AsValue().release());
"element", id.ToString());
if (layer_tree_host_ && inputs_.element_id)
layer_tree_host_->UnregisterElement(inputs_.element_id);

Expand Down
59 changes: 5 additions & 54 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,52 +419,6 @@ bool LayerImpl::IsAffectedByPageScale() const {
->in_subtree_of_page_scale_layer;
}

std::unique_ptr<base::DictionaryValue> LayerImpl::LayerAsJson() const {
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
result->SetInteger("LayerId", id());
if (element_id())
result->SetString("ElementId", element_id().ToString());
result->SetString("LayerType", LayerTypeAsString());

auto list = std::make_unique<base::ListValue>();
list->AppendInteger(bounds().width());
list->AppendInteger(bounds().height());
result->Set("Bounds", std::move(list));

list = std::make_unique<base::ListValue>();
list->AppendInteger(offset_to_transform_parent().x());
list->AppendInteger(offset_to_transform_parent().y());
result->Set("OffsetToTransformParent", std::move(list));

result->SetBoolean("DrawsContent", draws_content_);
result->SetBoolean("HitTestable", hit_testable_);
result->SetBoolean("Is3dSorted", Is3dSorted());
result->SetDouble("Opacity", Opacity());
result->SetBoolean("ContentsOpaque", contents_opaque_);

result->SetInteger("transform_tree_index", transform_tree_index());
result->SetInteger("clip_tree_index", clip_tree_index());
result->SetInteger("effect_tree_index", effect_tree_index());
result->SetInteger("scroll_tree_index", scroll_tree_index());

if (!GetAllTouchActionRegions().IsEmpty()) {
std::unique_ptr<base::Value> region = GetAllTouchActionRegions().AsValue();
result->Set("TouchRegion", std::move(region));
}

if (!wheel_event_handler_region_.IsEmpty()) {
std::unique_ptr<base::Value> region = wheel_event_handler_region_.AsValue();
result->Set("WheelRegion", std::move(region));
}

if (!non_fast_scrollable_region_.IsEmpty()) {
std::unique_ptr<base::Value> region = non_fast_scrollable_region_.AsValue();
result->Set("NonFastScrollableRegion", std::move(region));
}

return result;
}

bool LayerImpl::LayerPropertyChanged() const {
return layer_property_changed_not_from_property_trees_ ||
LayerPropertyChangedFromPropertyTrees();
Expand Down Expand Up @@ -628,7 +582,7 @@ void LayerImpl::SetElementId(ElementId element_id) {
return;

TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "LayerImpl::SetElementId",
"element", element_id.AsValue().release());
"element", element_id.ToString());

layer_tree_impl_->RemoveFromElementLayerList(element_id_);
element_id_ = element_id;
Expand Down Expand Up @@ -743,6 +697,7 @@ void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
state->EndArray();
}

state->SetBoolean("hit_testable", HitTestable());
state->SetBoolean("can_use_lcd_text", CanUseLCDText());
state->SetBoolean("contents_opaque", contents_opaque());

Expand Down Expand Up @@ -783,13 +738,9 @@ void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
}

std::string LayerImpl::ToString() const {
std::string str;
base::JSONWriter::WriteWithOptions(
*LayerAsJson(),
base::JSONWriter::OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION |
base::JSONWriter::OPTIONS_PRETTY_PRINT,
&str);
return str;
base::trace_event::TracedValueJSON value;
AsValueInto(&value);
return value.ToFormattedJSON();
}

size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
Expand Down
7 changes: 0 additions & 7 deletions cc/layers/layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "cc/base/region.h"
#include "cc/base/synced_property.h"
#include "cc/cc_export.h"
Expand All @@ -40,10 +39,6 @@
#include "ui/gfx/geometry/scroll_offset.h"
#include "ui/gfx/transform.h"

namespace base {
class DictionaryValue;
}

namespace viz {
class ClientResourceProvider;
class RenderPass;
Expand Down Expand Up @@ -298,8 +293,6 @@ class CC_EXPORT LayerImpl {
// as appropriate.
virtual gfx::Rect GetDamageRect() const;

virtual std::unique_ptr<base::DictionaryValue> LayerAsJson() const;

// This includes |layer_property_changed_not_from_property_trees_| and
// property_trees changes.
bool LayerPropertyChanged() const;
Expand Down
32 changes: 9 additions & 23 deletions cc/layers/nine_patch_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "cc/layers/nine_patch_generator.h"

#include "base/trace_event/traced_value.h"
#include "cc/base/math_util.h"
#include "cc/trees/layer_tree_impl.h"
#include "components/viz/common/quads/render_pass.h"
#include "components/viz/common/quads/texture_draw_quad.h"
Expand Down Expand Up @@ -368,29 +370,13 @@ void NinePatchGenerator::AppendQuads(LayerImpl* layer_impl,
}
}

void NinePatchGenerator::AsJson(base::DictionaryValue* dictionary) const {
auto list = std::make_unique<base::ListValue>();
list->AppendInteger(image_aperture_.origin().x());
list->AppendInteger(image_aperture_.origin().y());
list->AppendInteger(image_aperture_.size().width());
list->AppendInteger(image_aperture_.size().height());
dictionary->Set("ImageAperture", std::move(list));

list = std::make_unique<base::ListValue>();
list->AppendInteger(image_bounds_.width());
list->AppendInteger(image_bounds_.height());
dictionary->Set("ImageBounds", std::move(list));

dictionary->Set("Border", MathUtil::AsValue(border_));

dictionary->SetBoolean("FillCenter", fill_center_);

list = std::make_unique<base::ListValue>();
list->AppendInteger(output_occlusion_.x());
list->AppendInteger(output_occlusion_.y());
list->AppendInteger(output_occlusion_.width());
list->AppendInteger(output_occlusion_.height());
dictionary->Set("OutputOcclusion", std::move(list));
void NinePatchGenerator::AsValueInto(
base::trace_event::TracedValue* state) const {
MathUtil::AddToTracedValue("ImageAperture", image_aperture_, state);
MathUtil::AddToTracedValue("ImageBounds", image_bounds_, state);
MathUtil::AddToTracedValue("Border", border_, state);
state->SetBoolean("FillCenter", fill_center_);
MathUtil::AddToTracedValue("OutputOcclusion", output_occlusion_, state);
}

} // namespace cc
6 changes: 4 additions & 2 deletions cc/layers/nine_patch_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "ui/gfx/geometry/size.h"

namespace base {
class DictionaryValue;
namespace trace_event {
class TracedValue;
}
}

namespace viz {
Expand Down Expand Up @@ -103,7 +105,7 @@ class CC_EXPORT NinePatchGenerator {
viz::SharedQuadState* shared_quad_state,
const std::vector<Patch>& patches);

void AsJson(base::DictionaryValue* dictionary) const;
void AsValueInto(base::trace_event::TracedValue* state) const;
void CheckGeometryLimitations();

private:
Expand Down
10 changes: 5 additions & 5 deletions cc/layers/nine_patch_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "cc/layers/nine_patch_layer_impl.h"

#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "base/trace_event/traced_value.h"
#include "cc/base/math_util.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
Expand Down Expand Up @@ -85,10 +85,10 @@ const char* NinePatchLayerImpl::LayerTypeAsString() const {
return "cc::NinePatchLayerImpl";
}

std::unique_ptr<base::DictionaryValue> NinePatchLayerImpl::LayerAsJson() const {
std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerAsJson();
quad_generator_.AsJson(result.get());
return result;
void NinePatchLayerImpl::AsValueInto(
base::trace_event::TracedValue* state) const {
LayerImpl::AsValueInto(state);
quad_generator_.AsValueInto(state);
}

} // namespace cc
6 changes: 1 addition & 5 deletions cc/layers/nine_patch_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

namespace base {
class DictionaryValue;
}

namespace cc {

class CC_EXPORT NinePatchLayerImpl : public UIResourceLayerImpl {
Expand All @@ -46,7 +42,7 @@ class CC_EXPORT NinePatchLayerImpl : public UIResourceLayerImpl {
void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;

std::unique_ptr<base::DictionaryValue> LayerAsJson() const override;
void AsValueInto(base::trace_event::TracedValue* state) const override;

protected:
NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id);
Expand Down
21 changes: 0 additions & 21 deletions cc/layers/picture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1718,25 +1718,4 @@ gfx::ContentColorUsage PictureLayerImpl::GetContentColorUsage() const {
return gfx::ContentColorUsage::kSRGB;
}

std::unique_ptr<base::DictionaryValue> PictureLayerImpl::LayerAsJson() const {
auto result = LayerImpl::LayerAsJson();
auto dictionary = std::make_unique<base::DictionaryValue>();
if (raster_source_) {
dictionary->SetBoolean("IsSolidColor", raster_source_->IsSolidColor());
auto list = std::make_unique<base::ListValue>();
list->AppendInteger(raster_source_->GetSize().width());
list->AppendInteger(raster_source_->GetSize().height());
dictionary->Set("Size", std::move(list));
dictionary->SetBoolean("HasRecordings", raster_source_->HasRecordings());

const auto& display_list = raster_source_->GetDisplayItemList();
size_t op_count = display_list ? display_list->TotalOpCount() : 0;
size_t bytes_used = display_list ? display_list->BytesUsed() : 0;
dictionary->SetInteger("OpCount", op_count);
dictionary->SetInteger("BytesUsed", bytes_used);
}
result->Set("RasterSource", std::move(dictionary));
return result;
}

} // namespace cc
2 changes: 0 additions & 2 deletions cc/layers/picture_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ class CC_EXPORT PictureLayerImpl
void RegisterAnimatedImages();
void UnregisterAnimatedImages();

std::unique_ptr<base::DictionaryValue> LayerAsJson() const override;

// Set the collection of PaintWorkletInput as well as their PaintImageId that
// are part of this layer.
void SetPaintWorkletInputs(
Expand Down
28 changes: 13 additions & 15 deletions cc/layers/ui_resource_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "cc/layers/ui_resource_layer_impl.h"

#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "base/trace_event/traced_value.h"
#include "cc/base/math_util.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
Expand Down Expand Up @@ -138,23 +138,21 @@ const char* UIResourceLayerImpl::LayerTypeAsString() const {
return "cc::UIResourceLayerImpl";
}

std::unique_ptr<base::DictionaryValue> UIResourceLayerImpl::LayerAsJson()
const {
std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerAsJson();
void UIResourceLayerImpl::AsValueInto(
base::trace_event::TracedValue* state) const {
LayerImpl::AsValueInto(state);

result->Set("ImageBounds", MathUtil::AsValue(image_bounds_));
MathUtil::AddToTracedValue("ImageBounds", image_bounds_, state);

auto list = std::make_unique<base::ListValue>();
list->AppendDouble(vertex_opacity_[0]);
list->AppendDouble(vertex_opacity_[1]);
list->AppendDouble(vertex_opacity_[2]);
list->AppendDouble(vertex_opacity_[3]);
result->Set("VertexOpacity", std::move(list));
state->BeginArray("VertexOpacity");
state->AppendDouble(vertex_opacity_[0]);
state->AppendDouble(vertex_opacity_[1]);
state->AppendDouble(vertex_opacity_[2]);
state->AppendDouble(vertex_opacity_[3]);
state->EndArray();

result->Set("UVTopLeft", MathUtil::AsValue(uv_top_left_));
result->Set("UVBottomRight", MathUtil::AsValue(uv_bottom_right_));

return result;
MathUtil::AddToTracedValue("UVTopLeft", uv_top_left_, state);
MathUtil::AddToTracedValue("UVBottomRight", uv_bottom_right_, state);
}

} // namespace cc
6 changes: 1 addition & 5 deletions cc/layers/ui_resource_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

namespace base {
class DictionaryValue;
}

namespace viz {
class ClientResourceProvider;
}
Expand Down Expand Up @@ -54,7 +50,7 @@ class CC_EXPORT UIResourceLayerImpl : public LayerImpl {
void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;

std::unique_ptr<base::DictionaryValue> LayerAsJson() const override;
void AsValueInto(base::trace_event::TracedValue* state) const override;

protected:
UIResourceLayerImpl(LayerTreeImpl* tree_impl, int id);
Expand Down
Loading

0 comments on commit 61ace67

Please sign in to comment.