Removing rendering backend
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-texture.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_H
3
4 /*
5  * Copyright (c) 2018 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 <string>
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
25 #include <dali/public-api/rendering/sampler.h>
26 #include <dali/public-api/rendering/texture.h>
27 #include <dali/graphics-api/graphics-api-accessor.h>
28 #include <dali/graphics-api/graphics-api-texture.h>
29 #include <dali/integration-api/graphics/graphics.h>
30 #include <dali/internal/common/message.h>
31 #include <dali/internal/event/rendering/texture-impl.h>
32 #include <dali/internal/update/rendering/scene-graph-sampler.h>
33
34 namespace Dali
35 {
36 namespace Internal
37 {
38 namespace SceneGraph
39 {
40
41 /**
42  * The SceneGraph::Texture object wraps the Graphics texture object, and is owned
43  *  by the UpdateManager. It is used by SceneGraphRenderer to set up RenderCommands.
44  */
45 class Texture
46 {
47 public:
48   typedef Dali::TextureType::Type Type;
49
50   /**
51    * Constructor
52    * @param[in] type The type of the texture
53    * @param[in] format The format of the pixel data
54    * @param[in] size The size of the texture
55    */
56   Texture( Type type, Pixel::Format format, ImageDimensions size );
57
58   /**
59    * Constructor from native image
60    * @param[in] nativeImageInterface The native image
61    */
62   Texture( NativeImageInterfacePtr nativeImageInterface );
63
64   /**
65    * Destructor
66    */
67   ~Texture();
68
69   /**
70    * Initialize the texture object with the Graphics API when added to UpdateManager
71    *
72    * @param[in] graphics The Graphics API
73    */
74   void Initialize( Integration::Graphics::Graphics& graphics );
75
76   /**
77    * Retrieve wheter the texture has an alpha channel
78    * @return True if the texture has alpha channel, false otherwise
79    */
80   bool HasAlphaChannel();
81
82   /**
83    * Get the type of the texture
84    * @return Type of the texture
85    */
86   Type GetType() const
87   {
88     return mType;
89   }
90
91   /**
92    * Check if the texture is a native image
93    * @return if the texture is a native image
94    */
95   bool IsNativeImage() const
96   {
97     return mNativeImage;
98   }
99
100   /**
101    * Get the Graphics object associated with this texture
102    * @return The graphics object.
103    */
104   const Graphics::API::Accessor<Graphics::API::Texture>& GetGfxObject() const;
105
106   /**
107    * Get the texture id associated with the graphics texture
108    */
109   uint32_t GetId()
110   {
111     return mId;
112   }
113
114 public: // From messages
115   /**
116    * Uploads data to Graphics
117    * @param[in] pixelData The pixel data object
118    * @param[in] params The parameters for the upload
119    */
120   void UploadTexture( PixelDataPtr pixelData, const Internal::Texture::UploadParams& params );
121
122   /**
123    * Generates mipmaps
124    */
125   void GenerateMipmaps();
126
127
128 private:
129   Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
130   Graphics::API::Accessor<Graphics::API::Texture> mGraphicsTexture; ///< Graphics texture
131
132   NativeImageInterfacePtr mNativeImage;      ///< Pointer to native image
133   SceneGraph::Sampler     mSampler;          ///< The current sampler state
134   uint32_t                mId;               ///< The Graphics texture handle
135   uint16_t                mWidth;            ///< Width of the texture
136   uint16_t                mHeight;           ///< Height of the texture
137   uint16_t                mMaxMipMapLevel;   ///< Maximum mipmap level
138   Type                    mType:2;           ///< Type of the texture
139   bool                    mHasAlpha : 1;     ///< Whether the format has an alpha channel
140   bool                    mIsCompressed : 1; ///< Whether the format is compressed
141 };
142
143
144 inline void UploadTextureMessage( EventThreadServices& eventThreadServices, SceneGraph::Texture& texture, PixelDataPtr pixelData, const Internal::Texture::UploadParams& params )
145 {
146   typedef MessageValue2< SceneGraph::Texture, PixelDataPtr, Internal::Texture::UploadParams > LocalType;
147
148   // Reserve some memory inside the message queue
149   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
150
151   // Construct message in the message queue memory; note that delete should not be called on the return value
152   new (slot) LocalType( &texture, &SceneGraph::Texture::UploadTexture, pixelData, params );
153 }
154
155 inline void GenerateMipmapsMessage( EventThreadServices& eventThreadServices, SceneGraph::Texture& texture )
156 {
157   typedef Message< SceneGraph::Texture > LocalType;
158
159   // Reserve some memory inside the message queue
160   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
161
162   // Construct message in the message queue memory; note that delete should not be called on the return value
163   new (slot) LocalType( &texture, &SceneGraph::Texture::GenerateMipmaps );
164 }
165
166 } // namespace SceneGraph
167
168 } // namespace Internal
169
170 } // namespace Dali
171
172
173 #endif //  DALI_INTERNAL_SCENE_GRAPH_TEXTURE_H