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/public-api/object/type-registry.h>
23 #include <dali/internal/event/common/thread-local-storage.h>
24 #include <dali/internal/event/resources/resource-client.h>
34 TypeRegistration mType( typeid( Dali::FrameBufferImage ), typeid( Dali::Image ), NULL );
35 } // unnamed namespace
37 FrameBufferImage::~FrameBufferImage()
41 FrameBufferImagePtr FrameBufferImage::New(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
43 FrameBufferImagePtr image = new FrameBufferImage(width, height, pixelFormat, releasePolicy);
48 FrameBufferImagePtr FrameBufferImage::New( NativeImageInterface& nativeImage )
50 FrameBufferImagePtr image = new FrameBufferImage(nativeImage);
55 FrameBufferImagePtr FrameBufferImage::New( NativeImageInterface& nativeImage, ReleasePolicy releasePolicy )
57 FrameBufferImagePtr image = new FrameBufferImage(nativeImage, releasePolicy);
62 FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
63 : Image(releasePolicy),
64 mPixelFormat(pixelFormat)
70 FrameBufferImage::FrameBufferImage( NativeImageInterface& nativeImage )
72 mNativeImage(&nativeImage)
74 mWidth = nativeImage.GetWidth();
75 mHeight = nativeImage.GetHeight();
78 FrameBufferImage::FrameBufferImage( NativeImageInterface& nativeImage, ReleasePolicy releasePolicy )
79 : Image(releasePolicy),
80 mNativeImage(&nativeImage)
82 mWidth = nativeImage.GetWidth();
83 mHeight = nativeImage.GetHeight();
86 void FrameBufferImage::Connect()
90 if (mConnectionCount == 1)
92 // ticket was thrown away when related actors went offstage
95 ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
98 mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
99 mTicket->AddObserver(*this);
103 mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat);
104 mTicket->AddObserver(*this);
110 void FrameBufferImage::Disconnect()
117 DALI_ASSERT_DEBUG(mConnectionCount > 0);
119 if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::UNUSED)
121 // release image memory when it's not visible anymore (decrease ref. count of texture)
122 mTicket->RemoveObserver(*this);
127 } // namespace Internal