Merge "DALi Version 1.1.37" into devel/master
[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
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Render
34 {
35 class NewTexture;
36 }
37
38 class NewTexture;
39 typedef IntrusivePtr<NewTexture> NewTexturePtr;
40
41 class NewTexture : public BaseObject
42 {
43 public:
44
45   /**
46    * @brief Create a new Texture.
47    *
48    * @param[in] type The type of the texture
49    * @param[in] format The format of the pixel data
50    * @param[in] width The width of the texture
51    * @param[in] height The height of the texture
52    * @return A smart-pointer to the newly allocated Texture.
53    */
54   static NewTexturePtr New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height);
55
56   /**
57    * @brief Get the texture render object
58    *
59    * @return the texture render object
60    */
61   Render::NewTexture* GetRenderObject() const;
62
63   /**
64    * @copydoc Dali::Texture::Upload()
65    */
66   void Upload( Vector<unsigned char>& buffer, const TextureUploadParams& params );
67
68   /**
69    * @copydoc Dali::Texture::GenerateMipmaps()
70    */
71   void GenerateMipmaps();
72
73   /**
74    * @copydoc Dali::Texture::GetWidth()
75    */
76   unsigned int GetWidth() const;
77
78   /**
79    * @copydoc Dali::Texture::GetHeight()
80    */
81   unsigned int GetHeight() const;
82
83
84 private: // implementation
85
86   /**
87    * Constructor
88    */
89   NewTexture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height );
90
91   /**
92    * Second stage initialization of the Texture
93    */
94   void Initialize();
95
96 protected:
97
98   /**
99    * A reference counted object may only be deleted by calling Unreference()
100    */
101   virtual ~NewTexture();
102
103 private: // unimplemented methods
104   NewTexture( const NewTexture& );
105   NewTexture& operator=( const NewTexture& );
106
107 private: // data
108
109   Internal::EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
110   Internal::Render::NewTexture* mRenderObject;            ///<The Render::Texture associated to this texture
111
112   Dali::TextureType::Type mType;      ///< Texture type (cached)
113   Pixel::Format mFormat;              ///< Pixel format
114   unsigned int mWidth;                ///< Width of the texture
115   unsigned int mHeight;               ///< Height of the texture
116 };
117
118 } // namespace Internal
119
120 // Helpers for public-api forwarding methods
121 inline Internal::NewTexture& GetImplementation(Dali::Texture& handle)
122 {
123   DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
124
125   BaseObject& object = handle.GetBaseObject();
126
127   return static_cast<Internal::NewTexture&>(object);
128 }
129
130 inline const Internal::NewTexture& GetImplementation(const Dali::Texture& handle)
131 {
132   DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
133
134   const BaseObject& object = handle.GetBaseObject();
135
136   return static_cast<const Internal::NewTexture&>(object);
137 }
138
139 } // namespace Dali
140
141 #endif // DALI_INTERNAL_TEXTURE_H