提交 ab927e23 编写于 作者: C Chinmay Garde

Allow displaying compositor statistics from Dart

上级 eb6f2f06
......@@ -32,6 +32,8 @@ source_set("compositor") {
"picture_layer.h",
"picture_serializer.cc",
"picture_serializer.h",
"statistics_layer.cc",
"statistics_layer.h",
"transform_layer.cc",
"transform_layer.h",
]
......
......@@ -13,6 +13,15 @@ CompositorOptions::CompositorOptions() {
options_.resize(static_cast<OptionType>(Option::TerminationSentinel), false);
}
CompositorOptions::CompositorOptions(uint64_t mask) : CompositorOptions() {
OptionType sentinel = static_cast<OptionType>(Option::TerminationSentinel);
for (OptionType i = 0; i < sentinel; i++) {
if ((1 << i) & mask) {
setEnabled(static_cast<Option>(i), true);
}
}
}
bool CompositorOptions::isEnabled(Option option) const {
if (option >= Option::TerminationSentinel) {
return false;
......
......@@ -21,6 +21,8 @@ class CompositorOptions {
};
CompositorOptions();
CompositorOptions(uint64_t mask);
~CompositorOptions();
bool isEnabled(Option option) const;
......
......@@ -21,36 +21,6 @@ void PaintContext::beginFrame(ScopedFrame& frame) {
void PaintContext::endFrame(ScopedFrame& frame) {
frame_time_.stop();
DisplayStatistics(frame);
}
static void PaintContext_DrawStatisticsText(SkCanvas& canvas,
const std::string& string,
int x,
int y) {
SkPaint paint;
paint.setTextSize(14);
paint.setLinearText(false);
paint.setColor(SK_ColorRED);
canvas.drawText(string.c_str(), string.size(), x, y, paint);
}
void PaintContext::DisplayStatistics(ScopedFrame& frame) {
// TODO: We just draw text text on the top left corner for now. Make this
// better
const int x = 10;
int y = 20;
static const int kLineSpacing = 18;
if (options_.isEnabled(CompositorOptions::Option::DisplayFrameStatistics)) {
// Frame (2032): 3.26ms
std::stringstream stream;
stream << "Frame (" << frame_count_.count()
<< "): " << frame_time_.lastLap().InMillisecondsF() << "ms";
PaintContext_DrawStatisticsText(frame.canvas(), stream.str(), x, y);
y += kLineSpacing;
}
}
PaintContext::ScopedFrame PaintContext::AcquireFrame(SkCanvas& canvas) {
......
......@@ -9,7 +9,6 @@
#include "base/macros.h"
#include "base/logging.h"
#include "sky/compositor/compositor_options.h"
#include "sky/compositor/instrumentation.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
......@@ -24,6 +23,8 @@ class PaintContext {
public:
SkCanvas& canvas() { return *canvas_; }
const PaintContext& context() const { return context_; };
ScopedFrame(ScopedFrame&& frame);
~ScopedFrame();
......@@ -48,22 +49,21 @@ class PaintContext {
PaintContext();
~PaintContext();
CompositorOptions& options() { return options_; };
ScopedFrame AcquireFrame(SkCanvas& canvas);
ScopedFrame AcquireFrame(const std::string& trace_file_name,
gfx::Size frame_size);
private:
CompositorOptions options_;
const instrumentation::Counter& frame_count() const { return frame_count_; }
const instrumentation::Stopwatch& frame_time() const { return frame_time_; }
private:
instrumentation::Counter frame_count_;
instrumentation::Stopwatch frame_time_;
void beginFrame(ScopedFrame& frame);
void endFrame(ScopedFrame& frame);
void DisplayStatistics(ScopedFrame& frame);
DISALLOW_COPY_AND_ASSIGN(PaintContext);
};
......
// Copyright 2015 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.
#include "sky/compositor/statistics_layer.h"
namespace sky {
namespace compositor {
StatisticsLayer::StatisticsLayer(uint64_t enabledOptions)
: options_(enabledOptions) {
}
static void PaintContext_DrawStatisticsText(SkCanvas& canvas,
const std::string& string,
int x,
int y) {
SkPaint paint;
paint.setTextSize(14);
paint.setLinearText(false);
paint.setColor(SK_ColorRED);
canvas.drawText(string.c_str(), string.size(), x, y, paint);
}
void StatisticsLayer::Paint(PaintContext::ScopedFrame& frame) {
const int x = 10;
int y = 20;
static const int kLineSpacing = 18;
const PaintContext& context = frame.context();
if (options_.isEnabled(CompositorOptions::Option::DisplayFrameStatistics)) {
// Frame (2032): 3.26ms
std::stringstream stream;
stream << "Frame (" << context.frame_count().count()
<< "): " << context.frame_time().lastLap().InMillisecondsF() << "ms";
PaintContext_DrawStatisticsText(frame.canvas(), stream.str(), x, y);
y += kLineSpacing;
}
}
} // namespace compositor
} // namespace sky
// Copyright 2015 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 SKY_COMPOSITOR_STATISTICS_LAYER_H_
#define SKY_COMPOSITOR_STATISTICS_LAYER_H_
#include "base/macros.h"
#include "sky/compositor/compositor_options.h"
#include "sky/compositor/layer.h"
namespace sky {
namespace compositor {
class StatisticsLayer : public Layer {
public:
StatisticsLayer(uint64_t enabledOptions);
void Paint(PaintContext::ScopedFrame& frame) override;
private:
CompositorOptions options_;
DISALLOW_COPY_AND_ASSIGN(StatisticsLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_STATISTICS_LAYER_H_
......@@ -4,9 +4,8 @@
#include "sky/engine/core/compositing/SceneBuilder.h"
#include "sky/engine/core/painting/Matrix.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "sky/compositor/transform_layer.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/compositor/clip_path_layer.h"
#include "sky/compositor/clip_rect_layer.h"
#include "sky/compositor/clip_rrect_layer.h"
......@@ -14,6 +13,8 @@
#include "sky/compositor/container_layer.h"
#include "sky/compositor/opacity_layer.h"
#include "sky/compositor/picture_layer.h"
#include "sky/compositor/statistics_layer.h"
#include "sky/compositor/transform_layer.h"
namespace blink {
......@@ -110,6 +111,15 @@ void SceneBuilder::addPicture(const Offset& offset, Picture* picture, const Rect
m_currentLayer->Add(std::move(layer));
}
void SceneBuilder::pushStatistics(uint64_t enabledOptions, const Rect& bounds)
{
if (!m_currentLayer)
return;
std::unique_ptr<sky::compositor::StatisticsLayer> layer(new sky::compositor::StatisticsLayer(enabledOptions));
layer->set_paint_bounds(bounds.sk_rect);
m_currentLayer->Add(std::move(layer));
}
PassRefPtr<Scene> SceneBuilder::build()
{
m_currentLayer = nullptr;
......
......@@ -40,6 +40,8 @@ public:
void pushClipPath(const CanvasPath* path, const Rect& bounds);
void pushOpacity(int alpha, const Rect& bounds);
void pushColorFilter(SkColor color, SkXfermode::Mode transferMode, const Rect& bounds);
void pushStatistics(uint64_t enabledOptions, const Rect& bounds);
void pop();
void addPicture(const Offset& offset, Picture* picture, const Rect& bounds);
......
......@@ -11,6 +11,7 @@
void pushClipPath(Path path, Rect bounds);
void pushOpacity(long alpha, Rect bounds);
void pushColorFilter(Color color, TransferMode transferMode, Rect bounds);
void pushStatistics(unsigned long enabledOptions, Rect bounds);
void pop();
void addPicture(Offset offset, Picture picture, Rect bounds);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册