1 /* 2 * Copyright 2024 Google LLC. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 #ifndef SkPngRustEncoderImpl_DEFINED 8 #define SkPngRustEncoderImpl_DEFINED 9 10 #include <memory> 11 12 #include "experimental/rust_png/ffi/FFI.rs.h" 13 #include "src/encode/SkPngEncoderBase.h" 14 #include "third_party/rust/cxx/v1/cxx.h" 15 16 class SkWStream; 17 struct SkEncodedInfo; 18 class SkPixmap; 19 class SkPngEncoderMgr; 20 template <typename T> class SkSpan; 21 22 namespace SkPngRustEncoder { 23 struct Options; 24 } // namespace SkPngRustEncoder 25 26 // This class provides the Skia image encoding API (`SkEncoder`) on top of the 27 // third-party `png` crate (PNG compression and encoding implemented in Rust). 28 // 29 // TODO(https://crbug.com/379312510): Derive from `SkPngEncoderBase` (see 30 // http://review.skia.org/923336 and http://review.skia.org/922676). 31 class SkPngRustEncoderImpl final : public SkPngEncoderBase { 32 public: 33 static std::unique_ptr<SkEncoder> Make(SkWStream*, 34 const SkPixmap&, 35 const SkPngRustEncoder::Options& options); 36 37 // `public` to support `std::make_unique<SkPngRustEncoderImpl>(...)`. 38 SkPngRustEncoderImpl(TargetInfo targetInfo, 39 const SkPixmap& src, 40 rust::Box<rust_png::StreamWriter> streamWriter); 41 42 ~SkPngRustEncoderImpl() override; 43 44 protected: 45 bool onEncodeRow(SkSpan<const uint8_t> row) override; 46 bool onFinishEncoding() override; 47 48 private: 49 rust::Box<rust_png::StreamWriter> fStreamWriter; 50 }; 51 52 #endif // SkPngRustEncoderImpl_DEFINED 53