Skip to content

Commit

Permalink
Port //flow to //lib/ftl (flutter#2847)
Browse files Browse the repository at this point in the history
This patch removes almost all //base dependency of //flow. The only dependency
left is on tracing.
  • Loading branch information
abarth authored Aug 1, 2016
1 parent 27a77e4 commit d6476a6
Show file tree
Hide file tree
Showing 51 changed files with 236 additions and 258 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Thumbs.db
/build/linux/bin/eu-strip
/buildtools/
/dart/
/lib/
/mojo/devtools/
/mojo/public/
/native_client/
Expand Down
1 change: 1 addition & 0 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ source_set("flow") {

deps = [
"//base",
"//lib/ftl",
"//mojo/services/gfx/composition/interfaces",
"//mojo/skia",
"//skia",
Expand Down
3 changes: 2 additions & 1 deletion flow/checkerboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

namespace flow {

static sk_sp<SkShader> CreateCheckerboardShader(SkColor c1, SkColor c2,
static sk_sp<SkShader> CreateCheckerboardShader(SkColor c1,
SkColor c2,
int size) {
SkBitmap bm;
bm.allocN32Pixels(2 * size, 2 * size);
Expand Down
15 changes: 8 additions & 7 deletions flow/compositor_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

#include "flow/compositor_context.h"

#include "base/logging.h"
#include "third_party/skia/include/core/SkCanvas.h"

namespace flow {

CompositorContext::CompositorContext() {
}
CompositorContext::CompositorContext() {}

CompositorContext::~CompositorContext() {
}
CompositorContext::~CompositorContext() {}

void CompositorContext::BeginFrame(ScopedFrame& frame,
bool enable_instrumentation) {
Expand All @@ -32,15 +29,19 @@ void CompositorContext::EndFrame(ScopedFrame& frame,
}

CompositorContext::ScopedFrame CompositorContext::AcquireFrame(
GrContext* gr_context, SkCanvas& canvas, bool instrumentation_enabled) {
GrContext* gr_context,
SkCanvas& canvas,
bool instrumentation_enabled) {
return ScopedFrame(*this, gr_context, canvas, instrumentation_enabled);
}

CompositorContext::ScopedFrame::ScopedFrame(CompositorContext& context,
GrContext* gr_context,
SkCanvas& canvas,
bool instrumentation_enabled)
: context_(context), gr_context_(gr_context), canvas_(&canvas),
: context_(context),
gr_context_(gr_context),
canvas_(&canvas),
instrumentation_enabled_(instrumentation_enabled) {
context_.BeginFrame(*this, instrumentation_enabled_);
}
Expand Down
7 changes: 3 additions & 4 deletions flow/compositor_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#include <memory>
#include <string>

#include "base/macros.h"
#include "base/logging.h"
#include "flow/instrumentation.h"
#include "flow/raster_cache.h"
#include "lib/ftl/macros.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"

Expand Down Expand Up @@ -41,7 +40,7 @@ class CompositorContext {

friend class CompositorContext;

DISALLOW_COPY_AND_ASSIGN(ScopedFrame);
FTL_DISALLOW_COPY_AND_ASSIGN(ScopedFrame);
};

CompositorContext();
Expand All @@ -68,7 +67,7 @@ class CompositorContext {
void BeginFrame(ScopedFrame& frame, bool enable_instrumentation);
void EndFrame(ScopedFrame& frame, bool enable_instrumentation);

DISALLOW_COPY_AND_ASSIGN(CompositorContext);
FTL_DISALLOW_COPY_AND_ASSIGN(CompositorContext);
};

} // namespace flow
Expand Down
54 changes: 33 additions & 21 deletions flow/instrumentation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,43 @@ namespace flow {
static const size_t kMaxSamples = 120;
static const size_t kMaxFrameMarkers = 8;

Stopwatch::Stopwatch() : start_(base::TimeTicks::Now()), current_sample_(0) {
const base::TimeDelta delta;
Stopwatch::Stopwatch() : start_(ftl::TimePoint::Now()), current_sample_(0) {
const ftl::TimeDelta delta;
laps_.resize(kMaxSamples, delta);
}

void Stopwatch::Start() {
start_ = base::TimeTicks::Now();
start_ = ftl::TimePoint::Now();
current_sample_ = (current_sample_ + 1) % kMaxSamples;
}

void Stopwatch::Stop() {
laps_[current_sample_] = base::TimeTicks::Now() - start_;
laps_[current_sample_] = ftl::TimePoint::Now() - start_;
}

void Stopwatch::SetLapTime(const base::TimeDelta& delta) {
void Stopwatch::SetLapTime(const ftl::TimeDelta& delta) {
current_sample_ = (current_sample_ + 1) % kMaxSamples;
laps_[current_sample_] = delta;
}

const base::TimeDelta& Stopwatch::LastLap() const {
const ftl::TimeDelta& Stopwatch::LastLap() const {
return laps_[(current_sample_ - 1) % kMaxSamples];
}

static inline constexpr double UnitFrameInterval(double frame_time_ms) {
return frame_time_ms * 60.0 * 1e-3;
}

static inline double UnitHeight(double frame_time_ms, double max_unit_interval) {
static inline double UnitHeight(double frame_time_ms,
double max_unit_interval) {
double unitHeight = UnitFrameInterval(frame_time_ms) / max_unit_interval;
if (unitHeight > 1.0)
unitHeight = 1.0;
return unitHeight;
}

base::TimeDelta Stopwatch::MaxDelta() const {
base::TimeDelta max_delta;
ftl::TimeDelta Stopwatch::MaxDelta() const {
ftl::TimeDelta max_delta;
for (size_t i = 0; i < kMaxSamples; i++) {
if (laps_[i] > max_delta)
max_delta = laps_[i];
Expand All @@ -71,7 +72,8 @@ void Stopwatch::Visualize(SkCanvas& canvas, const SkRect& rect) const {
const SkScalar bottom = y + height;
const SkScalar right = x + width;

// Scale the graph to show frame times up to those that are 3 times the frame time.
// Scale the graph to show frame times up to those that are 3 times the frame
// time.
const double max_interval = kOneFrameMS * 3.0;
const double max_unit_interval = UnitFrameInterval(max_interval);

Expand All @@ -82,20 +84,26 @@ void Stopwatch::Visualize(SkCanvas& canvas, const SkRect& rect) const {
const double sample_margin_unit_width = sample_unit_width / 6.0;
const double sample_margin_width = width * sample_margin_unit_width;
path.moveTo(x, bottom);
path.lineTo(x, y + height * (1.0 - UnitHeight(laps_[0].InMillisecondsF(),
path.lineTo(x, y +
height * (1.0 - UnitHeight(laps_[0].ToMillisecondsF(),
max_unit_interval)));
double unit_x;
double unit_next_x = 0.0;
for (size_t i = 0; i < kMaxSamples; i += 1) {
unit_x = unit_next_x;
unit_next_x = (static_cast<double>(i + 1) / kMaxSamples);
const double sample_y = y + height * (1.0 - UnitHeight(laps_[i].InMillisecondsF(),
max_unit_interval));
const double sample_y =
y +
height *
(1.0 - UnitHeight(laps_[i].ToMillisecondsF(), max_unit_interval));
path.lineTo(x + width * unit_x + sample_margin_width, sample_y);
path.lineTo(x + width * unit_next_x - sample_margin_width, sample_y);
}
path.lineTo(right, y + height * (1.0 - UnitHeight(laps_[kMaxSamples - 1].InMillisecondsF(),
max_unit_interval)));
path.lineTo(
right,
y +
height * (1.0 - UnitHeight(laps_[kMaxSamples - 1].ToMillisecondsF(),
max_unit_interval)));
path.lineTo(right, bottom);
path.close();

Expand All @@ -104,7 +112,7 @@ void Stopwatch::Visualize(SkCanvas& canvas, const SkRect& rect) const {
canvas.drawPath(path, paint);

// Draw horizontal markers.
paint.setStrokeWidth(0); // hairline
paint.setStrokeWidth(0); // hairline
paint.setStyle(SkPaint::Style::kStroke_Style);
paint.setColor(0xCC000000);

Expand All @@ -117,7 +125,8 @@ void Stopwatch::Visualize(SkCanvas& canvas, const SkRect& rect) const {
if (frame_marker_count > kMaxFrameMarkers)
frame_marker_count = 1;

for (size_t frame_index = 0; frame_index < frame_marker_count; frame_index++) {
for (size_t frame_index = 0; frame_index < frame_marker_count;
frame_index++) {
const double frame_height =
height * (1.0 - (UnitFrameInterval((frame_index + 1) * kOneFrameMS) /
max_unit_interval));
Expand All @@ -129,16 +138,19 @@ void Stopwatch::Visualize(SkCanvas& canvas, const SkRect& rect) const {
// We paint it over the current frame, not after it, because when we
// paint this we don't yet have all the times for the current frame.
paint.setStyle(SkPaint::Style::kFill_Style);
if (UnitFrameInterval(LastLap().InMillisecondsF()) > 1.0) {
if (UnitFrameInterval(LastLap().ToMillisecondsF()) > 1.0) {
// budget exceeded
paint.setColor(SK_ColorRED);
} else {
// within budget
paint.setColor(SK_ColorGREEN);
}
double sample_x = x + width * (static_cast<double>(current_sample_) / kMaxSamples)
- sample_margin_width;
canvas.drawRectCoords(sample_x, y, sample_x + width * sample_unit_width + sample_margin_width * 2, bottom, paint);
double sample_x =
x + width * (static_cast<double>(current_sample_) / kMaxSamples) -
sample_margin_width;
canvas.drawRectCoords(sample_x, y, sample_x + width * sample_unit_width +
sample_margin_width * 2,
bottom, paint);
}

Stopwatch::~Stopwatch() = default;
Expand Down
24 changes: 13 additions & 11 deletions flow/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#define FLOW_INSTRUMENTATION_H_

#include <vector>
#include "base/macros.h"
#include "base/time/time.h"

#include "lib/ftl/macros.h"
#include "lib/ftl/time/time_delta.h"
#include "lib/ftl/time/time_point.h"
#include "third_party/skia/include/core/SkCanvas.h"

namespace flow {
Expand All @@ -27,26 +29,26 @@ class Stopwatch {
private:
Stopwatch& stopwatch_;

DISALLOW_COPY_AND_ASSIGN(ScopedLap);
FTL_DISALLOW_COPY_AND_ASSIGN(ScopedLap);
};

explicit Stopwatch();
~Stopwatch();

const base::TimeDelta& LastLap() const;
base::TimeDelta CurrentLap() const { return base::TimeTicks::Now() - start_; }
base::TimeDelta MaxDelta() const;
const ftl::TimeDelta& LastLap() const;
ftl::TimeDelta CurrentLap() const { return ftl::TimePoint::Now() - start_; }
ftl::TimeDelta MaxDelta() const;
void Visualize(SkCanvas& canvas, const SkRect& rect) const;
void Start();
void Stop();
void SetLapTime(const base::TimeDelta& delta);
void SetLapTime(const ftl::TimeDelta& delta);

private:
base::TimeTicks start_;
std::vector<base::TimeDelta> laps_;
ftl::TimePoint start_;
std::vector<ftl::TimeDelta> laps_;
size_t current_sample_;

DISALLOW_COPY_AND_ASSIGN(Stopwatch);
FTL_DISALLOW_COPY_AND_ASSIGN(Stopwatch);
};

class Counter {
Expand All @@ -60,7 +62,7 @@ class Counter {
private:
size_t count_;

DISALLOW_COPY_AND_ASSIGN(Counter);
FTL_DISALLOW_COPY_AND_ASSIGN(Counter);
};

} // namespace flow
Expand Down
10 changes: 4 additions & 6 deletions flow/layers/backdrop_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@

namespace flow {

BackdropFilterLayer::BackdropFilterLayer() {
}
BackdropFilterLayer::BackdropFilterLayer() {}

BackdropFilterLayer::~BackdropFilterLayer() {
}
BackdropFilterLayer::~BackdropFilterLayer() {}

void BackdropFilterLayer::Paint(PaintContext& context) {
TRACE_EVENT0("flutter", "BackdropFilterLayer::Paint");
SkAutoCanvasRestore save(&context.canvas, false);
context.canvas.saveLayer(SkCanvas::SaveLayerRec{
&paint_bounds(), nullptr, filter_.get(), 0});
context.canvas.saveLayer(
SkCanvas::SaveLayerRec{&paint_bounds(), nullptr, filter_.get(), 0});
PaintChildren(context);
}

Expand Down
2 changes: 1 addition & 1 deletion flow/layers/backdrop_filter_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BackdropFilterLayer : public ContainerLayer {
private:
sk_sp<SkImageFilter> filter_;

DISALLOW_COPY_AND_ASSIGN(BackdropFilterLayer);
FTL_DISALLOW_COPY_AND_ASSIGN(BackdropFilterLayer);
};

} // namespace flow
Expand Down
6 changes: 2 additions & 4 deletions flow/layers/child_scene_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ namespace flow {
// TODO(abarth): We need to figure out how to allocate these ids sensibly.
static uint32_t next_id = 10;

ChildSceneLayer::ChildSceneLayer() : device_pixel_ratio_(1.0f) {
}
ChildSceneLayer::ChildSceneLayer() : device_pixel_ratio_(1.0f) {}

ChildSceneLayer::~ChildSceneLayer() {
}
ChildSceneLayer::~ChildSceneLayer() {}

void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
transform_ = matrix;
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/child_scene_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ChildSceneLayer : public Layer {
mojo::gfx::composition::SceneTokenPtr scene_token_;
SkMatrix transform_;

DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer);
FTL_DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer);
};

} // namespace flow
Expand Down
6 changes: 2 additions & 4 deletions flow/layers/clip_path_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

namespace flow {

ClipPathLayer::ClipPathLayer() {
}
ClipPathLayer::ClipPathLayer() {}

ClipPathLayer::~ClipPathLayer() {
}
ClipPathLayer::~ClipPathLayer() {}

void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
PrerollChildren(context, matrix);
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/clip_path_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ClipPathLayer : public ContainerLayer {
private:
SkPath clip_path_;

DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
FTL_DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
};

} // namespace flow
Expand Down
6 changes: 2 additions & 4 deletions flow/layers/clip_rect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

namespace flow {

ClipRectLayer::ClipRectLayer() {
}
ClipRectLayer::ClipRectLayer() {}

ClipRectLayer::~ClipRectLayer() {
}
ClipRectLayer::~ClipRectLayer() {}

void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
PrerollChildren(context, matrix);
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/clip_rect_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ClipRectLayer : public ContainerLayer {
private:
SkRect clip_rect_;

DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
FTL_DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
};

} // namespace flow
Expand Down
Loading

0 comments on commit d6476a6

Please sign in to comment.