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  auto hint_freed_delegate = UIDartState::Current()->GetHintFreedDelegate();
48  if (hint_freed_delegate) {
49  hint_freed_delegate->HintFreed(GetAllocationSize());
50  }
51  image_.reset();
53 }
54 
56  if (auto image = image_.get()) {
57  const auto& info = image->imageInfo();
58  const auto kMipmapOverhead = 4.0 / 3.0;
59  const size_t image_byte_size = info.computeMinByteSize() * kMipmapOverhead;
60  return image_byte_size + sizeof(this);
61  } else {
62  return sizeof(CanvasImage);
63  }
64 }
65 
66 } // namespace flutter
CanvasImage Image
Definition: image.cc:15
~CanvasImage() override
sk_sp< SkiaObjectType > get() const
size_t GetAllocationSize() const override
Definition: image.cc:55
#define DART_NATIVE_CALLBACK(CLASS, METHOD)
static const tonic::DartWrapperInfo kDartWrapperInfo_ui_Image
Definition: image.cc:18
Dart_Handle toByteData(int format, Dart_Handle callback)
Definition: image.cc:42
Dart_Handle EncodeImage(CanvasImage *canvas_image, int format, Dart_Handle callback_handle)
#define FOR_EACH_BINDING(V)
Definition: image.cc:26
fml::WeakPtr< HintFreedDelegate > GetHintFreedDelegate() const
#define DART_REGISTER_NATIVE(CLASS, METHOD)
sk_sp< SkImage > image() const
Definition: image.h:37
static UIDartState * Current()