[dali_2.1.30] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / gl-view / gl-view.cpp
1 /*
2  * Copyright (c) 2021 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-toolkit/public-api/controls/gl-view/gl-view.h>
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/controls/gl-view/drawable-view-impl.h>
23 #include <dali-toolkit/internal/controls/gl-view/gl-view-impl.h>
24
25 namespace Dali::Toolkit
26 {
27
28 GlView::GlView() = default;
29
30 GlView::GlView(const GlView& GlView) = default;
31
32 GlView::GlView(GlView&& rhs) = default;
33
34 GlView& GlView::operator=(const GlView& GlView) = default;
35
36 GlView& GlView::operator=(GlView&& rhs) = default;
37
38 GlView::~GlView() = default;
39
40 GlView GlView::New(ColorFormat colorFormat)
41 {
42   // This function is backward compatible and always returns
43   // backend based on NativeImage.
44   return Internal::GlView::New( colorFormat );
45 }
46
47 GlView GlView::New(BackendMode backendMode, ColorFormat colorFormat)
48 {
49   switch(backendMode)
50   {
51     case BackendMode::DIRECT_RENDERING:
52     case BackendMode::DIRECT_RENDERING_THREADED:
53     {
54       return Internal::DrawableView::New(backendMode);
55     }
56     case BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING:
57     {
58       return Internal::GlView::New(colorFormat);
59     }
60     default:
61     {
62       DALI_ASSERT_ALWAYS("Invalid BackendMode");
63     }
64   }
65   return {};
66 }
67
68 GlView GlView::DownCast(BaseHandle handle)
69 {
70   return Control::DownCast<GlView, Internal::GlViewImpl>(handle);
71 }
72
73 void GlView::RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback)
74 {
75   Dali::Toolkit::GetImpl(*this).RegisterGlCallbacks(initCallback, renderFrameCallback, terminateCallback);
76 }
77
78 void GlView::SetResizeCallback(CallbackBase* resizeCallback)
79 {
80   Dali::Toolkit::GetImpl(*this).SetResizeCallback(resizeCallback);
81 }
82
83 bool GlView::SetGraphicsConfig(bool depth, bool stencil, int msaa, GraphicsApiVersion version)
84 {
85   return Dali::Toolkit::GetImpl(*this).SetGraphicsConfig(depth, stencil, msaa, version);
86 }
87
88 void GlView::SetRenderingMode(RenderingMode mode)
89 {
90   Dali::Toolkit::GetImpl(*this).SetRenderingMode(mode);
91 }
92
93 Dali::Toolkit::GlView::RenderingMode GlView::GetRenderingMode() const
94 {
95   return Dali::Toolkit::GetImpl(*this).GetRenderingMode();
96 }
97
98 Dali::Toolkit::GlView::BackendMode GlView::GetBackendMode() const
99 {
100   return Dali::Toolkit::GetImpl(*this).GetBackendMode();
101 }
102
103 void GlView::RenderOnce()
104 {
105   Dali::Toolkit::GetImpl(*this).RenderOnce();
106 }
107
108 GlView::GlView(Internal::GlViewImpl& implementation)
109 : Control(implementation)
110 {
111 }
112
113 GlView::GlView(Dali::Internal::CustomActor* internal)
114 : Control(internal)
115 {
116   VerifyCustomActorPointer<Internal::GlViewImpl>(internal);
117 }
118
119 } // namespace Dali