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