2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/images/frame-buffer-image-impl.h>
22 #include <dali/internal/event/common/thread-local-storage.h>
23 #include <dali/internal/event/resources/resource-client.h>
31 FrameBufferImage::~FrameBufferImage()
35 FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
36 : Image(Dali::Image::Immediate, releasePolicy),
37 mPixelFormat(pixelFormat)
43 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage )
44 : Image(Dali::Image::Immediate),
45 mNativeImage(&nativeImage),
46 mPixelFormat(nativeImage.GetPixelFormat())
48 mWidth = nativeImage.GetWidth();
49 mHeight = nativeImage.GetHeight();
52 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage, ReleasePolicy releasePolicy )
53 : Image(Dali::Image::Immediate, releasePolicy),
54 mNativeImage(&nativeImage),
55 mPixelFormat(nativeImage.GetPixelFormat())
57 mWidth = nativeImage.GetWidth();
58 mHeight = nativeImage.GetHeight();
61 void FrameBufferImage::Connect()
65 if (mConnectionCount == 1)
67 // ticket was thrown away when related actors went offstage
70 ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
73 mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
74 mTicket->AddObserver(*this);
78 mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat);
79 mTicket->AddObserver(*this);
85 void FrameBufferImage::Disconnect()
92 DALI_ASSERT_DEBUG(mConnectionCount > 0);
94 if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused)
96 // release image memory when it's not visible anymore (decrease ref. count of texture)
97 mTicket->RemoveObserver(*this);
102 } // namespace Internal