[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   mSizeChanged( false ),
37   mIsSurfaceInvalid( false ),
38   mPartialUpdateEnabled( true )
39 {
40 }
41
42 SurfaceFrameBuffer::~SurfaceFrameBuffer()
43 {}
44
45 void SurfaceFrameBuffer::Destroy( Context& context )
46 {
47   if ( IsSurfaceValid() )
48   {
49     mSurface->DestroySurface();
50     mSurface = nullptr;
51   }
52 }
53
54 void SurfaceFrameBuffer::GlContextDestroyed()
55 {
56   if ( mContext )
57   {
58     mContext->GlContextDestroyed();
59   }
60
61   if ( IsSurfaceValid() )
62   {
63     mSurface->DestroySurface();
64     mSurface = nullptr;
65   }
66 }
67
68 void SurfaceFrameBuffer::Initialize(Context& context)
69 {
70   mContext = &context;
71   mContext->GlContextCreated();
72
73   if ( IsSurfaceValid() )
74   {
75     mSurface->InitializeGraphics();
76   }
77 }
78
79 void SurfaceFrameBuffer::Bind( Context& context )
80 {
81   if ( IsSurfaceValid() )
82   {
83     mSurface->PreRender( mSizeChanged );
84
85     context.BindFramebuffer( GL_FRAMEBUFFER, 0u );
86   }
87 }
88
89 uint32_t SurfaceFrameBuffer::GetWidth() const
90 {
91   return mWidth;
92 }
93
94 uint32_t SurfaceFrameBuffer::GetHeight() const
95 {
96   return mHeight;
97 }
98
99 void SurfaceFrameBuffer::PostRender()
100 {
101   if ( IsSurfaceValid() )
102   {
103     mSurface->PostRender( false, false, mSizeChanged );
104   }
105
106   mSizeChanged = false;
107   mPartialUpdateEnabled = true;
108 }
109
110 void SurfaceFrameBuffer::SetDamagedRect( const Dali::DamagedRect& damagedRect, Dali::DamagedRect& mergedRect )
111 {
112   if ( IsSurfaceValid() )
113   {
114     mSurface->SetDamagedRect( damagedRect, mergedRect );
115   }
116 }
117
118 Context* SurfaceFrameBuffer::GetContext()
119 {
120   return mContext;
121 }
122
123 void SurfaceFrameBuffer::MakeContextCurrent()
124 {
125   if ( IsSurfaceValid() )
126   {
127     mSurface->MakeContextCurrent();
128   }
129 }
130
131 void SurfaceFrameBuffer::SetSize( uint32_t width, uint32_t height )
132 {
133   mWidth = width;
134   mHeight = height;
135   mSizeChanged = true;
136 }
137
138 bool SurfaceFrameBuffer::IsSurfaceValid() const
139 {
140   return mSurface && !mIsSurfaceInvalid;
141 }
142
143 bool SurfaceFrameBuffer::IsPartialUpdateEnabled() const
144 {
145   bool ret = false;
146   if ( IsSurfaceValid() )
147   {
148     ret = mSurface->GetBufferAge() && ( mPartialUpdateEnabled && !mSizeChanged );
149   }
150   return ret;
151 }
152
153 void SurfaceFrameBuffer::SetPartialUpdateEnabled( bool value )
154 {
155   mPartialUpdateEnabled = value;
156 }
157
158 } //Render
159
160 } //Internal
161
162 } //Dali