SingleFrameCodec GetAllocationSize and ImageDescriptor.dispose (flutter/engine#26435)
This commit is contained in:
@@ -393,6 +393,7 @@ FILE: ../../../flutter/lib/ui/painting/shader.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/shader.h
|
||||
FILE: ../../../flutter/lib/ui/painting/single_frame_codec.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/single_frame_codec.h
|
||||
FILE: ../../../flutter/lib/ui/painting/single_frame_codec_unittests.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/vertices.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/vertices.h
|
||||
FILE: ../../../flutter/lib/ui/painting/vertices_unittests.cc
|
||||
|
||||
@@ -203,6 +203,7 @@ if (enable_unittests) {
|
||||
"painting/image_encoding_unittests.cc",
|
||||
"painting/image_generator_registry_unittests.cc",
|
||||
"painting/path_unittests.cc",
|
||||
"painting/single_frame_codec_unittests.cc",
|
||||
"painting/vertices_unittests.cc",
|
||||
"window/platform_configuration_unittests.cc",
|
||||
"window/pointer_data_packet_converter_unittests.cc",
|
||||
|
||||
@@ -9,6 +9,27 @@ import 'dart:ui';
|
||||
|
||||
void main() {}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> createSingleFrameCodec() async {
|
||||
final ImmutableBuffer buffer = await ImmutableBuffer.fromUint8List(Uint8List.fromList(List<int>.filled(4, 100)));
|
||||
final ImageDescriptor descriptor = ImageDescriptor.raw(
|
||||
buffer,
|
||||
width: 1,
|
||||
height: 1,
|
||||
pixelFormat: PixelFormat.rgba8888,
|
||||
);
|
||||
final Codec codec = await descriptor.instantiateCodec();
|
||||
_validateCodec(codec);
|
||||
await codec.getNextFrame();
|
||||
_validateCodec(codec);
|
||||
codec.dispose();
|
||||
descriptor.dispose();
|
||||
buffer.dispose();
|
||||
_finish();
|
||||
}
|
||||
void _validateCodec(Codec codec) native 'ValidateCodec';
|
||||
void _finish() native 'Finish';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void createVertices() {
|
||||
const int uint16max = 65535;
|
||||
|
||||
@@ -22,7 +22,8 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, ImageDescriptor);
|
||||
V(ImageDescriptor, instantiateCodec) \
|
||||
V(ImageDescriptor, width) \
|
||||
V(ImageDescriptor, height) \
|
||||
V(ImageDescriptor, bytesPerPixel)
|
||||
V(ImageDescriptor, bytesPerPixel) \
|
||||
V(ImageDescriptor, dispose)
|
||||
|
||||
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
|
||||
|
||||
|
||||
@@ -107,8 +107,9 @@ class ImageDescriptor : public RefCountedDartWrappable<ImageDescriptor> {
|
||||
bool get_pixels(const SkPixmap& pixmap) const;
|
||||
|
||||
void dispose() {
|
||||
ClearDartWrapper();
|
||||
buffer_.reset();
|
||||
generator_.reset();
|
||||
ClearDartWrapper();
|
||||
}
|
||||
|
||||
size_t GetAllocationSize() const override {
|
||||
|
||||
@@ -54,8 +54,8 @@ class ImmutableBuffer : public RefCountedDartWrappable<ImmutableBuffer> {
|
||||
/// The byte buffer will continue to live if other objects hold a reference to
|
||||
/// it.
|
||||
void dispose() {
|
||||
ClearDartWrapper();
|
||||
data_.reset();
|
||||
ClearDartWrapper();
|
||||
}
|
||||
|
||||
size_t GetAllocationSize() const override;
|
||||
|
||||
@@ -111,10 +111,7 @@ Dart_Handle SingleFrameCodec::getNextFrame(Dart_Handle callback_handle) {
|
||||
}
|
||||
|
||||
size_t SingleFrameCodec::GetAllocationSize() const {
|
||||
const auto& data_size = descriptor_->GetAllocationSize();
|
||||
const auto frame_byte_size =
|
||||
cached_image_ ? cached_image_->GetAllocationSize() : 0;
|
||||
return data_size + frame_byte_size + sizeof(this);
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright 2013 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/lib/ui/painting/single_frame_codec.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/common/task_runners.h"
|
||||
#include "flutter/fml/synchronization/waitable_event.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/shell/common/shell_test.h"
|
||||
#include "flutter/shell/common/thread_host.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
TEST_F(ShellTest, SingleFrameCodecAccuratelyReportsSize) {
|
||||
auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
|
||||
|
||||
auto validate_codec = [](Dart_NativeArguments args) {
|
||||
auto handle = Dart_GetNativeArgument(args, 0);
|
||||
intptr_t peer = 0;
|
||||
Dart_Handle result = Dart_GetNativeInstanceField(
|
||||
handle, tonic::DartWrappable::kPeerIndex, &peer);
|
||||
ASSERT_FALSE(Dart_IsError(result));
|
||||
SingleFrameCodec* codec = reinterpret_cast<SingleFrameCodec*>(peer);
|
||||
ASSERT_EQ(codec->GetAllocationSize(), sizeof(SingleFrameCodec));
|
||||
};
|
||||
auto finish = [message_latch](Dart_NativeArguments args) {
|
||||
message_latch->Signal();
|
||||
};
|
||||
|
||||
Settings settings = CreateSettingsForFixture();
|
||||
TaskRunners task_runners("test", // label
|
||||
GetCurrentTaskRunner(), // platform
|
||||
CreateNewThread(), // raster
|
||||
CreateNewThread(), // ui
|
||||
CreateNewThread() // io
|
||||
);
|
||||
|
||||
AddNativeCallback("ValidateCodec", CREATE_NATIVE_ENTRY(validate_codec));
|
||||
AddNativeCallback("Finish", CREATE_NATIVE_ENTRY(finish));
|
||||
|
||||
std::unique_ptr<Shell> shell =
|
||||
CreateShell(std::move(settings), std::move(task_runners));
|
||||
|
||||
ASSERT_TRUE(shell->IsSetup());
|
||||
auto configuration = RunConfiguration::InferFromSettings(settings);
|
||||
configuration.SetEntrypoint("createSingleFrameCodec");
|
||||
|
||||
shell->RunEngine(std::move(configuration), [](auto result) {
|
||||
ASSERT_EQ(result, Engine::RunStatus::Success);
|
||||
});
|
||||
|
||||
message_latch->Wait();
|
||||
DestroyShell(std::move(shell), std::move(task_runners));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
Reference in New Issue
Block a user