2 * Copyright (c) 2015 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 FrameBufferImagePtr FrameBufferImage::New( unsigned int width,
39 Pixel::Format pixelFormat,
40 RenderBuffer::Format bufferformat )
42 FrameBufferImagePtr image = new FrameBufferImage( width, height, pixelFormat, bufferformat );
47 FrameBufferImagePtr FrameBufferImage::New( NativeImageInterface& nativeImage )
49 FrameBufferImagePtr image = new FrameBufferImage( nativeImage );
55 FrameBufferImage::FrameBufferImage( unsigned int width,
57 Pixel::Format pixelFormat,
58 RenderBuffer::Format bufferformat )
61 mPixelFormat( pixelFormat ),
62 mBufferFormat( bufferformat ),
69 FrameBufferImage::FrameBufferImage( NativeImageInterface& nativeImage )
71 mNativeImage( &nativeImage ),
72 mPixelFormat( Pixel::FIRST_VALID_PIXEL_FORMAT ),
73 mBufferFormat( RenderBuffer::COLOR ),
76 mWidth = nativeImage.GetWidth();
77 mHeight = nativeImage.GetHeight();
80 void FrameBufferImage::Connect()
84 if (mConnectionCount == 1)
86 // ticket was thrown away when related actors went offstage
89 ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
92 mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
93 mTicket->AddObserver(*this);
97 mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat, mBufferFormat);
98 mTicket->AddObserver(*this);
104 void FrameBufferImage::Disconnect()
111 DALI_ASSERT_DEBUG(mConnectionCount > 0);
113 if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::UNUSED)
115 // release image memory when it's not visible anymore (decrease ref. count of texture)
116 mTicket->RemoveObserver(*this);
121 bool FrameBufferImage::IsNativeFbo() const
125 FrameBufferImage::~FrameBufferImage()
129 } // namespace Internal