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,
43 Pixel::Format pixelFormat,
44 ReleasePolicy releasePolicy,
45 RenderBuffer::Format bufferformat)
47 FrameBufferImagePtr image = new FrameBufferImage(width, height, pixelFormat, releasePolicy, bufferformat);
52 FrameBufferImagePtr FrameBufferImage::New( NativeImageInterface& nativeImage )
54 FrameBufferImagePtr image = new FrameBufferImage(nativeImage);
59 FrameBufferImagePtr FrameBufferImage::New( NativeImageInterface& nativeImage, ReleasePolicy releasePolicy )
61 FrameBufferImagePtr image = new FrameBufferImage(nativeImage, releasePolicy);
66 FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy, RenderBuffer::Format bufferformat)
67 : Image( releasePolicy ),
69 mPixelFormat( pixelFormat ),
70 mBufferFormat( bufferformat )
76 FrameBufferImage::FrameBufferImage( NativeImageInterface& nativeImage )
78 mNativeImage( &nativeImage ),
79 mPixelFormat( Pixel::FIRST_VALID_PIXEL_FORMAT ),
80 mBufferFormat( RenderBuffer::COLOR )
82 mWidth = nativeImage.GetWidth();
83 mHeight = nativeImage.GetHeight();
86 FrameBufferImage::FrameBufferImage( NativeImageInterface& nativeImage, ReleasePolicy releasePolicy )
87 : Image( releasePolicy ),
88 mNativeImage( &nativeImage ),
89 mPixelFormat( Pixel::FIRST_VALID_PIXEL_FORMAT ),
90 mBufferFormat( RenderBuffer::COLOR )
92 mWidth = nativeImage.GetWidth();
93 mHeight = nativeImage.GetHeight();
96 void FrameBufferImage::Connect()
100 if (mConnectionCount == 1)
102 // ticket was thrown away when related actors went offstage
105 ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
108 mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
109 mTicket->AddObserver(*this);
113 mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat, mBufferFormat);
114 mTicket->AddObserver(*this);
120 void FrameBufferImage::Disconnect()
127 DALI_ASSERT_DEBUG(mConnectionCount > 0);
129 if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::UNUSED)
131 // release image memory when it's not visible anymore (decrease ref. count of texture)
132 mTicket->RemoveObserver(*this);
137 } // namespace Internal