xref: /aosp_15_r20/external/skia/include/encode/SkEncoder.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2017 Google Inc.
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 
8 #ifndef SkEncoder_DEFINED
9 #define SkEncoder_DEFINED
10 
11 #include "include/core/SkPixmap.h"
12 #include "include/private/base/SkAPI.h"
13 #include "include/private/base/SkNoncopyable.h"
14 #include "include/private/base/SkTemplates.h"
15 
16 #include <cstddef>
17 #include <cstdint>
18 
19 class SK_API SkEncoder : SkNoncopyable {
20 public:
21     /**
22      * A single frame to be encoded into an animated image.
23      *
24      * If a frame does not fit in the canvas size, this is an error.
25      * TODO(skia:13705): Add offsets when we have support for an encoder that supports using
26      * offsets.
27      */
28     struct SK_API Frame {
29         /**
30          *  Pixmap of the frame.
31          */
32         SkPixmap pixmap;
33         /**
34          *  Duration of the frame in millseconds.
35          */
36         int duration;
37     };
38 
39     /**
40      *  Encode |numRows| rows of input.  If the caller requests more rows than are remaining
41      *  in the src, this will encode all of the remaining rows.  |numRows| must be greater
42      *  than zero.
43      */
44     bool encodeRows(int numRows);
45 
~SkEncoder()46     virtual ~SkEncoder() {}
47 
48 protected:
49 
50     virtual bool onEncodeRows(int numRows) = 0;
51 
SkEncoder(const SkPixmap & src,size_t storageBytes)52     SkEncoder(const SkPixmap& src, size_t storageBytes)
53         : fSrc(src)
54         , fCurrRow(0)
55         , fStorage(storageBytes)
56     {}
57 
58     const SkPixmap&        fSrc;
59     int                    fCurrRow;
60     skia_private::AutoTMalloc<uint8_t> fStorage;
61 };
62 
63 #endif
64