Skip to content

Commit b49de93

Browse files
authored
Create an ImageHandle wrapper (flutter#21057)
Allows for reference counting of images before disposal. This will allow multiple callers to hold a reference to an image and dispose of their reference without disposing the underlying image until all handles have been disposed. This will be used by the framework to help resolve some of the kludge I was trying to introduce in flutter#64582
1 parent dd35b5b commit b49de93

File tree

19 files changed

+476
-146
lines changed

19 files changed

+476
-146
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,6 @@ FILE: ../../../flutter/lib/ui/painting/color_filter.cc
328328
FILE: ../../../flutter/lib/ui/painting/color_filter.h
329329
FILE: ../../../flutter/lib/ui/painting/engine_layer.cc
330330
FILE: ../../../flutter/lib/ui/painting/engine_layer.h
331-
FILE: ../../../flutter/lib/ui/painting/frame_info.cc
332-
FILE: ../../../flutter/lib/ui/painting/frame_info.h
333331
FILE: ../../../flutter/lib/ui/painting/gradient.cc
334332
FILE: ../../../flutter/lib/ui/painting/gradient.h
335333
FILE: ../../../flutter/lib/ui/painting/image.cc

lib/ui/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ source_set("ui") {
3030
"painting/color_filter.h",
3131
"painting/engine_layer.cc",
3232
"painting/engine_layer.h",
33-
"painting/frame_info.cc",
34-
"painting/frame_info.h",
3533
"painting/gradient.cc",
3634
"painting/gradient.h",
3735
"painting/image.cc",

lib/ui/compositing.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ class Scene extends NativeFieldWrapperClass2 {
2323

2424
/// Creates a raster image representation of the current state of the scene.
2525
/// This is a slow operation that is performed on a background thread.
26+
///
27+
/// Callers must dispose the [Image] when they are done with it. If the result
28+
/// will be shared with other methods or classes, [Image.clone] should be used
29+
/// and each handle created must be disposed.
2630
Future<Image> toImage(int width, int height) {
2731
if (width <= 0 || height <= 0) {
2832
throw Exception('Invalid image dimensions.');
2933
}
30-
return _futurize((_Callback<Image> callback) => _toImage(width, height, callback));
34+
return _futurize((_Callback<Image> callback) => _toImage(width, height, (_Image image) {
35+
callback(Image._(image));
36+
}),
37+
);
3138
}
3239

33-
String _toImage(int width, int height, _Callback<Image> callback) native 'Scene_toImage';
40+
String _toImage(int width, int height, _Callback<_Image> callback) native 'Scene_toImage';
3441

3542
/// Releases the resources used by this scene.
3643
///

lib/ui/dart_ui.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "flutter/lib/ui/painting/codec.h"
1414
#include "flutter/lib/ui/painting/color_filter.h"
1515
#include "flutter/lib/ui/painting/engine_layer.h"
16-
#include "flutter/lib/ui/painting/frame_info.h"
1716
#include "flutter/lib/ui/painting/gradient.h"
1817
#include "flutter/lib/ui/painting/image.h"
1918
#include "flutter/lib/ui/painting/image_descriptor.h"
@@ -70,7 +69,6 @@ void DartUI::InitForGlobal() {
7069
DartRuntimeHooks::RegisterNatives(g_natives);
7170
EngineLayer::RegisterNatives(g_natives);
7271
FontCollection::RegisterNatives(g_natives);
73-
FrameInfo::RegisterNatives(g_natives);
7472
ImageDescriptor::RegisterNatives(g_natives);
7573
ImageFilter::RegisterNatives(g_natives);
7674
ImageShader::RegisterNatives(g_natives);

0 commit comments

Comments
 (0)