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