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.
18 #include <dali/internal/render/renderers/render-surface-frame-buffer.h>
21 #include <dali/internal/render/renderers/render-texture.h>
30 SurfaceFrameBuffer::SurfaceFrameBuffer( Integration::RenderSurface* surface )
34 mWidth( mSurface->GetPositionSize().width ),
35 mHeight( mSurface->GetPositionSize().height ),
36 mBackgroundColor( 0.f, 0.f, 0.f, 1.f ),
37 mSizeChanged( false ),
38 mBackgroundColorChanged( false ),
39 mIsSurfaceInvalid( false ),
40 mPartialUpdateEnabled( true )
44 SurfaceFrameBuffer::~SurfaceFrameBuffer()
47 void SurfaceFrameBuffer::Destroy( Context& context )
49 if ( IsSurfaceValid() )
51 mSurface->DestroySurface();
56 void SurfaceFrameBuffer::GlContextDestroyed()
60 mContext->GlContextDestroyed();
63 if ( IsSurfaceValid() )
65 mSurface->DestroySurface();
70 void SurfaceFrameBuffer::Initialize(Context& context)
73 mContext->GlContextCreated();
75 if ( IsSurfaceValid() )
77 mSurface->InitializeGraphics();
81 void SurfaceFrameBuffer::Bind( Context& context )
83 if ( IsSurfaceValid() )
85 mSurface->PreRender( mSizeChanged );
87 context.BindFramebuffer( GL_FRAMEBUFFER, 0u );
91 uint32_t SurfaceFrameBuffer::GetWidth() const
96 uint32_t SurfaceFrameBuffer::GetHeight() const
101 void SurfaceFrameBuffer::PostRender()
103 if ( IsSurfaceValid() )
105 mSurface->PostRender( false, false, mSizeChanged );
108 mSizeChanged = false;
109 mBackgroundColorChanged = false;
110 mPartialUpdateEnabled = true;
113 void SurfaceFrameBuffer::SetDamagedRect( const Dali::DamagedRect& damagedRect, Dali::DamagedRect& mergedRect )
115 if ( IsSurfaceValid() )
117 mSurface->SetDamagedRect( damagedRect, mergedRect );
121 Context* SurfaceFrameBuffer::GetContext()
126 void SurfaceFrameBuffer::MakeContextCurrent()
128 if ( IsSurfaceValid() )
130 mSurface->MakeContextCurrent();
134 Vector4 SurfaceFrameBuffer::GetBackgroundColor()
136 return mBackgroundColor;
139 void SurfaceFrameBuffer::SetSize( uint32_t width, uint32_t height )
146 void SurfaceFrameBuffer::SetBackgroundColor( const Vector4& color )
148 mBackgroundColor = color;
149 mBackgroundColorChanged = true;
152 bool SurfaceFrameBuffer::IsSurfaceValid() const
154 return mSurface && !mIsSurfaceInvalid;
157 bool SurfaceFrameBuffer::IsPartialUpdateEnabled() const
160 if ( IsSurfaceValid() )
162 ret = mSurface->GetBufferAge() && ( mPartialUpdateEnabled && !( mSizeChanged || mBackgroundColorChanged ) );
167 void SurfaceFrameBuffer::SetPartialUpdateEnabled( bool value )
169 mPartialUpdateEnabled = value;