[dali_2.3.33] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / images / bitmap-compressed.h
1 #ifndef DALI_INTERNAL_COMPRESSED_BITMAP_H
2 #define DALI_INTERNAL_COMPRESSED_BITMAP_H
3
4 /*
5  * Copyright (c) 2021 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
23 // INTERNAL INCLUDES
24 #include <dali/integration-api/bitmap.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class BitmapCompressed;
31 using BitmapCompressedPtr = IntrusivePtr<BitmapCompressed>;
32
33 /**
34  * BitmapCompressed class.
35  * A container for image data that remains in compresssed form as an opaque blob
36  * in memory rather than being decompressed at load time.
37  * Used for formats that are supported as GLES texture data directly.
38  */
39 class BitmapCompressed : public Dali::Integration::Bitmap, Dali::Integration::Bitmap::CompressedProfile
40 {
41 public:
42   /**
43    * Constructor
44    * @param[in] discardable Flag to tell the bitmap if it can delete the buffer with the pixel data.
45    */
46   BitmapCompressed(ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_RETAIN);
47
48   const Bitmap::CompressedProfile* GetCompressedProfile() const override
49   {
50     return this;
51   }
52   Bitmap::CompressedProfile* GetCompressedProfile() override
53   {
54     return this;
55   }
56
57 private:
58   /**
59    * Initializes internal class members
60    * @param[in] pixelFormat   pixel format
61    * @param[in] width         Image width in pixels
62    * @param[in] height        Image height in pixels
63    * @param[in] bufferSize    Buffer cpacity in pixels
64    */
65   void Initialize(Pixel::Format pixelFormat,
66                   uint32_t      width,
67                   uint32_t      height,
68                   uint32_t      bufferSize);
69
70 public:
71   /**
72    * (Re-)Allocate pixel buffer for the Bitmap. Any previously allocated pixel buffer
73    * is deleted.
74    * Dali has ownership of the buffer, and contents are opaque and immutable.
75    * Bitmap stores given size information about the image which the client is assumed
76    * to have retrieved from out-of-band image metadata.
77    * @param[in] pixelFormat   pixel format
78    * @param[in] width         Image width in pixels
79    * @param[in] height        Image height in pixels
80    * @param[in] bufferSize    Buffer size in bytes
81    * @return pixel buffer pointer
82    */
83   Dali::Integration::PixelBuffer* ReserveBufferOfSize(Pixel::Format  pixelFormat,
84                                                       const uint32_t width,
85                                                       const uint32_t height,
86                                                       const uint32_t numBytes) override;
87
88   /**
89    * Get the pixel buffer size in bytes
90    * @return The buffer size in bytes.
91    */
92   uint32_t GetBufferSize() const override
93   {
94     return mBufferSize;
95   }
96
97   /**
98    * See Dali::Integration::Bitmap::GetReleaseFunction()
99    */
100   ReleaseFunction GetReleaseFunction() override
101   {
102     return FREE;
103   }
104
105 protected:
106   /**
107    * A reference counted object may only be deleted by calling Unreference()
108    */
109   ~BitmapCompressed() override;
110
111 private:
112   uint32_t mBufferSize;
113
114   BitmapCompressed(const BitmapCompressed& other);            ///< defined private to prevent use
115   BitmapCompressed& operator=(const BitmapCompressed& other); ///< defined private to prevent use
116
117   // Changes scope, should be at end of class
118   DALI_LOG_OBJECT_STRING_DECLARATION;
119 };
120
121 } // namespace Internal
122
123 } // namespace Dali
124
125 #endif // DALI_INTERNAL_COMPRESSED_BITMAP_H