Enable -Wold-style-cast to ensure more consideration is given to types and their...
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / frame-buffer-impl.cpp
1 /*
2  * Copyright (c) 2017 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
18 // CLASS HEADER
19 #include <dali/internal/event/rendering/frame-buffer-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/update/manager/update-manager.h>
23 #include <dali/internal/event/common/stage-impl.h>
24 #include <dali/internal/render/renderers/render-frame-buffer.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30
31 FrameBufferPtr FrameBuffer::New( unsigned int width, unsigned int height, unsigned int attachments  )
32 {
33   FrameBufferPtr frameBuffer( new FrameBuffer( width, height, attachments ) );
34   frameBuffer->Initialize();
35   return frameBuffer;
36 }
37
38
39 Render::FrameBuffer* FrameBuffer::GetRenderObject() const
40 {
41   return mRenderObject;
42 }
43
44 FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments )
45 : mEventThreadServices( *Stage::GetCurrent() ),
46   mRenderObject( NULL ),
47   mColor( NULL ),
48   mWidth( width ),
49   mHeight( height ),
50   mAttachments( attachments )
51 {
52 }
53
54 void FrameBuffer::Initialize()
55 {
56   mRenderObject = new Render::FrameBuffer( mWidth, mHeight, mAttachments );
57   AddFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
58 }
59
60 void FrameBuffer::AttachColorTexture( TexturePtr texture, unsigned int mipmapLevel, unsigned int layer )
61 {
62   if( ( texture->GetWidth() / ( 1u << mipmapLevel ) == mWidth ) &&
63       ( texture->GetHeight() / ( 1u << mipmapLevel ) == mHeight ) )
64   {
65     mColor = texture;
66     AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer );
67   }
68   else
69   {
70     DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" );
71   }
72 }
73
74 Texture* FrameBuffer::GetColorTexture()
75 {
76   return mColor.Get();
77 }
78
79 FrameBuffer::~FrameBuffer()
80 {
81   if( EventThreadServices::IsCoreRunning() && mRenderObject )
82   {
83     RemoveFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
84   }
85 }
86
87
88 } // namespace Internal
89 } // namespace Dali