Skip to content

Commit

Permalink
add flow events to the timeline to track the lifecycle of cache images (
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Oct 25, 2021
1 parent f9bd71b commit 842cb87
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
16 changes: 10 additions & 6 deletions flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
namespace flutter {

RasterCacheResult::RasterCacheResult(sk_sp<SkImage> image,
const SkRect& logical_rect)
: image_(std::move(image)), logical_rect_(logical_rect) {}
const SkRect& logical_rect,
const char* type)
: image_(std::move(image)), logical_rect_(logical_rect), flow_(type) {}

void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
TRACE_EVENT0("flutter", "RasterCacheResult::draw");
Expand All @@ -32,6 +33,7 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
std::abs(bounds.size().width() - image_->dimensions().width()) <= 1 &&
std::abs(bounds.size().height() - image_->dimensions().height()) <= 1);
canvas.resetMatrix();
flow_.Step();
canvas.drawImage(image_, bounds.fLeft, bounds.fTop, SkSamplingOptions(),
paint);
}
Expand Down Expand Up @@ -117,6 +119,7 @@ static std::unique_ptr<RasterCacheResult> Rasterize(
SkColorSpace* dst_color_space,
bool checkerboard,
const SkRect& logical_rect,
const char* type,
const std::function<void(SkCanvas*)>& draw_function) {
TRACE_EVENT0("flutter", "RasterCachePopulate");
SkIRect cache_rect = RasterCache::GetDeviceBounds(logical_rect, ctm);
Expand Down Expand Up @@ -144,7 +147,7 @@ static std::unique_ptr<RasterCacheResult> Rasterize(
}

return std::make_unique<RasterCacheResult>(surface->makeImageSnapshot(),
logical_rect);
logical_rect, type);
}

std::unique_ptr<RasterCacheResult> RasterCache::RasterizePicture(
Expand All @@ -154,7 +157,7 @@ std::unique_ptr<RasterCacheResult> RasterCache::RasterizePicture(
SkColorSpace* dst_color_space,
bool checkerboard) const {
return Rasterize(context, ctm, dst_color_space, checkerboard,
picture->cullRect(),
picture->cullRect(), "RasterCacheFlow::SkPicture",
[=](SkCanvas* canvas) { canvas->drawPicture(picture); });
}

Expand All @@ -165,7 +168,7 @@ std::unique_ptr<RasterCacheResult> RasterCache::RasterizeDisplayList(
SkColorSpace* dst_color_space,
bool checkerboard) const {
return Rasterize(context, ctm, dst_color_space, checkerboard,
display_list->bounds(),
display_list->bounds(), "RasterCacheFlow::DisplayList",
[=](SkCanvas* canvas) { display_list->RenderTo(canvas); });
}

Expand All @@ -188,7 +191,8 @@ std::unique_ptr<RasterCacheResult> RasterCache::RasterizeLayer(
bool checkerboard) const {
return Rasterize(
context->gr_context, ctm, context->dst_color_space, checkerboard,
layer->paint_bounds(), [layer, context](SkCanvas* canvas) {
layer->paint_bounds(), "RasterCacheFlow::Layer",
[layer, context](SkCanvas* canvas) {
SkISize canvas_size = canvas->getBaseLayerSize();
SkNWayCanvas internal_nodes_canvas(canvas_size.width(),
canvas_size.height());
Expand Down
6 changes: 5 additions & 1 deletion flow/raster_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
#include "flutter/flow/raster_cache_key.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/trace_event.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSize.h"

namespace flutter {

class RasterCacheResult {
public:
RasterCacheResult(sk_sp<SkImage> image, const SkRect& logical_rect);
RasterCacheResult(sk_sp<SkImage> image,
const SkRect& logical_rect,
const char* type);

virtual ~RasterCacheResult() = default;

Expand All @@ -36,6 +39,7 @@ class RasterCacheResult {
private:
sk_sp<SkImage> image_;
SkRect logical_rect_;
fml::tracing::TraceFlow flow_;
};

struct PrerollContext;
Expand Down
2 changes: 1 addition & 1 deletion flow/testing/mock_raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace flutter {
namespace testing {

MockRasterCacheResult::MockRasterCacheResult(SkIRect device_rect)
: RasterCacheResult(nullptr, SkRect::MakeEmpty()),
: RasterCacheResult(nullptr, SkRect::MakeEmpty(), "RasterCacheFlow::test"),
device_rect_(device_rect) {}

std::unique_ptr<RasterCacheResult> MockRasterCache::RasterizePicture(
Expand Down
6 changes: 3 additions & 3 deletions fml/trace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ class TraceFlow {
other.nonce_ = 0;
}

void Step(const char* label) const {
TraceEventFlowStep0("flutter", label, nonce_);
void Step(const char* label = nullptr) const {
TraceEventFlowStep0("flutter", label ? label : label_, nonce_);
}

void End(const char* label = nullptr) {
if (nonce_ != 0) {
TraceEventFlowEnd0("flutter", label == nullptr ? label_ : label, nonce_);
TraceEventFlowEnd0("flutter", label ? label : label_, nonce_);
nonce_ = 0;
}
}
Expand Down

0 comments on commit 842cb87

Please sign in to comment.