2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 #include <dali/internal/event/images/frame-buffer-image-impl.h>
21 #include <dali/internal/event/common/thread-local-storage.h>
22 #include <dali/internal/event/resources/resource-client.h>
30 FrameBufferImage::~FrameBufferImage()
34 FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
35 : Image(Dali::Image::Immediate, releasePolicy)
38 , mPixelFormat(pixelFormat)
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())
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())
62 void FrameBufferImage::Connect()
66 if (mConnectionCount == 1)
68 // ticket was thrown away when related actors went offstage
71 ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
74 mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
75 mTicket->AddObserver(*this);
79 mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat);
80 mTicket->AddObserver(*this);
86 void FrameBufferImage::Disconnect()
93 DALI_ASSERT_DEBUG(mConnectionCount > 0);
95 if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused)
97 // release image memory when it's not visible anymore (decrease ref. count of texture)
98 mTicket->RemoveObserver(*this);
103 } // namespace Internal