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