[Tizen] Add IsUploaded devel api in Texture
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / texture-impl.h
1 #ifndef DALI_INTERNAL_NEW_TEXTURE_H
2 #define DALI_INTERNAL_NEW_TEXTURE_H
3
4 /*
5  * Copyright (c) 2020 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 // INTERNAL INCLUDES
22 #include <dali/internal/event/common/event-thread-services.h>
23 #include <dali/internal/event/images/pixel-data-impl.h>
24 #include <dali/public-api/common/dali-common.h>      // DALI_ASSERT_ALWAYS
25 #include <dali/public-api/common/intrusive-ptr.h>    // Dali::IntrusivePtr
26 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
27 #include <dali/public-api/images/pixel.h>
28 #include <dali/public-api/object/base-object.h>
29 #include <dali/public-api/rendering/texture.h> // Dali::Internal::Render::Texture
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35 namespace Render
36 {
37 class Texture;
38 }
39
40 class Texture;
41 using TexturePtr = IntrusivePtr<Texture>;
42
43 class Texture : public BaseObject
44 {
45 public:
46   /**
47    * @brief Structure used to pass parameters to the Upload method
48    */
49   struct UploadParams
50   {
51     uint16_t layer;   ///< Specifies the layer of a cube map or array texture
52     uint16_t mipmap;  ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
53     uint16_t xOffset; ///< Specifies a texel offset in the x direction within the texture array.
54     uint16_t yOffset; ///< Specifies a texel offset in the y direction within the texture array.
55     uint16_t width;   ///< Specifies the width of the texture subimage
56     uint16_t height;  ///< Specifies the height of the texture subimage.
57   };
58
59   /**
60    * @brief Create a new Texture.
61    *
62    * @param[in] type The type of the texture
63    * @param[in] format The format of the pixel data
64    * @param[in] width The width of the texture
65    * @param[in] height The height of the texture
66    * @return A smart-pointer to the newly allocated Texture.
67    */
68   static TexturePtr New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height);
69
70   /**
71    * @brief Creates a new Texture from a native image
72    * @param[in] nativeImageInterface The native image
73    * @return A smart-pointer to the newly allocated Texture.
74    */
75   static TexturePtr New(NativeImageInterface& nativeImageInterface);
76
77   /**
78    * @brief Get the texture render object
79    *
80    * @return the texture render object
81    */
82   Render::Texture* GetRenderObject() const;
83
84   /**
85    * @copydoc Dali::Texture::Upload()
86    */
87   bool Upload(PixelDataPtr pixelData);
88
89   /**
90    * @copydoc Dali::Texture::Upload()
91    */
92   bool Upload(PixelDataPtr pixelData,
93               unsigned int layer,
94               unsigned int mipmap,
95               unsigned int xOffset,
96               unsigned int yOffset,
97               unsigned int width,
98               unsigned int height);
99
100   /**
101    * @copydoc Dali::Texture::GenerateMipmaps()
102    */
103   void GenerateMipmaps();
104
105   /**
106    * @copydoc Dali::Texture::GetWidth()
107    */
108   unsigned int GetWidth() const;
109
110   /**
111    * @copydoc Dali::Texture::GetHeight()
112    */
113   unsigned int GetHeight() const;
114
115   /**
116    * @brief Determine if the texture is a native image
117    *
118    * @return true if the texture has been initialized with a native image
119    */
120   bool IsNative() const;
121
122   /**
123    * @brief Apply any native texture code to the given fragment shader
124    *
125    * @param[in,out] shader The fragment shader
126    * @return true if the shader has been modified.
127    */
128   bool ApplyNativeFragmentShader(std::string& shader);
129
130   /**
131    * @brief Check whether texture is uploaded or not.
132    */
133   bool IsUploaded();
134
135 private: // implementation
136   /**
137    * Constructor
138    * @param[in] type The type of the texture
139    * @param[in] format The format of the pixel data
140    * @param[in] size The size of the texture
141    */
142   Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size);
143
144   /**
145    * Constructor from native image
146    * @param[in] nativeImageInterface The native image
147    */
148   Texture(NativeImageInterfacePtr nativeImageInterface);
149
150   /**
151    * Second stage initialization of the Texture
152    */
153   void Initialize();
154
155 protected:
156   /**
157    * A reference counted object may only be deleted by calling Unreference()
158    */
159   ~Texture() override;
160
161 private: // unimplemented methods
162   Texture(const Texture&);
163   Texture& operator=(const Texture&);
164
165 private:                                               // data
166   Internal::EventThreadServices& mEventThreadServices; ///<Used to send messages to the render thread via update thread
167   Internal::Render::Texture*     mRenderObject;        ///<The Render::Texture associated to this texture
168
169   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
170   ImageDimensions         mSize;        ///< Size of the texture
171   Dali::TextureType::Type mType;        ///< Texture type (cached)
172   Pixel::Format           mFormat;      ///< Pixel format
173 };
174
175 } // namespace Internal
176
177 // Helpers for public-api forwarding methods
178 inline Internal::Texture& GetImplementation(Dali::Texture& handle)
179 {
180   DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
181
182   BaseObject& object = handle.GetBaseObject();
183
184   return static_cast<Internal::Texture&>(object);
185 }
186
187 inline const Internal::Texture& GetImplementation(const Dali::Texture& handle)
188 {
189   DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
190
191   const BaseObject& object = handle.GetBaseObject();
192
193   return static_cast<const Internal::Texture&>(object);
194 }
195
196 } // namespace Dali
197
198 #endif // DALI_INTERNAL_TEXTURE_H