[Tizen] Implement partial update
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-surface-frame-buffer.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 // CLASS HEADER
18 #include <dali/internal/render/renderers/render-surface-frame-buffer.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/render/renderers/render-texture.h>
22
23 namespace Dali
24 {
25 namespace Internal
26 {
27 namespace Render
28 {
29
30 SurfaceFrameBuffer::SurfaceFrameBuffer( Integration::RenderSurface* surface )
31 : FrameBuffer(),
32   mSurface( surface ),
33   mContext( nullptr ),
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 )
41 {
42 }
43
44 SurfaceFrameBuffer::~SurfaceFrameBuffer()
45 {}
46
47 void SurfaceFrameBuffer::Destroy( Context& context )
48 {
49   if ( IsSurfaceValid() )
50   {
51     mSurface->DestroySurface();
52     mSurface = nullptr;
53   }
54 }
55
56 void SurfaceFrameBuffer::GlContextDestroyed()
57 {
58   if ( mContext )
59   {
60     mContext->GlContextDestroyed();
61   }
62
63   if ( IsSurfaceValid() )
64   {
65     mSurface->DestroySurface();
66     mSurface = nullptr;
67   }
68 }
69
70 void SurfaceFrameBuffer::Initialize(Context& context)
71 {
72   mContext = &context;
73   mContext->GlContextCreated();
74
75   if ( IsSurfaceValid() )
76   {
77     mSurface->InitializeGraphics();
78   }
79 }
80
81 void SurfaceFrameBuffer::Bind( Context& context )
82 {
83   if ( IsSurfaceValid() )
84   {
85     mSurface->PreRender( mSizeChanged );
86
87     context.BindFramebuffer( GL_FRAMEBUFFER, 0u );
88   }
89 }
90
91 uint32_t SurfaceFrameBuffer::GetWidth() const
92 {
93   return mWidth;
94 }
95
96 uint32_t SurfaceFrameBuffer::GetHeight() const
97 {
98   return mHeight;
99 }
100
101 void SurfaceFrameBuffer::PostRender()
102 {
103   if ( IsSurfaceValid() )
104   {
105     mSurface->PostRender( false, false, mSizeChanged );
106   }
107
108   mSizeChanged = false;
109   mBackgroundColorChanged = false;
110   mPartialUpdateEnabled = true;
111 }
112
113 void SurfaceFrameBuffer::SetDamagedRect( const Dali::DamagedRect& damagedRect, Dali::DamagedRect& mergedRect )
114 {
115   if ( IsSurfaceValid() )
116   {
117     mSurface->SetDamagedRect( damagedRect, mergedRect );
118   }
119 }
120
121 Context* SurfaceFrameBuffer::GetContext()
122 {
123   return mContext;
124 }
125
126 void SurfaceFrameBuffer::MakeContextCurrent()
127 {
128   if ( IsSurfaceValid() )
129   {
130     mSurface->MakeContextCurrent();
131   }
132 }
133
134 Vector4 SurfaceFrameBuffer::GetBackgroundColor()
135 {
136   return mBackgroundColor;
137 }
138
139 void SurfaceFrameBuffer::SetSize( uint32_t width, uint32_t height )
140 {
141   mWidth = width;
142   mHeight = height;
143   mSizeChanged = true;
144 }
145
146 void SurfaceFrameBuffer::SetBackgroundColor( const Vector4& color )
147 {
148   mBackgroundColor = color;
149   mBackgroundColorChanged = true;
150 }
151
152 bool SurfaceFrameBuffer::IsSurfaceValid() const
153 {
154   return mSurface && !mIsSurfaceInvalid;
155 }
156
157 bool SurfaceFrameBuffer::IsPartialUpdateEnabled() const
158 {
159   bool ret = false;
160   if ( IsSurfaceValid() )
161   {
162     ret = mSurface->GetBufferAge() && ( mPartialUpdateEnabled && !( mSizeChanged || mBackgroundColorChanged ) );
163   }
164   return ret;
165 }
166
167 void SurfaceFrameBuffer::SetPartialUpdateEnabled( bool value )
168 {
169   mPartialUpdateEnabled = value;
170 }
171
172 } //Render
173
174 } //Internal
175
176 } //Dali