mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #1378 from chinmaygarde/master
Allow display of compositor statistics from Dart
This commit is contained in:
commit
13ee86e585
@ -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();
|
||||
explicit 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);
|
||||
};
|
||||
|
||||
43
sky/compositor/statistics_layer.cc
Normal file
43
sky/compositor/statistics_layer.cc
Normal file
@ -0,0 +1,43 @@
|
||||
// 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
|
||||
30
sky/compositor/statistics_layer.h
Normal file
30
sky/compositor/statistics_layer.h
Normal file
@ -0,0 +1,30 @@
|
||||
// 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::addStatistics(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;
|
||||
|
||||
@ -41,7 +41,9 @@ public:
|
||||
void pushOpacity(int alpha, const Rect& bounds);
|
||||
void pushColorFilter(SkColor color, SkXfermode::Mode transferMode, const Rect& bounds);
|
||||
void pop();
|
||||
|
||||
void addPicture(const Offset& offset, Picture* picture, const Rect& bounds);
|
||||
void addStatistics(uint64_t enabledOptions, const Rect& bounds);
|
||||
|
||||
PassRefPtr<Scene> build();
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
void pop();
|
||||
|
||||
void addPicture(Offset offset, Picture picture, Rect bounds);
|
||||
void addStatistics(unsigned long enabledOptions, Rect bounds);
|
||||
|
||||
Scene build();
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user