Commit b3d4b1ca452965ace8cd91d76acb0c536309a0ce

Authored by Adeel Kazmi
Committed by Gerrit Code Review
2 parents d4e770e1 dd92f825

Merge "Adding back/touch to quit in direct-rendering demo" into devel/master

examples/direct-rendering/direct-rendering-example.cpp
1 /* 1 /*
2 - * Copyright (c) 2022 Samsung Electronics Co., Ltd. 2 + * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
@@ -46,32 +46,32 @@ const uint32_t DR_THREAD_ENABLED = GetEnvInt("DR_THREAD_ENABLED", 0); @@ -46,32 +46,32 @@ const uint32_t DR_THREAD_ENABLED = GetEnvInt("DR_THREAD_ENABLED", 0);
46 */ 46 */
47 const Toolkit::GlView::BackendMode BACKEND_MODE = 47 const Toolkit::GlView::BackendMode BACKEND_MODE =
48 Toolkit::GlView::BackendMode(GetEnvInt("EGL_ENABLED", 0)); 48 Toolkit::GlView::BackendMode(GetEnvInt("EGL_ENABLED", 0));
49 -} 49 +} // namespace
50 50
51 /** 51 /**
52 * RenderView encapsulates single GLView callback and its parameters. 52 * RenderView encapsulates single GLView callback and its parameters.
53 */ 53 */
54 struct RenderView 54 struct RenderView
55 { 55 {
56 - explicit RenderView( const Dali::Window& window ) 56 + explicit RenderView(const Dali::Window& window)
57 { 57 {
58 mWindow = window; 58 mWindow = window;
59 } 59 }
60 60
61 - int Create(const Vector2& pos, Toolkit::GlView::BackendMode mode ) 61 + int Create(const Vector2& pos, Toolkit::GlView::BackendMode mode)
62 { 62 {
63 auto w = mWindow.GetSize().GetWidth(); 63 auto w = mWindow.GetSize().GetWidth();
64 auto h = mWindow.GetSize().GetHeight(); 64 auto h = mWindow.GetSize().GetHeight();
65 65
66 NativeRenderer::CreateInfo info{}; 66 NativeRenderer::CreateInfo info{};
67 info.clearColor = {0, 0, 0, 0}; 67 info.clearColor = {0, 0, 0, 0};
68 - info.name = "DR";  
69 - info.offscreen = (mode == Toolkit::GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING || DR_THREAD_ENABLED);  
70 - info.viewportX = 0;  
71 - info.viewportY = 0;  
72 - info.width = w;  
73 - info.height = h;  
74 - info.threaded = (mode != Toolkit::GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING) && (DR_THREAD_ENABLED); 68 + info.name = "DR";
  69 + info.offscreen = (mode == Toolkit::GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING || DR_THREAD_ENABLED);
  70 + info.viewportX = 0;
  71 + info.viewportY = 0;
  72 + info.width = w;
  73 + info.height = h;
  74 + info.threaded = (mode != Toolkit::GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING) && (DR_THREAD_ENABLED);
75 75
76 // Enable threaded rendering 76 // Enable threaded rendering
77 if(info.threaded && mode == Dali::Toolkit::GlView::BackendMode::DIRECT_RENDERING) 77 if(info.threaded && mode == Dali::Toolkit::GlView::BackendMode::DIRECT_RENDERING)
@@ -103,9 +103,8 @@ struct RenderView @@ -103,9 +103,8 @@ struct RenderView
103 return 0; 103 return 0;
104 } 104 }
105 105
106 -  
107 - Dali::Window mWindow;  
108 - Toolkit::GlView mGlView; 106 + Dali::Window mWindow;
  107 + Toolkit::GlView mGlView;
109 std::unique_ptr<NativeRenderer> mRenderer{}; 108 std::unique_ptr<NativeRenderer> mRenderer{};
110 109
111 CallbackBase* mGlInitCallback{}; 110 CallbackBase* mGlInitCallback{};
@@ -119,9 +118,8 @@ struct RenderView @@ -119,9 +118,8 @@ struct RenderView
119 class DirectRenderingExampleController : public ConnectionTracker 118 class DirectRenderingExampleController : public ConnectionTracker
120 { 119 {
121 public: 120 public:
122 -  
123 explicit DirectRenderingExampleController(Application& application) 121 explicit DirectRenderingExampleController(Application& application)
124 - : mApplication(application) 122 + : mApplication(application)
125 { 123 {
126 // Connect to the Application's Init signal 124 // Connect to the Application's Init signal
127 mApplication.InitSignal().Connect(this, &DirectRenderingExampleController::Create); 125 mApplication.InitSignal().Connect(this, &DirectRenderingExampleController::Create);
@@ -135,8 +133,11 @@ public: @@ -135,8 +133,11 @@ public:
135 Dali::Window window = application.GetWindow(); 133 Dali::Window window = application.GetWindow();
136 window.SetBackgroundColor(Color::WHITE); 134 window.SetBackgroundColor(Color::WHITE);
137 135
  136 + window.KeyEventSignal().Connect(this, &DirectRenderingExampleController::OnKeyEvent);
  137 + window.GetRootLayer().TouchedSignal().Connect(this, &DirectRenderingExampleController::OnTouch);
  138 +
138 mDRView = std::make_unique<RenderView>(window); 139 mDRView = std::make_unique<RenderView>(window);
139 - mDRView->Create( Vector2::ZERO, BACKEND_MODE ); 140 + mDRView->Create(Vector2::ZERO, BACKEND_MODE);
140 } 141 }
141 142
142 bool OnTouch(Actor actor, const TouchEvent& touch) 143 bool OnTouch(Actor actor, const TouchEvent& touch)
@@ -158,13 +159,13 @@ public: @@ -158,13 +159,13 @@ public:
158 } 159 }
159 160
160 private: 161 private:
161 - Application& mApplication; 162 + Application& mApplication;
162 std::unique_ptr<RenderView> mDRView; 163 std::unique_ptr<RenderView> mDRView;
163 }; 164 };
164 165
165 int DALI_EXPORT_API main(int argc, char** argv) 166 int DALI_EXPORT_API main(int argc, char** argv)
166 { 167 {
167 - Application application = Application::New(&argc, &argv); 168 + Application application = Application::New(&argc, &argv);
168 DirectRenderingExampleController test(application); 169 DirectRenderingExampleController test(application);
169 application.MainLoop(); 170 application.MainLoop();
170 return 0; 171 return 0;