spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Kristian H. Kristensen | 30a4f93 | 2018-03-05 18:58:59 | [diff] [blame] | 5 | #include <iostream> |
Michael Spang | 2829d0d | 2019-03-21 21:10:25 | [diff] [blame] | 6 | #include <memory> |
martina.kollarova | c0f8a96 | 2015-12-21 09:09:00 | [diff] [blame] | 7 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 8 | #include "base/at_exit.h" |
| 9 | #include "base/command_line.h" |
Peng Huang | b97e188 | 2018-02-23 18:43:21 | [diff] [blame] | 10 | #include "base/debug/stack_trace.h" |
Alexander Timin | 4f9c35c | 2018-11-01 20:15:20 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 12 | #include "base/run_loop.h" |
Gabriel Charette | 52fa3ae | 2019-04-15 21:44:37 | [diff] [blame^] | 13 | #include "base/task/thread_pool/thread_pool.h" |
Robert Kroeger | b0c2e45 | 2017-06-19 21:36:19 | [diff] [blame] | 14 | #include "base/trace_event/trace_event.h" |
Mustafa Çamurcu | 92fe48f | 2018-04-24 21:51:01 | [diff] [blame] | 15 | #include "build/build_config.h" |
Robert Kroeger | b0c2e45 | 2017-06-19 21:36:19 | [diff] [blame] | 16 | #include "components/tracing/common/trace_to_console.h" |
| 17 | #include "components/tracing/common/tracing_switches.h" |
Michael Spang | 1523cdb | 2019-03-18 22:01:55 | [diff] [blame] | 18 | #include "mojo/core/embedder/embedder.h" |
dnicoara | 6e408ee8 | 2015-01-14 03:55:27 | [diff] [blame] | 19 | #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
| 20 | #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
Michael Spang | c44ad7df | 2018-04-25 20:23:27 | [diff] [blame] | 21 | #include "ui/ozone/demo/simple_renderer_factory.h" |
Daniel Nicoara | e0723f13 | 2018-03-22 22:00:08 | [diff] [blame] | 22 | #include "ui/ozone/demo/window_manager.h" |
Michael Spang | 1523cdb | 2019-03-18 22:01:55 | [diff] [blame] | 23 | #include "ui/ozone/public/ozone_gpu_test_helper.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 24 | #include "ui/ozone/public/ozone_platform.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 25 | |
Kristian H. Kristensen | 30a4f93 | 2018-03-05 18:58:59 | [diff] [blame] | 26 | const char kHelp[] = "help"; |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 27 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 28 | int main(int argc, char** argv) { |
avi | 6b10fd0 | 2014-12-23 05:51:23 | [diff] [blame] | 29 | base::CommandLine::Init(argc, argv); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 30 | base::AtExitManager exit_manager; |
| 31 | |
Peng Huang | b97e188 | 2018-02-23 18:43:21 | [diff] [blame] | 32 | base::debug::EnableInProcessStackDumping(); |
| 33 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 34 | // Initialize logging so we can enable VLOG messages. |
| 35 | logging::LoggingSettings settings; |
Mustafa Çamurcu | 92fe48f | 2018-04-24 21:51:01 | [diff] [blame] | 36 | |
| 37 | // Logs to system debug by default on POSIX. |
| 38 | #if defined(OS_WIN) |
| 39 | settings.log_file = FILE_PATH_LITERAL("ozone_demo.log"); |
| 40 | #endif |
| 41 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 42 | logging::InitLogging(settings); |
| 43 | |
Kristian H. Kristensen | 30a4f93 | 2018-03-05 18:58:59 | [diff] [blame] | 44 | if (base::CommandLine::ForCurrentProcess()->HasSwitch(kHelp)) { |
Alexandros Frantzis | ddd5a91 | 2018-05-17 03:24:22 | [diff] [blame] | 45 | std::cout << "Usage:\n\n" |
| 46 | " --disable-gpu Force software rendering\n" |
| 47 | " --disable-surfaceless Don't use surfaceless EGL\n" |
| 48 | " --window-size=WIDTHxHEIGHT Specify window size\n" |
| 49 | " --partial-primary-plane " |
| 50 | "Use smaller than fullscreen primary plane\n" |
| 51 | " --enable-overlay Use an overlay plane\n" |
| 52 | " --disable-primary-plane Don't use the primary plane\n" |
| 53 | " --use-gpu-fences " |
| 54 | "Use GpuFences for buffer display synchronization\n"; |
Kristian H. Kristensen | 30a4f93 | 2018-03-05 18:58:59 | [diff] [blame] | 55 | |
| 56 | // TODO(hoegsberg): We should add a little more help text about how these |
| 57 | // options interact and depend on each other. |
| 58 | |
| 59 | exit(EXIT_SUCCESS); |
| 60 | } |
| 61 | |
Robert Kroeger | b0c2e45 | 2017-06-19 21:36:19 | [diff] [blame] | 62 | // Initialize tracing. |
| 63 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 64 | switches::kTraceToConsole)) { |
| 65 | base::trace_event::TraceConfig trace_config = |
| 66 | tracing::GetConfigForTraceToConsole(); |
| 67 | base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 68 | trace_config, base::trace_event::TraceLog::RECORDING_MODE); |
| 69 | } |
| 70 | |
Michael Spang | 1523cdb | 2019-03-18 22:01:55 | [diff] [blame] | 71 | mojo::core::Init(); |
| 72 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 73 | base::MessageLoopForUI message_loop; |
Gabriel Charette | 52fa3ae | 2019-04-15 21:44:37 | [diff] [blame^] | 74 | base::ThreadPool::CreateAndStartWithDefaultParams("OzoneDemo"); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 75 | |
kylechar | d0cd2b3 | 2017-09-19 00:30:16 | [diff] [blame] | 76 | ui::OzonePlatform::InitParams params; |
| 77 | params.single_process = true; |
Michael Spang | 1523cdb | 2019-03-18 22:01:55 | [diff] [blame] | 78 | params.using_mojo = ui::OzonePlatform::EnsureInstance() |
| 79 | ->GetPlatformProperties() |
| 80 | .requires_mojo; |
kylechar | d0cd2b3 | 2017-09-19 00:30:16 | [diff] [blame] | 81 | ui::OzonePlatform::InitializeForUI(params); |
dnicoara | 6e408ee8 | 2015-01-14 03:55:27 | [diff] [blame] | 82 | ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() |
| 83 | ->SetCurrentLayoutByName("us"); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 84 | |
Michael Spang | 1523cdb | 2019-03-18 22:01:55 | [diff] [blame] | 85 | ui::OzonePlatform::InitializeForGPU(params); |
| 86 | ui::OzonePlatform::GetInstance()->AfterSandboxEntry(); |
| 87 | |
| 88 | std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper; |
| 89 | if (!params.using_mojo) { |
| 90 | // OzoneGpuTestHelper transports Chrome IPC messages between host & gpu code |
| 91 | // in single process mode. We don't use both Chrome IPC and mojo, so only |
| 92 | // initialize it for non-mojo platforms. |
| 93 | gpu_helper = std::make_unique<ui::OzoneGpuTestHelper>(); |
| 94 | gpu_helper->Initialize(base::ThreadTaskRunnerHandle::Get()); |
| 95 | } |
| 96 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 97 | base::RunLoop run_loop; |
spang | bb91b33b | 2015-01-09 23:06:17 | [diff] [blame] | 98 | |
Michael Spang | c44ad7df | 2018-04-25 20:23:27 | [diff] [blame] | 99 | ui::WindowManager window_manager( |
| 100 | std::make_unique<ui::SimpleRendererFactory>(), run_loop.QuitClosure()); |
spang | bb91b33b | 2015-01-09 23:06:17 | [diff] [blame] | 101 | |
| 102 | run_loop.Run(); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 103 | |
| 104 | return 0; |
| 105 | } |