1 #ifndef DALI_INTERNAL_RENDER_TEXTURE_H
2 #define DALI_INTERNAL_RENDER_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.
21 #include <cstdint> // uint16_t, uint32_t
25 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
26 #include <dali/public-api/rendering/sampler.h>
27 #include <dali/public-api/rendering/texture.h>
29 #include <dali/graphics-api/graphics-controller.h>
30 #include <dali/graphics-api/graphics-texture-create-info.h>
31 #include <dali/graphics-api/graphics-texture.h>
32 #include <dali/graphics-api/graphics-types.h>
33 #include <dali/internal/event/rendering/texture-impl.h>
34 #include <dali/internal/render/renderers/render-sampler.h>
47 using Type = Dali::TextureType::Type;
50 * Factory method to return a new texture accessed by key.
52 static TextureKey NewKey(Type type, Pixel::Format format, ImageDimensions size);
55 * Factory method to return a new texture accessed by key.
57 static TextureKey NewKey(NativeImageInterfacePtr nativeImageInterface);
61 * @param[in] type The type of the texture
62 * @param[in] format The format of the pixel data
63 * @param[in] size The size of the texture
65 Texture(Type type, Pixel::Format format, ImageDimensions size);
68 * Constructor from native image
69 * @param[in] nativeImageInterface The native image
71 explicit Texture(NativeImageInterfacePtr nativeImageInterface);
79 * Deletes the texture from it's global memory pool
81 void operator delete(void* ptr);
83 static Texture* Get(TextureKey::KeyType);
86 * Get the key of the given renderer in the associated memory pool.
87 * @param[in] renderer the given renderer
88 * @return The key in the associated memory pool.
90 static TextureKey GetKey(const Render::Texture& renderer);
93 * Get the key of the given renderer in the associated memory pool.
94 * @param[in] renderer the given renderer
95 * @return The key in the associated memory pool, or -1 if not
98 static TextureKey GetKey(Render::Texture* renderer);
101 * Stores the graphics controller for use when required.
103 * @param[in] graphicsController The graphics controller to use
105 void Initialize(Graphics::Controller& graphicsController);
108 * Create the texture without a buffer
109 * @param[in] usage How texture will be used
111 void Create(Graphics::TextureUsageFlags usage);
114 * Deletes the texture from the GPU
119 * Uploads data to the texture.
120 * @param[in] pixelData A pixel data object
121 * @param[in] params Upload parameters. See UploadParams
123 void Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params);
126 * Auto generates mipmaps for the texture
128 void GenerateMipmaps();
131 * Retrieve whether the texture has an alpha channel
132 * @return True if the texture has alpha channel, false otherwise
134 [[nodiscard]] bool HasAlphaChannel() const;
137 * Get the graphics object associated with this texture
139 [[nodiscard]] Graphics::Texture* GetGraphicsObject() const;
142 * Get the type of the texture
143 * @return Type of the texture
145 [[nodiscard]] Type GetType() const
151 * Check if the texture is a native image
152 * @return if the texture is a native image
154 [[nodiscard]] bool IsNativeImage() const
156 return static_cast<bool>(mNativeImage);
160 * Return the pixel format of the texture
161 * @return The pixel format of the texture data.
163 Pixel::Format GetPixelFormat() const
169 * Return the width of the texture
170 * @return The width of the texture
172 uint16_t GetWidth() const
178 * Return the height of the texture
179 * @return The height of the texture
181 uint32_t GetHeight() const
187 * Called from RenderManager to notify the texture that current rendering pass has finished.
189 void OnRenderFinished();
192 * Set the updated flag.
193 * @param[in] updated The updated flag
195 void SetUpdated(bool updated)
201 * Check if the texture is updated
202 * @return True if the texture is updated
204 [[nodiscard]] bool Updated()
206 if(mUpdated || (mNativeImage && mNativeImage->SourceChanged()))
214 * Get the updated area
215 * @return The updated area if the texture is updated, otherwise an empty area
216 * @note The origin of the area is the top-left corner of the texture.
218 Rect<uint16_t> GetUpdatedArea();
222 * Helper method to apply a sampler to the texture
223 * @param[in] sampler The sampler
225 void ApplySampler(Render::Sampler* sampler);
228 * Create the texture without a buffer
229 * @param[in] usage How texture will be used
230 * @param[in] allocationPolicy Policy of texture allocation
232 void Create(Graphics::TextureUsageFlags usage, Graphics::TextureAllocationPolicy allocationPolicy);
235 * Create a texture with a buffer if non-null
236 * @param[in] usage How texture will be used
237 * @param[in] allocationPolicy Policy of texture allocation
238 * @param[in] buffer Buffer to copy
239 * @param[in] bufferSize Size of buffer to copy
241 void CreateWithData(Graphics::TextureUsageFlags usage, Graphics::TextureAllocationPolicy allocationPolicy, uint8_t* buffer, uint32_t bufferSize);
244 Graphics::Controller* mGraphicsController;
245 Graphics::UniquePtr<Graphics::Texture> mGraphicsTexture;
247 NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
248 Render::Sampler mSampler; ///< The current sampler state
250 Rect<uint16_t> mUpdatedArea{}; ///< Updated area of the texture
252 Pixel::Format mPixelFormat; ///< Pixel format of the texture
253 uint16_t mWidth; ///< Width of the texture
254 uint16_t mHeight; ///< Height of the texture
256 Type mType : 3; ///< Type of the texture
257 bool mHasAlpha : 1; ///< Whether the format has an alpha channel
258 bool mUpdated : 1; ///< Whether the texture is updated
260 bool mUseUploadedParameter : 1; ///< Whether ths texture size and format depend on uploaded image or not.
263 } // namespace Render
265 } // namespace Internal
269 #endif // DALI_INTERNAL_RENDER_TEXTURE_H