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 FrameBufferImagePtr FrameBufferImage::New(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
36 FrameBufferImagePtr image = new FrameBufferImage(width, height, pixelFormat, releasePolicy);
41 FrameBufferImagePtr FrameBufferImage::New( NativeImage& nativeImage )
43 FrameBufferImagePtr image = new FrameBufferImage(nativeImage);
48 FrameBufferImagePtr FrameBufferImage::New( NativeImage& nativeImage, ReleasePolicy releasePolicy )
50 FrameBufferImagePtr image = new FrameBufferImage(nativeImage, releasePolicy);
55 FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
56 : Image(Dali::Image::Immediate, releasePolicy),
57 mPixelFormat(pixelFormat)
64 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage )
65 : Image(Dali::Image::Immediate),
66 mNativeImage(&nativeImage),
67 mPixelFormat(nativeImage.GetPixelFormat())
69 mWidth = nativeImage.GetWidth();
70 mHeight = nativeImage.GetHeight();
74 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage, ReleasePolicy releasePolicy )
75 : Image(Dali::Image::Immediate, releasePolicy),
76 mNativeImage(&nativeImage),
77 mPixelFormat(nativeImage.GetPixelFormat())
79 mWidth = nativeImage.GetWidth();
80 mHeight = nativeImage.GetHeight();
83 void FrameBufferImage::Connect()
87 if (mConnectionCount == 1)
89 // ticket was thrown away when related actors went offstage
92 ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
95 mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
96 mTicket->AddObserver(*this);
100 mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat);
101 mTicket->AddObserver(*this);
107 void FrameBufferImage::Disconnect()
114 DALI_ASSERT_DEBUG(mConnectionCount > 0);
116 if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused)
118 // release image memory when it's not visible anymore (decrease ref. count of texture)
119 mTicket->RemoveObserver(*this);
124 } // namespace Internal