Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnimVisualElementSurface.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnimVisualElementSurface.cpp
20  * @brief       This file contains implementation of VisualElementSurface class
21  *
22  * This file contains implementation VisualElementSurface class.
23  */
24
25 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FUiAnimVisualElementSurface.h>
28
29 #include "FUiAnim_VisualElementCanvas.h"
30 #include "FUiAnim_VisualElementSurfaceImpl.h"
31
32 using namespace std;
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
35
36
37 #define CHECK_NOT_CONSTRUCTED \
38         SysAssertf(__pVisualElementSurfaceImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
39
40 #define CHECK_CONSTRUCTED \
41         SysAssertf(__pVisualElementSurfaceImpl, "Not yet constructed! Construct() should be called before use.");
42
43 #define CHECK_PARAMETER_CONSTRUCTED(element) \
44         SysAssertf((element).__pVisualElementSurfaceImpl, "Not yet constructed! Construct() should be called before use.");
45
46 namespace Tizen { namespace Ui { namespace Animations
47 {
48
49 VisualElementSurface::VisualElementSurface(void)
50         : __pVisualElementSurfaceImpl(null)
51 {
52 }
53
54 VisualElementSurface::VisualElementSurface(const VisualElementSurface& rhs)
55         : __pVisualElementSurfaceImpl(null)
56 {
57         CHECK_PARAMETER_CONSTRUCTED(rhs);
58
59         __pVisualElementSurfaceImpl = rhs.__pVisualElementSurfaceImpl;
60         __pVisualElementSurfaceImpl->AddRef();
61 }
62
63 VisualElementSurface&
64 VisualElementSurface::operator =(const VisualElementSurface& rhs)
65 {
66         CHECK_PARAMETER_CONSTRUCTED(rhs);
67
68         if (&rhs != this)
69         {
70                 if (__pVisualElementSurfaceImpl != null)
71                 {
72                         __pVisualElementSurfaceImpl->Release();
73                 }
74                 __pVisualElementSurfaceImpl = rhs.__pVisualElementSurfaceImpl;
75                 __pVisualElementSurfaceImpl->AddRef();
76         }
77
78         return *this;
79 }
80
81 VisualElementSurface::~VisualElementSurface(void)
82 {
83         CHECK_CONSTRUCTED;
84
85         if (__pVisualElementSurfaceImpl->Release())
86         {
87                 __pVisualElementSurfaceImpl = null;
88         }
89 }
90
91 result
92 VisualElementSurface::Construct(const DisplayContext& displayContext, const Dimension& size)
93 {
94         CHECK_NOT_CONSTRUCTED;
95
96         SysTryReturnResult(NID_UI_ANIM, size.width >= 0 && size.height >= 0, E_OUT_OF_RANGE, "Can't create the canvas which size is less than zero.");
97
98         unique_ptr<_VisualElementSurfaceImpl> pImpl(_VisualElementSurfaceImpl::CreateInstanceN(displayContext, size));
99         result r = GetLastResult();
100         SysTryReturnResult(NID_UI_ANIM, pImpl, r, "Propagating.");
101
102         __pVisualElementSurfaceImpl = pImpl.release();
103
104         return E_SUCCESS;
105 }
106
107 result
108 VisualElementSurface::GetBufferInfo(BufferInfo& bufferInfo) const
109 {
110         CHECK_CONSTRUCTED;
111
112         SysTryReturnResult(NID_UI_ANIM, &bufferInfo != null, E_INVALID_STATE, "BufferInfo is not initialized.");
113
114         __pVisualElementSurfaceImpl->GetBufferInfo(bufferInfo);
115
116         return E_SUCCESS;
117 }
118
119 Dimension
120 VisualElementSurface::GetSize(void) const
121 {
122         CHECK_CONSTRUCTED;
123
124         return __pVisualElementSurfaceImpl->GetSize();
125 }
126
127 bool
128 VisualElementSurface::Equals(const Tizen::Base::Object& obj) const
129 {
130         CHECK_CONSTRUCTED;
131
132         return __pVisualElementSurfaceImpl->Equals(obj);
133 }
134
135 int
136 VisualElementSurface::GetHashCode(void) const
137 {
138         CHECK_CONSTRUCTED;
139
140         return __pVisualElementSurfaceImpl->GetHashCode();
141 }
142
143 }}}             // Tizen::Ui::Animations
144