CanvasRenderer:: Add Picture class
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / ubuntu / picture-impl-ubuntu.cpp
1 /*
2  * Copyright (c) 2021 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/internal/canvas-renderer/ubuntu/picture-impl-ubuntu.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31 namespace // unnamed namespace
32 {
33 // Type Registration
34 Dali::BaseHandle Create()
35 {
36   return Dali::BaseHandle();
37 }
38
39 Dali::TypeRegistration type(typeid(Dali::CanvasRenderer::Picture), typeid(Dali::BaseHandle), Create);
40
41 } // unnamed namespace
42
43 PictureUbuntu* PictureUbuntu::New()
44 {
45   return new PictureUbuntu();
46 }
47
48 PictureUbuntu::PictureUbuntu()
49 #ifdef THORVG_SUPPORT
50 : mTvgPicture(nullptr)
51 #endif
52 {
53   Initialize();
54 }
55
56 PictureUbuntu::~PictureUbuntu()
57 {
58 }
59
60 void PictureUbuntu::Initialize()
61 {
62 #ifdef THORVG_SUPPORT
63   mTvgPicture = tvg::Picture::gen().release();
64   if(!mTvgPicture)
65   {
66     DALI_LOG_ERROR("Picture is null [%p]\n", this);
67   }
68
69   Drawable::Create();
70   Drawable::SetObject(static_cast<void*>(mTvgPicture));
71   Drawable::SetType(Drawable::Types::PICTURE);
72 #endif
73 }
74
75 bool PictureUbuntu::Load(const std::string& url)
76 {
77 #ifdef THORVG_SUPPORT
78   if(!Drawable::GetObject() || !mTvgPicture)
79   {
80     DALI_LOG_ERROR("Picture is null [%p]\n", this);
81     return false;
82   }
83   if(url.empty())
84   {
85     DALI_LOG_ERROR("Url is empty [%p]\n", this);
86     return false;
87   }
88
89   if(mTvgPicture->load(url.c_str()) != tvg::Result::Success)
90   {
91     DALI_LOG_ERROR("Load() fail. (%s)\n", url.c_str());
92     return false;
93   }
94
95   Drawable::SetChanged(true);
96   return true;
97 #else
98   return false;
99 #endif
100 }
101
102 bool PictureUbuntu::SetSize(Vector2 size)
103 {
104 #ifdef THORVG_SUPPORT
105   if(!Drawable::GetObject() || !mTvgPicture)
106   {
107     DALI_LOG_ERROR("Picture is null [%p]\n", this);
108     return false;
109   }
110   if(mTvgPicture->size(size.width, size.height) != tvg::Result::Success)
111   {
112     DALI_LOG_ERROR("SetSize() fail.\n");
113     return false;
114   }
115   Drawable::SetChanged(true);
116
117   return true;
118 #else
119   return false;
120 #endif
121 }
122
123 Vector2 PictureUbuntu::GetSize() const
124 {
125 #ifdef THORVG_SUPPORT
126   if(!Drawable::GetObject() || !mTvgPicture)
127   {
128     DALI_LOG_ERROR("Picture is null [%p]\n", this);
129     return Vector2::ZERO;
130   }
131
132   auto width  = 0.0f;
133   auto height = 0.0f;
134
135   if(mTvgPicture->size(&width, &height) != tvg::Result::Success)
136   {
137     DALI_LOG_ERROR("GetSize() fail.\n");
138     return Vector2::ZERO;
139   }
140
141   return Vector2(width, height);
142 #else
143   return Vector2::ZERO;
144 #endif
145 }
146
147 } // namespace Adaptor
148
149 } // namespace Internal
150
151 } // namespace Dali