xref: /aosp_15_r20/external/skia/experimental/rust_png/encoder/impl/SkPngRustEncoderImpl.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 // This class provides the Skia image encoding API (`SkEncoder`) on top of the
23 // third-party `png` crate (PNG compression and encoding implemented in Rust).
24 //
25 // TODO(https://crbug.com/379312510): Derive from `SkPngEncoderBase` (see
26 // http://review.skia.org/923336 and http://review.skia.org/922676).
27 class SkPngRustEncoderImpl final : public SkPngEncoderBase {
28 public:
29     static std::unique_ptr<SkEncoder> Make(SkWStream*, const SkPixmap&);
30 
31     // `public` to support `std::make_unique<SkPngRustEncoderImpl>(...)`.
32     SkPngRustEncoderImpl(TargetInfo targetInfo,
33                          const SkPixmap& src,
34                          rust::Box<rust_png::StreamWriter> streamWriter);
35 
36     ~SkPngRustEncoderImpl() override;
37 
38 protected:
39     bool onEncodeRow(SkSpan<const uint8_t> row) override;
40     bool onFinishEncoding() override;
41 
42 private:
43     rust::Box<rust_png::StreamWriter> fStreamWriter;
44 };
45 
46 #endif  // SkPngRustEncoderImpl_DEFINED
47