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

Setup infrastructure to capture SKP traces when the frame interval exceeds certain thresholds

上级 aa81cbad
......@@ -9,7 +9,7 @@
namespace sky {
namespace compositor {
LayerTree::LayerTree() {
LayerTree::LayerTree() : rasterizer_tracing_threashold_(0) {
}
LayerTree::~LayerTree() {
......
......@@ -5,6 +5,7 @@
#ifndef SKY_COMPOSITOR_LAYER_TREE_H_
#define SKY_COMPOSITOR_LAYER_TREE_H_
#include <stdint.h>
#include <memory>
#include "base/macros.h"
......@@ -38,11 +39,23 @@ class LayerTree {
return construction_time_;
}
// The number of frame intervals missed after which the compositor must
// trace the rasterized picture to a trace file. Specify 0 to disable all
// tracing
void set_rasterizer_tracing_threshold(uint32_t interval) {
rasterizer_tracing_threashold_ = interval;
}
uint32_t rasterizer_tracing_threshold() const {
return rasterizer_tracing_threashold_;
}
private:
SkISize frame_size_; // Physical pixels.
std::unique_ptr<Layer> root_layer_;
base::TimeDelta construction_time_;
uint32_t rasterizer_tracing_threashold_;
DISALLOW_COPY_AND_ASSIGN(LayerTree);
};
......
......@@ -50,6 +50,7 @@ PaintContext::ScopedFrame::ScopedFrame(PaintContext& context,
SkRect::MakeWH(frame_size.width(), frame_size.height()));
canvas_ = trace_recorder_->getRecordingCanvas();
DCHECK(canvas_);
DCHECK(trace_file_name.length() > 0);
context_.beginFrame(*this);
}
......
......@@ -10,14 +10,17 @@
namespace blink {
PassRefPtr<Scene> Scene::create(
std::unique_ptr<sky::compositor::Layer> rootLayer) {
std::unique_ptr<sky::compositor::Layer> rootLayer,
uint32_t rasterizerTracingThreshold) {
ASSERT(rootLayer);
return adoptRef(new Scene(std::move(rootLayer)));
return adoptRef(new Scene(std::move(rootLayer), rasterizerTracingThreshold));
}
Scene::Scene(std::unique_ptr<sky::compositor::Layer> rootLayer)
Scene::Scene(std::unique_ptr<sky::compositor::Layer> rootLayer,
uint32_t rasterizerTracingThreshold)
: m_layerTree(new sky::compositor::LayerTree()) {
m_layerTree->set_root_layer(std::move(rootLayer));
m_layerTree->set_rasterizer_tracing_threshold(rasterizerTracingThreshold);
}
Scene::~Scene() {}
......@@ -26,4 +29,4 @@ std::unique_ptr<sky::compositor::LayerTree> Scene::takeLayerTree() {
return std::move(m_layerTree);
}
} // namespace blink
} // namespace blink
......@@ -5,6 +5,7 @@
#ifndef SKY_ENGINE_CORE_COMPOSITING_SCENE_H_
#define SKY_ENGINE_CORE_COMPOSITING_SCENE_H_
#include <stdint.h>
#include <memory>
#include "sky/compositor/layer.h"
......@@ -22,16 +23,18 @@ class Scene : public RefCounted<Scene>, public DartWrappable {
public:
~Scene() override;
static PassRefPtr<Scene> create(
std::unique_ptr<sky::compositor::Layer> rootLayer);
std::unique_ptr<sky::compositor::Layer> rootLayer,
uint32_t rasterizerTracingThreshold);
std::unique_ptr<sky::compositor::LayerTree> takeLayerTree();
private:
explicit Scene(std::unique_ptr<sky::compositor::Layer> rootLayer);
explicit Scene(std::unique_ptr<sky::compositor::Layer> rootLayer,
uint32_t rasterizerTracingThreshold);
std::unique_ptr<sky::compositor::LayerTree> m_layerTree;
};
} // namespace blink
} // namespace blink
#endif // SKY_ENGINE_CORE_COMPOSITING_SCENE_H_
......@@ -21,6 +21,7 @@ namespace blink {
SceneBuilder::SceneBuilder(const Rect& bounds)
: m_rootPaintBounds(bounds.sk_rect)
, m_currentLayer(nullptr)
, m_currentRasterizerTracingThreshold(0)
{
}
......@@ -120,10 +121,17 @@ void SceneBuilder::addStatistics(uint64_t enabledOptions, const Rect& bounds)
m_currentLayer->Add(std::move(layer));
}
void SceneBuilder::setRasterizerTracingThreshold(uint32_t frameInterval)
{
m_currentRasterizerTracingThreshold = frameInterval;
}
PassRefPtr<Scene> SceneBuilder::build()
{
m_currentLayer = nullptr;
return Scene::create(std::move(m_rootLayer));
int32_t threshold = m_currentRasterizerTracingThreshold;
m_currentRasterizerTracingThreshold = 0;
return Scene::create(std::move(m_rootLayer), threshold);
}
} // namespace blink
......@@ -5,6 +5,7 @@
#ifndef SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_
#define SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_
#include <stdint.h>
#include <memory>
#include "sky/compositor/layer.h"
......@@ -45,6 +46,8 @@ public:
void addPicture(const Offset& offset, Picture* picture, const Rect& bounds);
void addStatistics(uint64_t enabledOptions, const Rect& bounds);
void setRasterizerTracingThreshold(uint32_t frameInterval);
PassRefPtr<Scene> build();
private:
......@@ -55,6 +58,7 @@ private:
SkRect m_rootPaintBounds;
std::unique_ptr<sky::compositor::ContainerLayer> m_rootLayer;
sky::compositor::ContainerLayer* m_currentLayer;
int32_t m_currentRasterizerTracingThreshold;
};
} // namespace blink
......
......@@ -15,6 +15,7 @@
void addPicture(Offset offset, Picture picture, Rect bounds);
void addStatistics(unsigned long enabledOptions, Rect bounds);
void setRasterizerTracingThreshold(unsigned long frameInterval);
Scene build();
};
......@@ -23,6 +23,8 @@
namespace sky {
namespace shell {
static const double kOneFrameDuration = 1e3 / 60.0;
Rasterizer::Rasterizer()
: share_group_(new gfx::GLShareGroup()), weak_factory_(this) {
}
......@@ -71,13 +73,22 @@ void Rasterizer::Draw(scoped_ptr<compositor::LayerTree> layer_tree) {
surface_->SwapBuffers();
}
// Optionally, if the user has specified tracing the current scene to a file,
// acquire another frame and draw into it to obtain an SkPicture to serialize
// Trace to a file if necessary
bool frameExceededThreshold = false;
if (layer_tree->rasterizer_tracing_threshold() * kOneFrameDuration >
paint_context_.frame_time().lastLap().InMillisecondsF()) {
// While rendering the last frame, if we exceeded the tracing threshold
// specified in the layer tree, we force a trace to disk.
frameExceededThreshold = true;
}
const auto& tracingController = Shell::Shared().tracing_controller();
auto options = Shell::Shared().tracing_controller().picture_tracing_options();
if (options.first) {
if (frameExceededThreshold || tracingController.picture_tracing_enabled()) {
base::FilePath path = tracingController.PictureTracingPathForCurrentTime();
sky::compositor::PaintContext::ScopedFrame to_file_frame =
paint_context_.AcquireFrame(options.second, size);
paint_context_.AcquireFrame(path.AsUTF8Unsafe(), size);
layer_tree->root_layer()->Paint(to_file_frame);
}
}
......
......@@ -101,20 +101,17 @@ class TouchMapper {
static std::string SkPictureTracingPath() {
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
char* temp = reinterpret_cast<char*>(calloc(256, sizeof(char)));
snprintf(temp, 256, "%s/layers.skp", [paths.firstObject UTF8String]);
std::string path(temp);
free(temp);
return path;
return [paths.firstObject UTF8String];
}
-(instancetype) initWithShellView:(sky::shell::ShellView *) shellView {
self = [super init];
if (self) {
sky::shell::Shell::Shared().tracing_controller().set_picture_tracing_path(
SkPictureTracingPath());
base::FilePath pictureTracingPath =
base::FilePath::FromUTF8Unsafe(SkPictureTracingPath());
sky::shell::Shell::Shared()
.tracing_controller()
.set_picture_tracing_base_path(pictureTracingPath);
_shell_view.reset(shellView);
self.multipleTouchEnabled = YES;
......
......@@ -10,6 +10,7 @@
#include "sky/shell/tracing_controller.h"
#include <string>
#include <sstream>
namespace sky {
namespace shell {
......@@ -120,21 +121,11 @@ void TracingController::UnregisterShellView(ShellView* view) {
view_ = nullptr;
}
TracingController::SkPictureTracingOptions
TracingController::picture_tracing_options() const {
return SkPictureTracingOptions(
picture_tracing_path_.length() == 0 ? false : picture_tracing_enabled_,
picture_tracing_path_ +
std::to_string((base::TimeTicks::Now() - trace_controller_start_)
.InMillisecondsRoundedUp()));
}
void TracingController::set_picture_tracing_path(const std::string& path) {
picture_tracing_path_ = path;
}
void TracingController::set_picture_tracing_enabled(bool enabled) {
picture_tracing_enabled_ = enabled;
base::FilePath TracingController::PictureTracingPathForCurrentTime() const {
base::TimeDelta duration = base::TimeTicks::Now() - trace_controller_start_;
std::stringstream stream;
stream << "trace_" << duration.InMillisecondsRoundedUp() << ".skp";
return picture_tracing_base_path_.Append(stream.str());
}
} // namespace shell
......
......@@ -36,13 +36,17 @@ class TracingController : public mojo::common::DataPipeDrainer::Client {
// be merged before viewing in the trace viewer
void StopTracing(const base::FilePath& path);
using SkPictureTracingOptions =
std::pair<bool /* enabled */, std::string /* path */>;
SkPictureTracingOptions picture_tracing_options() const;
base::FilePath PictureTracingPathForCurrentTime() const;
void set_picture_tracing_path(const std::string& path);
void set_picture_tracing_base_path(const base::FilePath& base_path) {
picture_tracing_base_path_ = base_path;
}
void set_picture_tracing_enabled(bool enabled);
void set_picture_tracing_enabled(bool enabled) {
picture_tracing_enabled_ = enabled;
}
bool picture_tracing_enabled() const { return picture_tracing_enabled_; }
private:
std::unique_ptr<mojo::common::DataPipeDrainer> drainer_;
......@@ -51,7 +55,7 @@ class TracingController : public mojo::common::DataPipeDrainer::Client {
// the ability to host multiple shell views, references to each must be stored
// instead and trace data from each serialized to the output trace.
ShellView* view_;
std::string picture_tracing_path_;
base::FilePath picture_tracing_base_path_;
bool picture_tracing_enabled_;
base::TimeTicks trace_controller_start_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册