[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / internal / event / images / frame-buffer-image-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/event/images/frame-buffer-image-impl.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/event/common/thread-local-storage.h>
22 #include <dali/internal/event/resources/resource-client.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 FrameBufferImage::~FrameBufferImage()
31 {
32 }
33
34 FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
35   : Image(Dali::Image::Immediate, releasePolicy)
36   , mWidth(width)
37   , mHeight(height)
38   , mPixelFormat(pixelFormat)
39 {}
40
41 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage )
42   : Image(Dali::Image::Immediate)
43   , mNativeImage(&nativeImage)
44   , mWidth(nativeImage.GetWidth())
45   , mHeight(nativeImage.GetHeight())
46   , mPixelFormat(nativeImage.GetPixelFormat())
47 {
48
49 }
50
51 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage, ReleasePolicy releasePolicy )
52   : Image(Dali::Image::Immediate, releasePolicy)
53   , mNativeImage(&nativeImage)
54   , mWidth(nativeImage.GetWidth())
55   , mHeight(nativeImage.GetHeight())
56   , mPixelFormat(nativeImage.GetPixelFormat())
57 {
58
59
60 }
61
62 void FrameBufferImage::Connect()
63 {
64   ++mConnectionCount;
65
66   if (mConnectionCount == 1)
67   {
68     // ticket was thrown away when related actors went offstage
69     if (!mTicket)
70     {
71       ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
72       if (mNativeImage)
73       {
74         mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
75         mTicket->AddObserver(*this);
76       }
77       else
78       {
79         mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat);
80         mTicket->AddObserver(*this);
81       }
82     }
83   }
84 }
85
86 void FrameBufferImage::Disconnect()
87 {
88   if(!mTicket)
89   {
90     return;
91   }
92
93   DALI_ASSERT_DEBUG(mConnectionCount > 0);
94   --mConnectionCount;
95   if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused)
96   {
97     // release image memory when it's not visible anymore (decrease ref. count of texture)
98     mTicket->RemoveObserver(*this);
99     mTicket.Reset();
100   }
101 }
102
103 } // namespace Internal
104
105 } // namespace Dali
106