20496201d158b7bb03fc25ecb61a79686b7283fc
[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   mIsSurfaceInvalid( false )
39 {
40 }
41
42 SurfaceFrameBuffer::~SurfaceFrameBuffer()
43 {}
44
45 void SurfaceFrameBuffer::Destroy( Context& context )
46 {
47   if ( mSurface && !mIsSurfaceInvalid )
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 ( mSurface && !mIsSurfaceInvalid )
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 ( mSurface && !mIsSurfaceInvalid )
74   {
75     mSurface->InitializeGraphics();
76   }
77 }
78
79 void SurfaceFrameBuffer::Bind( Context& context )
80 {
81   if ( mSurface && !mIsSurfaceInvalid )
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 ( mSurface && !mIsSurfaceInvalid )
102   {
103     mSurface->PostRender( false, false, mSizeChanged );
104   }
105
106   mSizeChanged = false;
107 }
108
109 Context* SurfaceFrameBuffer::GetContext()
110 {
111   return mContext;
112 }
113
114 Integration::DepthBufferAvailable SurfaceFrameBuffer::GetDepthBufferRequired()
115 {
116   return mSurface && !mIsSurfaceInvalid ? Integration::DepthBufferAvailable::FALSE : mSurface->GetDepthBufferRequired();
117 }
118
119 Integration::StencilBufferAvailable SurfaceFrameBuffer::GetStencilBufferRequired()
120 {
121   return mSurface && !mIsSurfaceInvalid ? Integration::StencilBufferAvailable::TRUE : mSurface->GetStencilBufferRequired();
122 }
123
124 Vector4 SurfaceFrameBuffer::GetBackgroundColor()
125 {
126   return mBackgroundColor;
127 }
128
129 void SurfaceFrameBuffer::SetSize( uint32_t width, uint32_t height )
130 {
131   mWidth = width;
132   mHeight = height;
133   mSizeChanged = true;
134 }
135
136 void SurfaceFrameBuffer::SetBackgroundColor( const Vector4& color )
137 {
138   mBackgroundColor = color;
139 }
140
141 } //Render
142
143 } //Internal
144
145 } //Dali