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&, uint32_t, uint32_t )
69 bool Upload( BufferImage& bufferImage,
74 * @copydoc Dali::Atlas::Upload( const std::string&, uint32_t, uint32_t )
76 bool Upload( const std::string& url,
81 * @copydoc Dali::Atlas::Upload( Dali::PixelData, uint32_t, uint32_t )
83 bool Upload( PixelDataPtr pixelData,
88 * @copydoc ContextRecoveryInterface::RecoverFromContextLoss
90 virtual void RecoverFromContextLoss();
95 * @brief Protected constructor.
97 * @pre width & height are greater than zero.
98 * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
99 * @param [in] width The atlas width in pixels.
100 * @param [in] height The atlas height in pixels.
101 * @param [in] pixelFormat The pixel format.
102 * @param [in] recoverContext Whether re-uploading the resource images automatically when regaining the context
104 Atlas( SizeType width,
106 Pixel::Format pixelFormat,
107 bool recoverContext);
110 * A reference counted object may only be deleted by calling Unreference()
115 * @copydoc Dali::Internal::Image::Connect
117 virtual void Connect();
120 * @copydoc Dali::Internal::Image::Disconnect
122 virtual void Disconnect();
127 * Helper for Upload methods
128 * @return True if the size of the bitmap fits within the atlas at the specified offset
130 bool IsInside( SizeType x, SizeType y );
133 * Helper to create the Atlas resource
135 void AllocateAtlas();
138 * Helper to release the Atlas resource
143 * Upload a bitmap with the given color to clear the background.
145 void ClearBackground( const Vector4& color );
148 * Clear all the current tiles and resources of the atlas
153 * Load the bitmap data from the url
155 Integration::BitmapPtr LoadBitmap( const std::string& url );
160 * Record of the url resource in the Atlas.
164 Tile( SizeType xOffset, SizeType yOffset, const std::string& url )
165 : xOffset( xOffset ), yOffset( yOffset ), url(url)
170 SizeType xOffset; ///< Offset in the x direction within the atlas
171 SizeType yOffset; ///< Offset in the y direction within the atlas
172 std::string url; ///< The URL of the resource image file to use
175 Tile(const Tile& rhs); ///< not defined
176 Tile& operator=(const Tile& rhs); ///< not defined
181 ResourceClient& mResourceClient;
182 ImageFactory& mImageFactory;
183 Vector4 mClearColor; ///< The background clear color
184 Vector<Tile*> mTiles; ///< The url resources, which would recover automatically when regaining context
185 Pixel::Format mPixelFormat; ///< The pixel format (rgba 32 bit by default)
186 bool mClear:1; ///< Clear the backgound or not
187 bool mRecoverContext:1; ///< Re-upload the url resources or not when regaining context
190 } // namespace Internal
193 * Helper methods for public API.
195 inline Internal::Atlas& GetImplementation(Dali::Atlas& image)
197 DALI_ASSERT_ALWAYS( image && "Atlas handle is empty" );
199 BaseObject& handle = image.GetBaseObject();
201 return static_cast<Internal::Atlas&>(handle);
204 inline const Internal::Atlas& GetImplementation(const Dali::Atlas& image)
206 DALI_ASSERT_ALWAYS( image && "Atlas handle is empty" );
208 const BaseObject& handle = image.GetBaseObject();
210 return static_cast<const Internal::Atlas&>(handle);
215 #endif // __DALI_INTERNAL_ATLAS_H__