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 );
54 if( IsWithin(bitmapImage, xOffset, yOffset) )
56 ResourceId destId = GetResourceId();
57 ResourceId srcId = bitmapImage.GetResourceId();
61 mResourceClient.UploadBitmap( destId, srcId, xOffset, yOffset );
74 Atlas::Atlas( std::size_t width,
76 Pixel::Format pixelFormat )
77 : mResourceClient( ThreadLocalStorage::Get().GetResourceClient() ),
78 mPixelFormat( pixelFormat )
88 if( mConnectionCount == 1 )
94 void Atlas::Disconnect()
96 if( mConnectionCount )
100 if ( Dali::Image::UNUSED == mReleasePolicy &&
101 mConnectionCount == 0 )
108 bool Atlas::IsWithin( const BitmapImage& bitmapImage,
110 std::size_t yOffset )
114 if( mPixelFormat != bitmapImage.GetPixelFormat() )
116 DALI_LOG_ERROR( "Pixel format %d does not match Atlas format %d\n", bitmapImage.GetPixelFormat(), mPixelFormat );
120 const unsigned int width = bitmapImage.GetWidth();
121 const unsigned int height = bitmapImage.GetHeight();
123 if( xOffset < mWidth &&
125 xOffset+width <= mWidth &&
126 yOffset+height <= mHeight )
132 DALI_LOG_ERROR( "%dx%d image does not fit at offset %d,%d\n", width, height, xOffset, yOffset );
139 void Atlas::AllocateAtlas()
143 mTicket = mResourceClient.AllocateTexture( mWidth, mHeight, mPixelFormat );
147 void Atlas::ReleaseAtlas()
152 } // namespace Internal