Merge "(Partial Update) Mark as not rendered if the node is transparent or culled...
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-texture.h
1 #ifndef DALI_INTERNAL_RENDER_TEXTURE_H
2 #define DALI_INTERNAL_RENDER_TEXTURE_H
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
21 #include <cstdint> // uint16_t, uint32_t
22 #include <string>
23
24 // INTERNAL INCLUDES
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>
28
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>
35
36 namespace Dali
37 {
38 namespace Internal
39 {
40 namespace Render
41 {
42 struct Sampler;
43
44 class Texture
45 {
46 public:
47   using Type = Dali::TextureType::Type;
48
49   /**
50    * Constructor
51    * @param[in] type The type of the texture
52    * @param[in] format The format of the pixel data
53    * @param[in] size The size of the texture
54    */
55   Texture(Type type, Pixel::Format format, ImageDimensions size);
56
57   /**
58    * Constructor from native image
59    * @param[in] nativeImageInterface The native image
60    */
61   explicit Texture(NativeImageInterfacePtr nativeImageInterface);
62
63   /**
64    * Destructor
65    */
66   ~Texture();
67
68   /**
69    * Stores the graphics controller for use when required.
70    *
71    * @param[in] graphicsController The graphics controller to use
72    */
73   void Initialize(Graphics::Controller& graphicsController);
74
75   /**
76    * Create the texture without a buffer
77    * @param[in] usage How texture will be used
78    */
79   void Create(Graphics::TextureUsageFlags usage);
80
81   /**
82    * Create a texture with a buffer if non-null
83    * @param[in] usage How texture will be used
84    * @param[in] buffer Buffer to copy
85    */
86   void CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* buffer, uint32_t bufferSize);
87
88   /**
89    * Deletes the texture from the GPU
90    */
91   void Destroy();
92
93   /**
94    * Uploads data to the texture.
95    * @param[in] pixelData A pixel data object
96    * @param[in] params Upload parameters. See UploadParams
97    */
98   void Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params);
99
100   /**
101    * Auto generates mipmaps for the texture
102    */
103   void GenerateMipmaps();
104
105   /**
106    * Retrieve whether the texture has an alpha channel
107    * @return True if the texture has alpha channel, false otherwise
108    */
109   [[nodiscard]] bool HasAlphaChannel() const;
110
111   /**
112    * Get the graphics object associated with this texture
113    */
114   [[nodiscard]] Graphics::Texture* GetGraphicsObject() const;
115
116   /**
117    * Get the type of the texture
118    * @return Type of the texture
119    */
120   [[nodiscard]] Type GetType() const
121   {
122     return mType;
123   }
124
125   /**
126    * Check if the texture is a native image
127    * @return if the texture is a native image
128    */
129   [[nodiscard]] bool IsNativeImage() const
130   {
131     return static_cast<bool>(mNativeImage);
132   }
133
134 private:
135   /**
136    * Helper method to apply a sampler to the texture
137    * @param[in] sampler The sampler
138    */
139   void ApplySampler(Render::Sampler* sampler);
140
141 private:
142   Graphics::Controller*                  mGraphicsController;
143   Graphics::UniquePtr<Graphics::Texture> mGraphicsTexture;
144
145   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
146   Render::Sampler         mSampler;     ///< The current sampler state
147
148   Pixel::Format mPixelFormat;  ///< Pixel format of the texture
149   uint16_t      mWidth;        ///< Width of the texture
150   uint16_t      mHeight;       ///< Height of the texture
151   Type          mType : 3;     ///< Type of the texture
152   bool          mHasAlpha : 1; ///< Whether the format has an alpha channel
153 };
154
155 } // namespace Render
156
157 } // namespace Internal
158
159 } // namespace Dali
160
161 #endif //  DALI_INTERNAL_RENDER_TEXTURE_H