1 #ifndef __DALI_INTERNAL_ATLAS_H__
2 #define __DALI_INTERNAL_ATLAS_H__
5 * Copyright (c) 2015 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-vector.h>
23 #include <dali/devel-api/images/atlas.h>
24 #include <dali/internal/event/images/context-recovery-interface.h>
25 #include <dali/internal/event/images/image-impl.h>
26 #include <dali/internal/event/images/buffer-image-impl.h>
36 typedef Dali::Atlas::SizeType SizeType;
39 * Internal class for Dali::Atlas
41 class Atlas : public Image, public ContextRecoveryInterface
46 * @brief Create a new Atlas.
48 * @pre width & height are greater than zero.
49 * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
50 * @param [in] width The atlas width in pixels.
51 * @param [in] height The atlas height in pixels.
52 * @param [in] pixelFormat The pixel format.
53 * @param [in] recoverContext Whether re-uploading the resource images automatically when regaining the context
54 * @return A pointer to a new Atlas.
56 static Atlas* New( SizeType width,
58 Pixel::Format pixelFormat,
62 * @copydoc Dali::Atlas::Clear
64 void Clear( const Vector4& color );
67 * @copydoc Dali::Atlas::Upload( const BufferImage&, unsigned int, unsigned int )
69 bool Upload( BufferImage& bufferImage,
74 * @copydoc Dali::Atlas::Upload( const std::string&, unsigned int, unsigned int )
76 bool Upload( const std::string& url,
81 * @copydoc ContextRecoveryInterface::RecoverFromContextLoss
83 virtual void RecoverFromContextLoss();
88 * @brief Protected constructor.
90 * @pre width & height are greater than zero.
91 * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
92 * @param [in] width The atlas width in pixels.
93 * @param [in] height The atlas height in pixels.
94 * @param [in] pixelFormat The pixel format.
95 * @param [in] recoverContext Whether re-uploading the resource images automatically when regaining the context
97 Atlas( SizeType width,
99 Pixel::Format pixelFormat,
100 bool recoverContext);
103 * A reference counted object may only be deleted by calling Unreference()
108 * @copydoc Dali::Internal::Image::Connect
110 virtual void Connect();
113 * @copydoc Dali::Internal::Image::Disconnect
115 virtual void Disconnect();
120 * Helper for Upload methods
121 * @return True if the bitmap has the same pixel format and its size fits within the atlas at the specified offset
123 bool Compatible( Pixel::Format pixelFormat,
127 * Helper to create the Atlas resource
129 void AllocateAtlas();
132 * Helper to release the Atlas resource
137 * Upload a bitmap with the given color to clear the background.
139 void ClearBackground( const Vector4& color );
142 * Clear all the current tiles and resources of the atlas
147 * Load the bitmap data from the url
149 Integration::BitmapPtr LoadBitmap( const std::string& url );
154 * Record of the url resource in the Atlas.
158 Tile( SizeType xOffset, SizeType yOffset, const std::string& url )
159 : xOffset( xOffset ), yOffset( yOffset ), url(url)
164 SizeType xOffset; ///< Offset in the x direction within the atlas
165 SizeType yOffset; ///< Offset in the y direction within the atlas
166 std::string url; ///< The URL of the resource image file to use
169 Tile(const Tile& rhs); ///< not defined
170 Tile& operator=(const Tile& rhs); ///< not defined
175 ResourceClient& mResourceClient;
176 ImageFactory& mImageFactory;
177 Vector4 mClearColor; ///< The background clear color
178 Vector<Tile*> mTiles; ///< The url resources, which would recover automatically when regaining context
179 Pixel::Format mPixelFormat; ///< The pixel format (rgba 32 bit by default)
180 bool mClear:1; ///< Clear the backgound or not
181 bool mRecoverContext:1; ///< Re-upload the url resources or not when regaining context
184 } // namespace Internal
187 * Helper methods for public API.
189 inline Internal::Atlas& GetImplementation(Dali::Atlas& image)
191 DALI_ASSERT_ALWAYS( image && "Atlas handle is empty" );
193 BaseObject& handle = image.GetBaseObject();
195 return static_cast<Internal::Atlas&>(handle);
198 inline const Internal::Atlas& GetImplementation(const Dali::Atlas& image)
200 DALI_ASSERT_ALWAYS( image && "Atlas handle is empty" );
202 const BaseObject& handle = image.GetBaseObject();
204 return static_cast<const Internal::Atlas&>(handle);
209 #endif // __DALI_INTERNAL_ATLAS_H__