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

Drop last usages of Dart_New from engine #16838

Merged
merged 31 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cca233e
experiment
dnfield Feb 20, 2020
3296a12
some layers and scene
dnfield Feb 20, 2020
d444f64
more layers, path
dnfield Feb 20, 2020
09d5a99
paths, images, more layers
dnfield Feb 20, 2020
ad4a654
start paragraph, fix images,drop frame_info
dnfield Feb 20, 2020
670aaa1
merge
dnfield Feb 22, 2020
027ce42
merge more
dnfield Feb 22, 2020
25106df
remove usage of Dart_New for paragraph/libtxt
dnfield Feb 27, 2020
6971c40
merge
dnfield Feb 27, 2020
658783b
merge
dnfield Feb 27, 2020
600ff75
format
dnfield Feb 27, 2020
9af252e
format
dnfield Feb 27, 2020
6bcb7df
Merge branch 'paragraph_faster' into picture_dart
dnfield Feb 27, 2020
3f72ff2
The last bits
dnfield Feb 27, 2020
58778cc
more dead code
dnfield Feb 27, 2020
33cc2e5
review, fixes, tests
dnfield Feb 28, 2020
61c2ae7
Merge branch 'paragraph_faster' into picture_dart
dnfield Feb 28, 2020
8f8eb80
more permissive test
dnfield Feb 28, 2020
cbd7568
more permissive test
dnfield Feb 28, 2020
b648364
epsillon for top
dnfield Feb 28, 2020
016351f
semantics
dnfield Feb 28, 2020
b8e6f8b
merge
dnfield Feb 28, 2020
7709586
format again
dnfield Feb 28, 2020
be4a042
Merge remote-tracking branch 'upstream/master' into picture_dart
dnfield Feb 28, 2020
e001c35
more foramt
dnfield Feb 28, 2020
0252872
retain canvas image
dnfield Feb 28, 2020
bf2fb5f
Merge remote-tracking branch 'upstream/master' into picture_dart
dnfield Feb 28, 2020
e519e56
cleanup, retain handles, fix toImage
dnfield Feb 28, 2020
9619a78
review
dnfield Mar 2, 2020
b3c7687
Merge remote-tracking branch 'upstream/master' into picture_dart
dnfield Mar 2, 2020
cd55995
remove debug logging, unneeded includes
dnfield Mar 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ FILE: ../../../flutter/lib/ui/painting/color_filter.cc
FILE: ../../../flutter/lib/ui/painting/color_filter.h
FILE: ../../../flutter/lib/ui/painting/engine_layer.cc
FILE: ../../../flutter/lib/ui/painting/engine_layer.h
FILE: ../../../flutter/lib/ui/painting/frame_info.cc
FILE: ../../../flutter/lib/ui/painting/frame_info.h
FILE: ../../../flutter/lib/ui/painting/gradient.cc
FILE: ../../../flutter/lib/ui/painting/gradient.h
FILE: ../../../flutter/lib/ui/painting/image.cc
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ source_set("ui") {
"painting/color_filter.h",
"painting/engine_layer.cc",
"painting/engine_layer.h",
"painting/frame_info.cc",
"painting/frame_info.h",
"painting/gradient.cc",
"painting/gradient.h",
"painting/image.cc",
Expand Down
8 changes: 5 additions & 3 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ class Scene extends NativeFieldWrapperClass2 {

/// Creates a raster image representation of the current state of the scene.
/// This is a slow operation that is performed on a background thread.
Future<Image> toImage(int width, int height) {
Future<Image> toImage(int width, int height) async {
if (width <= 0 || height <= 0) {
throw Exception('Invalid image dimensions.');
}
return _futurize((_Callback<Image> callback) => _toImage(width, height, callback));
final Image image = Image._();
await _futurize((_Callback<bool> callback) => _toImage(image, width, height, callback));
return image;
}

String _toImage(int width, int height, _Callback<Image> callback) native 'Scene_toImage';
String _toImage(Image outImage, int width, int height, _Callback<bool> callback) native 'Scene_toImage';

/// Releases the resources used by this scene.
///
Expand Down
6 changes: 4 additions & 2 deletions lib/ui/compositing/scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void Scene::dispose() {
ClearDartWrapper();
}

Dart_Handle Scene::toImage(uint32_t width,
Dart_Handle Scene::toImage(Dart_Handle image_handle,
uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
TRACE_EVENT0("flutter", "Scene::toImage");
Expand All @@ -75,7 +76,8 @@ Dart_Handle Scene::toImage(uint32_t width,
return tonic::ToDart("Could not flatten scene into a layer tree.");
}

return Picture::RasterizeToImage(picture, width, height, raw_image_callback);
return Picture::RasterizeToImage(image_handle, picture, width, height,
raw_image_callback);
}

std::unique_ptr<flutter::LayerTree> Scene::takeLayerTree() {
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/compositing/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Scene : public RefCountedDartWrappable<Scene> {

std::unique_ptr<flutter::LayerTree> takeLayerTree();

Dart_Handle toImage(uint32_t width,
Dart_Handle toImage(Dart_Handle image_handle,
uint32_t width,
uint32_t height,
Dart_Handle image_callback);

Expand Down
2 changes: 0 additions & 2 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "flutter/lib/ui/painting/codec.h"
#include "flutter/lib/ui/painting/color_filter.h"
#include "flutter/lib/ui/painting/engine_layer.h"
#include "flutter/lib/ui/painting/frame_info.h"
#include "flutter/lib/ui/painting/gradient.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/image_filter.h"
Expand Down Expand Up @@ -80,7 +79,6 @@ void DartUI::InitForGlobal() {
DartRuntimeHooks::RegisterNatives(g_natives);
EngineLayer::RegisterNatives(g_natives);
FontCollection::RegisterNatives(g_natives);
FrameInfo::RegisterNatives(g_natives);
ImageFilter::RegisterNatives(g_natives);
ImageShader::RegisterNatives(g_natives);
IsolateNameServerNatives::RegisterNatives(g_natives);
Expand Down
63 changes: 38 additions & 25 deletions lib/ui/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1639,22 +1639,19 @@ typedef ImageDecoderCallback = void Function(Image result);
///
/// To obtain an instance of the [FrameInfo] interface, see
/// [Codec.getNextFrame].
@pragma('vm:entry-point')
class FrameInfo extends NativeFieldWrapperClass2 {
class FrameInfo {
/// This class is created by the engine, and should not be instantiated
/// or extended directly.
///
/// To obtain an instance of the [FrameInfo] interface, see
/// [Codec.getNextFrame].
@pragma('vm:entry-point')
FrameInfo._();
FrameInfo._(int durationMilliseconds, this.image) : duration = Duration(milliseconds: durationMilliseconds);

/// The duration this frame should be shown.
Duration get duration => Duration(milliseconds: _durationMillis);
int get _durationMillis native 'FrameInfo_durationMillis';
final Duration duration;

/// The [Image] object for this frame.
Image get image native 'FrameInfo_image';
final Image image;
}

/// A handle to an image codec.
Expand Down Expand Up @@ -1684,21 +1681,32 @@ class Codec extends NativeFieldWrapperClass2 {
/// * -1 for infinity repetitions.
int get repetitionCount native 'Codec_repetitionCount';

FrameInfo _cachedFrame;

/// Fetches the next animation frame.
///
/// Wraps back to the first frame after returning the last frame.
///
/// The returned future can complete with an error if the decoding has failed.
Future<FrameInfo> getNextFrame() {
return _futurize(_getNextFrame);
Future<FrameInfo> getNextFrame() async {
if (_cachedFrame == null || frameCount != 1) {
final Image image = Image._();
final int durationMilliseconds = await _futurize((_Callback<int> callback) => _getNextFrame(image, callback));
_cachedFrame = FrameInfo._(durationMilliseconds, image);
}
return _cachedFrame;
}

/// Returns an error message on failure, null on success.
String _getNextFrame(_Callback<FrameInfo> callback) native 'Codec_getNextFrame';
String _getNextFrame(Image outImage, _Callback<int> callback) native 'Codec_getNextFrame';

/// Release the resources used by this object. The object is no longer usable
/// after this method is called.
void dispose() native 'Codec_dispose';
void dispose() {
_cachedFrame = null;
_dispose();
}
void _dispose() native 'Codec_dispose';
}

/// Instantiates an image codec [Codec] object.
Expand All @@ -1718,10 +1726,12 @@ class Codec extends NativeFieldWrapperClass2 {
Future<Codec> instantiateImageCodec(Uint8List list, {
int targetWidth,
int targetHeight,
}) {
return _futurize(
(_Callback<Codec> callback) => _instantiateImageCodec(list, callback, null, targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension)
);
}) async {
final Codec codec = Codec._();
await _futurize((_Callback<bool> callback) {
return _instantiateImageCodec(codec, list, callback, null, targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension);
});
return codec;
}

/// Instantiates a [Codec] object for an image binary data.
Expand All @@ -1735,7 +1745,7 @@ Future<Codec> instantiateImageCodec(Uint8List list, {
/// If both are equal to [_kDoNotResizeDimension], then the image maintains its real size.
///
/// Returns an error message if the instantiation has failed, null otherwise.
String _instantiateImageCodec(Uint8List list, _Callback<Codec> callback, _ImageInfo imageInfo, int targetWidth, int targetHeight)
String _instantiateImageCodec(Codec outCodec, Uint8List list, _Callback<bool> callback, _ImageInfo imageInfo, int targetWidth, int targetHeight)
native 'instantiateImageCodec';

/// Loads a single image frame from a byte array into an [Image] object.
Expand Down Expand Up @@ -1776,11 +1786,12 @@ void decodeImageFromPixels(
{int rowBytes, int targetWidth, int targetHeight}
) {
final _ImageInfo imageInfo = _ImageInfo(width, height, format.index, rowBytes);
final Future<Codec> codecFuture = _futurize(
(_Callback<Codec> callback) => _instantiateImageCodec(pixels, callback, imageInfo, targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension)
);
codecFuture.then((Codec codec) => codec.getNextFrame())
.then((FrameInfo frameInfo) => callback(frameInfo.image));
final Codec codec = Codec._();
_futurize(
(_Callback<bool> callback) => _instantiateImageCodec(codec, pixels, callback, imageInfo, targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension)
).then((bool _) {
codec.getNextFrame().then((FrameInfo frameInfo) => callback(frameInfo.image));
});
}

/// Determines the winding rule that decides how the interior of a [Path] is
Expand Down Expand Up @@ -4125,15 +4136,17 @@ class Picture extends NativeFieldWrapperClass2 {
///
/// Although the image is returned synchronously, the picture is actually
/// rasterized the first time the image is drawn and then cached.
Future<Image> toImage(int width, int height) {
Future<Image> toImage(int width, int height) async {
if (width <= 0 || height <= 0)
throw Exception('Invalid image dimensions.');
return _futurize(
(_Callback<Image> callback) => _toImage(width, height, callback)
final Image image = Image._();
await _futurize(
(_Callback<bool> callback) => _toImage(image, width, height, callback)
);
return image;
}

String _toImage(int width, int height, _Callback<Image> callback) native 'Picture_toImage';
String _toImage(Image outImage, int width, int height, _Callback<bool> callback) native 'Picture_toImage';

/// Release the resources used by this object. The object is no longer usable
/// after this method is called.
Expand Down
23 changes: 11 additions & 12 deletions lib/ui/painting/codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "flutter/fml/logging.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/trace_event.h"
#include "flutter/lib/ui/painting/frame_info.h"
#include "flutter/lib/ui/painting/multi_frame_codec.h"
#include "flutter/lib/ui/painting/single_frame_codec.h"
#include "third_party/skia/include/codec/SkCodec.h"
Expand Down Expand Up @@ -145,13 +144,14 @@ static std::variant<ImageDecoder::ImageInfo, std::string> ConvertImageInfo(
}

static void InstantiateImageCodec(Dart_NativeArguments args) {
Dart_Handle callback_handle = Dart_GetNativeArgument(args, 1);
Dart_Handle codec_handle = Dart_GetNativeArgument(args, 0);
Dart_Handle callback_handle = Dart_GetNativeArgument(args, 2);
if (!Dart_IsClosure(callback_handle)) {
Dart_SetReturnValue(args, tonic::ToDart("Callback must be a function"));
return;
}

Dart_Handle image_info_handle = Dart_GetNativeArgument(args, 2);
Dart_Handle image_info_handle = Dart_GetNativeArgument(args, 3);

std::optional<ImageDecoder::ImageInfo> image_info;

Expand All @@ -171,7 +171,7 @@ static void InstantiateImageCodec(Dart_NativeArguments args) {
{
Dart_Handle exception = nullptr;
tonic::Uint8List list =
tonic::DartConverter<tonic::Uint8List>::FromArguments(args, 0,
tonic::DartConverter<tonic::Uint8List>::FromArguments(args, 1,
exception);
if (exception) {
Dart_SetReturnValue(args, exception);
Expand All @@ -191,9 +191,9 @@ static void InstantiateImageCodec(Dart_NativeArguments args) {
}

const int targetWidth =
tonic::DartConverter<int>::FromDart(Dart_GetNativeArgument(args, 3));
const int targetHeight =
tonic::DartConverter<int>::FromDart(Dart_GetNativeArgument(args, 4));
const int targetHeight =
tonic::DartConverter<int>::FromDart(Dart_GetNativeArgument(args, 5));

std::unique_ptr<SkCodec> codec;
bool single_frame;
Expand All @@ -208,8 +208,6 @@ static void InstantiateImageCodec(Dart_NativeArguments args) {
single_frame = codec->getFrameCount() == 1;
}

fml::RefPtr<Codec> ui_codec;

if (single_frame) {
ImageDecoder::ImageDescriptor descriptor;
descriptor.decompressed_image_info = image_info;
Expand All @@ -222,12 +220,13 @@ static void InstantiateImageCodec(Dart_NativeArguments args) {
}
descriptor.data = std::move(buffer);

ui_codec = fml::MakeRefCounted<SingleFrameCodec>(std::move(descriptor));
SingleFrameCodec::Create(codec_handle, std::move(descriptor));
} else {
ui_codec = fml::MakeRefCounted<MultiFrameCodec>(std::move(codec));
MultiFrameCodec::Create(codec_handle, std::move(codec));
}

tonic::DartInvoke(callback_handle, {ToDart(ui_codec)});
tonic::DartInvoke(callback_handle, {Dart_True()});
Dart_SetReturnValue(args, Dart_Null());
}

IMPLEMENT_WRAPPERTYPEINFO(ui, Codec);
Expand All @@ -246,7 +245,7 @@ void Codec::dispose() {

void Codec::RegisterNatives(tonic::DartLibraryNatives* natives) {
natives->Register({
{"instantiateImageCodec", InstantiateImageCodec, 5, true},
{"instantiateImageCodec", InstantiateImageCodec, 6, true},
});
natives->Register({FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/painting/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define FLUTTER_LIB_UI_PAINTING_CODEC_H_

#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/painting/frame_info.h"
#include "third_party/skia/include/codec/SkCodec.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImage.h"
Expand All @@ -30,7 +29,8 @@ class Codec : public RefCountedDartWrappable<Codec> {

virtual int repetitionCount() const = 0;

virtual Dart_Handle getNextFrame(Dart_Handle callback_handle) = 0;
virtual Dart_Handle getNextFrame(Dart_Handle image_handle,
Dart_Handle callback_handle) = 0;

void dispose();

Expand Down
30 changes: 0 additions & 30 deletions lib/ui/painting/frame_info.cc

This file was deleted.

37 changes: 0 additions & 37 deletions lib/ui/painting/frame_info.h

This file was deleted.

6 changes: 4 additions & 2 deletions lib/ui/painting/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class CanvasImage final : public RefCountedDartWrappable<CanvasImage> {

public:
~CanvasImage() override;
static fml::RefPtr<CanvasImage> Create() {
return fml::MakeRefCounted<CanvasImage>();
static fml::RefPtr<CanvasImage> Create(Dart_Handle dart_handle) {
auto image = fml::MakeRefCounted<CanvasImage>();
image->AssociateWithDartWrapper(dart_handle);
return image;
}

int width() { return image_.get()->width(); }
Expand Down
Loading