2 * Copyright (c) 2019 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/rendering/frame-buffer-impl.h>
22 #include <dali/internal/update/manager/update-manager.h>
23 #include <dali/internal/render/renderers/render-frame-buffer.h>
24 #include <dali/internal/render/renderers/render-texture-frame-buffer.h>
25 #include <dali/internal/render/renderers/render-surface-frame-buffer.h>
26 #include <dali/integration-api/render-surface.h>
33 FrameBufferPtr FrameBuffer::New( uint32_t width, uint32_t height, Mask attachments )
35 FrameBufferPtr frameBuffer( new FrameBuffer( width, height, attachments ) );
36 frameBuffer->Initialize();
40 FrameBufferPtr FrameBuffer::New( Dali::Integration::RenderSurface& renderSurface, Mask attachments )
42 Dali::PositionSize positionSize = renderSurface.GetPositionSize();
43 FrameBufferPtr frameBuffer( new FrameBuffer( positionSize.width, positionSize.height, attachments ) );
44 frameBuffer->Initialize( &renderSurface );
48 Render::FrameBuffer* FrameBuffer::GetRenderObject() const
53 FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
54 : mEventThreadServices( EventThreadServices::Get() ),
55 mRenderObject( NULL ),
59 mAttachments( attachments ),
60 mIsSurfaceBacked( false )
64 void FrameBuffer::Initialize( Integration::RenderSurface* renderSurface )
66 mIsSurfaceBacked = ( renderSurface != nullptr );
68 // If render surface backed, create a different scene object
69 // Make Render::FrameBuffer as a base class, and implement Render::TextureFrameBuffer & Render::WindowFrameBuffer
70 if ( mIsSurfaceBacked )
72 mRenderObject = new Render::SurfaceFrameBuffer( renderSurface );
76 mRenderObject = new Render::TextureFrameBuffer( mWidth, mHeight, mAttachments );
79 AddFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
82 void FrameBuffer::AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer )
84 if ( mIsSurfaceBacked )
86 DALI_LOG_ERROR( "Attempted to attach color texture to a render surface backed FrameBuffer \n" );
90 if( ( texture->GetWidth() / ( 1u << mipmapLevel ) == mWidth ) &&
91 ( texture->GetHeight() / ( 1u << mipmapLevel ) == mHeight ) )
94 AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer );
98 DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" );
103 Texture* FrameBuffer::GetColorTexture()
105 return mIsSurfaceBacked ? nullptr : mColor.Get();
108 void FrameBuffer::SetSize( uint32_t width, uint32_t height )
113 if( mRenderObject->IsSurfaceBacked() )
115 SetFrameBufferSizeMessage( mEventThreadServices.GetUpdateManager(), static_cast<Render::SurfaceFrameBuffer*>( mRenderObject ), width, height );
119 void FrameBuffer::SetBackgroundColor( const Vector4& color )
121 if( mRenderObject->IsSurfaceBacked() )
123 SetFrameBufferBackgroundColorMessage( mEventThreadServices.GetUpdateManager(), static_cast<Render::SurfaceFrameBuffer*>( mRenderObject ), color );
127 FrameBuffer::~FrameBuffer()
129 if( EventThreadServices::IsCoreRunning() && mRenderObject )
131 RemoveFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
136 } // namespace Internal