Delete the native implementation for ui.decodeImageFromList. (flutter/engine#4375)
The new ui.Codec API is a superset of the implementation in image_decoding.cc. While we are not using ui.decodeImageFromList in the framework anymore, we keep the dart function for backward compatability, and just make it a thin wrapper around the codec API.
This commit is contained in:
@@ -24,8 +24,6 @@ source_set("ui") {
|
||||
"painting/gradient.h",
|
||||
"painting/image.cc",
|
||||
"painting/image.h",
|
||||
"painting/image_decoding.cc",
|
||||
"painting/image_decoding.h",
|
||||
"painting/image_filter.cc",
|
||||
"painting/image_filter.h",
|
||||
"painting/image_shader.cc",
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#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_decoding.h"
|
||||
#include "flutter/lib/ui/painting/image_filter.h"
|
||||
#include "flutter/lib/ui/painting/image_shader.h"
|
||||
#include "flutter/lib/ui/painting/mask_filter.h"
|
||||
@@ -58,7 +57,6 @@ void DartUI::InitForGlobal() {
|
||||
Codec::RegisterNatives(g_natives);
|
||||
DartRuntimeHooks::RegisterNatives(g_natives);
|
||||
FrameInfo::RegisterNatives(g_natives);
|
||||
ImageDecoding::RegisterNatives(g_natives);
|
||||
ImageFilter::RegisterNatives(g_natives);
|
||||
ImageShader::RegisterNatives(g_natives);
|
||||
MaskFilter::RegisterNatives(g_natives);
|
||||
|
||||
@@ -928,9 +928,19 @@ Future<Codec> instantiateImageCodec(Uint8List list) {
|
||||
String _instantiateImageCodec(Uint8List list, _Callback<Codec> callback)
|
||||
native "instantiateImageCodec";
|
||||
|
||||
/// Convert an image file from a byte array into an [Image] object.
|
||||
void decodeImageFromList(Uint8List list, ImageDecoderCallback callback)
|
||||
native "decodeImageFromList";
|
||||
/// Loads a single image frame from a byte array into an [Image] object.
|
||||
///
|
||||
/// This is a convenience wrapper around [instantiateImageCodec].
|
||||
/// Prefer using [instantiateImageCodec] which also supports multi frame images.
|
||||
void decodeImageFromList(Uint8List list, ImageDecoderCallback callback) {
|
||||
_decodeImageFromListAsync(list, callback);
|
||||
}
|
||||
|
||||
Future<Null> _decodeImageFromListAsync(Uint8List list, ImageDecoderCallback callback) async {
|
||||
final Codec codec = await instantiateImageCodec(list);
|
||||
final FrameInfo frameInfo = await codec.getNextFrame();
|
||||
callback(frameInfo.image);
|
||||
}
|
||||
|
||||
/// Determines the winding rule that decides how the interior of a [Path] is
|
||||
/// calculated.
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
// Copyright 2015 The Chromium 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/lib/ui/painting/image_decoding.h"
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/glue/trace_event.h"
|
||||
#include "flutter/lib/ui/painting/image.h"
|
||||
#include "flutter/lib/ui/painting/resource_context.h"
|
||||
#include "lib/fxl/build_config.h"
|
||||
#include "lib/fxl/functional/make_copyable.h"
|
||||
#include "lib/tonic/dart_persistent_value.h"
|
||||
#include "lib/tonic/dart_state.h"
|
||||
#include "lib/tonic/logging/dart_invoke.h"
|
||||
#include "lib/tonic/typed_data/uint8_list.h"
|
||||
#include "third_party/skia/include/core/SkImageGenerator.h"
|
||||
|
||||
using tonic::DartInvoke;
|
||||
using tonic::DartPersistentValue;
|
||||
using tonic::ToDart;
|
||||
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
static constexpr const char* kDecodeImageTraceTag = "DecodeImage";
|
||||
|
||||
sk_sp<SkImage> DecodeImage(sk_sp<SkData> buffer, size_t trace_id) {
|
||||
TRACE_FLOW_STEP("flutter", kDecodeImageTraceTag, trace_id);
|
||||
TRACE_EVENT0("blink", "DecodeImage");
|
||||
|
||||
if (buffer == nullptr || buffer->isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrContext* context = ResourceContext::Get();
|
||||
if (context) {
|
||||
// This indicates that we do not want a "linear blending" decode.
|
||||
sk_sp<SkColorSpace> dstColorSpace = nullptr;
|
||||
return SkImage::MakeCrossContextFromEncoded(context, std::move(buffer),
|
||||
false, dstColorSpace.get());
|
||||
} else {
|
||||
return SkImage::MakeFromEncoded(std::move(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
void InvokeImageCallback(sk_sp<SkImage> image,
|
||||
std::unique_ptr<DartPersistentValue> callback,
|
||||
size_t trace_id) {
|
||||
tonic::DartState* dart_state = callback->dart_state().get();
|
||||
if (!dart_state) {
|
||||
TRACE_FLOW_END("flutter", kDecodeImageTraceTag, trace_id);
|
||||
return;
|
||||
}
|
||||
tonic::DartState::Scope scope(dart_state);
|
||||
if (!image) {
|
||||
DartInvoke(callback->value(), {Dart_Null()});
|
||||
} else {
|
||||
fxl::RefPtr<CanvasImage> resultImage = CanvasImage::Create();
|
||||
resultImage->set_image(std::move(image));
|
||||
DartInvoke(callback->value(), {ToDart(resultImage)});
|
||||
}
|
||||
TRACE_FLOW_END("flutter", kDecodeImageTraceTag, trace_id);
|
||||
}
|
||||
|
||||
void DecodeImageAndInvokeImageCallback(
|
||||
std::unique_ptr<DartPersistentValue> callback,
|
||||
sk_sp<SkData> buffer,
|
||||
size_t trace_id) {
|
||||
sk_sp<SkImage> image = DecodeImage(std::move(buffer), trace_id);
|
||||
Threads::UI()->PostTask(fxl::MakeCopyable([
|
||||
callback = std::move(callback), image, trace_id
|
||||
]() mutable { InvokeImageCallback(image, std::move(callback), trace_id); }));
|
||||
}
|
||||
|
||||
void DecodeImageFromList(Dart_NativeArguments args) {
|
||||
static size_t trace_counter = 1;
|
||||
const size_t trace_id = trace_counter++;
|
||||
TRACE_FLOW_BEGIN("flutter", kDecodeImageTraceTag, trace_id);
|
||||
|
||||
Dart_Handle exception = nullptr;
|
||||
|
||||
tonic::Uint8List list =
|
||||
tonic::DartConverter<tonic::Uint8List>::FromArguments(args, 0, exception);
|
||||
if (exception) {
|
||||
TRACE_FLOW_END("flutter", kDecodeImageTraceTag, trace_id);
|
||||
Dart_ThrowException(exception);
|
||||
return;
|
||||
}
|
||||
|
||||
Dart_Handle callback_handle = Dart_GetNativeArgument(args, 1);
|
||||
if (!Dart_IsClosure(callback_handle)) {
|
||||
TRACE_FLOW_END("flutter", kDecodeImageTraceTag, trace_id);
|
||||
Dart_ThrowException(ToDart("Callback must be a function"));
|
||||
return;
|
||||
}
|
||||
|
||||
auto buffer = SkData::MakeWithCopy(list.data(), list.num_elements());
|
||||
|
||||
Threads::IO()->PostTask(fxl::MakeCopyable([
|
||||
callback = std::make_unique<DartPersistentValue>(
|
||||
tonic::DartState::Current(), callback_handle),
|
||||
buffer = std::move(buffer), trace_id
|
||||
]() mutable {
|
||||
DecodeImageAndInvokeImageCallback(std::move(callback), std::move(buffer),
|
||||
trace_id);
|
||||
}));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ImageDecoding::RegisterNatives(tonic::DartLibraryNatives* natives) {
|
||||
natives->Register({
|
||||
{"decodeImageFromList", DecodeImageFromList, 2, true},
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2015 The Chromium 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_LIB_UI_PAINTING_IMAGE_DECODING_H_
|
||||
#define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_
|
||||
|
||||
#include "lib/tonic/dart_library_natives.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class ImageDecoding {
|
||||
public:
|
||||
static void RegisterNatives(tonic::DartLibraryNatives* natives);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_
|
||||
Reference in New Issue
Block a user