Line data Source code
1 : import 'dart:async';
2 :
3 : import 'package:flutter/cupertino.dart';
4 : import 'dart:typed_data';
5 : import 'dart:ui' as ui;
6 :
7 : class PowerTextureImageInfo extends PowerImageInfo {
8 : static ui.Image? dummy;
9 :
10 : final int? textureId;
11 : final int? width;
12 : final int? height;
13 :
14 1 : PowerTextureImageInfo(
15 : {this.textureId,
16 : this.width,
17 : this.height,
18 : required ui.Image image,
19 : double scale = 1.0,
20 : String? debugLabel})
21 1 : : super(image: image, scale: scale, debugLabel: debugLabel);
22 :
23 0 : ImageInfo clone() {
24 0 : return PowerTextureImageInfo(
25 0 : image: image.clone(),
26 0 : textureId: textureId,
27 0 : width: width,
28 0 : height: height,
29 0 : scale: scale,
30 0 : debugLabel: debugLabel,
31 : );
32 : }
33 :
34 1 : static FutureOr<PowerTextureImageInfo> create(
35 : {int? textureId, int? width, int? height}) async {
36 : if (dummy != null) {
37 0 : return PowerTextureImageInfo(
38 : textureId: textureId,
39 : width: width,
40 : height: height,
41 0 : image: dummy!.clone());
42 : }
43 :
44 2 : dummy = await _createImage(1, 1);
45 1 : return PowerTextureImageInfo(
46 : textureId: textureId,
47 : width: width,
48 : height: height,
49 1 : image: dummy!.clone());
50 : }
51 : }
52 :
53 1 : Future<ui.Image> _createImage(int width, int height) async {
54 1 : final Completer<ui.Image> completer = Completer<ui.Image>();
55 1 : ui.decodeImageFromPixels(
56 1 : Uint8List.fromList(
57 3 : List<int>.filled(width * height * 4, 0, growable: false)),
58 : width,
59 : height,
60 : ui.PixelFormat.rgba8888,
61 1 : (ui.Image image) {
62 1 : completer.complete(image);
63 : },
64 : );
65 1 : return completer.future;
66 : }
67 :
68 : class PowerImageInfo extends ImageInfo {
69 : /// DO NOT use powerImageInfo.image.width/.height
70 : /// Use powerImageInfo.width/.height directly.
71 0 : int? get width => image.width;
72 0 : int? get height => image.height;
73 1 : PowerImageInfo({required ui.Image image, double scale = 1.0, String? debugLabel})
74 1 : : super(image: image, scale: scale, debugLabel: debugLabel);
75 :
76 0 : ImageInfo clone() {
77 0 : return PowerImageInfo(
78 0 : image: image.clone(),
79 0 : scale: scale,
80 0 : debugLabel: debugLabel,
81 : );
82 : }
83 : }
|