Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Updates in flutter/flow for the shell refactor (Patch 4). #4832

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ source_set("flow") {
"matrix_decomposition.h",
"paint_utils.cc",
"paint_utils.h",
"process_info.h",
"raster_cache.cc",
"raster_cache.h",
"raster_cache_key.cc",
"raster_cache_key.h",
"skia_gpu_object.cc",
"skia_gpu_object.h",
"texture.cc",
"texture.h",
]
Expand All @@ -61,12 +62,11 @@ source_set("flow") {
"//garnet/public/lib/fxl",
]

public_configs = [
"$flutter_root:config",
]
public_configs = [ "$flutter_root:config" ]

deps = [
"$flutter_root/common",
"$flutter_root/fml",
"$flutter_root/glue",
"$flutter_root/synchronization",
"//third_party/skia",
Expand Down Expand Up @@ -103,8 +103,8 @@ executable("flow_unittests") {

deps = [
":flow",
"//third_party/dart/runtime:libdart_jit", # for tracing
"$flutter_root/testing",
"//third_party/dart/runtime:libdart_jit", # for tracing
"//third_party/skia",
]
}
26 changes: 14 additions & 12 deletions flow/compositor_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include "flutter/flow/compositor_context.h"

#include "flutter/flow/layers/layer_tree.h"
#include "third_party/skia/include/core/SkCanvas.h"

namespace flow {

CompositorContext::CompositorContext(std::unique_ptr<ProcessInfo> info)
: process_info_(std::move(info)) {}
CompositorContext::CompositorContext() = default;

CompositorContext::~CompositorContext() = default;

Expand All @@ -18,10 +18,6 @@ void CompositorContext::BeginFrame(ScopedFrame& frame,
if (enable_instrumentation) {
frame_count_.Increment();
frame_time_.Start();

if (process_info_ && process_info_->SampleNow()) {
memory_usage_.Add(process_info_->GetResidentMemorySize());
}
}
}

Expand All @@ -33,11 +29,12 @@ void CompositorContext::EndFrame(ScopedFrame& frame,
}
}

CompositorContext::ScopedFrame CompositorContext::AcquireFrame(
std::unique_ptr<CompositorContext::ScopedFrame> CompositorContext::AcquireFrame(
GrContext* gr_context,
SkCanvas* canvas,
bool instrumentation_enabled) {
return ScopedFrame(*this, gr_context, canvas, instrumentation_enabled);
return std::make_unique<ScopedFrame>(*this, gr_context, canvas,
instrumentation_enabled);
}

CompositorContext::ScopedFrame::ScopedFrame(CompositorContext& context,
Expand All @@ -51,18 +48,23 @@ CompositorContext::ScopedFrame::ScopedFrame(CompositorContext& context,
context_.BeginFrame(*this, instrumentation_enabled_);
}

CompositorContext::ScopedFrame::ScopedFrame(ScopedFrame&& frame) = default;

CompositorContext::ScopedFrame::~ScopedFrame() {
context_.EndFrame(*this, instrumentation_enabled_);
}

bool CompositorContext::ScopedFrame::Raster(flow::LayerTree& layer_tree,
bool ignore_raster_cache) {
layer_tree.Preroll(*this, ignore_raster_cache);
layer_tree.Paint(*this);
return true;
}

void CompositorContext::OnGrContextCreated() {
texture_registry_->OnGrContextCreated();
texture_registry_.OnGrContextCreated();
}

void CompositorContext::OnGrContextDestroyed() {
texture_registry_->OnGrContextDestroyed();
texture_registry_.OnGrContextDestroyed();
raster_cache_.Clear();
}

Expand Down
44 changes: 18 additions & 26 deletions flow/compositor_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <string>

#include "flutter/flow/instrumentation.h"
#include "flutter/flow/process_info.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/flow/texture.h"
#include "lib/fxl/macros.h"
Expand All @@ -18,72 +17,65 @@

namespace flow {

class LayerTree;

class CompositorContext {
public:
class ScopedFrame {
public:
ScopedFrame(CompositorContext& context,
GrContext* gr_context,
SkCanvas* canvas,
bool instrumentation_enabled);

virtual ~ScopedFrame();

SkCanvas* canvas() { return canvas_; }

CompositorContext& context() const { return context_; }

GrContext* gr_context() const { return gr_context_; }

ScopedFrame(ScopedFrame&& frame);

~ScopedFrame();
virtual bool Raster(LayerTree& layer_tree, bool ignore_raster_cache);

private:
CompositorContext& context_;
GrContext* gr_context_;
SkCanvas* canvas_;
const bool instrumentation_enabled_;

ScopedFrame(CompositorContext& context,
GrContext* gr_context,
SkCanvas* canvas,
bool instrumentation_enabled);

friend class CompositorContext;

FXL_DISALLOW_COPY_AND_ASSIGN(ScopedFrame);
};

CompositorContext(std::unique_ptr<ProcessInfo> info);
CompositorContext();

~CompositorContext();
virtual ~CompositorContext();

ScopedFrame AcquireFrame(GrContext* gr_context,
SkCanvas* canvas,
bool instrumentation_enabled = true);
virtual std::unique_ptr<ScopedFrame> AcquireFrame(
GrContext* gr_context,
SkCanvas* canvas,
bool instrumentation_enabled);

void OnGrContextCreated();

void OnGrContextDestroyed();

RasterCache& raster_cache() { return raster_cache_; }

TextureRegistry& texture_registry() { return *texture_registry_; }
TextureRegistry& texture_registry() { return texture_registry_; }

const Counter& frame_count() const { return frame_count_; }

const Stopwatch& frame_time() const { return frame_time_; }

Stopwatch& engine_time() { return engine_time_; }

const CounterValues& memory_usage() const { return memory_usage_; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wondering where this went and the answer is apparently we never used it. Nice! :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only ever wired up on iOS and never exposed in the framework.


void SetTextureRegistry(TextureRegistry* textureRegistry) {
texture_registry_ = textureRegistry;
}

private:
RasterCache raster_cache_;
TextureRegistry* texture_registry_;
std::unique_ptr<ProcessInfo> process_info_;
TextureRegistry texture_registry_;
Counter frame_count_;
Stopwatch frame_time_;
Stopwatch engine_time_;
CounterValues memory_usage_;

void BeginFrame(ScopedFrame& frame, bool enable_instrumentation);

Expand Down
5 changes: 5 additions & 0 deletions flow/debug_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ std::ostream& operator<<(std::ostream& os, const flow::RasterCacheKey& k) {
;
return os;
}

std::ostream& operator<<(std::ostream& os, const SkISize& size) {
os << size.width() << ", " << size.height();
return os;
}
9 changes: 5 additions & 4 deletions flow/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

#define DEF_PRINTER(x) std::ostream& operator<<(std::ostream&, const x&);

DEF_PRINTER(flow::RasterCacheKey);
DEF_PRINTER(flow::MatrixDecomposition);
DEF_PRINTER(flow::RasterCacheKey);
DEF_PRINTER(SkISize);
DEF_PRINTER(SkMatrix);
DEF_PRINTER(SkMatrix44);
DEF_PRINTER(SkVector3);
DEF_PRINTER(SkVector4);
DEF_PRINTER(SkPoint);
DEF_PRINTER(SkRect);
DEF_PRINTER(SkRRect);
DEF_PRINTER(SkPoint);
DEF_PRINTER(SkVector3);
DEF_PRINTER(SkVector4);

#endif // FLUTTER_FLOW_DEBUG_PRINT_H_
15 changes: 5 additions & 10 deletions flow/export_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@

#include "flutter/flow/export_node.h"

#include "flutter/common/threads.h"
#include "lib/fxl/functional/make_copyable.h"

namespace flow {

ExportNodeHolder::ExportNodeHolder(
fxl::RefPtr<fxl::TaskRunner> gpu_task_runner,
fxl::RefPtr<zircon::dart::Handle> export_token_handle)
: export_node_(std::make_unique<ExportNode>(export_token_handle)) {
ASSERT_IS_UI_THREAD;
: gpu_task_runner_(std::move(gpu_task_runner)),
export_node_(std::make_unique<ExportNode>(export_token_handle)) {
FXL_DCHECK(gpu_task_runner_);
}

void ExportNodeHolder::Bind(SceneUpdateContext& context,
scenic_lib::ContainerNode& container,
const SkPoint& offset,
bool hit_testable) {
ASSERT_IS_GPU_THREAD;
export_node_->Bind(context, container, offset, hit_testable);
}

ExportNodeHolder::~ExportNodeHolder() {
ASSERT_IS_UI_THREAD;
blink::Threads::Gpu()->PostTask(
gpu_task_runner_->PostTask(
fxl::MakeCopyable([export_node = std::move(export_node_)]() {
export_node->Dispose(true);
}));
Expand All @@ -44,8 +43,6 @@ void ExportNode::Bind(SceneUpdateContext& context,
scenic_lib::ContainerNode& container,
const SkPoint& offset,
bool hit_testable) {
ASSERT_IS_GPU_THREAD;

if (export_token_) {
// Happens first time we bind.
node_.reset(new scenic_lib::EntityNode(container.session()));
Expand All @@ -67,8 +64,6 @@ void ExportNode::Bind(SceneUpdateContext& context,
}

void ExportNode::Dispose(bool remove_from_scene_update_context) {
ASSERT_IS_GPU_THREAD;

// If scene_update_context_ is set, then we should still have a node left to
// dereference.
// If scene_update_context_ is null, then either:
Expand Down
5 changes: 4 additions & 1 deletion flow/export_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/ref_counted.h"
#include "lib/ui/scenic/client/resources.h"
#include "third_party/flutter/fml/task_runner.h"
#include "third_party/skia/include/core/SkPoint.h"

namespace flow {
Expand All @@ -24,7 +25,8 @@ namespace flow {
// held by the ExportNode.
class ExportNodeHolder : public fxl::RefCountedThreadSafe<ExportNodeHolder> {
public:
ExportNodeHolder(fxl::RefPtr<zircon::dart::Handle> export_token_handle);
ExportNodeHolder(fxl::RefPtr<fxl::TaskRunner> gpu_task_runner,
fxl::RefPtr<zircon::dart::Handle> export_token_handle);
~ExportNodeHolder();

// Calls Bind() on the wrapped ExportNode.
Expand All @@ -36,6 +38,7 @@ class ExportNodeHolder : public fxl::RefCountedThreadSafe<ExportNodeHolder> {
ExportNode* export_node() { return export_node_.get(); }

private:
fxl::RefPtr<fxl::TaskRunner> gpu_task_runner_;
std::unique_ptr<ExportNode> export_node_;

FRIEND_MAKE_REF_COUNTED(ExportNodeHolder);
Expand Down
6 changes: 3 additions & 3 deletions flow/layers/default_layer_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ void DefaultLayerBuilder::PushPerformanceOverlay(uint64_t enabled_options,
}

void DefaultLayerBuilder::PushPicture(const SkPoint& offset,
sk_sp<SkPicture> picture,
SkiaGPUObject<SkPicture> picture,
bool picture_is_complex,
bool picture_will_change) {
if (!current_layer_) {
return;
}
SkRect pictureRect = picture->cullRect();
SkRect pictureRect = picture.get()->cullRect();
pictureRect.offset(offset.x(), offset.y());
if (!SkRect::Intersects(pictureRect, cull_rects_.top())) {
return;
}
auto layer = std::make_unique<flow::PictureLayer>();
layer->set_offset(offset);
layer->set_picture(picture);
layer->set_picture(std::move(picture));
layer->set_is_complex(picture_is_complex);
layer->set_will_change(picture_will_change);
current_layer_->Add(std::move(layer));
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/default_layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DefaultLayerBuilder final : public LayerBuilder {

// |flow::LayerBuilder|
void PushPicture(const SkPoint& offset,
sk_sp<SkPicture> picture,
SkiaGPUObject<SkPicture> picture,
bool picture_is_complex,
bool picture_will_change) override;

Expand Down
4 changes: 0 additions & 4 deletions flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class Layer {
virtual ~Layer();

struct PrerollContext {
#if defined(OS_FUCHSIA)
ui::gfx::Metrics* metrics = nullptr;
#endif
RasterCache* raster_cache;
GrContext* gr_context;
SkColorSpace* dst_color_space;
Expand All @@ -59,7 +56,6 @@ class Layer {
SkCanvas& canvas;
const Stopwatch& frame_time;
const Stopwatch& engine_time;
const CounterValues& memory_usage;
TextureRegistry& texture_registry;
const bool checkerboard_offscreen_layers;
};
Expand Down
3 changes: 2 additions & 1 deletion flow/layers/layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>

#include "flutter/flow/layers/layer.h"
#include "flutter/flow/skia_gpu_object.h"
#include "garnet/public/lib/fxl/macros.h"
#include "third_party/skia/include/core/SkBlendMode.h"
#include "third_party/skia/include/core/SkColor.h"
Expand Down Expand Up @@ -57,7 +58,7 @@ class LayerBuilder {
const SkRect& rect) = 0;

virtual void PushPicture(const SkPoint& offset,
sk_sp<SkPicture> picture,
SkiaGPUObject<SkPicture> picture,
bool picture_is_complex,
bool picture_will_change) = 0;

Expand Down
Loading