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#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_H_
6#define FLUTTER_LIB_UI_PAINTING_IMAGE_H_
7
8#include "flutter/flow/skia_gpu_object.h"
9#include "flutter/lib/ui/dart_wrapper.h"
10#include "flutter/lib/ui/ui_dart_state.h"
11#include "third_party/skia/include/core/SkImage.h"
12
13namespace tonic {
14class DartLibraryNatives;
15} // namespace tonic
16
17namespace flutter {
18
19class CanvasImage final : public RefCountedDartWrappable<CanvasImage> {
20 DEFINE_WRAPPERTYPEINFO();
21 FML_FRIEND_MAKE_REF_COUNTED(CanvasImage);
22
23 public:
24 ~CanvasImage() override;
25 static fml::RefPtr<CanvasImage> Create() {
26 return fml::MakeRefCounted<CanvasImage>();
27 }
28
29 int width() { return image_.get()->width(); }
30
31 int height() { return image_.get()->height(); }
32
33 Dart_Handle toByteData(int format, Dart_Handle callback);
34
35 void dispose();
36
37 sk_sp<SkImage> image() const { return image_.get(); }
38 void set_image(flutter::SkiaGPUObject<SkImage> image) {
39 image_ = std::move(image);
40 }
41
42 size_t GetAllocationSize() const override;
43
44 static void RegisterNatives(tonic::DartLibraryNatives* natives);
45
46 private:
47 CanvasImage();
48
49 flutter::SkiaGPUObject<SkImage> image_;
50};
51
52} // namespace flutter
53
54#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_H_
55