Added UIThreadLoader to GLIB framework
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / native-bitmap-buffer-impl.h
1 #ifndef DALI_NATIVE_BITMAP_BUFFER_H
2 #define DALI_NATIVE_BITMAP_BUFFER_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 HEADERS
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/lockless-buffer.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/images/native-image-interface.h>
26 #include <dali/public-api/images/pixel.h>
27
28 // INTERNAL HEADERS
29 #include <dali/internal/adaptor/common/adaptor-impl.h>
30 #include <dali/internal/graphics/common/graphics-interface.h>
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38 class NativeBitmapBuffer;
39 typedef IntrusivePtr<NativeBitmapBuffer> NativeBitmapBufferPtr;
40
41 /**
42  * A Bitmap-based implementation of the NativeImage interface.
43  */
44 class NativeBitmapBuffer : public NativeImageInterface
45 {
46 public:
47   /**
48    * Constructor.
49    * @param adaptor Adaptor used
50    * @param width width of image
51    * @param height height of image
52    * @param pixelFormat pixel format for image
53    */
54   NativeBitmapBuffer(Adaptor* adaptor, unsigned int width, unsigned int height, Pixel::Format pixelFormat);
55
56   /**
57    * virtual destructor
58    */
59   virtual ~NativeBitmapBuffer();
60
61   /**
62    * Write to buffer. Does not block.
63    * @param[in] src  data source
64    * @param[in] size size of data in bytes
65    * @return true if successful, false if currently reading from buffer in render thread
66    */
67   void Write(const unsigned char* src, size_t size);
68
69 public:
70   /**
71    * @copydoc Dali::NativeImageInterface::CreateResource()
72    */
73   bool CreateResource() override;
74
75   /**
76    * @copydoc Dali::NativeImageInterface::DestroyResource()
77    */
78   void DestroyResource() override;
79
80   /**
81    * @copydoc Dali::NativeImageInterface::TargetTexture()
82    */
83   unsigned int TargetTexture() override;
84
85   /**
86    * @copydoc Dali::NativeImageInterface::PrepareTexture()
87    */
88   void PrepareTexture() override;
89
90   /**
91    * @copydoc Dali::NativeImageInterface::GetWidth()
92    */
93   unsigned int GetWidth() const override;
94
95   /**
96    * @copydoc Dali::NativeImageInterface::GetHeight()
97    */
98   unsigned int GetHeight() const override;
99
100   /**
101    * @copydoc Dali::NativeImageInterface::RequiresBlending()
102    */
103   bool RequiresBlending() const override;
104
105   /**
106    * @copydoc Dali::NativeImageInterface::RequiresBlending()
107    */
108   int GetTextureTarget() const override;
109
110   /**
111    * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
112    */
113   bool ApplyNativeFragmentShader(std::string& shader) override;
114
115   /**
116    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
117    */
118   const char* GetCustomSamplerTypename() const override;
119
120   /**
121    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
122    */
123   Any GetNativeImageHandle() const override;
124
125   /**
126    * @copydoc Dali::NativeImageInterface::SourceChanged()
127    */
128   bool SourceChanged() const override;
129
130   /**
131    * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
132    */
133   Rect<uint32_t> GetUpdatedArea() override
134   {
135     return Rect<uint32_t>{0, 0, mWidth, mHeight};
136   }
137
138 private:
139   NativeBitmapBuffer(const NativeBitmapBuffer&);            ///< not defined
140   NativeBitmapBuffer& operator=(const NativeBitmapBuffer&); ///< not defined
141   NativeBitmapBuffer();                                     ///< not defined
142
143 private:
144   Integration::GlAbstraction* mGlAbstraction; ///< GlAbstraction used
145
146   Integration::LocklessBuffer* mBuffer;         ///< bitmap data double buffered
147   unsigned int                 mWidth;          ///< Image width
148   unsigned int                 mHeight;         ///< Image height
149   Pixel::Format                mPixelFormat;    ///< Image pixelformat
150   const unsigned char*         mLastReadBuffer; ///< last buffer that was read
151 };
152
153 } // namespace Adaptor
154
155 } // namespace Internal
156
157 } // namespace Dali
158
159 #endif // DALI_NATIVE_BITMAP_BUFFER_H