[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 Rect<int32_t> SurfaceFrameBuffer::SetDamagedRect( Rect<int32_t> damagedRect )
114 {
115   Rect<int32_t> ret;
116   if ( IsSurfaceValid() )
117   {
118     ret = mSurface->SetDamagedRect( damagedRect );
119   }
120   return ret;
121 }
122
123 Context* SurfaceFrameBuffer::GetContext()
124 {
125   return mContext;
126 }
127
128 void SurfaceFrameBuffer::MakeContextCurrent()
129 {
130   if ( IsSurfaceValid() )
131   {
132     mSurface->MakeContextCurrent();
133   }
134 }
135
136 Vector4 SurfaceFrameBuffer::GetBackgroundColor()
137 {
138   return mBackgroundColor;
139 }
140
141 void SurfaceFrameBuffer::SetSize( uint32_t width, uint32_t height )
142 {
143   mWidth = width;
144   mHeight = height;
145   mSizeChanged = true;
146 }
147
148 void SurfaceFrameBuffer::SetBackgroundColor( const Vector4& color )
149 {
150   mBackgroundColor = color;
151   mBackgroundColorChanged = true;
152 }
153
154 bool SurfaceFrameBuffer::IsSurfaceValid() const
155 {
156   return mSurface && !mIsSurfaceInvalid;
157 }
158
159 bool SurfaceFrameBuffer::IsPartialUpdateEnabled() const
160 {
161   bool ret = false;
162   if ( IsSurfaceValid() )
163   {
164     ret = mSurface->GetBufferAge() && ( mPartialUpdateEnabled && !( mSizeChanged || mBackgroundColorChanged ) );
165   }
166   return ret;
167 }
168
169 void SurfaceFrameBuffer::SetPartialUpdateEnabled( bool value )
170 {
171   mPartialUpdateEnabled = value;
172 }
173
174 } //Render
175
176 } //Internal
177
178 } //Dali