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 13 namespace tonic { 14 class DartLibraryNatives; 15 } // namespace tonic 16 17 namespace flutter { 18 19 class CanvasImage final : public RefCountedDartWrappable<CanvasImage> { 20 DEFINE_WRAPPERTYPEINFO(); 21 FML_FRIEND_MAKE_REF_COUNTED(CanvasImage); 22 23 public: 24 ~CanvasImage() override; Create()25 static fml::RefPtr<CanvasImage> Create() { 26 return fml::MakeRefCounted<CanvasImage>(); 27 } 28 width()29 int width() { return image_.get()->width(); } 30 height()31 int height() { return image_.get()->height(); } 32 33 Dart_Handle toByteData(int format, Dart_Handle callback); 34 35 void dispose(); 36 image()37 sk_sp<SkImage> image() const { return image_.get(); } set_image(flutter::SkiaGPUObject<SkImage> image)38 void set_image(flutter::SkiaGPUObject<SkImage> image) { 39 image_ = std::move(image); 40 } 41 42 size_t GetAllocationSize() override; 43 44 static void RegisterNatives(tonic::DartLibraryNatives* natives); 45 compressData()46 sk_sp<SkData> compressData() const { return compressData_; } compressWidth()47 int compressWidth() { return compressWidth_; } compressHeight()48 int compressHeight() { return compressHeight_; } setCompress(sk_sp<SkData> data,int width,int height)49 void setCompress(sk_sp<SkData> data, int width, int height) { 50 compressData_ = data; 51 compressWidth_ = width; 52 compressHeight_ = height; 53 } 54 private: 55 CanvasImage(); 56 57 flutter::SkiaGPUObject<SkImage> image_; 58 sk_sp<SkData> compressData_; 59 int compressWidth_; 60 int compressHeight_; 61 }; 62 63 } // namespace flutter 64 65 #endif // FLUTTER_LIB_UI_PAINTING_IMAGE_H_ 66