2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/images/atlas-impl.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/internal/event/common/thread-local-storage.h>
24 #include <dali/internal/event/images/bitmap-image-impl.h>
25 #include <dali/internal/event/resources/resource-client.h>
26 #include <dali/integration-api/bitmap.h>
36 TypeRegistration mType( typeid( Dali::Atlas ), typeid( Dali::Image ), NULL );
39 Atlas* Atlas::New( std::size_t width,
41 Pixel::Format pixelFormat )
43 return new Atlas( width, height, pixelFormat );
46 bool Atlas::Upload( const BitmapImage& bitmapImage,
50 bool uploadSuccess( false );
52 if( IsWithin(bitmapImage, xOffset, yOffset) )
54 ResourceId destId = GetResourceId();
55 ResourceId srcId = bitmapImage.GetResourceId();
59 mResourceClient.UploadBitmap( destId, srcId, xOffset, yOffset );
72 Atlas::Atlas( std::size_t width,
74 Pixel::Format pixelFormat )
75 : mResourceClient( ThreadLocalStorage::Get().GetResourceClient() ),
76 mPixelFormat( pixelFormat )
81 if( Dali::Image::Immediate == mLoadPolicy )
91 if( Dali::Image::OnDemand == mLoadPolicy &&
92 mConnectionCount == 1 )
98 void Atlas::Disconnect()
100 if( mConnectionCount )
104 if ( Dali::Image::Unused == mReleasePolicy &&
105 mConnectionCount == 0 )
112 bool Atlas::IsWithin( const BitmapImage& bitmapImage,
114 std::size_t yOffset )
118 if( mPixelFormat != bitmapImage.GetPixelFormat() )
120 DALI_LOG_ERROR( "Pixel format %d does not match Atlas format %d\n", bitmapImage.GetPixelFormat(), mPixelFormat );
124 const unsigned int width = bitmapImage.GetWidth();
125 const unsigned int height = bitmapImage.GetHeight();
127 if( xOffset < mWidth &&
129 xOffset+width <= mWidth &&
130 yOffset+height <= mHeight )
136 DALI_LOG_ERROR( "%dx%d image does not fit at offset %d,%d\n", width, height, xOffset, yOffset );
143 void Atlas::AllocateAtlas()
147 mTicket = mResourceClient.AllocateTexture( mWidth, mHeight, mPixelFormat );
151 void Atlas::ReleaseAtlas()
156 } // namespace Internal