diff options
author | skaslev@chromium.org <skaslev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 08:38:55 +0000 |
---|---|---|
committer | skaslev@chromium.org <skaslev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 08:38:55 +0000 |
commit | 4a23c374cff73a038c95ecb1e82e25399d45ed46 (patch) | |
tree | cf073baa8920802a0773d6a81120d7be7aa0536d /cc | |
parent | 3c3fef5e1c6799b524a4786b5f6f86eaaf39cd28 (diff) | |
download | chromium_src-4a23c374cff73a038c95ecb1e82e25399d45ed46.zip chromium_src-4a23c374cff73a038c95ecb1e82e25399d45ed46.tar.gz chromium_src-4a23c374cff73a038c95ecb1e82e25399d45ed46.tar.bz2 |
Added LayerTreeHostImpl::layerTreeAsJson which serializes a layer tree
to JSON format which can then be loaded and used from our cc_perftests.
BUG=
Review URL: https://chromiumcodereview.appspot.com/11446076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171963 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layer_impl.cc | 36 | ||||
-rw-r--r-- | cc/layer_impl.h | 5 | ||||
-rw-r--r-- | cc/layer_tree_host_impl.cc | 12 | ||||
-rw-r--r-- | cc/layer_tree_host_impl.h | 1 | ||||
-rw-r--r-- | cc/layer_tree_host_perftest.cc | 26 | ||||
-rw-r--r-- | cc/nine_patch_layer_impl.cc | 15 | ||||
-rw-r--r-- | cc/nine_patch_layer_impl.h | 6 |
7 files changed, 92 insertions, 9 deletions
diff --git a/cc/layer_impl.cc b/cc/layer_impl.cc index fa68613..c9615dc 100644 --- a/cc/layer_impl.cc +++ b/cc/layer_impl.cc @@ -6,6 +6,7 @@ #include "base/debug/trace_event.h" #include "base/stringprintf.h" +#include "base/values.h" #include "cc/debug_border_draw_quad.h" #include "cc/debug_colors.h" #include "cc/layer_tree_host_impl.h" @@ -342,6 +343,41 @@ void LayerImpl::dumpLayer(std::string* str, int indent) const m_children[i]->dumpLayer(str, indent+1); } +base::DictionaryValue* LayerImpl::layerTreeAsJson() const +{ + base::ListValue* list; + base::DictionaryValue* result = new base::DictionaryValue; + result->SetString("LayerType", layerTypeAsString()); + + list = new base::ListValue; + list->AppendInteger(bounds().width()); + list->AppendInteger(bounds().height()); + result->Set("Bounds", list); + + list = new base::ListValue; + list->AppendDouble(m_position.x()); + list->AppendDouble(m_position.y()); + result->Set("Position", list); + + const gfx::Transform& gfxTransform = m_drawProperties.target_space_transform; + double transform[16]; + gfxTransform.matrix().asColMajord(transform); + list = new base::ListValue; + for (int i = 0; i < 16; ++i) + list->AppendDouble(transform[i]); + result->Set("DrawTransform", list); + + result->SetBoolean("DrawsContent", m_drawsContent); + result->SetDouble("Opacity", opacity()); + + list = new base::ListValue; + for (size_t i = 0; i < m_children.size(); ++i) + list->Append(m_children[i]->layerTreeAsJson()); + result->Set("Children", list); + + return result; +} + void LayerImpl::setStackingOrderChanged(bool stackingOrderChanged) { // We don't need to store this flag; we only need to track that the change occurred. diff --git a/cc/layer_impl.h b/cc/layer_impl.h index e155e49..8e25f57 100644 --- a/cc/layer_impl.h +++ b/cc/layer_impl.h @@ -27,6 +27,10 @@ #include "ui/gfx/rect_f.h" #include "ui/gfx/transform.h" +namespace base { +class DictionaryValue; +} + namespace cc { class LayerTreeHostImpl; @@ -241,6 +245,7 @@ public: void setUpdateRect(const gfx::RectF& updateRect) { m_updateRect = updateRect; } std::string layerTreeAsText() const; + virtual base::DictionaryValue* layerTreeAsJson() const; void setStackingOrderChanged(bool); diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc index e0b1f30..236a63a 100644 --- a/cc/layer_tree_host_impl.cc +++ b/cc/layer_tree_host_impl.cc @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/debug/trace_event.h" +#include "base/json/json_writer.h" #include "base/stl_util.h" #include "cc/append_quads_data.h" #include "cc/damage_tracker.h" @@ -1568,6 +1569,17 @@ std::string LayerTreeHostImpl::layerTreeAsText() const return str; } +std::string LayerTreeHostImpl::layerTreeAsJson() const +{ + std::string str; + if (rootLayer()) { + scoped_ptr<base::Value> json(rootLayer()->layerTreeAsJson()); + base::JSONWriter::WriteWithOptions( + json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); + } + return str; +} + void LayerTreeHostImpl::dumpRenderSurfaces(std::string* str, int indent, const LayerImpl* layer) const { if (layer->renderSurface()) diff --git a/cc/layer_tree_host_impl.h b/cc/layer_tree_host_impl.h index ff61b75..1babd36 100644 --- a/cc/layer_tree_host_impl.h +++ b/cc/layer_tree_host_impl.h @@ -191,6 +191,7 @@ public: OutputSurface* outputSurface() const; std::string layerTreeAsText() const; + std::string layerTreeAsJson() const; void finishAllRendering(); int sourceAnimationFrameNumber() const; diff --git a/cc/layer_tree_host_perftest.cc b/cc/layer_tree_host_perftest.cc index d1cc08c..1dde37ca 100644 --- a/cc/layer_tree_host_perftest.cc +++ b/cc/layer_tree_host_perftest.cc @@ -60,21 +60,21 @@ class LayerTreeHostPerfTest : public ThreadedTest { return layer; } - scoped_refptr<ContentLayer> CreateContentLayer(float x, float y, int width, int height) { + scoped_refptr<ContentLayer> CreateContentLayer(float x, float y, int width, int height, bool drawable=true) { scoped_refptr<ContentLayer> layer = ContentLayer::create(&fake_delegate_); layer->setAnchorPoint(gfx::Point()); layer->setPosition(gfx::PointF(x, y)); layer->setBounds(gfx::Size(width, height)); - layer->setIsDrawable(true); + layer->setIsDrawable(drawable); return layer; } - scoped_refptr<SolidColorLayer> CreateColorLayer(float x, float y, int width, int height) { + scoped_refptr<SolidColorLayer> CreateColorLayer(float x, float y, int width, int height, bool drawable=true) { scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create(); layer->setAnchorPoint(gfx::Point()); layer->setPosition(gfx::PointF(x, y)); layer->setBounds(gfx::Size(width, height)); - layer->setIsDrawable(true); + layer->setIsDrawable(drawable); return layer; } @@ -82,12 +82,12 @@ class LayerTreeHostPerfTest : public ThreadedTest { return CreateDecorationLayer(x, y, width, height, gfx::Rect(0, 0, width, height)); } - scoped_refptr<NinePatchLayer> CreateDecorationLayer(float x, float y, int width, int height, gfx::Rect aperture) { + scoped_refptr<NinePatchLayer> CreateDecorationLayer(float x, float y, int width, int height, gfx::Rect aperture, bool drawable=true) { scoped_refptr<NinePatchLayer> layer = NinePatchLayer::create(); layer->setAnchorPoint(gfx::Point()); layer->setPosition(gfx::PointF(x, y)); layer->setBounds(gfx::Size(width, height)); - layer->setIsDrawable(true); + layer->setIsDrawable(drawable); SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); @@ -265,11 +265,14 @@ class LayerTreeHostPerfTestJsonReader : public LayerTreeHostPerfTest { success &= list->GetDouble(0, &position_x); success &= list->GetDouble(1, &position_y); + bool draws_content; + success &= dict->GetBoolean("DrawsContent", &draws_content); + scoped_refptr<Layer> new_layer; if (layer_type == "SolidColorLayer") { - new_layer = CreateColorLayer(position_x, position_y, width, height); + new_layer = CreateColorLayer(position_x, position_y, width, height, draws_content); } else if (layer_type == "ContentLayer") { - new_layer = CreateContentLayer(position_x, position_y, width, height); + new_layer = CreateContentLayer(position_x, position_y, width, height, draws_content); } else if (layer_type == "NinePatchLayer") { success &= dict->GetList("ImageAperture", &list); int aperture_x, aperture_y, aperture_width, aperture_height; @@ -280,12 +283,17 @@ class LayerTreeHostPerfTestJsonReader : public LayerTreeHostPerfTest { new_layer = CreateDecorationLayer( position_x, position_y, width, height, - gfx::Rect(aperture_x, aperture_y, aperture_width, aperture_height)); + gfx::Rect(aperture_x, aperture_y, aperture_width, aperture_height), + draws_content); } else { // Type "Layer" or "unknown" new_layer = CreateLayer(position_x, position_y, width, height); } + double opacity; + if (dict->GetDouble("Opacity", &opacity)) + new_layer->setOpacity(opacity); + success &= dict->GetList("DrawTransform", &list); double transform[16]; for (int i = 0; i < 16; ++i) diff --git a/cc/nine_patch_layer_impl.cc b/cc/nine_patch_layer_impl.cc index e4d36eb..3185abd 100644 --- a/cc/nine_patch_layer_impl.cc +++ b/cc/nine_patch_layer_impl.cc @@ -5,6 +5,7 @@ #include "nine_patch_layer_impl.h" #include "base/stringprintf.h" +#include "base/values.h" #include "cc/quad_sink.h" #include "cc/texture_draw_quad.h" #include "ui/gfx/rect_f.h" @@ -163,4 +164,18 @@ void NinePatchLayerImpl::dumpLayerProperties(std::string* str, int indent) const LayerImpl::dumpLayerProperties(str, indent); } +base::DictionaryValue* NinePatchLayerImpl::layerTreeAsJson() const +{ + base::DictionaryValue* result = LayerImpl::layerTreeAsJson(); + + base::ListValue* list = new base::ListValue; + list->AppendInteger(m_imageAperture.origin().x()); + list->AppendInteger(m_imageAperture.origin().y()); + list->AppendInteger(m_imageAperture.size().width()); + list->AppendInteger(m_imageAperture.size().height()); + result->Set("ImageAperture", list); + + return result; +} + } diff --git a/cc/nine_patch_layer_impl.h b/cc/nine_patch_layer_impl.h index 404ae2b..de757a2 100644 --- a/cc/nine_patch_layer_impl.h +++ b/cc/nine_patch_layer_impl.h @@ -11,6 +11,10 @@ #include "ui/gfx/size.h" #include "ui/gfx/rect.h" +namespace base { +class DictionaryValue; +} + namespace cc { class CC_EXPORT NinePatchLayerImpl : public LayerImpl { @@ -31,6 +35,8 @@ public: virtual void dumpLayerProperties(std::string*, int indent) const OVERRIDE; virtual void didLoseOutputSurface() OVERRIDE; + virtual base::DictionaryValue* layerTreeAsJson() const OVERRIDE; + protected: NinePatchLayerImpl(LayerTreeHostImpl* hostImpl, int id); |