Remove all dependencies on Garnet. (flutter/engine#5869)
This commit is contained in:
3
DEPS
3
DEPS
@@ -122,9 +122,6 @@ deps = {
|
||||
# build. Eventually, we'll manage these dependencies together with Fuchsia
|
||||
# and not have to specific specific hashes.
|
||||
|
||||
'src/garnet':
|
||||
Var('fuchsia_git') + '/garnet' + '@' + 'b7492b5f34e32248b164eb48ae8e67995aebda67',
|
||||
|
||||
'src/third_party/tonic':
|
||||
Var('fuchsia_git') + '/tonic' + '@' + '57d508b12462db686573edcbc97891d90cf92f90',
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ group("flutter") {
|
||||
"$flutter_root/shell/platform/embedder:flutter_engine",
|
||||
"$flutter_root/synchronization:synchronization_unittests",
|
||||
"$flutter_root/third_party/txt:txt_unittests",
|
||||
"//garnet/public/lib/fxl:fxl_unittests",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ source_set("common") {
|
||||
|
||||
deps = [
|
||||
"$flutter_root/fml",
|
||||
"//garnet/public/lib/fxl",
|
||||
]
|
||||
|
||||
public_configs = [
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/closure.h"
|
||||
#include "flutter/fml/unique_fd.h"
|
||||
#include "lib/fxl/functional/closure.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
using TaskObserverAdd =
|
||||
std::function<void(intptr_t /* key */, fxl::Closure /* callback */)>;
|
||||
std::function<void(intptr_t /* key */, fml::closure /* callback */)>;
|
||||
using TaskObserverRemove = std::function<void(intptr_t /* key */)>;
|
||||
|
||||
struct Settings {
|
||||
@@ -70,10 +70,10 @@ struct Settings {
|
||||
TaskObserverRemove task_observer_remove;
|
||||
// The main isolate is current when this callback is made. This is a good spot
|
||||
// to perform native Dart bindings for libraries not built in.
|
||||
fxl::Closure root_isolate_create_callback;
|
||||
fml::closure root_isolate_create_callback;
|
||||
// The isolate is not current and may have already been destroyed when this
|
||||
// call is made.
|
||||
fxl::Closure root_isolate_shutdown_callback;
|
||||
fml::closure root_isolate_shutdown_callback;
|
||||
bool enable_software_rendering = false;
|
||||
bool skia_deterministic_rendering_on_cpu = false;
|
||||
bool verbose_logging = false;
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
namespace blink {
|
||||
|
||||
TaskRunners::TaskRunners(std::string label,
|
||||
fxl::RefPtr<fxl::TaskRunner> platform,
|
||||
fxl::RefPtr<fxl::TaskRunner> gpu,
|
||||
fxl::RefPtr<fxl::TaskRunner> ui,
|
||||
fxl::RefPtr<fxl::TaskRunner> io)
|
||||
fml::RefPtr<fml::TaskRunner> platform,
|
||||
fml::RefPtr<fml::TaskRunner> gpu,
|
||||
fml::RefPtr<fml::TaskRunner> ui,
|
||||
fml::RefPtr<fml::TaskRunner> io)
|
||||
: label_(std::move(label)),
|
||||
platform_(std::move(platform)),
|
||||
gpu_(std::move(gpu)),
|
||||
@@ -25,19 +25,19 @@ const std::string& TaskRunners::GetLabel() const {
|
||||
return label_;
|
||||
}
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> TaskRunners::GetPlatformTaskRunner() const {
|
||||
fml::RefPtr<fml::TaskRunner> TaskRunners::GetPlatformTaskRunner() const {
|
||||
return platform_;
|
||||
}
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> TaskRunners::GetUITaskRunner() const {
|
||||
fml::RefPtr<fml::TaskRunner> TaskRunners::GetUITaskRunner() const {
|
||||
return ui_;
|
||||
}
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> TaskRunners::GetIOTaskRunner() const {
|
||||
fml::RefPtr<fml::TaskRunner> TaskRunners::GetIOTaskRunner() const {
|
||||
return io_;
|
||||
}
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> TaskRunners::GetGPUTaskRunner() const {
|
||||
fml::RefPtr<fml::TaskRunner> TaskRunners::GetGPUTaskRunner() const {
|
||||
return gpu_;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,40 +7,41 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/tasks/task_runner.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/task_runner.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class TaskRunners {
|
||||
public:
|
||||
TaskRunners(std::string label,
|
||||
fxl::RefPtr<fxl::TaskRunner> platform,
|
||||
fxl::RefPtr<fxl::TaskRunner> gpu,
|
||||
fxl::RefPtr<fxl::TaskRunner> ui,
|
||||
fxl::RefPtr<fxl::TaskRunner> io);
|
||||
fml::RefPtr<fml::TaskRunner> platform,
|
||||
fml::RefPtr<fml::TaskRunner> gpu,
|
||||
fml::RefPtr<fml::TaskRunner> ui,
|
||||
fml::RefPtr<fml::TaskRunner> io);
|
||||
|
||||
~TaskRunners();
|
||||
|
||||
const std::string& GetLabel() const;
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> GetPlatformTaskRunner() const;
|
||||
fml::RefPtr<fml::TaskRunner> GetPlatformTaskRunner() const;
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> GetUITaskRunner() const;
|
||||
fml::RefPtr<fml::TaskRunner> GetUITaskRunner() const;
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> GetIOTaskRunner() const;
|
||||
fml::RefPtr<fml::TaskRunner> GetIOTaskRunner() const;
|
||||
|
||||
fxl::RefPtr<fxl::TaskRunner> GetGPUTaskRunner() const;
|
||||
fml::RefPtr<fml::TaskRunner> GetGPUTaskRunner() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
const std::string label_;
|
||||
fxl::RefPtr<fxl::TaskRunner> platform_;
|
||||
fxl::RefPtr<fxl::TaskRunner> gpu_;
|
||||
fxl::RefPtr<fxl::TaskRunner> ui_;
|
||||
fxl::RefPtr<fxl::TaskRunner> io_;
|
||||
fml::RefPtr<fml::TaskRunner> platform_;
|
||||
fml::RefPtr<fml::TaskRunner> gpu_;
|
||||
fml::RefPtr<fml::TaskRunner> ui_;
|
||||
fml::RefPtr<fml::TaskRunner> io_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_COMMON_TASK_RUNNERS_H_
|
||||
|
||||
@@ -58,10 +58,6 @@ source_set("flow") {
|
||||
"texture.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//garnet/public/lib/fxl",
|
||||
]
|
||||
|
||||
public_configs = [ "$flutter_root:config" ]
|
||||
|
||||
deps = [
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "flutter/flow/instrumentation.h"
|
||||
#include "flutter/flow/raster_cache.h"
|
||||
#include "flutter/flow/texture.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkPictureRecorder.h"
|
||||
|
||||
@@ -44,7 +44,7 @@ class CompositorContext {
|
||||
SkCanvas* canvas_;
|
||||
const bool instrumentation_enabled_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ScopedFrame);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ScopedFrame);
|
||||
};
|
||||
|
||||
CompositorContext();
|
||||
@@ -81,7 +81,7 @@ class CompositorContext {
|
||||
|
||||
void EndFrame(ScopedFrame& frame, bool enable_instrumentation);
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(CompositorContext);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(CompositorContext);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "flutter/flow/matrix_decomposition.h"
|
||||
#include "flutter/flow/raster_cache_key.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "third_party/skia/include/core/SkMatrix.h"
|
||||
#include "third_party/skia/include/core/SkMatrix44.h"
|
||||
#include "third_party/skia/include/core/SkPoint3.h"
|
||||
|
||||
@@ -4,16 +4,16 @@
|
||||
|
||||
#include "flutter/flow/export_node.h"
|
||||
|
||||
#include "lib/fxl/functional/make_copyable.h"
|
||||
#include "flutter/fml/make_copyable.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
ExportNodeHolder::ExportNodeHolder(
|
||||
fxl::RefPtr<fxl::TaskRunner> gpu_task_runner,
|
||||
fxl::RefPtr<zircon::dart::Handle> export_token_handle)
|
||||
fml::RefPtr<fml::TaskRunner> gpu_task_runner,
|
||||
fml::RefPtr<zircon::dart::Handle> export_token_handle)
|
||||
: gpu_task_runner_(std::move(gpu_task_runner)),
|
||||
export_node_(std::make_unique<ExportNode>(export_token_handle)) {
|
||||
FXL_DCHECK(gpu_task_runner_);
|
||||
FML_DCHECK(gpu_task_runner_);
|
||||
}
|
||||
|
||||
void ExportNodeHolder::Bind(SceneUpdateContext& context,
|
||||
@@ -25,18 +25,18 @@ void ExportNodeHolder::Bind(SceneUpdateContext& context,
|
||||
|
||||
ExportNodeHolder::~ExportNodeHolder() {
|
||||
gpu_task_runner_->PostTask(
|
||||
fxl::MakeCopyable([export_node = std::move(export_node_)]() {
|
||||
fml::MakeCopyable([export_node = std::move(export_node_)]() {
|
||||
export_node->Dispose(true);
|
||||
}));
|
||||
}
|
||||
|
||||
ExportNode::ExportNode(fxl::RefPtr<zircon::dart::Handle> export_token_handle)
|
||||
ExportNode::ExportNode(fml::RefPtr<zircon::dart::Handle> export_token_handle)
|
||||
: export_token_(export_token_handle->ReleaseHandle()) {}
|
||||
|
||||
ExportNode::~ExportNode() {
|
||||
// Ensure that we properly released the node.
|
||||
FXL_DCHECK(!node_);
|
||||
FXL_DCHECK(scene_update_context_ == nullptr);
|
||||
FML_DCHECK(!node_);
|
||||
FML_DCHECK(scene_update_context_ == nullptr);
|
||||
}
|
||||
|
||||
void ExportNode::Bind(SceneUpdateContext& context,
|
||||
@@ -57,9 +57,9 @@ void ExportNode::Bind(SceneUpdateContext& context,
|
||||
if (node_) {
|
||||
container.AddChild(*node_);
|
||||
node_->SetTranslation(offset.x(), offset.y(), 0.f);
|
||||
node_->SetHitTestBehavior(hit_testable
|
||||
? fuchsia::ui::gfx::HitTestBehavior::kDefault
|
||||
: fuchsia::ui::gfx::HitTestBehavior::kSuppress);
|
||||
node_->SetHitTestBehavior(
|
||||
hit_testable ? fuchsia::ui::gfx::HitTestBehavior::kDefault
|
||||
: fuchsia::ui::gfx::HitTestBehavior::kSuppress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ void ExportNode::Dispose(bool remove_from_scene_update_context) {
|
||||
// 1. A node was never created, or
|
||||
// 2. A node was created but was already dereferenced (i.e. Dispose has
|
||||
// already been called).
|
||||
FXL_DCHECK(scene_update_context_ || !node_);
|
||||
FML_DCHECK(scene_update_context_ || !node_);
|
||||
|
||||
if (remove_from_scene_update_context && scene_update_context_) {
|
||||
scene_update_context_->RemoveExportNode(this);
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
#include "dart-pkg/zircon/sdk_ext/handle.h"
|
||||
#include "flutter/flow/scene_update_context.h"
|
||||
#include "lib/fxl/build_config.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "lib/ui/scenic/cpp/resources.h"
|
||||
#include "third_party/flutter/fml/task_runner.h"
|
||||
#include "third_party/skia/include/core/SkPoint.h"
|
||||
@@ -23,10 +23,10 @@ namespace flow {
|
||||
// Wrapper class for ExportNode to use on UI Thread. When ExportNodeHolder is
|
||||
// destroyed, a task is posted on the Rasterizer thread to dispose the resources
|
||||
// held by the ExportNode.
|
||||
class ExportNodeHolder : public fxl::RefCountedThreadSafe<ExportNodeHolder> {
|
||||
class ExportNodeHolder : public fml::RefCountedThreadSafe<ExportNodeHolder> {
|
||||
public:
|
||||
ExportNodeHolder(fxl::RefPtr<fxl::TaskRunner> gpu_task_runner,
|
||||
fxl::RefPtr<zircon::dart::Handle> export_token_handle);
|
||||
ExportNodeHolder(fml::RefPtr<fml::TaskRunner> gpu_task_runner,
|
||||
fml::RefPtr<zircon::dart::Handle> export_token_handle);
|
||||
~ExportNodeHolder();
|
||||
|
||||
// Calls Bind() on the wrapped ExportNode.
|
||||
@@ -38,12 +38,12 @@ class ExportNodeHolder : public fxl::RefCountedThreadSafe<ExportNodeHolder> {
|
||||
ExportNode* export_node() { return export_node_.get(); }
|
||||
|
||||
private:
|
||||
fxl::RefPtr<fxl::TaskRunner> gpu_task_runner_;
|
||||
fml::RefPtr<fml::TaskRunner> gpu_task_runner_;
|
||||
std::unique_ptr<ExportNode> export_node_;
|
||||
|
||||
FRIEND_MAKE_REF_COUNTED(ExportNodeHolder);
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(ExportNodeHolder);
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ExportNodeHolder);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(ExportNodeHolder);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(ExportNodeHolder);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ExportNodeHolder);
|
||||
};
|
||||
|
||||
// Represents a node which is being exported from the session.
|
||||
@@ -51,7 +51,7 @@ class ExportNodeHolder : public fxl::RefCountedThreadSafe<ExportNodeHolder> {
|
||||
// must be created and destroyed by the rasterizer thread.
|
||||
class ExportNode {
|
||||
public:
|
||||
ExportNode(fxl::RefPtr<zircon::dart::Handle> export_token_handle);
|
||||
ExportNode(fml::RefPtr<zircon::dart::Handle> export_token_handle);
|
||||
|
||||
~ExportNode();
|
||||
|
||||
@@ -75,7 +75,7 @@ class ExportNode {
|
||||
zx::eventpair export_token_;
|
||||
std::unique_ptr<scenic::EntityNode> node_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ExportNode);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ExportNode);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -14,28 +14,28 @@ namespace flow {
|
||||
static const size_t kMaxSamples = 120;
|
||||
static const size_t kMaxFrameMarkers = 8;
|
||||
|
||||
Stopwatch::Stopwatch() : start_(fxl::TimePoint::Now()), current_sample_(0) {
|
||||
const fxl::TimeDelta delta = fxl::TimeDelta::Zero();
|
||||
Stopwatch::Stopwatch() : start_(fml::TimePoint::Now()), current_sample_(0) {
|
||||
const fml::TimeDelta delta = fml::TimeDelta::Zero();
|
||||
laps_.resize(kMaxSamples, delta);
|
||||
}
|
||||
|
||||
Stopwatch::~Stopwatch() = default;
|
||||
|
||||
void Stopwatch::Start() {
|
||||
start_ = fxl::TimePoint::Now();
|
||||
start_ = fml::TimePoint::Now();
|
||||
current_sample_ = (current_sample_ + 1) % kMaxSamples;
|
||||
}
|
||||
|
||||
void Stopwatch::Stop() {
|
||||
laps_[current_sample_] = fxl::TimePoint::Now() - start_;
|
||||
laps_[current_sample_] = fml::TimePoint::Now() - start_;
|
||||
}
|
||||
|
||||
void Stopwatch::SetLapTime(const fxl::TimeDelta& delta) {
|
||||
void Stopwatch::SetLapTime(const fml::TimeDelta& delta) {
|
||||
current_sample_ = (current_sample_ + 1) % kMaxSamples;
|
||||
laps_[current_sample_] = delta;
|
||||
}
|
||||
|
||||
const fxl::TimeDelta& Stopwatch::LastLap() const {
|
||||
const fml::TimeDelta& Stopwatch::LastLap() const {
|
||||
return laps_[(current_sample_ - 1) % kMaxSamples];
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ static inline double UnitHeight(double frame_time_ms,
|
||||
return unitHeight;
|
||||
}
|
||||
|
||||
fxl::TimeDelta Stopwatch::MaxDelta() const {
|
||||
fxl::TimeDelta max_delta;
|
||||
fml::TimeDelta Stopwatch::MaxDelta() const {
|
||||
fml::TimeDelta max_delta;
|
||||
for (size_t i = 0; i < kMaxSamples; i++) {
|
||||
if (laps_[i] > max_delta)
|
||||
max_delta = laps_[i];
|
||||
@@ -148,8 +148,7 @@ void Stopwatch::Visualize(SkCanvas& canvas, const SkRect& rect) const {
|
||||
x + width * (static_cast<double>(current_sample_) / kMaxSamples);
|
||||
|
||||
const auto marker_rect = SkRect::MakeLTRB(
|
||||
sample_x, y,
|
||||
sample_x + width * sample_unit_width, bottom);
|
||||
sample_x, y, sample_x + width * sample_unit_width, bottom);
|
||||
canvas.drawRect(marker_rect, paint);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/time/time_delta.h"
|
||||
#include "lib/fxl/time/time_point.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/time/time_delta.h"
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
|
||||
namespace flow {
|
||||
@@ -22,11 +22,11 @@ class Stopwatch {
|
||||
|
||||
~Stopwatch();
|
||||
|
||||
const fxl::TimeDelta& LastLap() const;
|
||||
const fml::TimeDelta& LastLap() const;
|
||||
|
||||
fxl::TimeDelta CurrentLap() const { return fxl::TimePoint::Now() - start_; }
|
||||
fml::TimeDelta CurrentLap() const { return fml::TimePoint::Now() - start_; }
|
||||
|
||||
fxl::TimeDelta MaxDelta() const;
|
||||
fml::TimeDelta MaxDelta() const;
|
||||
|
||||
void Visualize(SkCanvas& canvas, const SkRect& rect) const;
|
||||
|
||||
@@ -34,14 +34,14 @@ class Stopwatch {
|
||||
|
||||
void Stop();
|
||||
|
||||
void SetLapTime(const fxl::TimeDelta& delta);
|
||||
void SetLapTime(const fml::TimeDelta& delta);
|
||||
|
||||
private:
|
||||
fxl::TimePoint start_;
|
||||
std::vector<fxl::TimeDelta> laps_;
|
||||
fml::TimePoint start_;
|
||||
std::vector<fml::TimeDelta> laps_;
|
||||
size_t current_sample_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(Stopwatch);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Stopwatch);
|
||||
};
|
||||
|
||||
class Counter {
|
||||
@@ -57,7 +57,7 @@ class Counter {
|
||||
private:
|
||||
size_t count_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(Counter);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Counter);
|
||||
};
|
||||
|
||||
class CounterValues {
|
||||
@@ -80,7 +80,7 @@ class CounterValues {
|
||||
std::vector<int64_t> values_;
|
||||
size_t current_sample_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(CounterValues);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(CounterValues);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -14,7 +14,7 @@ BackdropFilterLayer::~BackdropFilterLayer() = default;
|
||||
|
||||
void BackdropFilterLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "BackdropFilterLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
Layer::AutoSaveLayer(context, SkCanvas::SaveLayerRec{&paint_bounds(), nullptr,
|
||||
filter_.get(), 0});
|
||||
|
||||
@@ -21,7 +21,7 @@ class BackdropFilterLayer : public ContainerLayer {
|
||||
private:
|
||||
sk_sp<SkImageFilter> filter_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(BackdropFilterLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(BackdropFilterLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -19,7 +19,7 @@ void ChildSceneLayer::Paint(PaintContext& context) const {
|
||||
}
|
||||
|
||||
void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
FXL_DCHECK(needs_system_composite());
|
||||
FML_DCHECK(needs_system_composite());
|
||||
|
||||
// TODO(MZ-191): Set clip.
|
||||
// It's worth asking whether all children should be clipped implicitly
|
||||
|
||||
@@ -21,7 +21,7 @@ class ChildSceneLayer : public Layer {
|
||||
void set_size(const SkSize& size) { size_ = size; }
|
||||
|
||||
void set_export_node_holder(
|
||||
fxl::RefPtr<ExportNodeHolder> export_node_holder) {
|
||||
fml::RefPtr<ExportNodeHolder> export_node_holder) {
|
||||
export_node_holder_ = std::move(export_node_holder);
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ class ChildSceneLayer : public Layer {
|
||||
private:
|
||||
SkPoint offset_;
|
||||
SkSize size_;
|
||||
fxl::RefPtr<ExportNodeHolder> export_node_holder_;
|
||||
fml::RefPtr<ExportNodeHolder> export_node_holder_;
|
||||
bool hit_testable_ = true;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -29,7 +29,7 @@ void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
#if defined(OS_FUCHSIA)
|
||||
|
||||
void ClipPathLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
FXL_DCHECK(needs_system_composite());
|
||||
FML_DCHECK(needs_system_composite());
|
||||
|
||||
// TODO(MZ-140): Must be able to specify paths as shapes to nodes.
|
||||
// Treating the shape as a rectangle for now.
|
||||
@@ -48,7 +48,7 @@ void ClipPathLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
|
||||
void ClipPathLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "ClipPathLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
SkAutoCanvasRestore save(&context.canvas, true);
|
||||
context.canvas.clipPath(clip_path_, clip_behavior_ != Clip::hardEdge);
|
||||
|
||||
@@ -28,7 +28,7 @@ class ClipPathLayer : public ContainerLayer {
|
||||
SkPath clip_path_;
|
||||
Clip clip_behavior_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -23,7 +23,7 @@ void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
#if defined(OS_FUCHSIA)
|
||||
|
||||
void ClipRectLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
FXL_DCHECK(needs_system_composite());
|
||||
FML_DCHECK(needs_system_composite());
|
||||
|
||||
scenic::Rectangle shape(context.session(), // session
|
||||
clip_rect_.width(), // width
|
||||
@@ -39,7 +39,7 @@ void ClipRectLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
|
||||
void ClipRectLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "ClipRectLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
SkAutoCanvasRestore save(&context.canvas, clip_behavior_ != Clip::hardEdge);
|
||||
context.canvas.clipRect(paint_bounds());
|
||||
|
||||
@@ -27,7 +27,7 @@ class ClipRectLayer : public ContainerLayer {
|
||||
SkRect clip_rect_;
|
||||
Clip clip_behavior_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -23,7 +23,7 @@ void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
#if defined(OS_FUCHSIA)
|
||||
|
||||
void ClipRRectLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
FXL_DCHECK(needs_system_composite());
|
||||
FML_DCHECK(needs_system_composite());
|
||||
|
||||
// TODO(MZ-137): Need to be able to express the radii as vectors.
|
||||
scenic::RoundedRectangle shape(
|
||||
@@ -46,7 +46,7 @@ void ClipRRectLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
|
||||
void ClipRRectLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "ClipRRectLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
SkAutoCanvasRestore save(&context.canvas, true);
|
||||
context.canvas.clipRRect(clip_rrect_, clip_behavior_ != Clip::hardEdge);
|
||||
|
||||
@@ -28,7 +28,7 @@ class ClipRRectLayer : public ContainerLayer {
|
||||
SkRRect clip_rrect_;
|
||||
Clip clip_behavior_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ClipRRectLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ClipRRectLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -12,7 +12,7 @@ ColorFilterLayer::~ColorFilterLayer() = default;
|
||||
|
||||
void ColorFilterLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "ColorFilterLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
sk_sp<SkColorFilter> color_filter =
|
||||
SkColorFilter::MakeModeFilter(color_, blend_mode_);
|
||||
|
||||
@@ -24,7 +24,7 @@ class ColorFilterLayer : public ContainerLayer {
|
||||
SkColor color_;
|
||||
SkBlendMode blend_mode_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ColorFilterLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ColorFilterLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -38,7 +38,7 @@ void ContainerLayer::PrerollChildren(PrerollContext* context,
|
||||
}
|
||||
|
||||
void ContainerLayer::PaintChildren(PaintContext& context) const {
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
// Intentionally not tracing here as there should be no self-time
|
||||
// and the trace event on this common function has a small overhead.
|
||||
@@ -56,7 +56,7 @@ void ContainerLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
}
|
||||
|
||||
void ContainerLayer::UpdateSceneChildren(SceneUpdateContext& context) {
|
||||
FXL_DCHECK(needs_system_composite());
|
||||
FML_DCHECK(needs_system_composite());
|
||||
|
||||
// Paint all of the layers which need to be drawn into the container.
|
||||
// These may be flattened down to a containing
|
||||
|
||||
@@ -38,7 +38,7 @@ class ContainerLayer : public Layer {
|
||||
private:
|
||||
std::vector<std::unique_ptr<Layer>> layers_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ContainerLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ContainerLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -72,7 +72,7 @@ void DefaultLayerBuilder::PushClipRoundedRect(const SkRRect& rrect,
|
||||
}
|
||||
|
||||
void DefaultLayerBuilder::PushClipPath(const SkPath& path, Clip clip_behavior) {
|
||||
FXL_DCHECK(clip_behavior != Clip::none);
|
||||
FML_DCHECK(clip_behavior != Clip::none);
|
||||
SkRect cullRect;
|
||||
if (!cullRect.intersect(path.getBounds(), cull_rects_.top())) {
|
||||
cullRect = SkRect::MakeEmpty();
|
||||
@@ -178,7 +178,7 @@ void DefaultLayerBuilder::PushTexture(const SkPoint& offset,
|
||||
void DefaultLayerBuilder::PushChildScene(
|
||||
const SkPoint& offset,
|
||||
const SkSize& size,
|
||||
fxl::RefPtr<flow::ExportNodeHolder> export_token_holder,
|
||||
fml::RefPtr<flow::ExportNodeHolder> export_token_holder,
|
||||
bool hit_testable) {
|
||||
if (!current_layer_) {
|
||||
return;
|
||||
@@ -211,7 +211,7 @@ std::unique_ptr<flow::Layer> DefaultLayerBuilder::TakeLayer() {
|
||||
|
||||
void DefaultLayerBuilder::PushLayer(std::unique_ptr<flow::ContainerLayer> layer,
|
||||
const SkRect& cullRect) {
|
||||
FXL_DCHECK(layer);
|
||||
FML_DCHECK(layer);
|
||||
|
||||
cull_rects_.push(cullRect);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "flutter/flow/layers/container_layer.h"
|
||||
#include "flutter/flow/layers/layer_builder.h"
|
||||
#include "garnet/public/lib/fxl/macros.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
@@ -76,7 +76,7 @@ class DefaultLayerBuilder final : public LayerBuilder {
|
||||
// |flow::LayerBuilder|
|
||||
void PushChildScene(const SkPoint& offset,
|
||||
const SkSize& size,
|
||||
fxl::RefPtr<flow::ExportNodeHolder> export_token_holder,
|
||||
fml::RefPtr<flow::ExportNodeHolder> export_token_holder,
|
||||
bool hit_testable) override;
|
||||
#endif // defined(OS_FUCHSIA)
|
||||
|
||||
@@ -95,7 +95,7 @@ class DefaultLayerBuilder final : public LayerBuilder {
|
||||
void PushLayer(std::unique_ptr<flow::ContainerLayer> layer,
|
||||
const SkRect& cullRect);
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(DefaultLayerBuilder);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(DefaultLayerBuilder);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
#include "flutter/flow/instrumentation.h"
|
||||
#include "flutter/flow/raster_cache.h"
|
||||
#include "flutter/flow/texture.h"
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "lib/fxl/build_config.h"
|
||||
#include "lib/fxl/logging.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkColorFilter.h"
|
||||
@@ -112,7 +112,7 @@ class Layer {
|
||||
bool needs_system_composite_;
|
||||
SkRect paint_bounds_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(Layer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Layer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "flutter/flow/layers/layer.h"
|
||||
#include "flutter/flow/skia_gpu_object.h"
|
||||
#include "garnet/public/lib/fxl/macros.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "third_party/skia/include/core/SkBlendMode.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkImageFilter.h"
|
||||
@@ -74,7 +74,7 @@ class LayerBuilder {
|
||||
virtual void PushChildScene(
|
||||
const SkPoint& offset,
|
||||
const SkSize& size,
|
||||
fxl::RefPtr<flow::ExportNodeHolder> export_token_holder,
|
||||
fml::RefPtr<flow::ExportNodeHolder> export_token_holder,
|
||||
bool hit_testable) = 0;
|
||||
#endif // defined(OS_FUCHSIA)
|
||||
|
||||
@@ -99,7 +99,7 @@ class LayerBuilder {
|
||||
bool checkerboard_raster_cache_images_ = false;
|
||||
bool checkerboard_offscreen_layers_ = false;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(LayerBuilder);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(LayerBuilder);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
#include "flutter/flow/compositor_context.h"
|
||||
#include "flutter/flow/layers/layer.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/time/time_delta.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/time/time_delta.h"
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
#include "third_party/skia/include/core/SkSize.h"
|
||||
|
||||
@@ -46,11 +46,11 @@ class LayerTree {
|
||||
|
||||
void set_frame_size(const SkISize& frame_size) { frame_size_ = frame_size; }
|
||||
|
||||
void set_construction_time(const fxl::TimeDelta& delta) {
|
||||
void set_construction_time(const fml::TimeDelta& delta) {
|
||||
construction_time_ = delta;
|
||||
}
|
||||
|
||||
const fxl::TimeDelta& construction_time() const { return construction_time_; }
|
||||
const fml::TimeDelta& construction_time() const { 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
|
||||
@@ -74,12 +74,12 @@ class LayerTree {
|
||||
private:
|
||||
SkISize frame_size_; // Physical pixels.
|
||||
std::unique_ptr<Layer> root_layer_;
|
||||
fxl::TimeDelta construction_time_;
|
||||
fml::TimeDelta construction_time_;
|
||||
uint32_t rasterizer_tracing_threshold_;
|
||||
bool checkerboard_raster_cache_images_;
|
||||
bool checkerboard_offscreen_layers_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(LayerTree);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(LayerTree);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -12,7 +12,7 @@ OpacityLayer::~OpacityLayer() = default;
|
||||
|
||||
void OpacityLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "OpacityLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
SkPaint paint;
|
||||
paint.setAlpha(alpha_);
|
||||
|
||||
@@ -24,7 +24,7 @@ class OpacityLayer : public ContainerLayer {
|
||||
private:
|
||||
int alpha_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(OpacityLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(OpacityLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define FLUTTER_FLOW_LAYERS_PERFORMANCE_OVERLAY_LAYER_H_
|
||||
|
||||
#include "flutter/flow/layers/layer.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
@@ -24,7 +24,7 @@ class PerformanceOverlayLayer : public Layer {
|
||||
private:
|
||||
int options_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(PerformanceOverlayLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PerformanceOverlayLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -64,7 +64,7 @@ void PhysicalShapeLayer::Preroll(PrerollContext* context,
|
||||
#if defined(OS_FUCHSIA)
|
||||
|
||||
void PhysicalShapeLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
FXL_DCHECK(needs_system_composite());
|
||||
FML_DCHECK(needs_system_composite());
|
||||
|
||||
SceneUpdateContext::Frame frame(context, frameRRect_, color_, elevation_);
|
||||
for (auto& layer : layers()) {
|
||||
@@ -80,7 +80,7 @@ void PhysicalShapeLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
|
||||
void PhysicalShapeLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "PhysicalShapeLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
if (elevation_ != 0) {
|
||||
DrawShadow(&context.canvas, path_, shadow_color_, elevation_,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "flutter/flow/layers/picture_layer.h"
|
||||
|
||||
#include "lib/fxl/logging.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
@@ -34,8 +34,8 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
|
||||
void PictureLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "PictureLayer::Paint");
|
||||
FXL_DCHECK(picture_.get());
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(picture_.get());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
SkAutoCanvasRestore save(&context.canvas, true);
|
||||
context.canvas.translate(offset_.x(), offset_.y());
|
||||
|
||||
@@ -41,7 +41,7 @@ class PictureLayer : public Layer {
|
||||
bool will_change_ = false;
|
||||
RasterCacheResult raster_cache_result_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(PictureLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PictureLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -12,7 +12,7 @@ ShaderMaskLayer::~ShaderMaskLayer() = default;
|
||||
|
||||
void ShaderMaskLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "ShaderMaskLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
Layer::AutoSaveLayer(context, paint_bounds(), nullptr);
|
||||
PaintChildren(context);
|
||||
|
||||
@@ -29,7 +29,7 @@ class ShaderMaskLayer : public ContainerLayer {
|
||||
SkRect mask_rect_;
|
||||
SkBlendMode blend_mode_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(ShaderMaskLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShaderMaskLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -31,7 +31,7 @@ class TextureLayer : public Layer {
|
||||
SkSize size_;
|
||||
int64_t texture_id_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(TextureLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(TextureLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -24,7 +24,7 @@ void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
#if defined(OS_FUCHSIA)
|
||||
|
||||
void TransformLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
FXL_DCHECK(needs_system_composite());
|
||||
FML_DCHECK(needs_system_composite());
|
||||
|
||||
SceneUpdateContext::Transform transform(context, transform_);
|
||||
UpdateSceneChildren(context);
|
||||
@@ -34,7 +34,7 @@ void TransformLayer::UpdateScene(SceneUpdateContext& context) {
|
||||
|
||||
void TransformLayer::Paint(PaintContext& context) const {
|
||||
TRACE_EVENT0("flutter", "TransformLayer::Paint");
|
||||
FXL_DCHECK(needs_painting());
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
SkAutoCanvasRestore save(&context.canvas, true);
|
||||
context.canvas.concat(transform_);
|
||||
|
||||
@@ -27,7 +27,7 @@ class TransformLayer : public ContainerLayer {
|
||||
private:
|
||||
SkMatrix transform_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(TransformLayer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(TransformLayer);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef FLUTTER_FLOW_MATRIX_DECOMPOSITION_H_
|
||||
#define FLUTTER_FLOW_MATRIX_DECOMPOSITION_H_
|
||||
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "third_party/skia/include/core/SkMatrix.h"
|
||||
#include "third_party/skia/include/core/SkMatrix44.h"
|
||||
#include "third_party/skia/include/core/SkPoint3.h"
|
||||
@@ -43,7 +43,7 @@ class MatrixDecomposition {
|
||||
SkVector4 perspective_;
|
||||
SkVector4 rotation_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(MatrixDecomposition);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MatrixDecomposition);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "lib/fxl/build_config.h"
|
||||
#include "flutter/fml/build_config.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/flow/paint_utils.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "lib/fxl/logging.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkColorSpaceXformCanvas.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
@@ -21,7 +21,7 @@ void RasterCacheResult::draw(SkCanvas& canvas) const {
|
||||
SkAutoCanvasRestore auto_restore(&canvas, true);
|
||||
SkIRect bounds =
|
||||
RasterCache::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix());
|
||||
FXL_DCHECK(bounds.size() == image_->dimensions());
|
||||
FML_DCHECK(bounds.size() == image_->dimensions());
|
||||
canvas.resetMatrix();
|
||||
canvas.drawImage(image_, bounds.fLeft, bounds.fTop);
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
#include "flutter/flow/instrumentation.h"
|
||||
#include "flutter/flow/raster_cache_key.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/memory/weak_ptr.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/memory/weak_ptr.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkSize.h"
|
||||
|
||||
@@ -79,9 +79,9 @@ class RasterCache {
|
||||
const size_t threshold_;
|
||||
RasterCacheKey::Map<Entry> cache_;
|
||||
bool checkerboard_images_;
|
||||
fxl::WeakPtrFactory<RasterCache> weak_factory_;
|
||||
fml::WeakPtrFactory<RasterCache> weak_factory_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(RasterCache);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(RasterCache);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include <unordered_map>
|
||||
#include "flutter/flow/matrix_decomposition.h"
|
||||
#include "lib/fxl/logging.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
|
||||
@@ -21,7 +21,7 @@ class RasterCacheKey {
|
||||
matrix_[SkMatrix::kMTransX] = SkScalarFraction(ctm.getTranslateX());
|
||||
matrix_[SkMatrix::kMTransY] = SkScalarFraction(ctm.getTranslateY());
|
||||
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
|
||||
FXL_DCHECK(matrix_.getTranslateX() == 0 && matrix_.getTranslateY() == 0);
|
||||
FML_DCHECK(matrix_.getTranslateX() == 0 && matrix_.getTranslateY() == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace flow {
|
||||
SceneUpdateContext::SceneUpdateContext(scenic::Session* session,
|
||||
SurfaceProducer* surface_producer)
|
||||
: session_(session), surface_producer_(surface_producer) {
|
||||
FXL_DCHECK(surface_producer_ != nullptr);
|
||||
FML_DCHECK(surface_producer_ != nullptr);
|
||||
}
|
||||
|
||||
SceneUpdateContext::~SceneUpdateContext() {
|
||||
@@ -27,7 +27,7 @@ SceneUpdateContext::~SceneUpdateContext() {
|
||||
void SceneUpdateContext::AddChildScene(ExportNode* export_node,
|
||||
SkPoint offset,
|
||||
bool hit_testable) {
|
||||
FXL_DCHECK(top_entity_);
|
||||
FML_DCHECK(top_entity_);
|
||||
|
||||
export_node->Bind(*this, top_entity_->entity_node(), offset, hit_testable);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ scenic::Image* SceneUpdateContext::GenerateImageIfNeeded(
|
||||
auto surface = surface_producer_->ProduceSurface(physical_size);
|
||||
|
||||
if (!surface) {
|
||||
FXL_LOG(ERROR) << "Could not acquire a surface from the surface producer "
|
||||
FML_LOG(ERROR) << "Could not acquire a surface from the surface producer "
|
||||
"of size: "
|
||||
<< physical_size.width() << "x" << physical_size.height();
|
||||
return nullptr;
|
||||
@@ -185,7 +185,7 @@ SceneUpdateContext::ExecutePaintTasks(CompositorContext::ScopedFrame& frame) {
|
||||
TRACE_EVENT0("flutter", "SceneUpdateContext::ExecutePaintTasks");
|
||||
std::vector<std::unique_ptr<SurfaceProducerSurface>> surfaces_to_submit;
|
||||
for (auto& task : paint_tasks_) {
|
||||
FXL_DCHECK(task.surface);
|
||||
FML_DCHECK(task.surface);
|
||||
SkCanvas* canvas = task.surface->GetSkiaSurface()->getCanvas();
|
||||
Layer::PaintContext context = {*canvas, frame.context().frame_time(),
|
||||
frame.context().engine_time(),
|
||||
@@ -214,7 +214,7 @@ SceneUpdateContext::Entity::Entity(SceneUpdateContext& context)
|
||||
}
|
||||
|
||||
SceneUpdateContext::Entity::~Entity() {
|
||||
FXL_DCHECK(context_.top_entity_ == this);
|
||||
FML_DCHECK(context_.top_entity_ == this);
|
||||
context_.top_entity_ = previous_entity_;
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ SceneUpdateContext::Frame::~Frame() {
|
||||
}
|
||||
|
||||
void SceneUpdateContext::Frame::AddPaintedLayer(Layer* layer) {
|
||||
FXL_DCHECK(layer->needs_painting());
|
||||
FML_DCHECK(layer->needs_painting());
|
||||
paint_layers_.push_back(layer);
|
||||
paint_bounds_.join(layer->paint_bounds());
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/flow/compositor_context.h"
|
||||
#include "lib/fxl/build_config.h"
|
||||
#include "lib/fxl/logging.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "lib/ui/scenic/cpp/resources.h"
|
||||
#include "third_party/skia/include/core/SkRect.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
@@ -142,7 +142,7 @@ class SceneUpdateContext {
|
||||
// CPU wait. Once Vulkan semaphores are available, this method must return
|
||||
// void and the implementation must submit surfaces on its own as soon as the
|
||||
// specific canvas operations are done.
|
||||
FXL_WARN_UNUSED_RESULT
|
||||
FML_WARN_UNUSED_RESULT
|
||||
std::vector<std::unique_ptr<SurfaceProducerSurface>> ExecutePaintTasks(
|
||||
CompositorContext::ScopedFrame& frame);
|
||||
|
||||
@@ -170,10 +170,10 @@ class SceneUpdateContext {
|
||||
std::vector<Layer*> paint_layers);
|
||||
void SetShapeColor(scenic::ShapeNode& shape_node, SkColor color);
|
||||
scenic::Image* GenerateImageIfNeeded(SkColor color,
|
||||
SkScalar scale_x,
|
||||
SkScalar scale_y,
|
||||
const SkRect& paint_bounds,
|
||||
std::vector<Layer*> paint_layers);
|
||||
SkScalar scale_x,
|
||||
SkScalar scale_y,
|
||||
const SkRect& paint_bounds,
|
||||
std::vector<Layer*> paint_layers);
|
||||
|
||||
Entity* top_entity_ = nullptr;
|
||||
float top_scale_x_ = 1.f;
|
||||
@@ -189,7 +189,7 @@ class SceneUpdateContext {
|
||||
// Save ExportNodes so we can dispose them in our destructor.
|
||||
std::set<ExportNode*> export_nodes_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(SceneUpdateContext);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(SceneUpdateContext);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
namespace flow {
|
||||
|
||||
SkiaUnrefQueue::SkiaUnrefQueue(fxl::RefPtr<fxl::TaskRunner> task_runner,
|
||||
fxl::TimeDelta delay)
|
||||
SkiaUnrefQueue::SkiaUnrefQueue(fml::RefPtr<fml::TaskRunner> task_runner,
|
||||
fml::TimeDelta delay)
|
||||
: task_runner_(std::move(task_runner)),
|
||||
drain_delay_(delay),
|
||||
drain_pending_(false) {}
|
||||
@@ -24,7 +24,7 @@ void SkiaUnrefQueue::Unref(SkRefCnt* object) {
|
||||
if (!drain_pending_) {
|
||||
drain_pending_ = true;
|
||||
task_runner_->PostDelayedTask(
|
||||
[strong = fxl::Ref(this)]() { strong->Drain(); }, drain_delay_);
|
||||
[strong = fml::Ref(this)]() { strong->Drain(); }, drain_delay_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/weak_ptr.h"
|
||||
#include "flutter/fml/task_runner.h"
|
||||
#include "lib/fxl/memory/ref_ptr.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
// A queue that holds Skia objects that must be destructed on the the given task
|
||||
// runner.
|
||||
class SkiaUnrefQueue : public fxl::RefCountedThreadSafe<SkiaUnrefQueue> {
|
||||
class SkiaUnrefQueue : public fml::RefCountedThreadSafe<SkiaUnrefQueue> {
|
||||
public:
|
||||
void Unref(SkRefCnt* object);
|
||||
|
||||
@@ -29,20 +29,20 @@ class SkiaUnrefQueue : public fxl::RefCountedThreadSafe<SkiaUnrefQueue> {
|
||||
void Drain();
|
||||
|
||||
private:
|
||||
const fxl::RefPtr<fxl::TaskRunner> task_runner_;
|
||||
const fxl::TimeDelta drain_delay_;
|
||||
const fml::RefPtr<fml::TaskRunner> task_runner_;
|
||||
const fml::TimeDelta drain_delay_;
|
||||
std::mutex mutex_;
|
||||
std::deque<SkRefCnt*> objects_;
|
||||
bool drain_pending_;
|
||||
|
||||
SkiaUnrefQueue(fxl::RefPtr<fxl::TaskRunner> task_runner,
|
||||
fxl::TimeDelta delay);
|
||||
SkiaUnrefQueue(fml::RefPtr<fml::TaskRunner> task_runner,
|
||||
fml::TimeDelta delay);
|
||||
|
||||
~SkiaUnrefQueue();
|
||||
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(SkiaUnrefQueue);
|
||||
FRIEND_MAKE_REF_COUNTED(SkiaUnrefQueue);
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(SkiaUnrefQueue);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(SkiaUnrefQueue);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(SkiaUnrefQueue);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(SkiaUnrefQueue);
|
||||
};
|
||||
|
||||
/// An object whose deallocation needs to be performed on an specific unref
|
||||
@@ -55,9 +55,9 @@ class SkiaGPUObject {
|
||||
|
||||
SkiaGPUObject() = default;
|
||||
|
||||
SkiaGPUObject(sk_sp<SkiaObjectType> object, fxl::RefPtr<SkiaUnrefQueue> queue)
|
||||
SkiaGPUObject(sk_sp<SkiaObjectType> object, fml::RefPtr<SkiaUnrefQueue> queue)
|
||||
: object_(std::move(object)), queue_(std::move(queue)) {
|
||||
FXL_DCHECK(queue_ && object_);
|
||||
FML_DCHECK(queue_ && object_);
|
||||
}
|
||||
|
||||
SkiaGPUObject(SkiaGPUObject&&) = default;
|
||||
@@ -73,14 +73,14 @@ class SkiaGPUObject {
|
||||
queue_->Unref(object_.release());
|
||||
}
|
||||
queue_ = nullptr;
|
||||
FXL_DCHECK(object_ == nullptr);
|
||||
FML_DCHECK(object_ == nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
sk_sp<SkiaObjectType> object_;
|
||||
fxl::RefPtr<SkiaUnrefQueue> queue_;
|
||||
fml::RefPtr<SkiaUnrefQueue> queue_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(SkiaGPUObject);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(SkiaGPUObject);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/synchronization/waitable_event.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
|
||||
namespace flow {
|
||||
@@ -38,7 +38,7 @@ class Texture {
|
||||
private:
|
||||
int64_t id_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(Texture);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Texture);
|
||||
};
|
||||
|
||||
class TextureRegistry {
|
||||
@@ -64,7 +64,7 @@ class TextureRegistry {
|
||||
private:
|
||||
std::map<int64_t, std::shared_ptr<Texture>> mapping_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(TextureRegistry);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(TextureRegistry);
|
||||
};
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
|
||||
source_set("fml") {
|
||||
sources = [
|
||||
"arraysize.h",
|
||||
"build_config.h",
|
||||
"closure.h",
|
||||
"command_line.cc",
|
||||
"command_line.h",
|
||||
"compiler_specific.h",
|
||||
"eintr_wrapper.h",
|
||||
"export.h",
|
||||
@@ -18,6 +21,7 @@ source_set("fml") {
|
||||
"log_settings_state.cc",
|
||||
"logging.cc",
|
||||
"logging.h",
|
||||
"make_copyable.h",
|
||||
"mapping.cc",
|
||||
"mapping.h",
|
||||
"memory/ref_counted.h",
|
||||
@@ -35,6 +39,8 @@ source_set("fml") {
|
||||
"native_library.h",
|
||||
"paths.cc",
|
||||
"paths.h",
|
||||
"string_view.cc",
|
||||
"string_view.h",
|
||||
"synchronization/thread_annotations.h",
|
||||
"synchronization/thread_checker.h",
|
||||
"synchronization/waitable_event.cc",
|
||||
@@ -55,7 +61,6 @@ source_set("fml") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//garnet/public/lib/fxl",
|
||||
"//third_party/dart/runtime:dart_api",
|
||||
|
||||
# These need to be in sync with the Fuchsia buildroot.
|
||||
@@ -141,6 +146,7 @@ source_set("fml") {
|
||||
"platform/posix/file_posix.cc",
|
||||
"platform/posix/mapping_posix.cc",
|
||||
"platform/posix/native_library_posix.cc",
|
||||
"platform/posix/paths_posix.cc",
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -149,9 +155,11 @@ executable("fml_unittests") {
|
||||
testonly = true
|
||||
|
||||
sources = [
|
||||
"command_line_unittest.cc",
|
||||
"memory/ref_counted_unittest.cc",
|
||||
"memory/weak_ptr_unittest.cc",
|
||||
"message_loop_unittests.cc",
|
||||
"string_view_unittest.cc",
|
||||
"synchronization/thread_annotations_unittest.cc",
|
||||
"synchronization/thread_checker_unittest.cc",
|
||||
"synchronization/waitable_event_unittest.cc",
|
||||
@@ -165,7 +173,6 @@ executable("fml_unittests") {
|
||||
deps = [
|
||||
"$flutter_root/fml",
|
||||
"$flutter_root/testing",
|
||||
"//garnet/public/lib/fxl",
|
||||
"//third_party/dart/runtime:libdart_jit",
|
||||
]
|
||||
}
|
||||
|
||||
16
engine/src/flutter/fml/arraysize.h
Normal file
16
engine/src/flutter/fml/arraysize.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2016 The Fuchsia 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 FLUTTER_FML_ARRAYSIZE_H_
|
||||
#define FLUTTER_FML_ARRAYSIZE_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef arraysize
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(T (&array)[N]))[N];
|
||||
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
||||
#endif
|
||||
|
||||
#endif // FLUTTER_FML_ARRAYSIZE_H_
|
||||
165
engine/src/flutter/fml/command_line.cc
Normal file
165
engine/src/flutter/fml/command_line.cc
Normal file
@@ -0,0 +1,165 @@
|
||||
// Copyright 2016 The Fuchsia 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 "flutter/fml/command_line.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
// CommandLine -----------------------------------------------------------------
|
||||
|
||||
CommandLine::Option::Option(const std::string& name) : name(name) {}
|
||||
|
||||
CommandLine::Option::Option(const std::string& name, const std::string& value)
|
||||
: name(name), value(value) {}
|
||||
|
||||
CommandLine::CommandLine() = default;
|
||||
|
||||
CommandLine::CommandLine(const CommandLine& from) = default;
|
||||
|
||||
CommandLine::CommandLine(CommandLine&& from) = default;
|
||||
|
||||
CommandLine::CommandLine(const std::string& argv0,
|
||||
const std::vector<Option>& options,
|
||||
const std::vector<std::string>& positional_args)
|
||||
: has_argv0_(true),
|
||||
argv0_(argv0),
|
||||
options_(options),
|
||||
positional_args_(positional_args) {
|
||||
for (size_t i = 0; i < options_.size(); i++)
|
||||
option_index_[options_[i].name] = i;
|
||||
}
|
||||
|
||||
CommandLine::~CommandLine() = default;
|
||||
|
||||
CommandLine& CommandLine::operator=(const CommandLine& from) = default;
|
||||
|
||||
CommandLine& CommandLine::operator=(CommandLine&& from) = default;
|
||||
|
||||
bool CommandLine::HasOption(StringView name, size_t* index) const {
|
||||
auto it = option_index_.find(name.ToString());
|
||||
if (it == option_index_.end())
|
||||
return false;
|
||||
if (index)
|
||||
*index = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandLine::GetOptionValue(StringView name, std::string* value) const {
|
||||
size_t index;
|
||||
if (!HasOption(name, &index))
|
||||
return false;
|
||||
*value = options_[index].value;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<fml::StringView> CommandLine::GetOptionValues(
|
||||
StringView name) const {
|
||||
std::vector<fml::StringView> ret;
|
||||
for (const auto& option : options_) {
|
||||
if (option.name == name)
|
||||
ret.push_back(option.value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CommandLine::GetOptionValueWithDefault(
|
||||
StringView name,
|
||||
StringView default_value) const {
|
||||
size_t index;
|
||||
if (!HasOption(name, &index))
|
||||
return default_value.ToString();
|
||||
return options_[index].value;
|
||||
}
|
||||
|
||||
// Factory functions (etc.) ----------------------------------------------------
|
||||
|
||||
namespace internal {
|
||||
|
||||
CommandLineBuilder::CommandLineBuilder() {}
|
||||
CommandLineBuilder::~CommandLineBuilder() {}
|
||||
|
||||
bool CommandLineBuilder::ProcessArg(const std::string& arg) {
|
||||
if (!has_argv0_) {
|
||||
has_argv0_ = true;
|
||||
argv0_ = arg;
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we've seen a positional argument, then the remaining arguments are also
|
||||
// positional.
|
||||
if (started_positional_args_) {
|
||||
bool rv = positional_args_.empty();
|
||||
positional_args_.push_back(arg);
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Anything that doesn't start with "--" is a positional argument.
|
||||
if (arg.size() < 2u || arg[0] != '-' || arg[1] != '-') {
|
||||
bool rv = positional_args_.empty();
|
||||
started_positional_args_ = true;
|
||||
positional_args_.push_back(arg);
|
||||
return rv;
|
||||
}
|
||||
|
||||
// "--" ends option processing, but isn't stored as a positional argument.
|
||||
if (arg.size() == 2u) {
|
||||
started_positional_args_ = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: The option name *must* be at least one character, so start at
|
||||
// position 3 -- "--=foo" will yield a name of "=foo" and no value. (Passing a
|
||||
// starting |pos| that's "too big" is OK.)
|
||||
size_t equals_pos = arg.find('=', 3u);
|
||||
if (equals_pos == std::string::npos) {
|
||||
options_.push_back(CommandLine::Option(arg.substr(2u)));
|
||||
return false;
|
||||
}
|
||||
|
||||
options_.push_back(CommandLine::Option(arg.substr(2u, equals_pos - 2u),
|
||||
arg.substr(equals_pos + 1u)));
|
||||
return false;
|
||||
}
|
||||
|
||||
CommandLine CommandLineBuilder::Build() const {
|
||||
if (!has_argv0_)
|
||||
return CommandLine();
|
||||
return CommandLine(argv0_, options_, positional_args_);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
|
||||
if (!command_line.has_argv0())
|
||||
return std::vector<std::string>();
|
||||
|
||||
std::vector<std::string> argv;
|
||||
const std::vector<CommandLine::Option>& options = command_line.options();
|
||||
const std::vector<std::string>& positional_args =
|
||||
command_line.positional_args();
|
||||
// Reserve space for argv[0], options, maybe a "--" (if needed), and the
|
||||
// positional arguments.
|
||||
argv.reserve(1u + options.size() + 1u + positional_args.size());
|
||||
|
||||
argv.push_back(command_line.argv0());
|
||||
for (const auto& option : options) {
|
||||
if (option.value.empty())
|
||||
argv.push_back("--" + option.name);
|
||||
else
|
||||
argv.push_back("--" + option.name + "=" + option.value);
|
||||
}
|
||||
|
||||
if (!positional_args.empty()) {
|
||||
// Insert a "--" if necessary.
|
||||
if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' &&
|
||||
positional_args[0][1] == '-')
|
||||
argv.push_back("--");
|
||||
|
||||
argv.insert(argv.end(), positional_args.begin(), positional_args.end());
|
||||
}
|
||||
|
||||
return argv;
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
242
engine/src/flutter/fml/command_line.h
Normal file
242
engine/src/flutter/fml/command_line.h
Normal file
@@ -0,0 +1,242 @@
|
||||
// Copyright 2016 The Fuchsia Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Provides a simple class, |CommandLine|, for dealing with command lines (and
|
||||
// flags and positional arguments).
|
||||
//
|
||||
// * Options (a.k.a. flags or switches) are all of the form "--name=<value>" (or
|
||||
// "--name", but this is indistinguishable from "--name="), where <value> is a
|
||||
// string. Not supported: "-name", "-n", "--name <value>", "-n <value>", etc.
|
||||
// * Option order is preserved.
|
||||
// * Option processing is stopped after the first positional argument[*]. Thus
|
||||
// in the command line "my_program --foo bar --baz", only "--foo" is an option
|
||||
// ("bar" and "--baz" are positional arguments).
|
||||
// * Options can be looked up by name. If the same option occurs multiple times,
|
||||
// convention is to use the last occurrence (and the provided look-up
|
||||
// functions behave this way).
|
||||
// * "--" may also be used to separate options from positional arguments. Thus
|
||||
// in the command line "my_program --foo -- --bar", "--bar" is a positional
|
||||
// argument.
|
||||
// * |CommandLine|s store |argv[0]| and distinguish between not having |argv[0]|
|
||||
// and |argv[0]| being empty.
|
||||
// * Apart from being copyable and movable, |CommandLine|s are immutable.
|
||||
//
|
||||
// There are factory functions to turn raw arguments into |CommandLine|s, in
|
||||
// accordance with the above rules. However, |CommandLine|s may be used more
|
||||
// generically (with the user transforming arguments using different rules,
|
||||
// e.g., accepting "-name" as an option), subject to certain limitations (e.g.,
|
||||
// not being able to distinguish "no value" from "empty value").
|
||||
//
|
||||
// [*] This is somewhat annoying for users, but: a. it's standard Unix behavior
|
||||
// for most command line parsers, b. it makes "my_program *" (etc.) safer (which
|
||||
// mostly explains a.), c. it makes parsing "subcommands", like "my_program
|
||||
// --flag_for_my_program subcommand --flag_for_subcommand" saner.
|
||||
|
||||
#ifndef LIB_FXL_COMMAND_LINE_H_
|
||||
#define LIB_FXL_COMMAND_LINE_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/string_view.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
// CommandLine -----------------------------------------------------------------
|
||||
|
||||
// Class that stores processed command lines ("argv[0]", options, and positional
|
||||
// arguments) and provides access to them. For more details, see the file-level
|
||||
// comment above. This class is thread-safe.
|
||||
class CommandLine final {
|
||||
private:
|
||||
class ConstructionHelper;
|
||||
|
||||
public:
|
||||
struct Option {
|
||||
Option() {}
|
||||
explicit Option(const std::string& name);
|
||||
Option(const std::string& name, const std::string& value);
|
||||
|
||||
bool operator==(const Option& other) const {
|
||||
return name == other.name && value == other.value;
|
||||
}
|
||||
bool operator!=(const Option& other) const { return !operator==(other); }
|
||||
|
||||
std::string name;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
// Default, copy, and move constructors (to be out-of-lined).
|
||||
CommandLine();
|
||||
CommandLine(const CommandLine& from);
|
||||
CommandLine(CommandLine&& from);
|
||||
|
||||
// Constructs a |CommandLine| from its "components". This is especially useful
|
||||
// for creating a new |CommandLine| based on an existing |CommandLine| (e.g.,
|
||||
// adding options or arguments).
|
||||
explicit CommandLine(const std::string& argv0,
|
||||
const std::vector<Option>& options,
|
||||
const std::vector<std::string>& positional_args);
|
||||
|
||||
~CommandLine();
|
||||
|
||||
// Copy and move assignment (to be out-of-lined).
|
||||
CommandLine& operator=(const CommandLine& from);
|
||||
CommandLine& operator=(CommandLine&& from);
|
||||
|
||||
bool has_argv0() const { return has_argv0_; }
|
||||
const std::string& argv0() const { return argv0_; }
|
||||
const std::vector<Option>& options() const { return options_; }
|
||||
const std::vector<std::string>& positional_args() const {
|
||||
return positional_args_;
|
||||
}
|
||||
|
||||
bool operator==(const CommandLine& other) const {
|
||||
// No need to compare |option_index_|.
|
||||
return has_argv0_ == other.has_argv0_ && argv0_ == other.argv0_ &&
|
||||
options_ == other.options_ &&
|
||||
positional_args_ == other.positional_args_;
|
||||
}
|
||||
bool operator!=(const CommandLine& other) const { return !operator==(other); }
|
||||
|
||||
// Returns true if this command line has the option |name| (and if |index| is
|
||||
// non-null, sets |*index| to the index of the *last* occurrence of the given
|
||||
// option in |options()|) and false if not.
|
||||
bool HasOption(StringView name, size_t* index = nullptr) const;
|
||||
|
||||
// Gets the value of the option |name|. Returns true (and sets |*value|) on
|
||||
// success and false (leaving |*value| alone) on failure.
|
||||
bool GetOptionValue(StringView name, std::string* value) const;
|
||||
|
||||
// Gets all values of the option |name|. Returns all values, which may be
|
||||
// empty if the option is not specified.
|
||||
std::vector<StringView> GetOptionValues(StringView name) const;
|
||||
|
||||
// Gets the value of the option |name|, with a default if the option is not
|
||||
// specified. (Note: This doesn't return a const reference, since this would
|
||||
// make the |default_value| argument inconvenient/dangerous.)
|
||||
std::string GetOptionValueWithDefault(StringView name,
|
||||
StringView default_value) const;
|
||||
|
||||
private:
|
||||
bool has_argv0_ = false;
|
||||
// The following should all be empty if |has_argv0_| is false.
|
||||
std::string argv0_;
|
||||
std::vector<Option> options_;
|
||||
std::vector<std::string> positional_args_;
|
||||
|
||||
// Maps option names to position in |options_|. If a given name occurs
|
||||
// multiple times, the index will be to the *last* occurrence.
|
||||
std::unordered_map<std::string, size_t> option_index_;
|
||||
|
||||
// Allow copy and assignment.
|
||||
};
|
||||
|
||||
// Factory functions (etc.) ----------------------------------------------------
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Helper class for building command lines (finding options, etc.) from raw
|
||||
// arguments.
|
||||
class CommandLineBuilder final {
|
||||
public:
|
||||
CommandLineBuilder();
|
||||
~CommandLineBuilder();
|
||||
|
||||
// Processes an additional argument in the command line. Returns true if |arg|
|
||||
// is the *first* positional argument.
|
||||
bool ProcessArg(const std::string& arg);
|
||||
|
||||
// Builds a |CommandLine| from the arguments processed so far.
|
||||
CommandLine Build() const;
|
||||
|
||||
private:
|
||||
bool has_argv0_ = false;
|
||||
std::string argv0_;
|
||||
std::vector<CommandLine::Option> options_;
|
||||
std::vector<std::string> positional_args_;
|
||||
|
||||
// True if we've started processing positional arguments.
|
||||
bool started_positional_args_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(CommandLineBuilder);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// The following factory functions create |CommandLine|s from raw arguments in
|
||||
// accordance with the rules outlined at the top of this file. (Other ways of
|
||||
// transforming raw arguments into options and positional arguments are
|
||||
// possible.)
|
||||
|
||||
// Like |CommandLineFromIterators()| (see below), but sets
|
||||
// |*first_positional_arg| to point to the first positional argument seen (or
|
||||
// |last| if none are seen). This is useful for processing "subcommands".
|
||||
template <typename InputIterator>
|
||||
inline CommandLine CommandLineFromIteratorsFindFirstPositionalArg(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
InputIterator* first_positional_arg) {
|
||||
if (first_positional_arg)
|
||||
*first_positional_arg = last;
|
||||
internal::CommandLineBuilder builder;
|
||||
for (auto it = first; it < last; ++it) {
|
||||
if (builder.ProcessArg(*it)) {
|
||||
if (first_positional_arg)
|
||||
*first_positional_arg = it;
|
||||
}
|
||||
}
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
// Builds a |CommandLine| from first/last iterators (where |last| is really
|
||||
// one-past-the-last, as usual) to |std::string|s or things that implicitly
|
||||
// convert to |std::string|.
|
||||
template <typename InputIterator>
|
||||
inline CommandLine CommandLineFromIterators(InputIterator first,
|
||||
InputIterator last) {
|
||||
return CommandLineFromIteratorsFindFirstPositionalArg<InputIterator>(
|
||||
first, last, nullptr);
|
||||
}
|
||||
|
||||
// Builds a |CommandLine| from first/last iterators (where |last| is really
|
||||
// one-past-the-last, as usual) to |std::string|s or things that implicitly
|
||||
// convert to |std::string|, where argv[0] is provided separately.
|
||||
template <typename InputIterator>
|
||||
inline CommandLine CommandLineFromIteratorsWithArgv0(const std::string& argv0,
|
||||
InputIterator first,
|
||||
InputIterator last) {
|
||||
internal::CommandLineBuilder builder;
|
||||
builder.ProcessArg(argv0);
|
||||
for (auto it = first; it < last; ++it)
|
||||
builder.ProcessArg(*it);
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
// Builds a |CommandLine| from the usual argc/argv.
|
||||
inline CommandLine CommandLineFromArgcArgv(int argc, const char* const* argv) {
|
||||
return CommandLineFromIterators(argv, argv + argc);
|
||||
}
|
||||
|
||||
// Builds a |CommandLine| from an initializer list of |std::string|s or things
|
||||
// that implicitly convert to |std::string|.
|
||||
template <typename StringType>
|
||||
inline CommandLine CommandLineFromInitializerList(
|
||||
std::initializer_list<StringType> argv) {
|
||||
return CommandLineFromIterators(argv.begin(), argv.end());
|
||||
}
|
||||
|
||||
// This is the "opposite" of the above factory functions, transforming a
|
||||
// |CommandLine| into a vector of argument strings according to the rules
|
||||
// outlined at the top of this file.
|
||||
std::vector<std::string> CommandLineToArgv(const CommandLine& command_line);
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // LIB_FXL_COMMAND_LINE_H_
|
||||
447
engine/src/flutter/fml/command_line_unittest.cc
Normal file
447
engine/src/flutter/fml/command_line_unittest.cc
Normal file
@@ -0,0 +1,447 @@
|
||||
// Copyright 2016 The Fuchsia 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 "flutter/fml/command_line.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace fml {
|
||||
namespace {
|
||||
|
||||
TEST(CommandLineTest, Basic) {
|
||||
// Making this const verifies that the methods called are const.
|
||||
const auto cl = CommandLineFromInitializerList(
|
||||
{"my_program", "--flag1", "--flag2=value2", "arg1", "arg2", "arg3"});
|
||||
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ("my_program", cl.argv0());
|
||||
|
||||
EXPECT_EQ(2u, cl.options().size());
|
||||
EXPECT_EQ("flag1", cl.options()[0].name);
|
||||
EXPECT_EQ(std::string(), cl.options()[0].value);
|
||||
EXPECT_EQ("flag2", cl.options()[1].name);
|
||||
EXPECT_EQ("value2", cl.options()[1].value);
|
||||
|
||||
EXPECT_EQ(3u, cl.positional_args().size());
|
||||
EXPECT_EQ("arg1", cl.positional_args()[0]);
|
||||
EXPECT_EQ("arg2", cl.positional_args()[1]);
|
||||
EXPECT_EQ("arg3", cl.positional_args()[2]);
|
||||
|
||||
EXPECT_TRUE(cl.HasOption("flag1"));
|
||||
EXPECT_TRUE(cl.HasOption("flag1", nullptr));
|
||||
size_t index = static_cast<size_t>(-1);
|
||||
EXPECT_TRUE(cl.HasOption("flag2", &index));
|
||||
EXPECT_EQ(1u, index);
|
||||
EXPECT_FALSE(cl.HasOption("flag3"));
|
||||
EXPECT_FALSE(cl.HasOption("flag3", nullptr));
|
||||
|
||||
std::string value = "nonempty";
|
||||
EXPECT_TRUE(cl.GetOptionValue("flag1", &value));
|
||||
EXPECT_EQ(std::string(), value);
|
||||
EXPECT_TRUE(cl.GetOptionValue("flag2", &value));
|
||||
EXPECT_EQ("value2", value);
|
||||
EXPECT_FALSE(cl.GetOptionValue("flag3", &value));
|
||||
|
||||
EXPECT_EQ(std::string(), cl.GetOptionValueWithDefault("flag1", "nope"));
|
||||
EXPECT_EQ("value2", cl.GetOptionValueWithDefault("flag2", "nope"));
|
||||
EXPECT_EQ("nope", cl.GetOptionValueWithDefault("flag3", "nope"));
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, DefaultConstructor) {
|
||||
CommandLine cl;
|
||||
EXPECT_FALSE(cl.has_argv0());
|
||||
EXPECT_EQ(std::string(), cl.argv0());
|
||||
EXPECT_EQ(std::vector<CommandLine::Option>(), cl.options());
|
||||
EXPECT_EQ(std::vector<std::string>(), cl.positional_args());
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, ComponentConstructor) {
|
||||
const std::string argv0 = "my_program";
|
||||
const std::vector<CommandLine::Option> options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
const std::vector<std::string> positional_args = {"arg"};
|
||||
|
||||
CommandLine cl(argv0, options, positional_args);
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(argv0, cl.argv0());
|
||||
EXPECT_EQ(options, cl.options());
|
||||
EXPECT_EQ(positional_args, cl.positional_args());
|
||||
EXPECT_EQ("value", cl.GetOptionValueWithDefault("flag", "nope"));
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, CommandLineFromIteratorsFindFirstPositionalArg) {
|
||||
// This shows how one might process subcommands.
|
||||
{
|
||||
static std::vector<std::string> argv = {"my_program", "--flag1",
|
||||
"--flag2", "subcommand",
|
||||
"--subflag", "subarg"};
|
||||
auto first = argv.cbegin();
|
||||
auto last = argv.cend();
|
||||
std::vector<std::string>::const_iterator sub_first;
|
||||
auto cl =
|
||||
CommandLineFromIteratorsFindFirstPositionalArg(first, last, &sub_first);
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(argv[0], cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag1"), CommandLine::Option("flag2")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {argv[3], argv[4],
|
||||
argv[5]};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
EXPECT_TRUE(cl.HasOption("flag1", nullptr));
|
||||
EXPECT_TRUE(cl.HasOption("flag2", nullptr));
|
||||
EXPECT_FALSE(cl.HasOption("subflag", nullptr));
|
||||
|
||||
EXPECT_EQ(first + 3, sub_first);
|
||||
auto sub_cl = CommandLineFromIterators(sub_first, last);
|
||||
EXPECT_TRUE(sub_cl.has_argv0());
|
||||
EXPECT_EQ(argv[3], sub_cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_sub_options = {
|
||||
CommandLine::Option("subflag")};
|
||||
EXPECT_EQ(expected_sub_options, sub_cl.options());
|
||||
std::vector<std::string> expected_sub_positional_args = {argv[5]};
|
||||
EXPECT_EQ(expected_sub_positional_args, sub_cl.positional_args());
|
||||
EXPECT_FALSE(sub_cl.HasOption("flag1", nullptr));
|
||||
EXPECT_FALSE(sub_cl.HasOption("flag2", nullptr));
|
||||
EXPECT_TRUE(sub_cl.HasOption("subflag", nullptr));
|
||||
}
|
||||
|
||||
// No positional argument.
|
||||
{
|
||||
static std::vector<std::string> argv = {"my_program", "--flag"};
|
||||
std::vector<std::string>::const_iterator sub_first;
|
||||
auto cl = CommandLineFromIteratorsFindFirstPositionalArg(
|
||||
argv.cbegin(), argv.cend(), &sub_first);
|
||||
EXPECT_EQ(argv.cend(), sub_first);
|
||||
}
|
||||
|
||||
// Multiple positional arguments.
|
||||
{
|
||||
static std::vector<std::string> argv = {"my_program", "arg1", "arg2"};
|
||||
std::vector<std::string>::const_iterator sub_first;
|
||||
auto cl = CommandLineFromIteratorsFindFirstPositionalArg(
|
||||
argv.cbegin(), argv.cend(), &sub_first);
|
||||
EXPECT_EQ(argv.cbegin() + 1, sub_first);
|
||||
}
|
||||
|
||||
// "--".
|
||||
{
|
||||
static std::vector<std::string> argv = {"my_program", "--", "--arg"};
|
||||
std::vector<std::string>::const_iterator sub_first;
|
||||
auto cl = CommandLineFromIteratorsFindFirstPositionalArg(
|
||||
argv.cbegin(), argv.cend(), &sub_first);
|
||||
EXPECT_EQ(argv.cbegin() + 2, sub_first);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, CommmandLineFromIterators) {
|
||||
{
|
||||
// Note (here and below): The |const| ensures that the factory method can
|
||||
// accept const iterators.
|
||||
const std::vector<std::string> argv = {"my_program", "--flag=value", "arg"};
|
||||
|
||||
auto cl = CommandLineFromIterators(argv.begin(), argv.end());
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(argv[0], cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {argv[2]};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
EXPECT_EQ("value", cl.GetOptionValueWithDefault("flag", "nope"));
|
||||
}
|
||||
|
||||
// Can handle empty argv.
|
||||
{
|
||||
const std::vector<std::string> argv;
|
||||
|
||||
auto cl = CommandLineFromIterators(argv.begin(), argv.end());
|
||||
EXPECT_FALSE(cl.has_argv0());
|
||||
EXPECT_EQ(std::string(), cl.argv0());
|
||||
EXPECT_EQ(std::vector<CommandLine::Option>(), cl.options());
|
||||
EXPECT_EQ(std::vector<std::string>(), cl.positional_args());
|
||||
}
|
||||
|
||||
// Can handle empty |argv[0]|.
|
||||
{
|
||||
const std::vector<std::string> argv = {""};
|
||||
|
||||
auto cl = CommandLineFromIterators(argv.begin(), argv.end());
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(std::string(), cl.argv0());
|
||||
EXPECT_EQ(std::vector<CommandLine::Option>(), cl.options());
|
||||
EXPECT_EQ(std::vector<std::string>(), cl.positional_args());
|
||||
}
|
||||
|
||||
// Can also take a vector of |const char*|s.
|
||||
{
|
||||
const std::vector<const char*> argv = {"my_program", "--flag=value", "arg"};
|
||||
|
||||
auto cl = CommandLineFromIterators(argv.begin(), argv.end());
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(argv[0], cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {argv[2]};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
EXPECT_EQ("value", cl.GetOptionValueWithDefault("flag", "nope"));
|
||||
}
|
||||
|
||||
// Or a plain old array.
|
||||
{
|
||||
static const char* const argv[] = {"my_program", "--flag=value", "arg"};
|
||||
|
||||
auto cl = CommandLineFromIterators(argv, argv + arraysize(argv));
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(argv[0], cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {argv[2]};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
EXPECT_EQ("value", cl.GetOptionValueWithDefault("flag", "nope"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, CommandLineFromArgcArgv) {
|
||||
static const char* const argv[] = {"my_program", "--flag=value", "arg"};
|
||||
const int argc = static_cast<int>(arraysize(argv));
|
||||
|
||||
auto cl = CommandLineFromArgcArgv(argc, argv);
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(argv[0], cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {argv[2]};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
EXPECT_EQ("value", cl.GetOptionValueWithDefault("flag", "nope"));
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, CommandLineFromInitializerList) {
|
||||
{
|
||||
std::initializer_list<const char*> il = {"my_program", "--flag=value",
|
||||
"arg"};
|
||||
auto cl = CommandLineFromInitializerList(il);
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ("my_program", cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {"arg"};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
EXPECT_EQ("value", cl.GetOptionValueWithDefault("flag", "nope"));
|
||||
}
|
||||
|
||||
{
|
||||
std::initializer_list<std::string> il = {"my_program", "--flag=value",
|
||||
"arg"};
|
||||
auto cl = CommandLineFromInitializerList(il);
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ("my_program", cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {"arg"};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
EXPECT_EQ("value", cl.GetOptionValueWithDefault("flag", "nope"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, OddArguments) {
|
||||
{
|
||||
// Except for "arg", these are all options.
|
||||
auto cl = CommandLineFromInitializerList(
|
||||
{"my_program", "--=", "--=foo", "--bar=", "--==", "--===", "--==x",
|
||||
"arg"});
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ("my_program", cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("="), CommandLine::Option("=foo"),
|
||||
CommandLine::Option("bar"), CommandLine::Option("="),
|
||||
CommandLine::Option("=", "="), CommandLine::Option("=", "x")};
|
||||
EXPECT_EQ(expected_options, cl.options());
|
||||
std::vector<std::string> expected_positional_args = {"arg"};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
}
|
||||
|
||||
// "-x" is an argument, not an options.
|
||||
{
|
||||
auto cl = CommandLineFromInitializerList({"", "-x"});
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(std::string(), cl.argv0());
|
||||
EXPECT_EQ(std::vector<CommandLine::Option>(), cl.options());
|
||||
std::vector<std::string> expected_positional_args = {"-x"};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
}
|
||||
|
||||
// Ditto for "-".
|
||||
{
|
||||
auto cl = CommandLineFromInitializerList({"", "-"});
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(std::string(), cl.argv0());
|
||||
EXPECT_EQ(std::vector<CommandLine::Option>(), cl.options());
|
||||
std::vector<std::string> expected_positional_args = {"-"};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
}
|
||||
|
||||
// "--" terminates option processing, but isn't an argument in the first
|
||||
// occurrence.
|
||||
{
|
||||
auto cl = CommandLineFromInitializerList(
|
||||
{"", "--flag=value", "--", "--not-a-flag", "arg", "--"});
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(std::string(), cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag", "value")};
|
||||
std::vector<std::string> expected_positional_args = {"--not-a-flag", "arg",
|
||||
"--"};
|
||||
EXPECT_EQ(expected_positional_args, cl.positional_args());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, MultipleOccurrencesOfOption) {
|
||||
auto cl = CommandLineFromInitializerList(
|
||||
{"my_program", "--flag1=value1", "--flag2=value2", "--flag1=value3"});
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
CommandLine::Option("flag1", "value1"),
|
||||
CommandLine::Option("flag2", "value2"),
|
||||
CommandLine::Option("flag1", "value3")};
|
||||
EXPECT_EQ("value3", cl.GetOptionValueWithDefault("flag1", "nope"));
|
||||
EXPECT_EQ("value2", cl.GetOptionValueWithDefault("flag2", "nope"));
|
||||
std::vector<StringView> values = cl.GetOptionValues("flag1");
|
||||
ASSERT_EQ(2u, values.size());
|
||||
EXPECT_EQ("value1", values[0]);
|
||||
EXPECT_EQ("value3", values[1]);
|
||||
}
|
||||
|
||||
// |cl1| and |cl2| should be not equal.
|
||||
void ExpectNotEqual(const char* message,
|
||||
std::initializer_list<std::string> c1,
|
||||
std::initializer_list<std::string> c2) {
|
||||
SCOPED_TRACE(message);
|
||||
|
||||
const auto cl1 = CommandLineFromInitializerList(c1);
|
||||
const auto cl2 = CommandLineFromInitializerList(c2);
|
||||
|
||||
// These are tautological.
|
||||
EXPECT_TRUE(cl1 == cl1);
|
||||
EXPECT_FALSE(cl1 != cl1);
|
||||
EXPECT_TRUE(cl2 == cl2);
|
||||
EXPECT_FALSE(cl2 != cl2);
|
||||
|
||||
// These rely on |cl1| not being equal to |cl2|.
|
||||
EXPECT_FALSE(cl1 == cl2);
|
||||
EXPECT_TRUE(cl1 != cl2);
|
||||
EXPECT_FALSE(cl2 == cl1);
|
||||
EXPECT_TRUE(cl2 != cl1);
|
||||
}
|
||||
|
||||
void ExpectEqual(const char* message,
|
||||
std::initializer_list<std::string> c1,
|
||||
std::initializer_list<std::string> c2) {
|
||||
SCOPED_TRACE(message);
|
||||
|
||||
const auto cl1 = CommandLineFromInitializerList(c1);
|
||||
const auto cl2 = CommandLineFromInitializerList(c2);
|
||||
|
||||
// These are tautological.
|
||||
EXPECT_TRUE(cl1 == cl1);
|
||||
EXPECT_FALSE(cl1 != cl1);
|
||||
EXPECT_TRUE(cl2 == cl2);
|
||||
EXPECT_FALSE(cl2 != cl2);
|
||||
|
||||
// These rely on |cl1| being equal to |cl2|.
|
||||
EXPECT_TRUE(cl1 == cl2);
|
||||
EXPECT_FALSE(cl1 != cl2);
|
||||
EXPECT_TRUE(cl2 == cl1);
|
||||
EXPECT_FALSE(cl2 != cl1);
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, ComparisonOperators) {
|
||||
ExpectNotEqual("1", {}, {""});
|
||||
ExpectNotEqual("2", {"abc"}, {"def"});
|
||||
ExpectNotEqual("3", {"abc", "--flag"}, {"abc"});
|
||||
ExpectNotEqual("4", {"abc", "--flag1"}, {"abc", "--flag2"});
|
||||
ExpectNotEqual("5", {"abc", "--flag1", "--flag2"}, {"abc", "--flag1"});
|
||||
ExpectNotEqual("6", {"abc", "arg"}, {"abc"});
|
||||
ExpectNotEqual("7", {"abc", "arg1"}, {"abc", "arg2"});
|
||||
ExpectNotEqual("8", {"abc", "arg1", "arg2"}, {"abc", "arg1"});
|
||||
ExpectNotEqual("9", {"abc", "--flag", "arg1"}, {"abc", "--flag", "arg2"});
|
||||
|
||||
// However, the presence of an unnecessary "--" shouldn't affect what's
|
||||
// constructed.
|
||||
ExpectEqual("10", {"abc", "--flag", "arg"}, {"abc", "--flag", "--", "arg"});
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, MoveAndCopy) {
|
||||
const auto cl = CommandLineFromInitializerList(
|
||||
{"my_program", "--flag1=value1", "--flag2", "arg"});
|
||||
|
||||
// Copy constructor.
|
||||
CommandLine cl2(cl);
|
||||
EXPECT_EQ(cl, cl2);
|
||||
// Check that |option_index_| gets copied too.
|
||||
EXPECT_EQ("value1", cl2.GetOptionValueWithDefault("flag1", "nope"));
|
||||
|
||||
// Move constructor.
|
||||
CommandLine cl3(std::move(cl2));
|
||||
EXPECT_EQ(cl, cl3);
|
||||
EXPECT_EQ("value1", cl3.GetOptionValueWithDefault("flag1", "nope"));
|
||||
|
||||
// Copy assignment.
|
||||
CommandLine cl4;
|
||||
EXPECT_NE(cl, cl4);
|
||||
cl4 = cl;
|
||||
EXPECT_EQ(cl, cl4);
|
||||
EXPECT_EQ("value1", cl4.GetOptionValueWithDefault("flag1", "nope"));
|
||||
|
||||
// Move assignment.
|
||||
CommandLine cl5;
|
||||
EXPECT_NE(cl, cl5);
|
||||
cl5 = std::move(cl4);
|
||||
EXPECT_EQ(cl, cl5);
|
||||
EXPECT_EQ("value1", cl5.GetOptionValueWithDefault("flag1", "nope"));
|
||||
}
|
||||
|
||||
void ToArgvHelper(const char* message, std::initializer_list<std::string> c) {
|
||||
SCOPED_TRACE(message);
|
||||
std::vector<std::string> argv = c;
|
||||
auto cl = CommandLineFromInitializerList(c);
|
||||
EXPECT_EQ(argv, CommandLineToArgv(cl));
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, CommandLineToArgv) {
|
||||
ToArgvHelper("1", {});
|
||||
ToArgvHelper("2", {""});
|
||||
ToArgvHelper("3", {"my_program"});
|
||||
ToArgvHelper("4", {"my_program", "--flag"});
|
||||
ToArgvHelper("5", {"my_program", "--flag1", "--flag2=value"});
|
||||
ToArgvHelper("6", {"my_program", "arg"});
|
||||
ToArgvHelper("7", {"my_program", "arg1", "arg2"});
|
||||
ToArgvHelper("8", {"my_program", "--flag1", "--flag2=value", "arg1", "arg2"});
|
||||
ToArgvHelper("9", {"my_program", "--flag", "--", "--not-a-flag"});
|
||||
ToArgvHelper("10", {"my_program", "--flag", "arg", "--"});
|
||||
|
||||
// However, |CommandLineToArgv()| will "strip" an unneeded "--".
|
||||
{
|
||||
auto cl = CommandLineFromInitializerList({"my_program", "--"});
|
||||
std::vector<std::string> argv = {"my_program"};
|
||||
EXPECT_EQ(argv, CommandLineToArgv(cl));
|
||||
}
|
||||
{
|
||||
auto cl =
|
||||
CommandLineFromInitializerList({"my_program", "--flag", "--", "arg"});
|
||||
std::vector<std::string> argv = {"my_program", "--flag", "arg"};
|
||||
EXPECT_EQ(argv, CommandLineToArgv(cl));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace fml
|
||||
@@ -30,6 +30,9 @@ fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor);
|
||||
|
||||
bool IsDirectory(const fml::UniqueFD& directory);
|
||||
|
||||
// Returns whether the given path is a file.
|
||||
bool IsFile(const std::string& path);
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_FILE_H_
|
||||
|
||||
63
engine/src/flutter/fml/make_copyable.h
Normal file
63
engine/src/flutter/fml/make_copyable.h
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2016 The Fuchsia 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 FLUTTER_FML_MAKE_COPYABLE_H_
|
||||
#define FLUTTER_FML_MAKE_COPYABLE_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
|
||||
namespace fml {
|
||||
namespace internal {
|
||||
|
||||
template <typename T>
|
||||
class CopyableLambda {
|
||||
public:
|
||||
explicit CopyableLambda(T func)
|
||||
: impl_(MakeRefCounted<Impl>(std::move(func))) {}
|
||||
|
||||
template <typename... ArgType>
|
||||
auto operator()(ArgType&&... args) const {
|
||||
return impl_->func_(std::forward<ArgType>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
class Impl : public RefCountedThreadSafe<Impl> {
|
||||
public:
|
||||
explicit Impl(T func) : func_(std::move(func)) {}
|
||||
T func_;
|
||||
};
|
||||
|
||||
RefPtr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Provides a wrapper for a move-only lambda that is implictly convertable to an
|
||||
// std::function.
|
||||
//
|
||||
// std::function is copyable, but if a lambda captures an argument with a
|
||||
// move-only type, the lambda itself is not copyable. In order to use the lambda
|
||||
// in places that accept std::functions, we provide a copyable object that wraps
|
||||
// the lambda and is implicitly convertable to an std::function.
|
||||
//
|
||||
// EXAMPLE:
|
||||
//
|
||||
// std::unique_ptr<Foo> foo = ...
|
||||
// std::function<int()> func =
|
||||
// fml::MakeCopyable([bar = std::move(foo)]() { return bar->count(); });
|
||||
//
|
||||
// Notice that the return type of MakeCopyable is rarely used directly. Instead,
|
||||
// callers typically erase the type by implicitly converting the return value
|
||||
// to an std::function.
|
||||
template <typename T>
|
||||
internal::CopyableLambda<T> MakeCopyable(T lambda) {
|
||||
return internal::CopyableLambda<T>(std::move(lambda));
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_MAKE_COPYABLE_H_
|
||||
@@ -21,8 +21,8 @@ namespace fml {
|
||||
//
|
||||
// |~Foo()| *may* be made private (e.g., to avoid accidental deletion of objects
|
||||
// while there are still references to them), |Foo| should friend
|
||||
// |RefCountedThreadSafe<Foo>|; use |FML_FRIEND_REF_COUNTED_THREAD_SAFE()| for
|
||||
// this:
|
||||
// |RefCountedThreadSafe<Foo>|; use |FML_FRIEND_REF_COUNTED_THREAD_SAFE()|
|
||||
// for this:
|
||||
//
|
||||
// class Foo : public RefCountedThreadSafe<Foo> {
|
||||
// ...
|
||||
|
||||
@@ -55,7 +55,9 @@ class ThreadChecker final {
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef NDEBUG
|
||||
// TODO(chinmaygarde): Re-enable this after auditing all new users of
|
||||
// fml::WeakPtr.
|
||||
#if !defined(NDEBUG) && false
|
||||
#define FML_DECLARE_THREAD_CHECKER(c) fml::ThreadChecker c
|
||||
#define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) \
|
||||
FML_DCHECK((c).IsCreationThreadCurrent())
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
#include "flutter/fml/message_loop_impl.h"
|
||||
#include "flutter/fml/task_runner.h"
|
||||
#include "flutter/fml/thread_local.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "lib/fxl/memory/ref_ptr.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
@@ -40,7 +40,7 @@ bool MessageLoop::IsInitializedForCurrentThread() {
|
||||
|
||||
MessageLoop::MessageLoop()
|
||||
: loop_(MessageLoopImpl::Create()),
|
||||
task_runner_(fxl::MakeRefCounted<fml::TaskRunner>(loop_)) {
|
||||
task_runner_(fml::MakeRefCounted<fml::TaskRunner>(loop_)) {
|
||||
FML_CHECK(loop_);
|
||||
FML_CHECK(task_runner_);
|
||||
}
|
||||
@@ -55,15 +55,15 @@ void MessageLoop::Terminate() {
|
||||
loop_->DoTerminate();
|
||||
}
|
||||
|
||||
fxl::RefPtr<fml::TaskRunner> MessageLoop::GetTaskRunner() const {
|
||||
fml::RefPtr<fml::TaskRunner> MessageLoop::GetTaskRunner() const {
|
||||
return task_runner_;
|
||||
}
|
||||
|
||||
fxl::RefPtr<MessageLoopImpl> MessageLoop::GetLoopImpl() const {
|
||||
fml::RefPtr<MessageLoopImpl> MessageLoop::GetLoopImpl() const {
|
||||
return loop_;
|
||||
}
|
||||
|
||||
void MessageLoop::AddTaskObserver(intptr_t key, fxl::Closure callback) {
|
||||
void MessageLoop::AddTaskObserver(intptr_t key, fml::closure callback) {
|
||||
loop_->AddTaskObserver(key, callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define FLUTTER_FML_MESSAGE_LOOP_H_
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "lib/fxl/tasks/task_runner.h"
|
||||
#include "flutter/fml/task_runner.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
@@ -24,11 +24,11 @@ class MessageLoop {
|
||||
|
||||
void Terminate();
|
||||
|
||||
void AddTaskObserver(intptr_t key, fxl::Closure callback);
|
||||
void AddTaskObserver(intptr_t key, fml::closure callback);
|
||||
|
||||
void RemoveTaskObserver(intptr_t key);
|
||||
|
||||
fxl::RefPtr<fml::TaskRunner> GetTaskRunner() const;
|
||||
fml::RefPtr<fml::TaskRunner> GetTaskRunner() const;
|
||||
|
||||
// Exposed for the embedder shell which allows clients to poll for events
|
||||
// instead of dedicating a thread to the message loop.
|
||||
@@ -44,12 +44,12 @@ class MessageLoop {
|
||||
friend class TaskRunner;
|
||||
friend class MessageLoopImpl;
|
||||
|
||||
fxl::RefPtr<MessageLoopImpl> loop_;
|
||||
fxl::RefPtr<fml::TaskRunner> task_runner_;
|
||||
fml::RefPtr<MessageLoopImpl> loop_;
|
||||
fml::RefPtr<fml::TaskRunner> task_runner_;
|
||||
|
||||
MessageLoop();
|
||||
|
||||
fxl::RefPtr<MessageLoopImpl> GetLoopImpl() const;
|
||||
fml::RefPtr<MessageLoopImpl> GetLoopImpl() const;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MessageLoop);
|
||||
};
|
||||
|
||||
@@ -25,15 +25,15 @@
|
||||
|
||||
namespace fml {
|
||||
|
||||
fxl::RefPtr<MessageLoopImpl> MessageLoopImpl::Create() {
|
||||
fml::RefPtr<MessageLoopImpl> MessageLoopImpl::Create() {
|
||||
#if OS_MACOSX
|
||||
return fxl::MakeRefCounted<MessageLoopDarwin>();
|
||||
return fml::MakeRefCounted<MessageLoopDarwin>();
|
||||
#elif OS_ANDROID
|
||||
return fxl::MakeRefCounted<MessageLoopAndroid>();
|
||||
return fml::MakeRefCounted<MessageLoopAndroid>();
|
||||
#elif OS_LINUX
|
||||
return fxl::MakeRefCounted<MessageLoopLinux>();
|
||||
return fml::MakeRefCounted<MessageLoopLinux>();
|
||||
#elif OS_WIN
|
||||
return fxl::MakeRefCounted<MessageLoopWin>();
|
||||
return fml::MakeRefCounted<MessageLoopWin>();
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
@@ -43,7 +43,7 @@ MessageLoopImpl::MessageLoopImpl() : order_(0), terminated_(false) {}
|
||||
|
||||
MessageLoopImpl::~MessageLoopImpl() = default;
|
||||
|
||||
void MessageLoopImpl::PostTask(fxl::Closure task, fxl::TimePoint target_time) {
|
||||
void MessageLoopImpl::PostTask(fml::closure task, fml::TimePoint target_time) {
|
||||
FML_DCHECK(task != nullptr);
|
||||
RegisterTask(task, target_time);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void MessageLoopImpl::RunExpiredTasksNow() {
|
||||
RunExpiredTasks();
|
||||
}
|
||||
|
||||
void MessageLoopImpl::AddTaskObserver(intptr_t key, fxl::Closure callback) {
|
||||
void MessageLoopImpl::AddTaskObserver(intptr_t key, fml::closure callback) {
|
||||
FML_DCHECK(callback != nullptr);
|
||||
FML_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this)
|
||||
<< "Message loop task observer must be added on the same thread as the "
|
||||
@@ -99,8 +99,8 @@ void MessageLoopImpl::DoTerminate() {
|
||||
Terminate();
|
||||
}
|
||||
|
||||
void MessageLoopImpl::RegisterTask(fxl::Closure task,
|
||||
fxl::TimePoint target_time) {
|
||||
void MessageLoopImpl::RegisterTask(fml::closure task,
|
||||
fml::TimePoint target_time) {
|
||||
FML_DCHECK(task != nullptr);
|
||||
if (terminated_) {
|
||||
// If the message loop has already been terminated, PostTask should destruct
|
||||
@@ -114,7 +114,7 @@ void MessageLoopImpl::RegisterTask(fxl::Closure task,
|
||||
|
||||
void MessageLoopImpl::RunExpiredTasks() {
|
||||
TRACE_EVENT0("fml", "MessageLoop::RunExpiredTasks");
|
||||
std::vector<fxl::Closure> invocations;
|
||||
std::vector<fml::closure> invocations;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
@@ -123,7 +123,7 @@ void MessageLoopImpl::RunExpiredTasks() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto now = fxl::TimePoint::Now();
|
||||
auto now = fml::TimePoint::Now();
|
||||
while (!delayed_tasks_.empty()) {
|
||||
const auto& top = delayed_tasks_.top();
|
||||
if (top.target_time > now) {
|
||||
@@ -133,7 +133,7 @@ void MessageLoopImpl::RunExpiredTasks() {
|
||||
delayed_tasks_.pop();
|
||||
}
|
||||
|
||||
WakeUp(delayed_tasks_.empty() ? fxl::TimePoint::Max()
|
||||
WakeUp(delayed_tasks_.empty() ? fml::TimePoint::Max()
|
||||
: delayed_tasks_.top().target_time);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/fml/closure.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/message_loop.h"
|
||||
#include "lib/fxl/functional/closure.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "lib/fxl/time/time_point.h"
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
class MessageLoopImpl : public fxl::RefCountedThreadSafe<MessageLoopImpl> {
|
||||
class MessageLoopImpl : public fml::RefCountedThreadSafe<MessageLoopImpl> {
|
||||
public:
|
||||
static fxl::RefPtr<MessageLoopImpl> Create();
|
||||
static fml::RefPtr<MessageLoopImpl> Create();
|
||||
|
||||
virtual ~MessageLoopImpl();
|
||||
|
||||
@@ -30,11 +30,11 @@ class MessageLoopImpl : public fxl::RefCountedThreadSafe<MessageLoopImpl> {
|
||||
|
||||
virtual void Terminate() = 0;
|
||||
|
||||
virtual void WakeUp(fxl::TimePoint time_point) = 0;
|
||||
virtual void WakeUp(fml::TimePoint time_point) = 0;
|
||||
|
||||
void PostTask(fxl::Closure task, fxl::TimePoint target_time);
|
||||
void PostTask(fml::closure task, fml::TimePoint target_time);
|
||||
|
||||
void AddTaskObserver(intptr_t key, fxl::Closure callback);
|
||||
void AddTaskObserver(intptr_t key, fml::closure callback);
|
||||
|
||||
void RemoveTaskObserver(intptr_t key);
|
||||
|
||||
@@ -52,12 +52,12 @@ class MessageLoopImpl : public fxl::RefCountedThreadSafe<MessageLoopImpl> {
|
||||
private:
|
||||
struct DelayedTask {
|
||||
size_t order;
|
||||
fxl::Closure task;
|
||||
fxl::TimePoint target_time;
|
||||
fml::closure task;
|
||||
fml::TimePoint target_time;
|
||||
|
||||
DelayedTask(size_t p_order,
|
||||
fxl::Closure p_task,
|
||||
fxl::TimePoint p_target_time)
|
||||
fml::closure p_task,
|
||||
fml::TimePoint p_target_time)
|
||||
: order(p_order), task(std::move(p_task)), target_time(p_target_time) {}
|
||||
};
|
||||
|
||||
@@ -71,13 +71,13 @@ class MessageLoopImpl : public fxl::RefCountedThreadSafe<MessageLoopImpl> {
|
||||
using DelayedTaskQueue = std::
|
||||
priority_queue<DelayedTask, std::deque<DelayedTask>, DelayedTaskCompare>;
|
||||
|
||||
std::map<intptr_t, fxl::Closure> task_observers_;
|
||||
std::map<intptr_t, fml::closure> task_observers_;
|
||||
std::mutex delayed_tasks_mutex_;
|
||||
DelayedTaskQueue delayed_tasks_;
|
||||
size_t order_;
|
||||
std::atomic_bool terminated_;
|
||||
|
||||
void RegisterTask(fxl::Closure task, fxl::TimePoint target_time);
|
||||
void RegisterTask(fml::closure task, fml::TimePoint target_time);
|
||||
|
||||
void RunExpiredTasks();
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ TEST(MessageLoop, DelayedTasksAtSameTimeAreRunInOrder) {
|
||||
auto& loop = fml::MessageLoop::GetCurrent();
|
||||
size_t current = 0;
|
||||
const auto now_plus_some =
|
||||
fxl::TimePoint::Now() + fxl::TimeDelta::FromMilliseconds(2);
|
||||
fml::TimePoint::Now() + fml::TimeDelta::FromMilliseconds(2);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
loop.GetTaskRunner()->PostTaskForTime(
|
||||
PLATFORM_SPECIFIC_CAPTURE(&terminated, i, ¤t)() {
|
||||
@@ -134,7 +134,7 @@ TEST(MessageLoop, DelayedTasksAtSameTimeAreRunInOrder) {
|
||||
}
|
||||
|
||||
TEST(MessageLoop, CheckRunsTaskOnCurrentThread) {
|
||||
fxl::RefPtr<fxl::TaskRunner> runner;
|
||||
fml::RefPtr<fml::TaskRunner> runner;
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
std::thread thread([&runner, &latch]() {
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
@@ -154,17 +154,17 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskByDelta)) {
|
||||
std::thread thread([&checked]() {
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
auto& loop = fml::MessageLoop::GetCurrent();
|
||||
auto begin = fxl::TimePoint::Now();
|
||||
auto begin = fml::TimePoint::Now();
|
||||
loop.GetTaskRunner()->PostDelayedTask(
|
||||
[begin, &checked]() {
|
||||
auto delta = fxl::TimePoint::Now() - begin;
|
||||
auto delta = fml::TimePoint::Now() - begin;
|
||||
auto ms = delta.ToMillisecondsF();
|
||||
ASSERT_GE(ms, 3);
|
||||
ASSERT_LE(ms, 7);
|
||||
checked = true;
|
||||
fml::MessageLoop::GetCurrent().Terminate();
|
||||
},
|
||||
fxl::TimeDelta::FromMilliseconds(5));
|
||||
fml::TimeDelta::FromMilliseconds(5));
|
||||
loop.Run();
|
||||
});
|
||||
thread.join();
|
||||
@@ -176,17 +176,17 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) {
|
||||
std::thread thread([&checked]() {
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
auto& loop = fml::MessageLoop::GetCurrent();
|
||||
auto begin = fxl::TimePoint::Now();
|
||||
auto begin = fml::TimePoint::Now();
|
||||
loop.GetTaskRunner()->PostTaskForTime(
|
||||
[begin, &checked]() {
|
||||
auto delta = fxl::TimePoint::Now() - begin;
|
||||
auto delta = fml::TimePoint::Now() - begin;
|
||||
auto ms = delta.ToMillisecondsF();
|
||||
ASSERT_GE(ms, 3);
|
||||
ASSERT_LE(ms, 7);
|
||||
checked = true;
|
||||
fml::MessageLoop::GetCurrent().Terminate();
|
||||
},
|
||||
fxl::TimePoint::Now() + fxl::TimeDelta::FromMilliseconds(5));
|
||||
fml::TimePoint::Now() + fml::TimeDelta::FromMilliseconds(5));
|
||||
loop.Run();
|
||||
});
|
||||
thread.join();
|
||||
@@ -200,10 +200,10 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
auto& loop = fml::MessageLoop::GetCurrent();
|
||||
for (int target_ms = 0 + 2; target_ms < count + 2; target_ms++) {
|
||||
auto begin = fxl::TimePoint::Now();
|
||||
auto begin = fml::TimePoint::Now();
|
||||
loop.GetTaskRunner()->PostDelayedTask(
|
||||
PLATFORM_SPECIFIC_CAPTURE(begin, target_ms, &checked)() {
|
||||
auto delta = fxl::TimePoint::Now() - begin;
|
||||
auto delta = fml::TimePoint::Now() - begin;
|
||||
auto ms = delta.ToMillisecondsF();
|
||||
ASSERT_GE(ms, target_ms - 2);
|
||||
ASSERT_LE(ms, target_ms + 2);
|
||||
@@ -212,7 +212,7 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
|
||||
fml::MessageLoop::GetCurrent().Terminate();
|
||||
}
|
||||
},
|
||||
fxl::TimeDelta::FromMilliseconds(target_ms));
|
||||
fml::TimeDelta::FromMilliseconds(target_ms));
|
||||
}
|
||||
loop.Run();
|
||||
});
|
||||
@@ -227,10 +227,10 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
auto& loop = fml::MessageLoop::GetCurrent();
|
||||
for (int target_ms = count + 2; target_ms > 0 + 2; target_ms--) {
|
||||
auto begin = fxl::TimePoint::Now();
|
||||
auto begin = fml::TimePoint::Now();
|
||||
loop.GetTaskRunner()->PostDelayedTask(
|
||||
PLATFORM_SPECIFIC_CAPTURE(begin, target_ms, &checked)() {
|
||||
auto delta = fxl::TimePoint::Now() - begin;
|
||||
auto delta = fml::TimePoint::Now() - begin;
|
||||
auto ms = delta.ToMillisecondsF();
|
||||
ASSERT_GE(ms, target_ms - 2);
|
||||
ASSERT_LE(ms, target_ms + 2);
|
||||
@@ -239,7 +239,7 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
|
||||
fml::MessageLoop::GetCurrent().Terminate();
|
||||
}
|
||||
},
|
||||
fxl::TimeDelta::FromMilliseconds(target_ms));
|
||||
fml::TimeDelta::FromMilliseconds(target_ms));
|
||||
}
|
||||
loop.Run();
|
||||
});
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
#ifndef FLUTTER_FML_NATIVE_LIBRARY_H_
|
||||
#define FLUTTER_FML_NATIVE_LIBRARY_H_
|
||||
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "lib/fxl/memory/ref_ptr.h"
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
|
||||
#if OS_WIN
|
||||
|
||||
@@ -16,7 +17,7 @@
|
||||
#endif // OS_WIN
|
||||
|
||||
namespace fml {
|
||||
class NativeLibrary : public fxl::RefCountedThreadSafe<NativeLibrary> {
|
||||
class NativeLibrary : public fml::RefCountedThreadSafe<NativeLibrary> {
|
||||
public:
|
||||
#if OS_WIN
|
||||
using Handle = HMODULE;
|
||||
@@ -24,13 +25,13 @@ class NativeLibrary : public fxl::RefCountedThreadSafe<NativeLibrary> {
|
||||
using Handle = void*;
|
||||
#endif // OS_WIN
|
||||
|
||||
static fxl::RefPtr<NativeLibrary> Create(const char* path);
|
||||
static fml::RefPtr<NativeLibrary> Create(const char* path);
|
||||
|
||||
static fxl::RefPtr<NativeLibrary> CreateWithHandle(
|
||||
static fml::RefPtr<NativeLibrary> CreateWithHandle(
|
||||
Handle handle,
|
||||
bool close_handle_when_done);
|
||||
|
||||
static fxl::RefPtr<NativeLibrary> CreateForCurrentProcess();
|
||||
static fml::RefPtr<NativeLibrary> CreateForCurrentProcess();
|
||||
|
||||
const uint8_t* ResolveSymbol(const char* symbol);
|
||||
|
||||
@@ -47,8 +48,8 @@ class NativeLibrary : public fxl::RefCountedThreadSafe<NativeLibrary> {
|
||||
Handle GetHandle() const;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(NativeLibrary);
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(NativeLibrary);
|
||||
FRIEND_MAKE_REF_COUNTED(NativeLibrary);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(NativeLibrary);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(NativeLibrary);
|
||||
};
|
||||
|
||||
} // namespace fml
|
||||
|
||||
@@ -15,6 +15,13 @@ std::pair<bool, std::string> GetExecutableDirectoryPath();
|
||||
|
||||
std::string JoinPaths(std::initializer_list<std::string> components);
|
||||
|
||||
// Returns the absolute path of a possibly relative path.
|
||||
// It doesn't consult the filesystem or simplify the path.
|
||||
std::string AbsolutePath(const std::string& path);
|
||||
|
||||
// Returns the directory name component of the given path.
|
||||
std::string GetDirectoryName(const std::string& path);
|
||||
|
||||
} // namespace paths
|
||||
} // namespace fml
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ void MessageLoopAndroid::Terminate() {
|
||||
ALooper_wake(looper_.get());
|
||||
}
|
||||
|
||||
void MessageLoopAndroid::WakeUp(fxl::TimePoint time_point) {
|
||||
void MessageLoopAndroid::WakeUp(fml::TimePoint time_point) {
|
||||
bool result = TimerRearm(timer_fd_.get(), time_point);
|
||||
FML_DCHECK(result);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/message_loop_impl.h"
|
||||
#include "flutter/fml/unique_fd.h"
|
||||
#include "lib/fxl/memory/unique_object.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
@@ -36,12 +35,12 @@ class MessageLoopAndroid : public MessageLoopImpl {
|
||||
|
||||
void Terminate() override;
|
||||
|
||||
void WakeUp(fxl::TimePoint time_point) override;
|
||||
void WakeUp(fml::TimePoint time_point) override;
|
||||
|
||||
void OnEventFired();
|
||||
|
||||
FRIEND_MAKE_REF_COUNTED(MessageLoopAndroid);
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopAndroid);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(MessageLoopAndroid);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopAndroid);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MessageLoopAndroid);
|
||||
};
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ class MessageLoopDarwin : public MessageLoopImpl {
|
||||
|
||||
void Terminate() override;
|
||||
|
||||
void WakeUp(fxl::TimePoint time_point) override;
|
||||
void WakeUp(fml::TimePoint time_point) override;
|
||||
|
||||
static void OnTimerFire(CFRunLoopTimerRef timer, MessageLoopDarwin* loop);
|
||||
|
||||
FRIEND_MAKE_REF_COUNTED(MessageLoopDarwin);
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopDarwin);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(MessageLoopDarwin);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopDarwin);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MessageLoopDarwin);
|
||||
};
|
||||
|
||||
|
||||
@@ -61,12 +61,12 @@ void MessageLoopDarwin::Terminate() {
|
||||
CFRunLoopStop(loop_);
|
||||
}
|
||||
|
||||
void MessageLoopDarwin::WakeUp(fxl::TimePoint time_point) {
|
||||
void MessageLoopDarwin::WakeUp(fml::TimePoint time_point) {
|
||||
// Rearm the timer. The time bases used by CoreFoundation and FXL are
|
||||
// different and must be accounted for.
|
||||
CFRunLoopTimerSetNextFireDate(
|
||||
delayed_wake_timer_,
|
||||
CFAbsoluteTimeGetCurrent() + (time_point - fxl::TimePoint::Now()).ToSecondsF());
|
||||
CFAbsoluteTimeGetCurrent() + (time_point - fml::TimePoint::Now()).ToSecondsF());
|
||||
}
|
||||
|
||||
void MessageLoopDarwin::OnTimerFire(CFRunLoopTimerRef timer, MessageLoopDarwin* loop) {
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include "lib/fxl/files/path.h"
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
return {true, files::GetDirectoryName([NSBundle mainBundle].executablePath.UTF8String)};
|
||||
return {true, GetDirectoryName([NSBundle mainBundle].executablePath.UTF8String)};
|
||||
}
|
||||
|
||||
} // namespace paths
|
||||
|
||||
@@ -73,10 +73,10 @@ void MessageLoopLinux::Run() {
|
||||
|
||||
void MessageLoopLinux::Terminate() {
|
||||
running_ = false;
|
||||
WakeUp(fxl::TimePoint::Now());
|
||||
WakeUp(fml::TimePoint::Now());
|
||||
}
|
||||
|
||||
void MessageLoopLinux::WakeUp(fxl::TimePoint time_point) {
|
||||
void MessageLoopLinux::WakeUp(fml::TimePoint time_point) {
|
||||
bool result = TimerRearm(timer_fd_.get(), time_point);
|
||||
FML_DCHECK(result);
|
||||
}
|
||||
|
||||
@@ -27,14 +27,14 @@ class MessageLoopLinux : public MessageLoopImpl {
|
||||
|
||||
void Terminate() override;
|
||||
|
||||
void WakeUp(fxl::TimePoint time_point) override;
|
||||
void WakeUp(fml::TimePoint time_point) override;
|
||||
|
||||
void OnEventFired();
|
||||
|
||||
bool AddOrRemoveTimerSource(bool add);
|
||||
|
||||
FRIEND_MAKE_REF_COUNTED(MessageLoopLinux);
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopLinux);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(MessageLoopLinux);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopLinux);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MessageLoopLinux);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lib/fxl/files/path.h"
|
||||
#include "flutter/fml/paths.h"
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace fml {
|
||||
#define NSEC_PER_SEC 1000000000
|
||||
#endif
|
||||
|
||||
bool TimerRearm(int fd, fxl::TimePoint time_point) {
|
||||
bool TimerRearm(int fd, fml::TimePoint time_point) {
|
||||
const uint64_t nano_secs = time_point.ToEpochDelta().ToNanoseconds();
|
||||
|
||||
struct itimerspec spec = {};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef FLUTTER_FML_PLATFORM_LINUX_TIMER_FD_H_
|
||||
#define FLUTTER_FML_PLATFORM_LINUX_TIMER_FD_H_
|
||||
|
||||
#include "lib/fxl/time/time_point.h"
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
|
||||
// clang-format off
|
||||
#if __has_include(<sys/timerfd.h>)
|
||||
@@ -41,7 +41,7 @@ int timerfd_settime(int ufc,
|
||||
namespace fml {
|
||||
|
||||
/// Rearms the timer to expire at the given time point.
|
||||
bool TimerRearm(int fd, fxl::TimePoint time_point);
|
||||
bool TimerRearm(int fd, fml::TimePoint time_point);
|
||||
|
||||
/// Drains the timer FD and retuns true if it has expired. This may be false in
|
||||
/// case the timer read is non-blocking and this routine was called before the
|
||||
|
||||
@@ -68,4 +68,11 @@ bool IsDirectory(const fml::UniqueFD& directory) {
|
||||
return S_ISDIR(stat_result.st_mode);
|
||||
}
|
||||
|
||||
bool IsFile(const std::string& path) {
|
||||
struct stat buf;
|
||||
if (stat(path.c_str(), &buf) != 0)
|
||||
return false;
|
||||
return S_ISREG(buf.st_mode);
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
|
||||
@@ -13,7 +13,7 @@ NativeLibrary::NativeLibrary(const char* path) {
|
||||
::dlerror();
|
||||
handle_ = ::dlopen(path, RTLD_NOW);
|
||||
if (handle_ == nullptr) {
|
||||
FXL_LOG(ERROR) << "Could not open library '" << path << "' due to error '"
|
||||
FML_LOG(ERROR) << "Could not open library '" << path << "' due to error '"
|
||||
<< ::dlerror() << "'.";
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ NativeLibrary::~NativeLibrary() {
|
||||
::dlerror();
|
||||
if (::dlclose(handle_) != 0) {
|
||||
handle_ = nullptr;
|
||||
FXL_LOG(ERROR) << "Could not close library due to error '" << ::dlerror()
|
||||
FML_LOG(ERROR) << "Could not close library due to error '" << ::dlerror()
|
||||
<< "'.";
|
||||
}
|
||||
}
|
||||
@@ -40,27 +40,27 @@ NativeLibrary::Handle NativeLibrary::GetHandle() const {
|
||||
return handle_;
|
||||
}
|
||||
|
||||
fxl::RefPtr<NativeLibrary> NativeLibrary::Create(const char* path) {
|
||||
auto library = fxl::AdoptRef(new NativeLibrary(path));
|
||||
fml::RefPtr<NativeLibrary> NativeLibrary::Create(const char* path) {
|
||||
auto library = fml::AdoptRef(new NativeLibrary(path));
|
||||
return library->GetHandle() != nullptr ? library : nullptr;
|
||||
}
|
||||
|
||||
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
|
||||
fml::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
|
||||
Handle handle,
|
||||
bool close_handle_when_done) {
|
||||
auto library =
|
||||
fxl::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
|
||||
fml::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
|
||||
return library->GetHandle() != nullptr ? library : nullptr;
|
||||
}
|
||||
|
||||
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
|
||||
return fxl::AdoptRef(new NativeLibrary(RTLD_DEFAULT, false));
|
||||
fml::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
|
||||
return fml::AdoptRef(new NativeLibrary(RTLD_DEFAULT, false));
|
||||
}
|
||||
|
||||
const uint8_t* NativeLibrary::ResolveSymbol(const char* symbol) {
|
||||
auto resolved_symbol = static_cast<const uint8_t*>(::dlsym(handle_, symbol));
|
||||
if (resolved_symbol == nullptr) {
|
||||
FXL_DLOG(INFO) << "Could not resolve symbol in library: " << symbol;
|
||||
FML_DLOG(INFO) << "Could not resolve symbol in library: " << symbol;
|
||||
}
|
||||
return resolved_symbol;
|
||||
}
|
||||
|
||||
48
engine/src/flutter/fml/platform/posix/paths_posix.cc
Normal file
48
engine/src/flutter/fml/platform/posix/paths_posix.cc
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2018 The Flutter 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 "flutter/fml/paths.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string GetCurrentDirectory() {
|
||||
char buffer[PATH_MAX];
|
||||
FML_CHECK(getcwd(buffer, sizeof(buffer)));
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string AbsolutePath(const std::string& path) {
|
||||
if (path.size() > 0) {
|
||||
if (path[0] == '/') {
|
||||
// Path is already absolute.
|
||||
return path;
|
||||
}
|
||||
return GetCurrentDirectory() + "/" + path;
|
||||
} else {
|
||||
// Path is empty.
|
||||
return GetCurrentDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetDirectoryName(const std::string& path) {
|
||||
size_t separator = path.rfind('/');
|
||||
if (separator == 0u)
|
||||
return "/";
|
||||
if (separator == std::string::npos)
|
||||
return std::string();
|
||||
return path.substr(0, separator);
|
||||
}
|
||||
|
||||
} // namespace paths
|
||||
} // namespace fml
|
||||
@@ -5,12 +5,20 @@
|
||||
#include "flutter/fml/file.h"
|
||||
|
||||
#include <Shlwapi.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/platform/win/wstring_conversion.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
namespace fml {
|
||||
|
||||
static fml::UniqueFD OpenFile(std::wstring path,
|
||||
@@ -124,4 +132,11 @@ bool IsDirectory(const fml::UniqueFD& directory) {
|
||||
return info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
||||
}
|
||||
|
||||
bool IsFile(const std::string& path) {
|
||||
struct stat buf;
|
||||
if (stat(path.c_str(), &buf) != 0)
|
||||
return false;
|
||||
return S_ISREG(buf.st_mode);
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
|
||||
@@ -26,12 +26,12 @@ void MessageLoopWin::Run() {
|
||||
|
||||
void MessageLoopWin::Terminate() {
|
||||
running_ = false;
|
||||
WakeUp(fxl::TimePoint::Now());
|
||||
WakeUp(fml::TimePoint::Now());
|
||||
}
|
||||
|
||||
void MessageLoopWin::WakeUp(fxl::TimePoint time_point) {
|
||||
void MessageLoopWin::WakeUp(fml::TimePoint time_point) {
|
||||
LARGE_INTEGER due_time = {0};
|
||||
fxl::TimePoint now = fxl::TimePoint::Now();
|
||||
fml::TimePoint now = fml::TimePoint::Now();
|
||||
if (time_point > now) {
|
||||
due_time.QuadPart = (time_point - now).ToNanoseconds() / -100;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/message_loop_impl.h"
|
||||
#include "lib/fxl/memory/unique_object.h"
|
||||
#include "flutter/fml/unique_object.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
@@ -24,7 +24,7 @@ class MessageLoopWin : public MessageLoopImpl {
|
||||
};
|
||||
|
||||
bool running_;
|
||||
fxl::UniqueObject<HANDLE, UniqueHandleTraits> timer_;
|
||||
fml::UniqueObject<HANDLE, UniqueHandleTraits> timer_;
|
||||
|
||||
MessageLoopWin();
|
||||
|
||||
@@ -34,10 +34,10 @@ class MessageLoopWin : public MessageLoopImpl {
|
||||
|
||||
void Terminate() override;
|
||||
|
||||
void WakeUp(fxl::TimePoint time_point) override;
|
||||
void WakeUp(fml::TimePoint time_point) override;
|
||||
|
||||
FRIEND_MAKE_REF_COUNTED(MessageLoopWin);
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopWin);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(MessageLoopWin);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopWin);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MessageLoopWin);
|
||||
};
|
||||
|
||||
|
||||
@@ -32,21 +32,21 @@ NativeLibrary::Handle NativeLibrary::GetHandle() const {
|
||||
return handle_;
|
||||
}
|
||||
|
||||
fxl::RefPtr<NativeLibrary> NativeLibrary::Create(const char* path) {
|
||||
auto library = fxl::AdoptRef(new NativeLibrary(path));
|
||||
fml::RefPtr<NativeLibrary> NativeLibrary::Create(const char* path) {
|
||||
auto library = fml::AdoptRef(new NativeLibrary(path));
|
||||
return library->GetHandle() != nullptr ? library : nullptr;
|
||||
}
|
||||
|
||||
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
|
||||
fml::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
|
||||
Handle handle,
|
||||
bool close_handle_when_done) {
|
||||
auto library =
|
||||
fxl::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
|
||||
fml::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
|
||||
return library->GetHandle() != nullptr ? library : nullptr;
|
||||
}
|
||||
|
||||
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
|
||||
return fxl::AdoptRef(new NativeLibrary(::GetModuleHandle(nullptr), false));
|
||||
fml::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
|
||||
return fml::AdoptRef(new NativeLibrary(::GetModuleHandle(nullptr), false));
|
||||
}
|
||||
|
||||
const uint8_t* NativeLibrary::ResolveSymbol(const char* symbol) {
|
||||
|
||||
@@ -6,11 +6,48 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "lib/fxl/files/path.h"
|
||||
#include "flutter/fml/paths.h"
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
namespace {
|
||||
|
||||
size_t RootLength(const std::string& path) {
|
||||
if (path.size() == 0)
|
||||
return 0;
|
||||
if (path[0] == '/')
|
||||
return 1;
|
||||
if (path[0] == '\\') {
|
||||
if (path.size() < 2 || path[1] != '\\')
|
||||
return 1;
|
||||
// The path is a network share. Search for up to two '\'s, as they are
|
||||
// the server and share - and part of the root part.
|
||||
size_t index = path.find('\\', 2);
|
||||
if (index > 0) {
|
||||
index = path.find('\\', index + 1);
|
||||
if (index > 0)
|
||||
return index;
|
||||
}
|
||||
return path.size();
|
||||
}
|
||||
// If the path is of the form 'C:/' or 'C:\', with C being any letter, it's
|
||||
// a root part.
|
||||
if (path.length() >= 2 && path[1] == ':' &&
|
||||
(path[2] == '/' || path[2] == '\\') &&
|
||||
((path[0] >= 'A' && path[0] <= 'Z') ||
|
||||
(path[0] >= 'a' && path[0] <= 'z'))) {
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t LastSeparator(const std::string& path) {
|
||||
return path.find_last_of("/\\");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
HMODULE module = GetModuleHandle(NULL);
|
||||
if (module == NULL) {
|
||||
@@ -21,7 +58,23 @@ std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
if (read_size == 0 || read_size == MAX_PATH) {
|
||||
return {false, ""};
|
||||
}
|
||||
return {true, files::GetDirectoryName(std::string{path, read_size})};
|
||||
return {true, GetDirectoryName(std::string{path, read_size})};
|
||||
}
|
||||
|
||||
std::string AbsolutePath(const std::string& path) {
|
||||
char absPath[MAX_PATH];
|
||||
_fullpath(absPath, path.c_str(), MAX_PATH);
|
||||
return std::string(absPath);
|
||||
}
|
||||
|
||||
std::string GetDirectoryName(const std::string& path) {
|
||||
size_t rootLength = RootLength(path);
|
||||
size_t separator = LastSeparator(path);
|
||||
if (separator < rootLength)
|
||||
separator = rootLength;
|
||||
if (separator == std::string::npos)
|
||||
return std::string();
|
||||
return path.substr(0, separator);
|
||||
}
|
||||
|
||||
} // namespace paths
|
||||
|
||||
212
engine/src/flutter/fml/string_view.cc
Normal file
212
engine/src/flutter/fml/string_view.cc
Normal file
@@ -0,0 +1,212 @@
|
||||
// Copyright 2016 The Fuchsia 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 "flutter/fml/string_view.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
namespace fml {
|
||||
|
||||
constexpr size_t StringView::npos;
|
||||
|
||||
namespace {
|
||||
|
||||
// For each character in characters_wanted, sets the index corresponding
|
||||
// to the code for that character to 1 in table. This is used by the
|
||||
// find_.*_of methods below to tell whether or not a character is in the lookup
|
||||
// table in constant time.
|
||||
// The argument `table' must be an array that is large enough to hold all
|
||||
// the possible values of an unsigned char. Thus it should be be declared
|
||||
// as follows:
|
||||
// bool table[std::numeric_limits<unsigned char>::max() + 1]
|
||||
inline void BuildLookupTable(StringView characters_wanted, bool* table) {
|
||||
size_t length = characters_wanted.size();
|
||||
const char* data = characters_wanted.data();
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
table[static_cast<unsigned char>(data[i])] = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int StringView::compare(StringView other) {
|
||||
size_t len = std::min(size_, other.size_);
|
||||
int retval = memcmp(data_, other.data_, len);
|
||||
if (retval == 0) {
|
||||
if (size_ == other.size_) {
|
||||
return 0;
|
||||
}
|
||||
return size_ < other.size_ ? -1 : 1;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool operator==(StringView lhs, StringView rhs) {
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
return lhs.compare(rhs) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(StringView lhs, StringView rhs) {
|
||||
if (lhs.size() != rhs.size())
|
||||
return true;
|
||||
return lhs.compare(rhs) != 0;
|
||||
}
|
||||
|
||||
bool operator<(StringView lhs, StringView rhs) {
|
||||
return lhs.compare(rhs) < 0;
|
||||
}
|
||||
|
||||
bool operator>(StringView lhs, StringView rhs) {
|
||||
return lhs.compare(rhs) > 0;
|
||||
}
|
||||
|
||||
bool operator<=(StringView lhs, StringView rhs) {
|
||||
return lhs.compare(rhs) <= 0;
|
||||
}
|
||||
|
||||
bool operator>=(StringView lhs, StringView rhs) {
|
||||
return lhs.compare(rhs) >= 0;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, StringView string_view) {
|
||||
o.write(string_view.data(), static_cast<std::streamsize>(string_view.size()));
|
||||
return o;
|
||||
}
|
||||
|
||||
size_t StringView::find(StringView s, size_t pos) const {
|
||||
if (pos > size_)
|
||||
return npos;
|
||||
if (s.empty())
|
||||
return pos;
|
||||
|
||||
auto result = std::search(begin() + pos, end(), s.begin(), s.end());
|
||||
if (result == end())
|
||||
return npos;
|
||||
return result - begin();
|
||||
}
|
||||
|
||||
size_t StringView::find(char c, size_t pos) const {
|
||||
if (pos > size_)
|
||||
return npos;
|
||||
|
||||
auto result = std::find(begin() + pos, end(), c);
|
||||
if (result == end())
|
||||
return npos;
|
||||
return result - begin();
|
||||
}
|
||||
|
||||
size_t StringView::rfind(StringView s, size_t pos) const {
|
||||
if (size_ < s.size())
|
||||
return npos;
|
||||
if (s.empty())
|
||||
return std::min(pos, size_);
|
||||
|
||||
auto last = begin() + std::min(size_ - s.size(), pos) + s.size();
|
||||
auto result = std::find_end(begin(), last, s.begin(), s.end());
|
||||
if (result == last)
|
||||
return npos;
|
||||
return result - begin();
|
||||
}
|
||||
|
||||
size_t StringView::rfind(char c, size_t pos) const {
|
||||
if (size_ == 0)
|
||||
return npos;
|
||||
|
||||
auto begin = rend() - std::min(size_ - 1, pos) - 1;
|
||||
auto result = std::find(begin, rend(), c);
|
||||
if (result == rend())
|
||||
return npos;
|
||||
return rend() - result - 1;
|
||||
}
|
||||
|
||||
size_t StringView::find_first_of(StringView s, size_t pos) const {
|
||||
if (pos >= size_ || s.size() == 0)
|
||||
return npos;
|
||||
|
||||
// Avoid the cost of BuildLookupTable() for a single-character search.
|
||||
if (s.size() == 1)
|
||||
return find(s.data()[0], pos);
|
||||
|
||||
bool lookup[std::numeric_limits<unsigned char>::max() + 1] = {false};
|
||||
BuildLookupTable(s, lookup);
|
||||
for (size_t i = pos; i < size_; ++i) {
|
||||
if (lookup[static_cast<unsigned char>(data_[i])]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t StringView::find_last_of(StringView s, size_t pos) const {
|
||||
if (size_ == 0 || s.size() == 0)
|
||||
return npos;
|
||||
|
||||
// Avoid the cost of BuildLookupTable() for a single-character search.
|
||||
if (s.size() == 1)
|
||||
return rfind(s.data()[0], pos);
|
||||
|
||||
bool lookup[std::numeric_limits<unsigned char>::max() + 1] = {false};
|
||||
BuildLookupTable(s, lookup);
|
||||
for (size_t i = std::min(pos, size_ - 1);; --i) {
|
||||
if (lookup[static_cast<unsigned char>(data_[i])])
|
||||
return i;
|
||||
if (i == 0)
|
||||
break;
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t StringView::find_first_not_of(StringView s, size_t pos) const {
|
||||
if (pos >= size_)
|
||||
return npos;
|
||||
|
||||
// Avoid the cost of BuildLookupTable() for a single-character search.
|
||||
if (s.size() == 1) {
|
||||
for (size_t i = pos; i < size_; ++i) {
|
||||
if (data_[i] != s[0])
|
||||
return i;
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
bool lookup[std::numeric_limits<unsigned char>::max() + 1] = {false};
|
||||
BuildLookupTable(s, lookup);
|
||||
for (size_t i = pos; i < size_; ++i) {
|
||||
if (!lookup[static_cast<unsigned char>(data_[i])]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t StringView::find_last_not_of(StringView s, size_t pos) const {
|
||||
if (size_ == 0)
|
||||
return npos;
|
||||
|
||||
// Avoid the cost of BuildLookupTable() for a single-character search.
|
||||
if (s.size() == 1) {
|
||||
for (size_t i = std::min(pos, size_ - 1);; --i) {
|
||||
if (data_[i] != s[0])
|
||||
return i;
|
||||
if (i == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool lookup[std::numeric_limits<unsigned char>::max() + 1] = {false};
|
||||
BuildLookupTable(s, lookup);
|
||||
for (size_t i = std::min(pos, size_ - 1);; --i) {
|
||||
if (!lookup[static_cast<unsigned char>(data_[i])])
|
||||
return i;
|
||||
if (i == 0)
|
||||
break;
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
167
engine/src/flutter/fml/string_view.h
Normal file
167
engine/src/flutter/fml/string_view.h
Normal file
@@ -0,0 +1,167 @@
|
||||
// Copyright 2016 The Fuchsia 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 FLUTTER_FML_STRING_VIEW_H_
|
||||
#define FLUTTER_FML_STRING_VIEW_H_
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
// MSVC 2015 doesn't support "extended constexpr" from C++14.
|
||||
#if __cplusplus >= 201402L
|
||||
// C++14 relaxed the limitation of the content of a constexpr function.
|
||||
#define CONSTEXPR_IN_CPP14 constexpr
|
||||
#else
|
||||
#define CONSTEXPR_IN_CPP14
|
||||
#endif
|
||||
|
||||
namespace fml {
|
||||
|
||||
// A string-like object that points to a sized piece of memory.
|
||||
class StringView {
|
||||
public:
|
||||
// Types.
|
||||
using const_iterator = const char*;
|
||||
using iterator = const_iterator;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
using reverse_iterator = const_reverse_iterator;
|
||||
|
||||
constexpr static size_t npos = static_cast<size_t>(-1);
|
||||
|
||||
// Constructors.
|
||||
constexpr StringView() : data_(""), size_(0u) {}
|
||||
|
||||
constexpr StringView(const StringView& string_view)
|
||||
: data_(string_view.data_), size_(string_view.size_) {}
|
||||
|
||||
constexpr StringView(const char* str, size_t len) : data_(str), size_(len) {}
|
||||
|
||||
explicit constexpr StringView(const char* str)
|
||||
: data_(str), size_(constexpr_strlen(str)) {}
|
||||
|
||||
// Implicit constructor for constant C strings.
|
||||
template <size_t N>
|
||||
constexpr StringView(const char (&str)[N])
|
||||
: data_(str), size_(constexpr_strlen(str)) {}
|
||||
|
||||
// Implicit constructor.
|
||||
StringView(const std::string& str) : data_(str.data()), size_(str.size()) {}
|
||||
|
||||
// Copy operators.
|
||||
StringView& operator=(const StringView& other) {
|
||||
data_ = other.data_;
|
||||
size_ = other.size_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Capacity methods.
|
||||
constexpr size_t size() const { return size_; }
|
||||
constexpr bool empty() const { return size_ == 0u; }
|
||||
|
||||
// Element access methods.
|
||||
constexpr char operator[](size_t pos) const { return data_[pos]; };
|
||||
constexpr char at(size_t pos) const { return data_[pos]; };
|
||||
constexpr char front() const { return data_[0]; };
|
||||
constexpr char back() const { return data_[size_ - 1]; };
|
||||
constexpr const char* data() const { return data_; }
|
||||
|
||||
// Iterators.
|
||||
constexpr const_iterator begin() const { return cbegin(); }
|
||||
constexpr const_iterator end() const { return cend(); }
|
||||
constexpr const_iterator cbegin() const { return data_; }
|
||||
constexpr const_iterator cend() const { return data_ + size_; }
|
||||
const_reverse_iterator rbegin() const {
|
||||
return const_reverse_iterator(cend());
|
||||
}
|
||||
const_reverse_iterator rend() const {
|
||||
return const_reverse_iterator(cbegin());
|
||||
}
|
||||
const_reverse_iterator crbegin() const {
|
||||
return const_reverse_iterator(cend());
|
||||
}
|
||||
const_reverse_iterator crend() const {
|
||||
return const_reverse_iterator(cbegin());
|
||||
}
|
||||
|
||||
// Modifier methods.
|
||||
CONSTEXPR_IN_CPP14 void clear() {
|
||||
data_ = "";
|
||||
size_ = 0;
|
||||
}
|
||||
CONSTEXPR_IN_CPP14 void remove_prefix(size_t n) {
|
||||
FML_DCHECK(n <= size_);
|
||||
data_ += n;
|
||||
size_ -= n;
|
||||
}
|
||||
CONSTEXPR_IN_CPP14 void remove_suffix(size_t n) {
|
||||
FML_DCHECK(n <= size_);
|
||||
size_ -= n;
|
||||
}
|
||||
CONSTEXPR_IN_CPP14 void swap(StringView& other) {
|
||||
const char* data = data_;
|
||||
data_ = other.data_;
|
||||
other.data_ = data;
|
||||
|
||||
size_t size = size_;
|
||||
size_ = other.size_;
|
||||
other.size_ = size;
|
||||
}
|
||||
|
||||
// String conversion.
|
||||
std::string ToString() const { return std::string(data_, size_); }
|
||||
|
||||
// String operations.
|
||||
constexpr StringView substr(size_t pos = 0, size_t n = npos) const {
|
||||
return StringView(data_ + pos, min(n, size_ - pos));
|
||||
}
|
||||
|
||||
// Returns negative, 0, or positive when |this| is lexigraphically
|
||||
// less than, equal to, or greater than |other|, a la
|
||||
// std::basic_string_view::compare.
|
||||
int compare(StringView other);
|
||||
|
||||
size_t find(StringView s, size_t pos = 0) const;
|
||||
size_t find(char c, size_t pos = 0) const;
|
||||
size_t rfind(StringView s, size_t pos = npos) const;
|
||||
size_t rfind(char c, size_t pos = npos) const;
|
||||
size_t find_first_of(StringView s, size_t pos = 0) const;
|
||||
size_t find_last_of(StringView s, size_t pos = npos) const;
|
||||
size_t find_first_not_of(StringView s, size_t pos = 0) const;
|
||||
size_t find_last_not_of(StringView s, size_t pos = npos) const;
|
||||
|
||||
private:
|
||||
constexpr static size_t min(size_t v1, size_t v2) {
|
||||
return v1 < v2 ? v1 : v2;
|
||||
}
|
||||
|
||||
constexpr static int constexpr_strlen(const char* str) {
|
||||
#if defined(_MSC_VER)
|
||||
return *str ? 1 + constexpr_strlen(str + 1) : 0;
|
||||
#else
|
||||
return __builtin_strlen(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* data_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
// Comparison.
|
||||
|
||||
bool operator==(StringView lhs, StringView rhs);
|
||||
bool operator!=(StringView lhs, StringView rhs);
|
||||
bool operator<(StringView lhs, StringView rhs);
|
||||
bool operator>(StringView lhs, StringView rhs);
|
||||
bool operator<=(StringView lhs, StringView rhs);
|
||||
bool operator>=(StringView lhs, StringView rhs);
|
||||
|
||||
// IO.
|
||||
std::ostream& operator<<(std::ostream& o, StringView string_view);
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_STRING_VIEW_H_
|
||||
418
engine/src/flutter/fml/string_view_unittest.cc
Normal file
418
engine/src/flutter/fml/string_view_unittest.cc
Normal file
@@ -0,0 +1,418 @@
|
||||
// Copyright 2016 The Fuchsia 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 "flutter/fml/string_view.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace fml {
|
||||
namespace {
|
||||
|
||||
#define TEST_STRING "Hello\0u"
|
||||
#define TEST_STRING_LENGTH 5u
|
||||
|
||||
// Loops over all substrings of |needles|, and calls |callback| for each.
|
||||
void LoopOverSubstrings(StringView haystack,
|
||||
StringView needles,
|
||||
std::function<void(std::string haystack_str,
|
||||
StringView haystack_sw,
|
||||
std::string to_find_str,
|
||||
StringView to_find_sw,
|
||||
int start_index)> callback) {
|
||||
std::string haystack_str = haystack.ToString();
|
||||
for (size_t substring_size = 0; substring_size < needles.size();
|
||||
++substring_size) {
|
||||
for (size_t start_index = 0; start_index <= needles.size(); ++start_index) {
|
||||
auto to_find = needles.substr(start_index, substring_size);
|
||||
for (size_t start_pos = 0; start_pos <= haystack.size(); ++start_pos) {
|
||||
callback(haystack_str, haystack, to_find.ToString(), to_find,
|
||||
start_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Loops over all characters in |needles|, and calls |callback| for each.
|
||||
void LoopOverChars(StringView haystack,
|
||||
StringView needles,
|
||||
std::function<void(std::string haystack_str,
|
||||
StringView haystack_sw,
|
||||
char c,
|
||||
int start_index)> callback) {
|
||||
std::string haystack_str = haystack.ToString();
|
||||
for (size_t index = 0; index < needles.size(); ++index) {
|
||||
for (size_t start_index = 0; start_index <= haystack.size();
|
||||
++start_index) {
|
||||
callback(haystack_str, haystack, needles[index], start_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loops over all combinations of characters present in |needles|, and calls
|
||||
// |callback| for each.
|
||||
void LoopOverCharCombinations(StringView haystack,
|
||||
StringView needles,
|
||||
std::function<void(std::string haystack_str,
|
||||
StringView haystack_sw,
|
||||
std::string current_chars,
|
||||
size_t pos)> callback) {
|
||||
// Look for all chars combinations, and compare with string.
|
||||
std::set<char> chars(needles.begin(), needles.end());
|
||||
std::string haystack_str = haystack.ToString();
|
||||
for (size_t selector = 0; selector < (1 << chars.size()); ++selector) {
|
||||
std::string current_chars;
|
||||
size_t current = selector;
|
||||
for (auto it = chars.begin(); it != chars.end(); ++it) {
|
||||
if (current & 1)
|
||||
current_chars += *it;
|
||||
current = current >> 1;
|
||||
}
|
||||
for (size_t pos = 0; pos <= haystack.size(); ++pos) {
|
||||
callback(haystack_str, haystack, current_chars, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(StringView, Constructors) {
|
||||
std::string str1("Hello");
|
||||
StringView sw1(str1);
|
||||
EXPECT_EQ(str1.data(), sw1.data());
|
||||
EXPECT_EQ(str1.size(), sw1.size());
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw1.size());
|
||||
|
||||
const char* str2 = str1.data();
|
||||
StringView sw2(str2);
|
||||
EXPECT_EQ(str1.data(), sw2.data());
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw2.size());
|
||||
}
|
||||
|
||||
TEST(StringView, ConstExprConstructors) {
|
||||
constexpr StringView sw1;
|
||||
EXPECT_EQ(0u, sw1.size());
|
||||
|
||||
constexpr StringView sw2(sw1);
|
||||
EXPECT_EQ(0u, sw2.size());
|
||||
EXPECT_EQ(sw1.data(), sw2.data());
|
||||
|
||||
constexpr StringView sw3(TEST_STRING, TEST_STRING_LENGTH);
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw3.size());
|
||||
|
||||
constexpr StringView sw4(TEST_STRING);
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw4.size());
|
||||
|
||||
constexpr const char* string_ptr = TEST_STRING;
|
||||
constexpr StringView sw5(string_ptr);
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw5.size());
|
||||
}
|
||||
|
||||
TEST(StringView, CopyOperator) {
|
||||
StringView sw1;
|
||||
|
||||
StringView sw2(TEST_STRING);
|
||||
sw1 = sw2;
|
||||
EXPECT_EQ(sw2.data(), sw1.data());
|
||||
|
||||
sw1 = TEST_STRING;
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw1.size());
|
||||
|
||||
sw1 = std::string(TEST_STRING);
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw1.size());
|
||||
}
|
||||
|
||||
TEST(StringView, CapacityMethods) {
|
||||
StringView sw1;
|
||||
EXPECT_EQ(0u, sw1.size());
|
||||
EXPECT_TRUE(sw1.empty());
|
||||
|
||||
StringView sw2(TEST_STRING);
|
||||
EXPECT_EQ(TEST_STRING_LENGTH, sw2.size());
|
||||
EXPECT_FALSE(sw2.empty());
|
||||
}
|
||||
|
||||
TEST(StringView, AccessMethods) {
|
||||
const char* str = TEST_STRING;
|
||||
StringView sw1(str);
|
||||
|
||||
EXPECT_EQ('H', sw1.front());
|
||||
EXPECT_EQ('e', sw1[1]);
|
||||
EXPECT_EQ('l', sw1.at(2));
|
||||
EXPECT_EQ('o', sw1.back());
|
||||
EXPECT_EQ(str, sw1.data());
|
||||
}
|
||||
|
||||
TEST(StringView, Iterators) {
|
||||
StringView sw1(TEST_STRING);
|
||||
|
||||
std::string str1(sw1.begin(), sw1.end());
|
||||
EXPECT_EQ(TEST_STRING, str1);
|
||||
|
||||
std::string str2(sw1.cbegin(), sw1.cend());
|
||||
EXPECT_EQ(TEST_STRING, str2);
|
||||
|
||||
std::string str3(sw1.rbegin(), sw1.rend());
|
||||
EXPECT_EQ("olleH", str3);
|
||||
|
||||
std::string str4(sw1.crbegin(), sw1.crend());
|
||||
EXPECT_EQ("olleH", str4);
|
||||
}
|
||||
|
||||
TEST(StringView, Modifiers) {
|
||||
StringView sw1(TEST_STRING);
|
||||
|
||||
sw1.remove_prefix(1);
|
||||
EXPECT_EQ("ello", sw1.ToString());
|
||||
|
||||
sw1.remove_suffix(1);
|
||||
EXPECT_EQ("ell", sw1.ToString());
|
||||
|
||||
sw1.clear();
|
||||
EXPECT_EQ(0u, sw1.size());
|
||||
|
||||
StringView sw2(TEST_STRING);
|
||||
sw1.swap(sw2);
|
||||
EXPECT_EQ(0u, sw2.size());
|
||||
EXPECT_EQ(TEST_STRING, sw1.ToString());
|
||||
}
|
||||
|
||||
TEST(StringView, SubString) {
|
||||
StringView sw1(TEST_STRING);
|
||||
|
||||
StringView sw2 = sw1.substr(1, 2);
|
||||
EXPECT_EQ("el", sw2.ToString());
|
||||
}
|
||||
|
||||
TEST(StringView, Compare) {
|
||||
StringView sw1(TEST_STRING);
|
||||
StringView sw2(TEST_STRING);
|
||||
|
||||
EXPECT_EQ(0, sw1.compare(sw2));
|
||||
|
||||
sw1 = "a";
|
||||
sw2 = "b";
|
||||
EXPECT_GT(0, sw1.compare(sw2));
|
||||
EXPECT_LT(0, sw2.compare(sw1));
|
||||
|
||||
sw1 = "a";
|
||||
sw2 = "aa";
|
||||
EXPECT_GT(0, sw1.compare(sw2));
|
||||
EXPECT_LT(0, sw2.compare(sw1));
|
||||
|
||||
std::string str1("a\0a", 3);
|
||||
std::string str2("a\0b", 3);
|
||||
sw1 = str1;
|
||||
sw2 = str2;
|
||||
|
||||
EXPECT_GT(0, sw1.compare(sw2));
|
||||
EXPECT_LT(0, sw2.compare(sw1));
|
||||
}
|
||||
|
||||
TEST(StringView, ComparaisonFunctions) {
|
||||
StringView sw1 = "a";
|
||||
StringView sw2 = "b";
|
||||
|
||||
EXPECT_TRUE(sw1 == sw1);
|
||||
EXPECT_FALSE(sw1 == sw2);
|
||||
EXPECT_FALSE(sw1 != sw1);
|
||||
EXPECT_TRUE(sw1 != sw2);
|
||||
|
||||
EXPECT_TRUE(sw1 < sw2);
|
||||
EXPECT_FALSE(sw2 < sw1);
|
||||
EXPECT_TRUE(sw1 <= sw1);
|
||||
EXPECT_TRUE(sw1 <= sw2);
|
||||
EXPECT_FALSE(sw2 <= sw1);
|
||||
|
||||
EXPECT_TRUE(sw2 > sw1);
|
||||
EXPECT_FALSE(sw1 > sw2);
|
||||
EXPECT_TRUE(sw1 >= sw1);
|
||||
EXPECT_TRUE(sw2 >= sw1);
|
||||
EXPECT_FALSE(sw1 >= sw2);
|
||||
}
|
||||
|
||||
TEST(StringView, Stream) {
|
||||
StringView sw1(TEST_STRING);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << sw1;
|
||||
EXPECT_EQ(TEST_STRING, ss.str());
|
||||
}
|
||||
|
||||
TEST(StringView, find_String) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.find("z"));
|
||||
EXPECT_EQ(StringView::npos, sw.find(" "));
|
||||
EXPECT_EQ(StringView::npos, sw.find("lll"));
|
||||
EXPECT_EQ(StringView::npos, sw.find("H", 1));
|
||||
EXPECT_EQ(StringView::npos, sw.find("H", 255));
|
||||
EXPECT_EQ(StringView::npos, sw.find("H", sw.size()));
|
||||
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
std::string to_find_str, StringView to_find_sw,
|
||||
int start_index) {
|
||||
EXPECT_EQ(haystack_str.find(to_find_str, start_index),
|
||||
haystack_sw.find(to_find_sw, start_index));
|
||||
};
|
||||
LoopOverSubstrings(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverSubstrings(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
TEST(StringView, find_Chars) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.find('z'));
|
||||
EXPECT_EQ(StringView::npos, sw.find('H', 1));
|
||||
EXPECT_EQ(StringView::npos, sw.find('H', 255));
|
||||
EXPECT_EQ(StringView::npos, sw.find('H', sw.size()));
|
||||
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
char c, int start_index) {
|
||||
EXPECT_EQ(haystack_str.find(c, start_index),
|
||||
haystack_sw.find(c, start_index));
|
||||
};
|
||||
|
||||
// Look for all chars at all position, and compare with string.
|
||||
LoopOverChars(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverChars(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
TEST(StringView, rfind_String) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.rfind("z"));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind(" "));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind("lll"));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind("d", sw.size() - 2));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind("d", 0));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind("d", 1));
|
||||
|
||||
// Look for all substring at all position, and compare with string.
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
std::string to_find_str, StringView to_find_sw,
|
||||
int start_index) {
|
||||
EXPECT_EQ(haystack_str.rfind(to_find_str, start_index),
|
||||
haystack_sw.rfind(to_find_sw, start_index));
|
||||
};
|
||||
LoopOverSubstrings(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverSubstrings(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
TEST(StringView, rfind_Char) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.rfind('z'));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind('d', sw.size() - 2));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind('d', 0));
|
||||
EXPECT_EQ(StringView::npos, sw.rfind('d', 1));
|
||||
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
char c, int start_index) {
|
||||
EXPECT_EQ(haystack_str.rfind(c, start_index),
|
||||
haystack_sw.rfind(c, start_index));
|
||||
};
|
||||
|
||||
// Look for all chars at all position, and compare with string.
|
||||
LoopOverChars(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverChars(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
TEST(StringView, find_first_of) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.find_first_of(""));
|
||||
EXPECT_EQ(StringView::npos, sw.find_first_of(std::string("xyz")));
|
||||
EXPECT_EQ(StringView::npos, sw.find_first_of("xyHz", 1));
|
||||
EXPECT_EQ(StringView::npos, sw.find_first_of("Hello World", sw.size()));
|
||||
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
std::string current_chars, size_t pos) {
|
||||
EXPECT_EQ(haystack_str.find_first_of(current_chars, pos),
|
||||
haystack_sw.find_first_of(current_chars, pos));
|
||||
};
|
||||
|
||||
// Look for all chars combinations, and compare with string.
|
||||
LoopOverCharCombinations(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverCharCombinations(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
TEST(StringView, find_last_of) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.find_last_of(""));
|
||||
EXPECT_EQ(StringView::npos, sw.find_last_of(std::string("xyz")));
|
||||
EXPECT_EQ(StringView::npos, sw.find_last_of("xydz", 1));
|
||||
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
std::string current_chars, size_t pos) {
|
||||
EXPECT_EQ(haystack_str.find_last_of(current_chars, pos),
|
||||
haystack_sw.find_last_of(current_chars, pos));
|
||||
};
|
||||
|
||||
// Look for all chars combinations, and compare with string.
|
||||
LoopOverCharCombinations(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverCharCombinations(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
TEST(StringView, find_first_not_of) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.find_first_not_of("Helo Wrd"));
|
||||
EXPECT_EQ(StringView::npos, sw.find_first_not_of("elo Wrd", 1));
|
||||
EXPECT_EQ(StringView::npos, sw.find_first_not_of("", sw.size()));
|
||||
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
std::string current_chars, size_t pos) {
|
||||
EXPECT_EQ(haystack_str.find_first_not_of(current_chars, pos),
|
||||
haystack_sw.find_first_not_of(current_chars, pos));
|
||||
};
|
||||
|
||||
// Look for all chars combinations, and compare with string.
|
||||
LoopOverCharCombinations(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverCharCombinations(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
TEST(StringView, find_last_not_of) {
|
||||
StringView sw("Hello World");
|
||||
|
||||
EXPECT_EQ(StringView::npos, sw.find_last_not_of("Helo Wrd"));
|
||||
EXPECT_EQ(StringView::npos, sw.find_last_not_of("H", 0));
|
||||
|
||||
auto test_callback = [](std::string haystack_str, StringView haystack_sw,
|
||||
std::string current_chars, size_t pos) {
|
||||
EXPECT_EQ(haystack_str.find_last_not_of(current_chars, pos),
|
||||
haystack_sw.find_last_not_of(current_chars, pos));
|
||||
};
|
||||
|
||||
// Look for all chars combinations, and compare with string.
|
||||
LoopOverCharCombinations(sw, sw, test_callback);
|
||||
|
||||
// Use another string for negative examples.
|
||||
StringView other_sw("Fuchsia World");
|
||||
LoopOverCharCombinations(sw, other_sw, test_callback);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace fml
|
||||
@@ -14,24 +14,24 @@
|
||||
|
||||
namespace fml {
|
||||
|
||||
TaskRunner::TaskRunner(fxl::RefPtr<MessageLoopImpl> loop)
|
||||
TaskRunner::TaskRunner(fml::RefPtr<MessageLoopImpl> loop)
|
||||
: loop_(std::move(loop)) {
|
||||
FML_CHECK(loop_);
|
||||
}
|
||||
|
||||
TaskRunner::~TaskRunner() = default;
|
||||
|
||||
void TaskRunner::PostTask(fxl::Closure task) {
|
||||
loop_->PostTask(std::move(task), fxl::TimePoint::Now());
|
||||
void TaskRunner::PostTask(fml::closure task) {
|
||||
loop_->PostTask(std::move(task), fml::TimePoint::Now());
|
||||
}
|
||||
|
||||
void TaskRunner::PostTaskForTime(fxl::Closure task,
|
||||
fxl::TimePoint target_time) {
|
||||
void TaskRunner::PostTaskForTime(fml::closure task,
|
||||
fml::TimePoint target_time) {
|
||||
loop_->PostTask(std::move(task), target_time);
|
||||
}
|
||||
|
||||
void TaskRunner::PostDelayedTask(fxl::Closure task, fxl::TimeDelta delay) {
|
||||
loop_->PostTask(std::move(task), fxl::TimePoint::Now() + delay);
|
||||
void TaskRunner::PostDelayedTask(fml::closure task, fml::TimeDelta delay) {
|
||||
loop_->PostTask(std::move(task), fml::TimePoint::Now() + delay);
|
||||
}
|
||||
|
||||
bool TaskRunner::RunsTasksOnCurrentThread() {
|
||||
@@ -41,8 +41,8 @@ bool TaskRunner::RunsTasksOnCurrentThread() {
|
||||
return MessageLoop::GetCurrent().GetLoopImpl() == loop_;
|
||||
}
|
||||
|
||||
void TaskRunner::RunNowOrPostTask(fxl::RefPtr<fxl::TaskRunner> runner,
|
||||
fxl::Closure task) {
|
||||
void TaskRunner::RunNowOrPostTask(fml::RefPtr<fml::TaskRunner> runner,
|
||||
fml::closure task) {
|
||||
FML_DCHECK(runner);
|
||||
if (runner->RunsTasksOnCurrentThread()) {
|
||||
task();
|
||||
|
||||
@@ -5,36 +5,38 @@
|
||||
#ifndef FLUTTER_FML_TASK_RUNNER_H_
|
||||
#define FLUTTER_FML_TASK_RUNNER_H_
|
||||
|
||||
#include "flutter/fml/closure.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "lib/fxl/tasks/task_runner.h"
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
class MessageLoopImpl;
|
||||
|
||||
class TaskRunner final : public fxl::TaskRunner {
|
||||
class TaskRunner : public fml::RefCountedThreadSafe<TaskRunner> {
|
||||
public:
|
||||
void PostTask(fxl::Closure task) override;
|
||||
void PostTask(fml::closure task);
|
||||
|
||||
void PostTaskForTime(fxl::Closure task, fxl::TimePoint target_time) override;
|
||||
void PostTaskForTime(fml::closure task, fml::TimePoint target_time);
|
||||
|
||||
void PostDelayedTask(fxl::Closure task, fxl::TimeDelta delay) override;
|
||||
void PostDelayedTask(fml::closure task, fml::TimeDelta delay);
|
||||
|
||||
bool RunsTasksOnCurrentThread() override;
|
||||
bool RunsTasksOnCurrentThread();
|
||||
|
||||
static void RunNowOrPostTask(fxl::RefPtr<fxl::TaskRunner> runner,
|
||||
fxl::Closure task);
|
||||
static void RunNowOrPostTask(fml::RefPtr<fml::TaskRunner> runner,
|
||||
fml::closure task);
|
||||
|
||||
private:
|
||||
fxl::RefPtr<MessageLoopImpl> loop_;
|
||||
fml::RefPtr<MessageLoopImpl> loop_;
|
||||
|
||||
TaskRunner(fxl::RefPtr<MessageLoopImpl> loop);
|
||||
TaskRunner(fml::RefPtr<MessageLoopImpl> loop);
|
||||
|
||||
~TaskRunner() override;
|
||||
~TaskRunner();
|
||||
|
||||
FRIEND_MAKE_REF_COUNTED(TaskRunner);
|
||||
FRIEND_REF_COUNTED_THREAD_SAFE(TaskRunner);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(TaskRunner);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(TaskRunner);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(TaskRunner);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace fml {
|
||||
|
||||
Thread::Thread(const std::string& name) : joined_(false) {
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
fxl::RefPtr<fml::TaskRunner> runner;
|
||||
fml::RefPtr<fml::TaskRunner> runner;
|
||||
thread_ = std::make_unique<std::thread>([&latch, &runner, name]() -> void {
|
||||
SetCurrentThreadName(name);
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
@@ -41,7 +41,7 @@ Thread::~Thread() {
|
||||
Join();
|
||||
}
|
||||
|
||||
fxl::RefPtr<fml::TaskRunner> Thread::GetTaskRunner() const {
|
||||
fml::RefPtr<fml::TaskRunner> Thread::GetTaskRunner() const {
|
||||
return task_runner_;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void Thread::SetCurrentThreadName(const std::string& name) {
|
||||
} __except (EXCEPTION_CONTINUE_EXECUTION) {
|
||||
}
|
||||
#else
|
||||
FXL_DLOG(INFO) << "Could not set the thread name to '" << name
|
||||
FML_DLOG(INFO) << "Could not set the thread name to '" << name
|
||||
<< "' on this platform.";
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ class Thread {
|
||||
|
||||
~Thread();
|
||||
|
||||
fxl::RefPtr<fml::TaskRunner> GetTaskRunner() const;
|
||||
fml::RefPtr<fml::TaskRunner> GetTaskRunner() const;
|
||||
|
||||
void Join();
|
||||
|
||||
private:
|
||||
std::unique_ptr<std::thread> thread_;
|
||||
fxl::RefPtr<fml::TaskRunner> task_runner_;
|
||||
fml::RefPtr<fml::TaskRunner> task_runner_;
|
||||
std::atomic_bool joined_;
|
||||
|
||||
static void SetCurrentThreadName(const std::string& name);
|
||||
|
||||
@@ -11,15 +11,10 @@ source_set("io") {
|
||||
deps = [
|
||||
"//third_party/dart/runtime:dart_api",
|
||||
"//third_party/dart/runtime/bin:embedded_dart_io",
|
||||
"//garnet/public/lib/fxl",
|
||||
"//third_party/tonic",
|
||||
]
|
||||
|
||||
configs += [
|
||||
"//third_party/dart/runtime:dart_config",
|
||||
]
|
||||
configs += [ "//third_party/dart/runtime:dart_config" ]
|
||||
|
||||
public_configs = [
|
||||
"$flutter_root:config",
|
||||
]
|
||||
public_configs = [ "$flutter_root:config" ]
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
@@ -17,7 +17,7 @@ class DartIO {
|
||||
static bool EntropySource(uint8_t* buffer, intptr_t length);
|
||||
|
||||
private:
|
||||
FXL_DISALLOW_IMPLICIT_CONSTRUCTORS(DartIO);
|
||||
FML_DISALLOW_IMPLICIT_CONSTRUCTORS(DartIO);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@@ -102,7 +102,6 @@ source_set("ui") {
|
||||
"$flutter_root/flow",
|
||||
"$flutter_root/fml",
|
||||
"$flutter_root/runtime:test_font",
|
||||
"//garnet/public/lib/fxl",
|
||||
"//third_party/dart/runtime/bin:embedded_dart_io",
|
||||
"//third_party/rapidjson",
|
||||
"//third_party/skia",
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
#include "flutter/lib/ui/compositing/scene.h"
|
||||
|
||||
#include "flutter/fml/make_copyable.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "flutter/lib/ui/painting/image.h"
|
||||
#include "lib/fxl/functional/make_copyable.h"
|
||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
#include "third_party/tonic/converter/dart_converter.h"
|
||||
@@ -26,11 +26,11 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Scene);
|
||||
|
||||
DART_BIND_ALL(Scene, FOR_EACH_BINDING)
|
||||
|
||||
fxl::RefPtr<Scene> Scene::create(std::unique_ptr<flow::Layer> rootLayer,
|
||||
fml::RefPtr<Scene> Scene::create(std::unique_ptr<flow::Layer> rootLayer,
|
||||
uint32_t rasterizerTracingThreshold,
|
||||
bool checkerboardRasterCacheImages,
|
||||
bool checkerboardOffscreenLayers) {
|
||||
return fxl::MakeRefCounted<Scene>(
|
||||
return fml::MakeRefCounted<Scene>(
|
||||
std::move(rootLayer), rasterizerTracingThreshold,
|
||||
checkerboardRasterCacheImages, checkerboardOffscreenLayers);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ Dart_Handle Scene::toImage(uint32_t width,
|
||||
|
||||
// The picture has been prepared on the UI thread.
|
||||
dart_state->GetTaskRunners().GetIOTaskRunner()->PostTask(
|
||||
fxl::MakeCopyable([picture = std::move(picture), //
|
||||
fml::MakeCopyable([picture = std::move(picture), //
|
||||
bounds_size, //
|
||||
resource_context = std::move(resource_context), //
|
||||
ui_task_runner = std::move(ui_task_runner), //
|
||||
@@ -147,7 +147,7 @@ Dart_Handle Scene::toImage(uint32_t width,
|
||||
// Send the image back to the UI thread for submission back to the
|
||||
// framework.
|
||||
ui_task_runner->PostTask(
|
||||
fxl::MakeCopyable([image = std::move(image), //
|
||||
fml::MakeCopyable([image = std::move(image), //
|
||||
image_callback = std::move(image_callback), //
|
||||
unref_queue = std::move(unref_queue) //
|
||||
]() mutable {
|
||||
|
||||
@@ -20,11 +20,11 @@ namespace blink {
|
||||
|
||||
class Scene : public RefCountedDartWrappable<Scene> {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
FRIEND_MAKE_REF_COUNTED(Scene);
|
||||
FML_FRIEND_MAKE_REF_COUNTED(Scene);
|
||||
|
||||
public:
|
||||
~Scene() override;
|
||||
static fxl::RefPtr<Scene> create(std::unique_ptr<flow::Layer> rootLayer,
|
||||
static fml::RefPtr<Scene> create(std::unique_ptr<flow::Layer> rootLayer,
|
||||
uint32_t rasterizerTracingThreshold,
|
||||
bool checkerboardRasterCacheImages,
|
||||
bool checkerboardOffscreenLayers);
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
#include "flutter/lib/ui/compositing/scene_builder.h"
|
||||
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/lib/ui/painting/matrix.h"
|
||||
#include "flutter/lib/ui/painting/shader.h"
|
||||
#include "flutter/lib/ui/ui_dart_state.h"
|
||||
#include "flutter/lib/ui/window/window.h"
|
||||
#include "lib/fxl/build_config.h"
|
||||
#include "third_party/skia/include/core/SkColorFilter.h"
|
||||
#include "third_party/tonic/converter/dart_converter.h"
|
||||
#include "third_party/tonic/dart_args.h"
|
||||
@@ -178,8 +178,8 @@ void SceneBuilder::setCheckerboardOffscreenLayers(bool checkerboard) {
|
||||
layer_builder_->SetCheckerboardOffscreenLayers(checkerboard);
|
||||
}
|
||||
|
||||
fxl::RefPtr<Scene> SceneBuilder::build() {
|
||||
fxl::RefPtr<Scene> scene =
|
||||
fml::RefPtr<Scene> SceneBuilder::build() {
|
||||
fml::RefPtr<Scene> scene =
|
||||
Scene::create(layer_builder_->TakeLayer(),
|
||||
layer_builder_->GetRasterizerTracingThreshold(),
|
||||
layer_builder_->GetCheckerboardRasterCacheImages(),
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user