Commit 33699e62 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Added some debugging code to print layer tree.

Also added a name attribute to the layer. IF !NDEBUG is defined, layer takes on the name of the view/window which created it

Please comment as to where the debug_utils.cc should be located, it feels like the wrong place.

I have another patch to print the window tree which I'll submit for review once I get this one in.

I think this is a bit simpler and more useful than http://codereview.chromium.org/8366008/

Review URL: http://codereview.chromium.org/8508009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110528 0039d316-1c4b-4281-b951-d872f2087c98
parent c0120044
......@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/string_util.h"
#include "ui/aura/client/stacking_client.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
......@@ -77,6 +78,18 @@ void Window::Init(ui::Layer::LayerType layer_type) {
layer_.reset(new ui::Layer(layer_type));
layer_->SetVisible(false);
layer_->set_delegate(this);
#if !defined(NDEBUG)
std::string layer_name(name_);
if (layer_name.empty())
layer_name.append("Unnamed Window");
if (id_ != -1) {
char id_buf[10];
base::snprintf(id_buf, sizeof(id_buf), " %d", id_);
layer_name.append(id_buf);
}
layer_->set_name(layer_name);
#endif
}
void Window::SetType(WindowType type) {
......
......@@ -46,6 +46,8 @@
'compositor_switches.cc',
'compositor_switches.h',
'compositor_win.cc',
'debug_utils.cc',
'debug_utils.h',
'layer.cc',
'layer.h',
'layer_animation_delegate.h',
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NDEBUG
#include "ui/gfx/compositor/debug_utils.h"
#include <iomanip>
#include <iostream>
#include <string>
#include "base/utf_string_conversions.h"
#include "base/logging.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/transform.h"
namespace ui {
namespace {
void PrintLayerHierarchyImp(const Layer* layer, int indent) {
if (!layer->visible())
return;
std::wostringstream buf;
std::string indent_str(indent, ' ');
std::string content_indent_str(indent+1, ' ');
buf << UTF8ToWide(indent_str);
buf << L'+' << UTF8ToWide(layer->name()) << L' ' << layer;
buf << L'\n' << UTF8ToWide(content_indent_str);
buf << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y();
buf << L' ' << layer->bounds().width() << L'x' << layer->bounds().height();
if (!layer->hole_rect().IsEmpty()) {
buf << L'\n' << UTF8ToWide(content_indent_str);
gfx::Rect hole_rect = layer->hole_rect();
buf << L"hole: " << hole_rect.x() << L',' << hole_rect.y();
buf << L' ' << hole_rect.width() << L'x' << hole_rect.height();
}
if (layer->opacity() != 1.0f) {
buf << L'\n' << UTF8ToWide(content_indent_str);
buf << L"opacity: " << std::setprecision(2) << layer->opacity();
}
if (layer->transform().HasChange()) {
gfx::Point translation;
float rotation;
gfx::Point3f scale;
if (ui::InterpolatedTransform::FactorTRS(layer->transform(),
&translation,
&rotation,
&scale)) {
if (translation != gfx::Point()) {
buf << L'\n' << UTF8ToWide(content_indent_str);
buf << L"translation: " << translation.x() << L", " << translation.y();
}
if (fabs(rotation) > 1e-5) {
buf << L'\n' << UTF8ToWide(content_indent_str);
buf << L"rotation: " << std::setprecision(4) << rotation;
}
if (scale.AsPoint() != gfx::Point()) {
buf << L'\n' << UTF8ToWide(content_indent_str);
buf << std::setprecision(4);
buf << L"scale: " << scale.x() << L", " << scale.y();
}
}
}
VLOG(1) << buf.str();
std::cout << buf.str() << std::endl;
for (size_t i = 0, count = layer->children().size(); i < count; ++i)
PrintLayerHierarchyImp(layer->children()[i], indent + 3);
}
} // namespace
void PrintLayerHierarchy(const Layer* layer) {
PrintLayerHierarchyImp(layer, 0);
}
} // namespace ui
#endif // NDEBUG
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_COMPOSITOR_DEBUG_UTILS_H_
#define UI_GFX_COMPOSITOR_DEBUG_UTILS_H_
#pragma once
#ifndef NDEBUG
#include "ui/gfx/compositor/compositor_export.h"
namespace ui {
class Layer;
// Log the layer hierarchy.
COMPOSITOR_EXPORT void PrintLayerHierarchy(const Layer* layer);
} // namespace ui
#endif // NDEBUG
#endif // UI_GFX_COMPOSITOR_DEBUG_UTILS_H_
......@@ -6,6 +6,7 @@
#define UI_GFX_COMPOSITOR_LAYER_H_
#pragma once
#include <string>
#include <vector>
#include "base/compiler_specific.h"
......@@ -149,6 +150,9 @@ class COMPOSITOR_EXPORT Layer :
const gfx::Rect& hole_rect() const { return hole_rect_; }
const std::string& name() const { return name_; }
void set_name(const std::string& name) { name_ = name; }
const ui::Texture* texture() const { return texture_.get(); }
// |texture| cannot be NULL, and this function cannot be called more than
......@@ -319,6 +323,8 @@ class COMPOSITOR_EXPORT Layer :
float opacity_;
std::string name_;
LayerDelegate* delegate_;
scoped_ptr<LayerAnimator> animator_;
......
......@@ -1781,6 +1781,9 @@ void View::CreateLayer() {
layer_.reset(new ui::Layer());
layer_->set_delegate(this);
#if !defined(NDEBUG)
layer_->set_name(GetClassName());
#endif
UpdateParentLayers();
UpdateLayerVisibility();
......
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