[Vulkan] Image and Swapchain upgrade
[platform/core/uifw/dali-core.git] / dali / integration-api / graphics / graphics.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 #include <dali/graphics/vulkan/vulkan-types.h>
19 #include <dali/graphics/vulkan/vulkan-graphics.h>
20 #include <dali/graphics/vulkan/vulkan-surface.h>
21 #include <dali/graphics/vulkan/vulkan-framebuffer.h>
22 #include <dali/graphics-api/graphics-api-controller.h>
23 #include <dali/integration-api/graphics/graphics.h>
24
25
26 namespace Dali
27 {
28 /// fixme: substituting directly the vulkan implementation
29 namespace Graphics
30 {
31 using GraphicsImpl = Dali::Graphics::Vulkan::Graphics;
32 }
33
34 namespace Integration
35 {
36 namespace Graphics
37 {
38 using Swapchain = Dali::Graphics::Vulkan::Swapchain;
39 using SwapchainRef = Dali::Graphics::Vulkan::SwapchainRef;
40
41 Graphics::Graphics()
42 {
43   // create device
44   auto impl = Dali::Graphics::MakeUnique<Dali::Graphics::GraphicsImpl>();
45
46   impl->Create();
47
48   mGraphicsImpl = std::move(impl);
49 }
50
51 Graphics::~Graphics()
52 {
53
54 }
55
56 Dali::Graphics::FBID Graphics::Create(
57   std::unique_ptr<Dali::Integration::Graphics::SurfaceFactory> surfaceFactory)
58 {
59   //@todo do we really need to have a surface that early???
60
61   // create surface
62   auto retval = mGraphicsImpl->CreateSurface(std::move(surfaceFactory));
63
64   // create device
65   mGraphicsImpl->CreateDevice();
66
67   // create swapchain from surface
68   auto surface = mGraphicsImpl->GetSurface( retval );
69
70   // create swapchain
71   mGraphicsImpl->CreateSwapchainForSurface( surface );
72
73   return retval;
74 }
75
76 Dali::Graphics::FBID Graphics::CreateSurface(
77   std::unique_ptr<Dali::Integration::Graphics::SurfaceFactory> surfaceFactory)
78 {
79   return 0u;
80 }
81
82 void Graphics::PreRender(Dali::Graphics::FBID framebufferId)
83 {
84   assert(framebufferId != 0 && "Invalid FBID!");
85   auto swapchain = mGraphicsImpl->GetSwapchainForFBID( framebufferId );
86   swapchain->AcquireNextFramebuffer();
87 }
88
89 Dali::Graphics::API::Controller& Graphics::GetController()
90 {
91   return mGraphicsImpl->GetController();
92 }
93
94 /*
95  * Postrender
96  */
97 void Graphics::PostRender(Dali::Graphics::FBID framebufferId)
98 {
99   auto swapchain = mGraphicsImpl->GetSwapchainForFBID( framebufferId );
100   swapchain->Present();
101 }
102
103 void IncludeThisLibrary()
104 {
105 // dummy function to create linker dependency
106 }
107
108 } // Namespace Graphics
109 } // Namespace Integration
110 } // Namespace Dali