Flutter Engine
image.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/lib/ui/painting/image.h"
6 
7 #include "flutter/lib/ui/painting/image_encoding.h"
12 
13 namespace flutter {
14 
16 
17 // Since _Image is a private class, we can't use IMPLEMENT_WRAPPERTYPEINFO
19  "ui",
20  "_Image",
21  sizeof(Image),
22 };
23 const tonic::DartWrapperInfo& Image::dart_wrapper_info_ =
25 
26 #define FOR_EACH_BINDING(V) \
27  V(Image, width) \
28  V(Image, height) \
29  V(Image, toByteData) \
30  V(Image, dispose)
31 
33 
34 void CanvasImage::RegisterNatives(tonic::DartLibraryNatives* natives) {
35  natives->Register({FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
36 }
37 
38 CanvasImage::CanvasImage() = default;
39 
40 CanvasImage::~CanvasImage() = default;
41 
42 Dart_Handle CanvasImage::toByteData(int format, Dart_Handle callback) {
43  return EncodeImage(this, format, callback);
44 }
45 
47  image_.reset();
49 }
50 
52  if (auto image = image_.skia_object()) {
53  const auto& info = image->imageInfo();
54  const auto kMipmapOverhead = 4.0 / 3.0;
55  const size_t image_byte_size = info.computeMinByteSize() * kMipmapOverhead;
56  return image_byte_size + sizeof(this);
57  } else {
58  return sizeof(CanvasImage);
59  }
60 }
61 
62 } // namespace flutter
CanvasImage Image
Definition: image.cc:15
~CanvasImage() override
size_t GetAllocationSize() const override
Definition: image.cc:51
uint32_t uint32_t * format
#define DART_NATIVE_CALLBACK(CLASS, METHOD)
FlKeyEvent FlKeyResponderAsyncCallback callback
static const tonic::DartWrapperInfo kDartWrapperInfo_ui_Image
Definition: image.cc:18
Dart_Handle toByteData(int format, Dart_Handle callback)
Definition: image.cc:42
sk_sp< SkiaObjectType > skia_object() const
Dart_Handle EncodeImage(CanvasImage *canvas_image, int format, Dart_Handle callback_handle)
#define FOR_EACH_BINDING(V)
Definition: image.cc:26
#define DART_REGISTER_NATIVE(CLASS, METHOD)
sk_sp< SkImage > image() const
Definition: image.h:37