• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
8 
9 namespace flutter {
10 
11 typedef CanvasImage Image;
12 
13 IMPLEMENT_WRAPPERTYPEINFO(ui, Image);
14 
15 #define FOR_EACH_BINDING(V) \
16   V(Image, width)           \
17   V(Image, height)          \
18   V(Image, toByteData)      \
19   V(Image, dispose)
20 
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)21 FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
22 
23 void CanvasImage::RegisterNatives(tonic::DartLibraryNatives* natives) {
24 }
25 
26 CanvasImage::CanvasImage() = default;
27 
28 CanvasImage::~CanvasImage() = default;
29 
toByteData(int format,Dart_Handle callback)30 Dart_Handle CanvasImage::toByteData(int format, Dart_Handle callback) {
31   return EncodeImage(this, format, callback);
32 }
33 
dispose()34 void CanvasImage::dispose() {
35   ClearDartWrapper();
36 }
37 
GetAllocationSize()38 size_t CanvasImage::GetAllocationSize() {
39   if (auto image = image_.get()) {
40 #ifdef USE_SYSTEM_SKIA
41     const auto& info = SkImageInfo::Make(image->width(), image->height(), image->colorType(), image->alphaType());
42 #else
43     const auto& info = image->imageInfo();
44 #endif
45     const auto kMipmapOverhead = 4.0 / 3.0;
46     const size_t image_byte_size = info.computeMinByteSize() * kMipmapOverhead;
47     return image_byte_size + sizeof(this);
48   } else {
49     return sizeof(CanvasImage);
50   }
51 }
52 
53 }  // namespace flutter
54