Submit render calls from update to graphics
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-api-controller.h
1 #ifndef DALI_GRAPHICS_API_CONTROLLER_H
2 #define DALI_GRAPHICS_API_CONTROLLER_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/graphics-api/graphics-api-accessor.h>
23 #include <dali/graphics-api/graphics-api-base-factory.h>
24 #include <dali/graphics-api/graphics-api-dynamic-buffer.h>
25 #include <dali/graphics-api/graphics-api-frame.h>
26 #include <dali/graphics-api/graphics-api-framebuffer.h>
27 #include <dali/graphics-api/graphics-api-generic-buffer.h>
28 #include <dali/graphics-api/graphics-api-render-command.h>
29 #include <dali/graphics-api/graphics-api-sampler.h>
30 #include <dali/graphics-api/graphics-api-shader.h>
31 #include <dali/graphics-api/graphics-api-static-buffer.h>
32 #include <dali/graphics-api/graphics-api-texture-factory.h>
33 #include <dali/graphics-api/graphics-api-texture-set.h>
34 #include <dali/graphics-api/graphics-api-texture.h>
35 #include <dali/graphics-api/utility/utility-builder.h>
36
37 namespace Dali
38 {
39 namespace Graphics
40 {
41 namespace API
42 {
43 /**
44  * @brief Interface class for Manager types in the graphics API.
45  */
46 class Controller
47 {
48 public:
49   /**
50    * @brief Create a new object
51    */
52   virtual Accessor<Shader> CreateShader( const BaseFactory<Shader>& factory ) = 0;
53
54   /**
55    * @brief Create a new object
56    */
57   virtual Accessor<Texture> CreateTexture( const BaseFactory<Texture>& factory ) = 0;
58
59   /**
60    * @brief Create a new object
61    */
62   virtual Accessor<TextureSet> CreateTextureSet( const BaseFactory<TextureSet>& factory ) = 0;
63
64   /**
65    * @brief Create a new object
66    */
67   virtual Accessor<DynamicBuffer> CreateDynamicBuffer( const BaseFactory<DynamicBuffer>& factory ) = 0;
68
69   /**
70    * @brief Create a new object
71    */
72   virtual Accessor<StaticBuffer> CreateStaticBuffer( const BaseFactory<StaticBuffer>& factory ) = 0;
73
74   /**
75    * @brief Create a new object
76    */
77   virtual Accessor<Sampler> CreateSampler( const BaseFactory<Sampler>& factory ) = 0;
78
79   /**
80    * @brief Create a new object
81    */
82   virtual Accessor<Framebuffer> CreateFramebuffer( const BaseFactory<Framebuffer>& factory ) = 0;
83
84   /**
85    * @brief Get a render list
86    */
87   virtual void GetRenderItemList() = 0;
88
89   /**
90    * @brief Create a buffer
91    */
92   template<typename T>
93   std::unique_ptr<GenericBuffer<T>> CreateBuffer( size_t numberOfElements );
94
95   /**
96    * @brief Submit a render command
97    */
98   virtual void SubmitCommand( API::RenderCommand&& command ) = 0;
99
100   /**
101    * @brief Mark the beginning of a frame
102    */
103   virtual void BeginFrame() = 0;
104
105   /**
106    * @brief Mark the end of a frame
107    */
108   virtual void EndFrame() = 0;
109
110 public:
111   // not copyable
112   Controller( const Controller& ) = delete;
113   Controller& operator=( const Controller& ) = delete;
114
115   virtual ~Controller() = default;
116
117 protected:
118   // derived types should not be moved direcly to prevent slicing
119   Controller( Controller&& ) = default;
120   Controller& operator=( Controller&& ) = default;
121
122   /**
123    * Objects of this type should not directly.
124    */
125   Controller() = default;
126
127   /**
128    * @brief create an element for the given number of elements and element size
129    */
130   virtual std::unique_ptr<char> CreateBuffer( size_t numberOfElements, size_t elementSize ) = 0;
131
132 private:
133 };
134
135 template<typename T>
136 std::unique_ptr<GenericBuffer<T>> Controller::CreateBuffer( size_t numberOfElements )
137 {
138     return std::make_unique<GenericBuffer<T>>(numberOfElements, std::move(CreateBuffer( numberOfElements, sizeof( T ) )));
139 }
140
141 } // namespace API
142 } // namespace Graphics
143 } // namespace Dali
144
145 #endif // DALI_GRAPHICS_API_CONTROLLER_H