API for eager GLTexture Creation in NativeImage
[platform/core/uifw/dali-core.git] / dali / internal / event / images / native-image-impl.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/internal/event/images/native-image-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/internal/event/resources/resource-ticket.h>
26 #include <dali/internal/event/common/thread-local-storage.h>
27 #include <dali/internal/event/resources/resource-client.h>
28 #include <dali/internal/event/common/stage-impl.h>
29
30 using namespace Dali::Integration;
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace
39 {
40 TypeRegistration mType( typeid(Dali::NativeImage), typeid(Dali::Image), NULL );
41 }
42
43 NativeImage::NativeImage()
44 : Image()
45 {
46 }
47
48 NativeImagePtr NativeImage::New( NativeImageInterface& resourceData )
49 {
50   NativeImagePtr image = new NativeImage;
51   image->Initialize();
52
53   ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
54
55   image->mWidth  = resourceData.GetWidth();
56   image->mHeight = resourceData.GetHeight();
57
58   const ResourceTicketPtr& ticket = resourceClient.AddNativeImage( resourceData );
59   DALI_ASSERT_DEBUG( dynamic_cast<ImageTicket*>( ticket.Get() ) && "Resource ticket not ImageTicket subclass for image resource.\n" );
60   image->mTicket = static_cast<ImageTicket*>(ticket.Get());
61   image->mTicket->AddObserver( *image );
62
63   return image;
64 }
65
66 NativeImage::~NativeImage()
67 {
68 }
69
70 void NativeImage::CreateGlTexture()
71 {
72   ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
73   resourceClient.CreateGlTexture( GetResourceId() );
74 }
75
76 } // namespace Internal
77
78 } // namespace Dali