1 #ifndef DALI_INTERNAL_NEW_TEXTURE_H
2 #define DALI_INTERNAL_NEW_TEXTURE_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/internal/event/common/event-thread-services.h>
23 #include <dali/internal/event/images/pixel-data-impl.h>
24 #include <dali/internal/render/renderers/render-texture-key.h>
25 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
26 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
27 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
28 #include <dali/public-api/images/pixel.h>
29 #include <dali/public-api/object/base-object.h>
30 #include <dali/public-api/rendering/texture.h> // Dali::Internal::Render::Texture
37 using TexturePtr = IntrusivePtr<Texture>;
39 class Texture : public BaseObject
43 * @brief Create a new Texture.
45 * @param[in] type The type of the texture
46 * @param[in] format The format of the pixel data
47 * @param[in] width The width of the texture
48 * @param[in] height The height of the texture
49 * @return A smart-pointer to the newly allocated Texture.
51 static TexturePtr New(TextureType::Type type, Pixel::Format format, uint32_t width, uint32_t height);
54 * @brief Creates a new Texture from a native image
55 * @param[in] nativeImageInterface The native image
56 * @return A smart-pointer to the newly allocated Texture.
58 static TexturePtr New(NativeImageInterface& nativeImageInterface);
61 * @brief Create a new Texture with resourceId.
63 * @param[in] type The type of the texture
64 * @param[in] resourceId The unique id of this texture combind with TextureUploadManager
65 * @return A smart-pointer to the newly allocated Texture.
67 static TexturePtr New(TextureType::Type type, uint32_t resourceId);
70 * @brief Get the texture render object
72 * @return the texture render object
74 Render::TextureKey GetRenderTextureKey() const;
77 * @copydoc Dali::Texture::Upload()
79 bool Upload(PixelDataPtr pixelData);
82 * @copydoc Dali::Texture::Upload()
84 bool Upload(PixelDataPtr pixelData,
93 * @copydoc Dali::Texture::UploadSubPixelData()
95 bool UploadSubPixelData(PixelDataPtr pixelData,
102 * @copydoc Dali::Texture::UploadSubPixelData()
104 bool UploadSubPixelData(PixelDataPtr pixelData,
105 uint32_t dataXOffset,
106 uint32_t dataYOffset,
117 * @copydoc Dali::Texture::GenerateMipmaps()
119 void GenerateMipmaps();
122 * @copydoc Dali::Texture::GetWidth()
124 uint32_t GetWidth() const;
127 * @copydoc Dali::Texture::GetHeight()
129 uint32_t GetHeight() const;
132 * @copydoc Dali::Texture::GetPixelFormat()
134 Pixel::Format GetPixelFormat() const;
137 * @copydoc Dali::Integration::GetTextureResourceId()
139 uint32_t GetResourceId() const;
142 * @copydoc Dali::Integration::GetTextureType()
144 Dali::TextureType::Type GetTextureType() const;
147 * @copydoc Dali::Integration::SetTextureSize()
149 void SetSize(const ImageDimensions& size);
152 * @copydoc Dali::Integration::SetTexturePixelFormat()
154 void SetPixelFormat(Pixel::Format format);
157 * @brief Determine if the texture is a native image
159 * @return true if the texture has been initialized with a native image
161 bool IsNative() const;
164 * @brief Apply any native texture code to the given fragment shader
166 * @param[in,out] shader The fragment shader
167 * @return true if the shader has been modified.
169 bool ApplyNativeFragmentShader(std::string& shader);
171 private: // implementation
174 * @param[in] type The type of the texture
175 * @param[in] format The format of the pixel data
176 * @param[in] size The size of the texture
178 Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size);
181 * Constructor from native image
182 * @param[in] nativeImageInterface The native image
184 Texture(NativeImageInterfacePtr nativeImageInterface);
187 * Constructor from resource id
188 * @param[in] type The type of the texture
189 * @param[in] resourceId The resouce id for texture upload manager using
191 Texture(TextureType::Type type, uint32_t resourceId);
194 * Second stage initialization of the Texture
200 * A reference counted object may only be deleted by calling Unreference()
204 private: // unimplemented methods
205 Texture(const Texture&);
206 Texture& operator=(const Texture&);
209 Internal::EventThreadServices& mEventThreadServices; ///<Used to send messages to the render thread via update thread
210 Internal::Render::TextureKey mTextureKey; ///<The Render::Texture associated to this texture
212 NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
213 ImageDimensions mSize; ///< Size of the texture
214 Dali::TextureType::Type mType; ///< Texture type (cached)
215 Pixel::Format mFormat; ///< Pixel format
217 uint32_t mResourceId;
219 bool mUseUploadedParameter : 1; ///< Whether ths texture size and format depend on uploaded image or not.
222 } // namespace Internal
224 // Helpers for public-api forwarding methods
225 inline Internal::Texture& GetImplementation(Dali::Texture& handle)
227 DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
229 BaseObject& object = handle.GetBaseObject();
231 return static_cast<Internal::Texture&>(object);
234 inline const Internal::Texture& GetImplementation(const Dali::Texture& handle)
236 DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
238 const BaseObject& object = handle.GetBaseObject();
240 return static_cast<const Internal::Texture&>(object);
245 #endif // DALI_INTERNAL_TEXTURE_H