[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / common / image-resource-loader.h
1 #ifndef DALI_SCENE3D_IMAGE_RESOURCE_LOADER_H
2 #define DALI_SCENE3D_IMAGE_RESOURCE_LOADER_H
3
4 /*
5  * Copyright (c) 2024 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 INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/images/image-operations.h>
24 #include <dali/public-api/images/pixel-data.h>
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/rendering/texture.h>
27
28 // INTERNAL INCLUDES
29
30 namespace Dali
31 {
32 namespace Scene3D
33 {
34 namespace Internal
35 {
36 /**
37  * The namespace to load the images and cache raw PixelData.
38  * The cached resources will be reused when the same input parameter is loaded multiple times.
39  * @note This class can be called from worker threads.
40  */
41 namespace ImageResourceLoader
42 {
43 // Called by main thread.
44 /**
45  * @brief Get cached texture handle filled as white with RGB888 format.
46  * @return A Texture object containing the white RGB888 color.
47  */
48 Dali::Texture GetEmptyTextureWhiteRGB();
49
50 /**
51  * @brief Get cached cube texture handle filled as white with RGB888 format at 6 faces.
52  * @return A Texture object containing the white RGB888 color at 6 faces.
53  */
54 Dali::Texture GetEmptyCubeTextureWhiteRGB();
55
56 /**
57  * @brief Get cached texture handle, or create new texture and upload.
58  * @param[in] pixelData The PixelData of image to upload
59  * @param[in] mipmapRequired True if this texture need to generate mipmap
60  * @return A Texture object containing the pixelData, or an invalid object on failure
61  */
62 Dali::Texture GetCachedTexture(Dali::PixelData pixelData, bool mipmapRequired);
63
64 /**
65  * @brief Request to remove unused Texture and PixelData. We can choose the collect garbages incrementally or fully.
66  *
67  * @param[in] fullCollect True if we want to collect whole garbages. Default is false.
68  */
69 void RequestGarbageCollect(bool fullCollect = false);
70
71 /**
72  * @brief Let we ensure to create a ResourceLoader cache handler.
73  */
74 void EnsureResourceLoaderCreated();
75
76 // Can be called by worker thread.
77 /**
78  * @brief Get cached pixelData handle filled as white with RGB888 format.
79  * @return A PixelData object containing the white RGB888 color.
80  */
81 Dali::PixelData GetEmptyPixelDataWhiteRGB();
82
83 /**
84  * @brief Get cached pixelData handle filled as white with RGBA8888 format.
85  * @return A PixelData object containing the white RGBA8888 color.
86  */
87 Dali::PixelData GetEmptyPixelDataWhiteRGBA();
88
89 /**
90  * @brief Get cached pixelData handle that will be used for Z-Axis with RGB8888 format.
91  * @return A PixelData object containing the Z-Axis RGB8888 color.
92  */
93 Dali::PixelData GetEmptyPixelDataZAxisRGB();
94
95 /**
96  * @brief Get cached pixelData handle that will be used for Z-Axis and 1.0 alpha with RGBA8888 format.
97  * @return A PixelData object containing the Z-Axis and 1.0 alpha RGBA8888 color.
98  */
99 Dali::PixelData GetEmptyPixelDataZAxisAndAlphaRGBA();
100
101 /**
102  * @brief Get cached image, or loads an image synchronously.
103  * @note If cache handler is not created yet, or destroyed due to app terminated, it will load image synchronously without cache.
104  * @param[in] url The URL of the image file to load
105  * @return A PixelData object containing the image, or an invalid object on failure
106  */
107 Dali::PixelData GetCachedPixelData(const std::string& url);
108
109 /**
110  * @brief Get cached image, or loads an image synchronously by specifying the target dimensions and options.
111  * @note If cache handler is not created yet, or destroyed due to app terminated, it will load image synchronously without cache.
112  * @param[in] url The URL of the image file to load
113  * @param[in] dimensions The width and height to fit the loaded image to
114  * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
115  * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
116  * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
117  * @return A PixelData object containing the image, or an invalid object on failure
118  */
119 Dali::PixelData GetCachedPixelData(const std::string& url,
120                                    ImageDimensions    dimensions,
121                                    FittingMode::Type  fittingMode,
122                                    SamplingMode::Type samplingMode,
123                                    bool               orientationCorrection);
124 } // namespace ImageResourceLoader
125
126 } // namespace Internal
127
128 } // namespace Scene3D
129
130 } // namespace Dali
131
132 #endif // DALI_SCENE3D_MODEL_CACHE_MANAGER_H