1 #ifndef DALI_INTERNAL_NEW_TEXTURE_H
2 #define DALI_INTERNAL_NEW_TEXTURE_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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/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>
40 typedef IntrusivePtr<Texture> TexturePtr;
42 class Texture : public BaseObject
47 * @brief Structure used to pass parameters to the Upload method
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.
60 * @brief Create a new Texture.
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.
68 static TexturePtr New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height);
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.
75 static TexturePtr New( NativeImageInterface& nativeImageInterface );
78 * @brief Get the texture render object
80 * @return the texture render object
82 Render::Texture* GetRenderObject() const;
85 * @copydoc Dali::Texture::Upload()
87 bool Upload( PixelDataPtr pixelData );
90 * @copydoc Dali::Texture::Upload()
92 bool Upload( PixelDataPtr pixelData,
93 unsigned int layer, unsigned int mipmap,
94 unsigned int xOffset, unsigned int yOffset,
95 unsigned int width, unsigned int height );
98 * @copydoc Dali::Texture::GenerateMipmaps()
100 void GenerateMipmaps();
103 * @copydoc Dali::Texture::GetWidth()
105 unsigned int GetWidth() const;
108 * @copydoc Dali::Texture::GetHeight()
110 unsigned int GetHeight() const;
112 private: // implementation
116 * @param[in] type The type of the texture
117 * @param[in] format The format of the pixel data
118 * @param[in] width The width of the texture
119 * @param[in] height The height of the texture
121 Texture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height );
124 * Constructor from native image
125 * @param[in] nativeImageInterface The native image
127 Texture( NativeImageInterfacePtr nativeImageInterface );
130 * Second stage initialization of the Texture
137 * A reference counted object may only be deleted by calling Unreference()
141 private: // unimplemented methods
142 Texture( const Texture& );
143 Texture& operator=( const Texture& );
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
150 NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
151 Dali::TextureType::Type mType; ///< Texture type (cached)
152 Pixel::Format mFormat; ///< Pixel format
153 unsigned int mWidth; ///< Width of the texture
154 unsigned int mHeight; ///< Height of the texture
157 } // namespace Internal
159 // Helpers for public-api forwarding methods
160 inline Internal::Texture& GetImplementation(Dali::Texture& handle)
162 DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
164 BaseObject& object = handle.GetBaseObject();
166 return static_cast<Internal::Texture&>(object);
169 inline const Internal::Texture& GetImplementation(const Dali::Texture& handle)
171 DALI_ASSERT_ALWAYS(handle && "Texture handle is empty");
173 const BaseObject& object = handle.GetBaseObject();
175 return static_cast<const Internal::Texture&>(object);
180 #endif // DALI_INTERNAL_TEXTURE_H