Implemented Upload methods in Texture to upload data from PixelData objects
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / texture-impl.h
1 #ifndef DALI_INTERNAL_NEW_TEXTURE_H
2 #define DALI_INTERNAL_NEW_TEXTURE_H
3
4 /*
5  * Copyright (c) 2016 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/images/pixel.h>
26 #include <dali/devel-api/rendering/texture.h> // Dali::Internal::Render::Texture
27 #include <dali/internal/event/common/event-thread-services.h>
28 #include <dali/internal/event/images/pixel-data-impl.h>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 namespace Render
35 {
36 class NewTexture;
37 }
38
39 class NewTexture;
40 typedef IntrusivePtr<NewTexture> NewTexturePtr;
41
42 class NewTexture : public BaseObject
43 {
44 public:
45
46   /**
47    * @brief Structure used to pass parameters to the Upload method
48    */
49   struct UploadParams
50   {
51     unsigned int layer;    ///< Specifies the layer of a cube map or array texture
52     unsigned int mipmap;   ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
53     unsigned int xOffset;  ///< Specifies a texel offset in the x direction within the texture array.
54     unsigned int yOffset;  ///< Specifies a texel offset in the y direction within the texture array.
55     unsigned int width;    ///< Specifies the width of the texture subimage
56     unsigned int height;   ///< Specifies the height of the texture subimage.
57   };
58
59   /**
60    * @brief Create a new Texture.
61    *
62    * @param[in] type The type of the texture
63    * @param[in] format The format of the pixel data
64    * @param[in] width The width of the texture
65    * @param[in] height The height of the texture
66    * @return A smart-pointer to the newly allocated Texture.
67    */
68   static NewTexturePtr New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height);
69
70   /**
71    * @brief Creates a new Texture from a native image
72    * @param[in] nativeImageInterface The native image
73    * @return A smart-pointer to the newly allocated Texture.
74    */
75   static NewTexturePtr New( NativeImageInterface& nativeImageInterface );
76
77   /**
78    * @brief Get the texture render object
79    *
80    * @return the texture render object
81    */
82   Render::NewTexture* GetRenderObject() const;
83
84   /**
85    * @copydoc Dali::Texture::Upload()
86    */
87   void Upload( PixelDataPtr pixelData );
88
89   /**
90    * @copydoc Dali::Texture::Upload()
91    */
92   void Upload( PixelDataPtr pixelData,
93                unsigned int layer, unsigned int mipmap,
94                unsigned int xOffset, unsigned int yOffset,
95                unsigned int width, unsigned int height );
96
97   /**
98    * @copydoc Dali::Texture::GenerateMipmaps()
99    */
100   void GenerateMipmaps();
101
102   /**
103    * @copydoc Dali::Texture::GetWidth()
104    */
105   unsigned int GetWidth() const;
106
107   /**
108    * @copydoc Dali::Texture::GetHeight()
109    */
110   unsigned int GetHeight() const;
111
112
113 private: // implementation
114
115   /**
116    * Constructor
117    * @param[in] type The type of the texture
118    * @param[in] format The format of the pixel data
119    * @param[in] width The width of the texture
120    * @param[in] height The height of the texture
121    */
122   NewTexture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height );
123
124   /**
125    * Constructor from native image
126    * @param[in] nativeImageInterface The native image
127    */
128   NewTexture( NativeImageInterfacePtr nativeImageInterface );
129
130   /**
131    * Second stage initialization of the Texture
132    */
133   void Initialize();
134
135 protected:
136
137   /**
138    * A reference counted object may only be deleted by calling Unreference()
139    */
140   virtual ~NewTexture();
141
142 private: // unimplemented methods
143   NewTexture( const NewTexture& );
144   NewTexture& operator=( const NewTexture& );
145
146 private: // data
147
148   Internal::EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
149   Internal::Render::NewTexture* mRenderObject;            ///<The Render::Texture associated to this texture
150
151   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
152   Dali::TextureType::Type mType;      ///< Texture type (cached)
153   Pixel::Format mFormat;              ///< Pixel format
154   unsigned int mWidth;                ///< Width of the texture
155   unsigned int mHeight;               ///< Height of the texture
156 };
157
158 } // namespace Internal
159
160 // Helpers for public-api forwarding methods
161 inline Internal::NewTexture& GetImplementation(Dali::Texture& handle)
162 {
163   DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
164
165   BaseObject& object = handle.GetBaseObject();
166
167   return static_cast<Internal::NewTexture&>(object);
168 }
169
170 inline const Internal::NewTexture& GetImplementation(const Dali::Texture& handle)
171 {
172   DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
173
174   const BaseObject& object = handle.GetBaseObject();
175
176   return static_cast<const Internal::NewTexture&>(object);
177 }
178
179 } // namespace Dali
180
181 #endif // DALI_INTERNAL_TEXTURE_H