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