Merge "Added travis.yml for auto-building patches" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / images / image-impl.cpp
1 /*
2  * Copyright (c) 2014 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/event/images/image-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/type-registry.h>
27
28 #include <dali/integration-api/debug.h>
29 #include <dali/internal/event/resources/resource-ticket.h>
30 #include <dali/internal/event/common/thread-local-storage.h>
31 #include <dali/internal/event/common/stage-impl.h>
32
33 using namespace Dali::Integration;
34
35 namespace Dali
36 {
37
38 namespace Internal
39 {
40
41 namespace
42 {
43
44 // Signals
45
46 const char* const SIGNAL_IMAGE_UPLOADED = "uploaded";
47
48 TypeRegistration mType( typeid( Dali::Image ), typeid( Dali::BaseHandle ), NULL );
49
50 Dali::SignalConnectorType signalConnector1( mType, SIGNAL_IMAGE_UPLOADED, &Image::DoConnectSignal );
51
52 }
53
54 bool Image::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
55 {
56   bool connected( true );
57   DALI_ASSERT_DEBUG( dynamic_cast<Image*>( object ) && "Resource ticket not ImageTicket subclass for image resource.\n" );
58   Image* image = static_cast<Image*>(object);
59
60   if( 0 == strcmp( signalName.c_str(), SIGNAL_IMAGE_UPLOADED ) )
61   {
62     image->UploadedSignal().Connect( tracker, functor );
63   }
64   else
65   {
66     // signalName does not match any signal
67     connected = false;
68   }
69
70   return connected;
71 }
72
73 ResourceId Image::GetResourceId() const
74 {
75   ResourceId ret = mTicket ? mTicket->GetId() : 0;
76
77   return ret;
78 }
79
80 void Image::ResourceLoadingFailed(const ResourceTicket& ticket)
81 {
82   // do nothing
83 }
84
85 void Image::ResourceLoadingSucceeded(const ResourceTicket& ticket)
86 {
87   // do nothing
88 }
89
90 void Image::ResourceUploaded(const ResourceTicket& ticket)
91 {
92   mUploaded.Emit( Dali::Image( this ) );
93 }
94
95 unsigned int Image::GetWidth() const
96 {
97   return mWidth;
98 }
99
100 unsigned int Image::GetHeight() const
101 {
102   return mHeight;
103 }
104
105 Vector2 Image::GetNaturalSize() const
106 {
107   return Vector2( mWidth, mHeight );
108 }
109
110 Image::Image()
111 : mTexture(),
112   mWidth( 0 ),
113   mHeight( 0 ),
114   mConnectionCount( 0 )
115 {
116 }
117
118 Image::~Image()
119 {
120   if( mTicket )
121   {
122     mTicket->RemoveObserver( *this );
123     mTicket.Reset();
124   }
125
126   if( Stage::IsInstalled() )
127   {
128     UnregisterObject();
129   }
130 }
131
132 void Image::Initialize()
133 {
134   RegisterObject();
135 }
136
137 } // namespace Internal
138
139 } // namespace Dali