Teach //flutter/lib/ui to build on Fuchsia (flutter/engine#2912)
This patch removes the //flutter/sky/engine dependency from //flutter/lib/ui, which lets us build the bulk of the dart:ui library without needing to build //flutter/sky/engine.
This commit is contained in:
@@ -8,10 +8,12 @@ group("flutter") {
|
|||||||
if (is_fuchsia) {
|
if (is_fuchsia) {
|
||||||
# TODO(abarth) Remove this specific list once Fuchsia can build everything.
|
# TODO(abarth) Remove this specific list once Fuchsia can build everything.
|
||||||
deps = [
|
deps = [
|
||||||
"//flutter/snapshotter",
|
|
||||||
"//flutter/assets",
|
"//flutter/assets",
|
||||||
"//flutter/flow",
|
"//flutter/flow",
|
||||||
"//flutter/glue",
|
"//flutter/glue",
|
||||||
|
"//flutter/lib/ui",
|
||||||
|
"//flutter/snapshotter",
|
||||||
|
"//flutter/tonic",
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
deps = [
|
deps = [
|
||||||
|
|||||||
@@ -41,15 +41,10 @@ source_set("ui") {
|
|||||||
]
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//base",
|
|
||||||
"//flutter/flow",
|
"//flutter/flow",
|
||||||
"//flutter/tonic",
|
|
||||||
"//flutter/glue",
|
"//flutter/glue",
|
||||||
"//lib/tonic",
|
|
||||||
"//flutter/skia",
|
"//flutter/skia",
|
||||||
|
"//flutter/tonic",
|
||||||
# For image_decoding:
|
"//lib/tonic",
|
||||||
"//flutter/sky/engine/platform",
|
|
||||||
"//flutter/sky/engine/wtf",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,13 +145,14 @@ void SceneBuilder::pushShaderMask(Shader* shader,
|
|||||||
addLayer(std::move(layer), m_cullRects.top());
|
addLayer(std::move(layer), m_cullRects.top());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneBuilder::addLayer(std::unique_ptr<flow::ContainerLayer> layer, const SkRect& cullRect) {
|
void SceneBuilder::addLayer(std::unique_ptr<flow::ContainerLayer> layer,
|
||||||
DCHECK(layer);
|
const SkRect& cullRect) {
|
||||||
|
FTL_DCHECK(layer);
|
||||||
|
|
||||||
m_cullRects.push(cullRect);
|
m_cullRects.push(cullRect);
|
||||||
|
|
||||||
if (!m_rootLayer) {
|
if (!m_rootLayer) {
|
||||||
DCHECK(!m_currentLayer);
|
FTL_DCHECK(!m_currentLayer);
|
||||||
m_rootLayer = std::move(layer);
|
m_rootLayer = std::move(layer);
|
||||||
m_currentLayer = m_rootLayer.get();
|
m_currentLayer = m_rootLayer.get();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -5,23 +5,21 @@
|
|||||||
#include "flutter/lib/ui/painting/image_decoding.h"
|
#include "flutter/lib/ui/painting/image_decoding.h"
|
||||||
|
|
||||||
#include "flutter/flow/texture_image.h"
|
#include "flutter/flow/texture_image.h"
|
||||||
#include "flutter/lib/ui/painting/image.h"
|
|
||||||
#include "flutter/lib/ui/painting/resource_context.h"
|
|
||||||
#include "flutter/glue/drain_data_pipe_job.h"
|
#include "flutter/glue/drain_data_pipe_job.h"
|
||||||
#include "flutter/glue/movable_wrapper.h"
|
#include "flutter/glue/movable_wrapper.h"
|
||||||
#include "flutter/glue/trace_event.h"
|
#include "flutter/glue/trace_event.h"
|
||||||
|
#include "flutter/lib/ui/painting/image.h"
|
||||||
|
#include "flutter/lib/ui/painting/resource_context.h"
|
||||||
|
#include "flutter/tonic/dart_state.h"
|
||||||
#include "lib/ftl/tasks/task_runner.h"
|
#include "lib/ftl/tasks/task_runner.h"
|
||||||
#include "lib/tonic/dart_persistent_value.h"
|
#include "lib/tonic/dart_persistent_value.h"
|
||||||
#include "lib/tonic/logging/dart_invoke.h"
|
#include "lib/tonic/logging/dart_invoke.h"
|
||||||
#include "lib/tonic/mojo_converter.h"
|
#include "lib/tonic/mojo_converter.h"
|
||||||
#include "lib/tonic/typed_data/uint8_list.h"
|
#include "lib/tonic/typed_data/uint8_list.h"
|
||||||
#include "flutter/sky/engine/public/platform/Platform.h"
|
|
||||||
#include "flutter/sky/engine/wtf/PassOwnPtr.h"
|
|
||||||
#include "third_party/skia/include/core/SkImageGenerator.h"
|
#include "third_party/skia/include/core/SkImageGenerator.h"
|
||||||
|
|
||||||
using tonic::DartInvoke;
|
using tonic::DartInvoke;
|
||||||
using tonic::DartPersistentValue;
|
using tonic::DartPersistentValue;
|
||||||
using tonic::DartState;
|
|
||||||
using tonic::ToDart;
|
using tonic::ToDart;
|
||||||
|
|
||||||
namespace blink {
|
namespace blink {
|
||||||
@@ -60,7 +58,7 @@ sk_sp<SkImage> DecodeImage(std::vector<char> buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InvokeImageCallback(sk_sp<SkImage> image,
|
void InvokeImageCallback(sk_sp<SkImage> image,
|
||||||
PassOwnPtr<DartPersistentValue> callback) {
|
std::unique_ptr<DartPersistentValue> callback) {
|
||||||
tonic::DartState* dart_state = callback->dart_state().get();
|
tonic::DartState* dart_state = callback->dart_state().get();
|
||||||
if (!dart_state)
|
if (!dart_state)
|
||||||
return;
|
return;
|
||||||
@@ -74,11 +72,14 @@ void InvokeImageCallback(sk_sp<SkImage> image,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecodeImageAndInvokeImageCallback(PassOwnPtr<DartPersistentValue> callback,
|
void DecodeImageAndInvokeImageCallback(
|
||||||
std::vector<char> buffer) {
|
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||||
|
glue::MovableWrapper<std::unique_ptr<DartPersistentValue>> callback,
|
||||||
|
std::vector<char> buffer) {
|
||||||
sk_sp<SkImage> image = DecodeImage(std::move(buffer));
|
sk_sp<SkImage> image = DecodeImage(std::move(buffer));
|
||||||
Platform::current()->GetUITaskRunner()->PostTask(
|
task_runner->PostTask([callback, image]() mutable {
|
||||||
[callback, image]() { InvokeImageCallback(image, callback); });
|
InvokeImageCallback(image, callback.Unwrap());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecodeImageFromDataPipe(Dart_NativeArguments args) {
|
void DecodeImageFromDataPipe(Dart_NativeArguments args) {
|
||||||
@@ -98,16 +99,21 @@ void DecodeImageFromDataPipe(Dart_NativeArguments args) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PassOwnPtr<DartPersistentValue> callback =
|
DartState* dart_state = DartState::Current();
|
||||||
adoptPtr(new DartPersistentValue(DartState::Current(), callback_handle));
|
ftl::RefPtr<ftl::TaskRunner> task_runner = dart_state->ui_task_runner();
|
||||||
|
|
||||||
Platform::current()->GetIOTaskRunner()->PostTask(
|
auto callback = glue::WrapMovable(std::unique_ptr<DartPersistentValue>(
|
||||||
[callback, consumer]() mutable {
|
new DartPersistentValue(dart_state, callback_handle)));
|
||||||
|
|
||||||
|
dart_state->io_task_runner()->PostTask(
|
||||||
|
[task_runner, callback, consumer]() mutable {
|
||||||
glue::DrainDataPipeJob* job = nullptr;
|
glue::DrainDataPipeJob* job = nullptr;
|
||||||
job = new glue::DrainDataPipeJob(
|
job = new glue::DrainDataPipeJob(
|
||||||
consumer.Unwrap(), [callback, job](std::vector<char> buffer) {
|
consumer.Unwrap(),
|
||||||
|
[task_runner, callback, job](std::vector<char> buffer) {
|
||||||
delete job;
|
delete job;
|
||||||
DecodeImageAndInvokeImageCallback(callback, std::move(buffer));
|
DecodeImageAndInvokeImageCallback(task_runner, callback,
|
||||||
|
std::move(buffer));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -127,16 +133,22 @@ void DecodeImageFromList(Dart_NativeArguments args) {
|
|||||||
Dart_ThrowException(ToDart("Callback must be a function"));
|
Dart_ThrowException(ToDart("Callback must be a function"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PassOwnPtr<DartPersistentValue> callback =
|
|
||||||
adoptPtr(new DartPersistentValue(DartState::Current(), callback_handle));
|
DartState* dart_state = DartState::Current();
|
||||||
|
ftl::RefPtr<ftl::TaskRunner> task_runner = dart_state->ui_task_runner();
|
||||||
|
|
||||||
|
auto callback = glue::WrapMovable(std::unique_ptr<DartPersistentValue>(
|
||||||
|
new DartPersistentValue(dart_state, callback_handle)));
|
||||||
|
|
||||||
const char* bytes = reinterpret_cast<const char*>(list.data());
|
const char* bytes = reinterpret_cast<const char*>(list.data());
|
||||||
PassOwnPtr<std::vector<char>> buffer =
|
auto buffer = glue::WrapMovable(std::unique_ptr<std::vector<char>>(
|
||||||
adoptPtr(new std::vector<char>(bytes, bytes + list.num_elements()));
|
new std::vector<char>(bytes, bytes + list.num_elements())));
|
||||||
|
|
||||||
Platform::current()->GetIOTaskRunner()->PostTask([callback, buffer]() {
|
dart_state->io_task_runner()->PostTask(
|
||||||
DecodeImageAndInvokeImageCallback(callback, std::move(*buffer));
|
[task_runner, callback, buffer]() mutable {
|
||||||
});
|
DecodeImageAndInvokeImageCallback(task_runner, callback,
|
||||||
|
std::move(*buffer.Unwrap()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
#ifndef FLUTTER_TONIC_DART_STATE_H_
|
#ifndef FLUTTER_TONIC_DART_STATE_H_
|
||||||
#define FLUTTER_TONIC_DART_STATE_H_
|
#define FLUTTER_TONIC_DART_STATE_H_
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "dart/runtime/include/dart_api.h"
|
#include "dart/runtime/include/dart_api.h"
|
||||||
|
#include "lib/ftl/tasks/task_runner.h"
|
||||||
#include "lib/tonic/dart_persistent_value.h"
|
#include "lib/tonic/dart_persistent_value.h"
|
||||||
#include "lib/tonic/dart_state.h"
|
#include "lib/tonic/dart_state.h"
|
||||||
#include "lib/tonic/scopes/dart_api_scope.h"
|
#include "lib/tonic/scopes/dart_api_scope.h"
|
||||||
@@ -21,7 +24,17 @@ class DartState : public tonic::DartState {
|
|||||||
static DartState* From(Dart_Isolate isolate);
|
static DartState* From(Dart_Isolate isolate);
|
||||||
static DartState* Current();
|
static DartState* Current();
|
||||||
|
|
||||||
|
const ftl::RefPtr<ftl::TaskRunner>& ui_task_runner() {
|
||||||
|
return ui_task_runner_;
|
||||||
|
}
|
||||||
|
const ftl::RefPtr<ftl::TaskRunner>& io_task_runner() {
|
||||||
|
return io_task_runner_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
ftl::RefPtr<ftl::TaskRunner> ui_task_runner_;
|
||||||
|
ftl::RefPtr<ftl::TaskRunner> io_task_runner_;
|
||||||
|
|
||||||
FTL_DISALLOW_COPY_AND_ASSIGN(DartState);
|
FTL_DISALLOW_COPY_AND_ASSIGN(DartState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user