Merge "AsyncTaskManager overhead reduce" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / glyph-buffer-data.h
1 #ifndef DALI_TEXT_ABSTRACTION_GLYPH_BUFFER_DATA_H
2 #define DALI_TEXT_ABSTRACTION_GLYPH_BUFFER_DATA_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/images/pixel.h>
23 #include <cstddef> /// for size_t
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
27 #include <dali/public-api/dali-adaptor-common.h>
28
29 namespace Dali
30 {
31 namespace TextAbstraction
32 {
33 /**
34   * @brief Struct used to retrieve the glyph's bitmap.
35   */
36 struct DALI_ADAPTOR_API GlyphBufferData
37 {
38   /**
39     * @brief Constructor.
40     *
41     * Initializes struct members to their defaults.
42     */
43   GlyphBufferData();
44
45   /**
46     * @brief Destructor.
47     */
48   ~GlyphBufferData();
49
50   /**
51     * @brief Move constructor.
52     *
53     * @param[in] rhs moved data.
54     */
55   GlyphBufferData(GlyphBufferData&& rhs) noexcept;
56
57   /**
58     * @brief Move assign operator.
59     *
60     * @param[in] rhs moved data.
61     * @return A reference to this.
62     */
63   GlyphBufferData& operator=(GlyphBufferData&& rhs) noexcept;
64
65   // Compression method of buffer. Each buffer compressed line by line
66   enum class CompressionType
67   {
68     NO_COMPRESSION = 0, // No compression
69     BPP_4          = 1, // Compress as 4 bit. Color become value * 17 (0x00, 0x11, 0x22, ... 0xee, 0xff).
70                         // Only works for Pixel::L8 format
71     RLE_4 = 2,          // Compress as 4 bit, and Run-Length-Encode. For more high compress rate, we store difference between previous scanline.
72                         // Only works for Pixel::L8 format
73   };
74
75   /**
76     * @brief Helper static function to compress raw buffer from inBuffer to outBufferData.buffer.
77     * outBufferData will have it's own buffer.
78     *
79     * @pre outBufferData must not have it's own buffer.
80     * @param[in] inBuffer The input raw data.
81     * @param[in, out] outBufferData The output glyph buffer data.
82     * @return Size of compressed out buffer, Or 0 if compress failed.
83     */
84   static size_t Compress(const uint8_t* const inBuffer, GlyphBufferData& outBufferData);
85
86   /**
87     * @brief Helper static function to decompress raw buffer from inBuffer to outBufferPtr.
88     * If outBuffer is nullptr, Do nothing.
89     *
90     * @pre outBuffer memory should be allocated.
91     * @param[in] inBufferData The input glyph buffer data.
92     * @param[in, out] outBuffer The output pointer of raw buffer data.
93     */
94   static void Decompress(const GlyphBufferData& inBufferData, uint8_t* outBuffer);
95
96   /**
97     * @brief Special Helper static function to decompress raw buffer from inBuffer to outBuffer one scanline.
98     * After decompress one scanline successed, offset will be changed.
99     *
100     * @pre outBuffer memory should be allocated.
101     * @pre if inBufferData's compression type is RLE4, outBuffer memory should store the previous scanline data.
102     * @param[in] inBufferData The input glyph buffer data.
103     * @param[in, out] outBuffer The output pointer of raw buffer data.
104     * @param[in, out] offset The offset of input. It will be changed as next scanline's offset.
105     */
106   static void DecompressScanline(const GlyphBufferData& inBufferData, uint8_t* outBuffer, uint32_t& offset);
107
108 private:
109   // Delete copy operation.
110   GlyphBufferData(const GlyphBufferData& rhs) = delete;
111   GlyphBufferData& operator=(const GlyphBufferData& rhs) = delete;
112
113 public:
114   uint8_t*        buffer;            ///< The glyph's bitmap buffer data.
115   uint32_t        width;             ///< The width of the bitmap.
116   uint32_t        height;            ///< The height of the bitmap.
117   int             outlineOffsetX;    ///< The additional horizontal offset to be added for the glyph's position for outline.
118   int             outlineOffsetY;    ///< The additional vertical offset to be added for the glyph's position for outline.
119   Pixel::Format   format;            ///< The pixel's format of the bitmap.
120   CompressionType compressionType;   ///< The type of buffer compression.
121   bool            isColorEmoji : 1;  ///< Whether the glyph is an emoji.
122   bool            isColorBitmap : 1; ///< Whether the glyph is a color bitmap.
123   bool            isBufferOwned : 1; ///< Whether the glyph's bitmap buffer data owned by this class or not. Becareful when you use non-owned buffer data.
124 };
125
126 } // namespace TextAbstraction
127
128 } // namespace Dali
129
130 #endif //DALI_TEXT_ABSTRACTION_GLYPH_INFO_H