[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / gl-view / gl-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_GL_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_GL_VIEW_H
3
4 /*
5  * Copyright (c) 2022 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 // EXTERNAL INCLUDES
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
24 #include <dali/public-api/adaptor-framework/window.h>
25 #include <dali/public-api/rendering/geometry.h>
26 #include <dali/public-api/rendering/shader.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/internal/controls/gl-view/gl-view-interface-impl.h>
30 #include <dali-toolkit/internal/controls/gl-view/gl-view-render-thread.h>
31 #include <dali-toolkit/public-api/controls/control-impl.h>
32 #include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
33
34 namespace Dali::Toolkit
35 {
36 class GlView;
37
38 namespace Internal
39 {
40 class GlView : public Dali::Toolkit::Internal::GlViewImpl
41 {
42 protected:
43   virtual ~GlView();
44
45 public:
46   /**
47    * @copydoc Dali::Toolkit::GlView::New()
48    */
49   static Dali::Toolkit::GlView New(Dali::Toolkit::GlView::ColorFormat colorFormat);
50
51   /**
52    * Construct a new GlView.
53    */
54   GlView(Dali::Toolkit::GlView::ColorFormat colorFormat);
55
56   /**
57    * @copydoc Dali::Toolkit::GlView::RegisterGlCallbacks()
58    */
59   void RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback) override;
60
61   /**
62    * @copydoc Dali::Toolkit::GlView::SetResizeCallback()
63    */
64   void SetResizeCallback(CallbackBase* resizeCallback) override;
65
66   /**
67    * @copydoc Dali::Toolkit::GlView::SetGraphicsConfig()
68    */
69   bool SetGraphicsConfig(bool depth, bool stencil, int msaa, Dali::Toolkit::GlView::GraphicsApiVersion version) override;
70
71   /**
72    * @copydoc Dali::Toolkit::GlView::SetRenderingMode()
73    */
74   void SetRenderingMode(Dali::Toolkit::GlView::RenderingMode mode) override;
75
76   /**
77    * @copydoc Dali::Toolkit::GlView::GetRenderingMode()
78    */
79   Dali::Toolkit::GlView::RenderingMode GetRenderingMode() const override;
80
81   /**
82    * @copydoc Dali::Toolkit::GlView::RenderOnce()
83    */
84   void RenderOnce() override;
85
86   /**
87    * @copydoc Dali::Toolkit::GlView::BindTextureResources()
88    */
89   void BindTextureResources(std::vector<Dali::Texture> textures) override;
90
91 private: // From Control
92   /**
93    * @copydoc Toolkit::Control::OnInitialize()
94    */
95   virtual void OnInitialize() override;
96
97   /**
98    * @copydoc Toolkit::Control::OnSceneConnection()
99    */
100   void OnSceneConnection(int depth) override;
101
102   /**
103    * @copydoc Toolkit::Control::OnSceneDisconnection()
104    */
105   void OnSceneDisconnection() override;
106
107   /**
108    * @copydoc Toolkit::Control::OnSizeSet()
109    */
110   void OnSizeSet(const Vector3& targetSize) override;
111
112 private:
113   // Undefined copy constructor and assignment operators
114   GlView(const GlView& GlView);
115   GlView& operator=(const GlView& GlView);
116
117   /**
118    * Callback when the visibility of the GlView is changed
119    */
120   void OnControlVisibilityChanged(Dali::Actor actor, bool visible, Dali::DevelActor::VisibilityChange::Type type);
121
122   /**
123    * Callback when the visibility of the window is changed
124    */
125   void OnWindowVisibilityChanged(Dali::Window window, bool visible);
126
127   /**
128    * Creates the geometry for texturing.
129    */
130   Dali::Geometry CreateTexturedQuad();
131
132   /**
133    * Adds renderer to Actor.
134    */
135   void AddRenderer();
136
137   /**
138    * Creates shader for rendering.
139    */
140   Dali::Shader CreateShader();
141
142   /**
143    * @brief Gets the NativeImageSourceQueue's ColorFormat with the GlView's ColorFormat.
144    * @param[in] colorFormat the color format of the GlView.
145    * @return The color format of NativeImageSourceQueue
146    */
147   Dali::NativeImageSourceQueue::ColorFormat GetColorFormat(Dali::Toolkit::GlView::ColorFormat format);
148
149 private:
150   std::unique_ptr<GlViewRenderThread>  mRenderThread;
151   Dali::NativeImageSourceQueuePtr      mNativeImageQueue;
152   Dali::Toolkit::GlView::RenderingMode mRenderingMode;
153   Dali::Toolkit::GlView::ColorFormat   mColorFormat;
154
155   bool mDepth;
156   bool mStencil;
157   int  mMSAA;
158 };
159
160 } // namespace Internal
161
162 } // namespace Dali::Toolkit
163
164 #endif // DALI_TOOLKIT_INTERNAL_GL_VIEW_H