Merge "Change PixelData to use the handle/body pattern" into devel/master
[platform/core/uifw/dali-core.git] / dali / devel-api / images / atlas.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/devel-api/images/atlas.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/images/atlas-impl.h>
23 #include <dali/internal/event/images/buffer-image-impl.h>
24 #include <dali/internal/event/images/pixel-data-impl.h>
25
26 namespace Dali
27 {
28
29 Atlas Atlas::New( SizeType width,
30                   SizeType height,
31                   Pixel::Format pixelFormat,
32                   bool recoverContext )
33 {
34   DALI_ASSERT_ALWAYS( 0u != width  && "Invalid Atlas width requested" );
35   DALI_ASSERT_ALWAYS( 0u != height && "Invalid Atlas height requested" );
36
37   return Atlas( Internal::Atlas::New( width, height, pixelFormat, recoverContext ) );
38 }
39
40 Atlas::Atlas()
41 {
42 }
43
44 void Atlas::Clear( const Vector4& color  )
45 {
46   GetImplementation( *this ).Clear( color );
47 }
48
49 bool Atlas::Upload( BufferImage bufferImage,
50                     SizeType xOffset,
51                     SizeType yOffset )
52 {
53   return GetImplementation(*this).Upload( GetImplementation(bufferImage), xOffset, yOffset );
54 }
55
56 bool Atlas::Upload( const std::string& url,
57                     SizeType xOffset,
58                     SizeType yOffset )
59 {
60   return GetImplementation(*this).Upload( url, xOffset, yOffset );
61 }
62
63 bool Atlas::Upload( PixelData pixelData,
64                     SizeType xOffset,
65                     SizeType yOffset )
66 {
67   Internal::PixelData& internalPixelData = GetImplementation( pixelData );
68   return GetImplementation(*this).Upload( &internalPixelData, xOffset, yOffset );
69 }
70
71 Atlas Atlas::DownCast( BaseHandle handle )
72 {
73   return Atlas( dynamic_cast<Dali::Internal::Atlas*>(handle.GetObjectPtr()) );
74 }
75
76 Atlas::~Atlas()
77 {
78 }
79
80 Atlas::Atlas( const Atlas& handle )
81 : Image( handle )
82 {
83 }
84
85 Atlas& Atlas::operator=( const Atlas& rhs )
86 {
87   BaseHandle::operator=(rhs);
88   return *this;
89 }
90
91 Atlas::Atlas( Internal::Atlas* internal )
92 : Image( internal )
93 {
94 }
95
96 } // namespace Dali