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 | |
martina.kollarova | c0f8a96 | 2015-12-21 09:09:00 | [diff] [blame] | 5 | #include <utility> |
| 6 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 7 | #include "base/at_exit.h" |
| 8 | #include "base/command_line.h" |
avi | 9a24d66 | 2015-12-24 05:38:28 | [diff] [blame] | 9 | #include "base/macros.h" |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 10 | #include "base/memory/ptr_util.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
| 12 | #include "base/run_loop.h" |
dcastagna | 7e223438 | 2017-01-17 17:15:05 | [diff] [blame] | 13 | #include "base/task_scheduler/task_scheduler.h" |
gab | 042f8e9 | 2016-05-11 20:37:03 | [diff] [blame] | 14 | #include "base/threading/thread_task_runner_handle.h" |
Robert Kroeger | b0c2e45 | 2017-06-19 21:36:19 | [diff] [blame^] | 15 | #include "base/trace_event/trace_event.h" |
| 16 | #include "components/tracing/common/trace_to_console.h" |
| 17 | #include "components/tracing/common/tracing_switches.h" |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 18 | #include "ui/display/types/display_snapshot.h" |
| 19 | #include "ui/display/types/native_display_delegate.h" |
| 20 | #include "ui/display/types/native_display_observer.h" |
spang | b7d9049 | 2015-01-12 16:07:56 | [diff] [blame] | 21 | #include "ui/events/event.h" |
kpschoedel | 3b0960a | 2015-05-11 17:52:11 | [diff] [blame] | 22 | #include "ui/events/keycodes/dom/dom_code.h" |
dnicoara | 6e408ee8 | 2015-01-14 03:55:27 | [diff] [blame] | 23 | #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
| 24 | #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
dnicoara | 3f6f5e05 | 2014-12-17 03:30:45 | [diff] [blame] | 25 | #include "ui/gfx/geometry/rect.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 26 | #include "ui/gfx/geometry/size.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 27 | #include "ui/gl/gl_surface.h" |
kylechar | 5b9dec1 | 2016-05-16 15:40:57 | [diff] [blame] | 28 | #include "ui/gl/init/gl_factory.h" |
dnicoara | 3f6f5e05 | 2014-12-17 03:30:45 | [diff] [blame] | 29 | #include "ui/ozone/demo/gl_renderer.h" |
| 30 | #include "ui/ozone/demo/software_renderer.h" |
dnicoara | 52f460f | 2014-12-17 17:18:10 | [diff] [blame] | 31 | #include "ui/ozone/demo/surfaceless_gl_renderer.h" |
dnicoara | 09b7de5d | 2015-02-21 01:20:01 | [diff] [blame] | 32 | #include "ui/ozone/public/ozone_gpu_test_helper.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 33 | #include "ui/ozone/public/ozone_platform.h" |
dnicoara | 52f460f | 2014-12-17 17:18:10 | [diff] [blame] | 34 | #include "ui/ozone/public/ozone_switches.h" |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 35 | #include "ui/platform_window/platform_window.h" |
| 36 | #include "ui/platform_window/platform_window_delegate.h" |
| 37 | |
| 38 | const int kTestWindowWidth = 800; |
| 39 | const int kTestWindowHeight = 600; |
| 40 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 41 | const char kDisableGpu[] = "disable-gpu"; |
| 42 | |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 43 | const char kDisableSurfaceless[] = "disable-surfaceless"; |
| 44 | |
dnicoara | 3f6f5e05 | 2014-12-17 03:30:45 | [diff] [blame] | 45 | const char kWindowSize[] = "window-size"; |
| 46 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 47 | class DemoWindow; |
| 48 | |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 49 | scoped_refptr<gl::GLSurface> CreateGLSurface(gfx::AcceleratedWidget widget) { |
| 50 | scoped_refptr<gl::GLSurface> surface; |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 51 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch(kDisableSurfaceless)) |
kylechar | 5b9dec1 | 2016-05-16 15:40:57 | [diff] [blame] | 52 | surface = gl::init::CreateSurfacelessViewGLSurface(widget); |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 53 | if (!surface) |
kylechar | 5b9dec1 | 2016-05-16 15:40:57 | [diff] [blame] | 54 | surface = gl::init::CreateViewGLSurface(widget); |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 55 | return surface; |
| 56 | } |
| 57 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 58 | class RendererFactory { |
| 59 | public: |
| 60 | enum RendererType { |
| 61 | GL, |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 62 | SOFTWARE, |
| 63 | }; |
| 64 | |
| 65 | RendererFactory(); |
| 66 | ~RendererFactory(); |
| 67 | |
| 68 | bool Initialize(); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 69 | std::unique_ptr<ui::Renderer> CreateRenderer(gfx::AcceleratedWidget widget, |
| 70 | const gfx::Size& size); |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 71 | |
| 72 | private: |
spang | 6f2e80c | 2015-06-17 17:41:04 | [diff] [blame] | 73 | RendererType type_ = SOFTWARE; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 74 | |
| 75 | // Helper for applications that do GL on main thread. |
dnicoara | 09b7de5d | 2015-02-21 01:20:01 | [diff] [blame] | 76 | ui::OzoneGpuTestHelper gpu_helper_; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 77 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(RendererFactory); |
| 79 | }; |
| 80 | |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 81 | class WindowManager : public display::NativeDisplayObserver { |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 82 | public: |
| 83 | WindowManager(const base::Closure& quit_closure); |
| 84 | ~WindowManager() override; |
| 85 | |
| 86 | void Quit(); |
| 87 | |
| 88 | void AddWindow(DemoWindow* window); |
| 89 | void RemoveWindow(DemoWindow* window); |
| 90 | |
| 91 | private: |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 92 | void OnDisplaysAquired( |
| 93 | const std::vector<display::DisplaySnapshot*>& displays); |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 94 | void OnDisplayConfigured(const gfx::Rect& bounds, bool success); |
| 95 | |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 96 | // display::NativeDisplayDelegate: |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 97 | void OnConfigurationChanged() override; |
kylechar | 3f0ff6fe9 | 2016-12-14 15:16:19 | [diff] [blame] | 98 | void OnDisplaySnapshotsInvalidated() override; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 99 | |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 100 | std::unique_ptr<display::NativeDisplayDelegate> delegate_; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 101 | base::Closure quit_closure_; |
| 102 | RendererFactory renderer_factory_; |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 103 | std::vector<std::unique_ptr<DemoWindow>> windows_; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 104 | |
| 105 | // Flags used to keep track of the current state of display configuration. |
| 106 | // |
| 107 | // True if configuring the displays. In this case a new display configuration |
| 108 | // isn't started. |
spang | 6f2e80c | 2015-06-17 17:41:04 | [diff] [blame] | 109 | bool is_configuring_ = false; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 110 | |
| 111 | // If |is_configuring_| is true and another display configuration event |
| 112 | // happens, the event is deferred. This is set to true and a display |
| 113 | // configuration will be scheduled after the current one finishes. |
spang | 6f2e80c | 2015-06-17 17:41:04 | [diff] [blame] | 114 | bool should_configure_ = false; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 115 | |
| 116 | DISALLOW_COPY_AND_ASSIGN(WindowManager); |
| 117 | }; |
| 118 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 119 | class DemoWindow : public ui::PlatformWindowDelegate { |
| 120 | public: |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 121 | DemoWindow(WindowManager* window_manager, |
| 122 | RendererFactory* renderer_factory, |
| 123 | const gfx::Rect& bounds) |
| 124 | : window_manager_(window_manager), |
| 125 | renderer_factory_(renderer_factory), |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 126 | weak_ptr_factory_(this) { |
| 127 | platform_window_ = |
| 128 | ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 129 | } |
spang | a3f3729 | 2014-11-07 23:19:01 | [diff] [blame] | 130 | ~DemoWindow() override {} |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 131 | |
| 132 | gfx::AcceleratedWidget GetAcceleratedWidget() { |
| 133 | // TODO(spang): We should start rendering asynchronously. |
spang@chromium.org | 5afd0bf | 2014-07-29 15:33:57 | [diff] [blame] | 134 | DCHECK_NE(widget_, gfx::kNullAcceleratedWidget) |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 135 | << "Widget not available synchronously"; |
| 136 | return widget_; |
| 137 | } |
| 138 | |
| 139 | gfx::Size GetSize() { return platform_window_->GetBounds().size(); } |
| 140 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 141 | void Start() { |
| 142 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 143 | FROM_HERE, |
| 144 | base::Bind(&DemoWindow::StartOnGpu, weak_ptr_factory_.GetWeakPtr())); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | void Quit() { |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 148 | window_manager_->Quit(); |
| 149 | } |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 150 | |
| 151 | // PlatformWindowDelegate: |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 152 | void OnBoundsChanged(const gfx::Rect& new_bounds) override {} |
| 153 | void OnDamageRect(const gfx::Rect& damaged_region) override {} |
| 154 | void DispatchEvent(ui::Event* event) override { |
moshayedi | 4e662301 | 2016-03-02 04:53:58 | [diff] [blame] | 155 | if (event->IsKeyEvent() && event->AsKeyEvent()->code() == ui::DomCode::US_Q) |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 156 | Quit(); |
| 157 | } |
| 158 | void OnCloseRequest() override { Quit(); } |
| 159 | void OnClosed() override {} |
| 160 | void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} |
| 161 | void OnLostCapture() override {} |
sky | b2afc80 | 2015-06-18 16:24:25 | [diff] [blame] | 162 | void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, |
| 163 | float device_pixel_ratio) override { |
spang@chromium.org | 5afd0bf | 2014-07-29 15:33:57 | [diff] [blame] | 164 | DCHECK_NE(widget, gfx::kNullAcceleratedWidget); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 165 | widget_ = widget; |
| 166 | } |
sievers | 58f43364 | 2015-10-19 18:47:50 | [diff] [blame] | 167 | void OnAcceleratedWidgetDestroyed() override { |
| 168 | NOTREACHED(); |
| 169 | } |
spang | a3f3729 | 2014-11-07 23:19:01 | [diff] [blame] | 170 | void OnActivationChanged(bool active) override {} |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 171 | |
| 172 | private: |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 173 | // Since we pretend to have a GPU process, we should also pretend to |
| 174 | // initialize the GPU resources via a posted task. |
| 175 | void StartOnGpu() { |
| 176 | renderer_ = |
| 177 | renderer_factory_->CreateRenderer(GetAcceleratedWidget(), GetSize()); |
dnicoara | 2f70d99 | 2015-05-25 16:14:24 | [diff] [blame] | 178 | renderer_->Initialize(); |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 179 | } |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 180 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 181 | WindowManager* window_manager_; // Not owned. |
| 182 | RendererFactory* renderer_factory_; // Not owned. |
spang | aa2a372 | 2014-09-03 05:14:58 | [diff] [blame] | 183 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 184 | std::unique_ptr<ui::Renderer> renderer_; |
dnicoara | 3f6f5e05 | 2014-12-17 03:30:45 | [diff] [blame] | 185 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 186 | // Window-related state. |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 187 | std::unique_ptr<ui::PlatformWindow> platform_window_; |
spang | 6f2e80c | 2015-06-17 17:41:04 | [diff] [blame] | 188 | gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 189 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 190 | base::WeakPtrFactory<DemoWindow> weak_ptr_factory_; |
spang | bb91b33b | 2015-01-09 23:06:17 | [diff] [blame] | 191 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 192 | DISALLOW_COPY_AND_ASSIGN(DemoWindow); |
| 193 | }; |
| 194 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 195 | /////////////////////////////////////////////////////////////////////////////// |
| 196 | // RendererFactory implementation: |
| 197 | |
spang | 6f2e80c | 2015-06-17 17:41:04 | [diff] [blame] | 198 | RendererFactory::RendererFactory() { |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | RendererFactory::~RendererFactory() { |
| 202 | } |
| 203 | |
| 204 | bool RendererFactory::Initialize() { |
Joone Hur | 792828838 | 2017-06-15 00:40:19 | [diff] [blame] | 205 | ui::OzonePlatform::InitParams params; |
| 206 | params.single_process = true; |
| 207 | ui::OzonePlatform::InitializeForGPU(params); |
| 208 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 209 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
kylechar | 5b9dec1 | 2016-05-16 15:40:57 | [diff] [blame] | 210 | if (!command_line->HasSwitch(kDisableGpu) && gl::init::InitializeGLOneOff() && |
dnicoara | 09b7de5d | 2015-02-21 01:20:01 | [diff] [blame] | 211 | gpu_helper_.Initialize(base::ThreadTaskRunnerHandle::Get(), |
| 212 | base::ThreadTaskRunnerHandle::Get())) { |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 213 | type_ = GL; |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 214 | } else { |
| 215 | type_ = SOFTWARE; |
| 216 | } |
| 217 | |
| 218 | return true; |
| 219 | } |
| 220 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 221 | std::unique_ptr<ui::Renderer> RendererFactory::CreateRenderer( |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 222 | gfx::AcceleratedWidget widget, |
| 223 | const gfx::Size& size) { |
| 224 | switch (type_) { |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 225 | case GL: { |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 226 | scoped_refptr<gl::GLSurface> surface = CreateGLSurface(widget); |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 227 | if (!surface) |
| 228 | LOG(FATAL) << "Failed to create GL surface"; |
fwang | 0054fa9 | 2016-09-21 13:34:16 | [diff] [blame] | 229 | if (!surface->SupportsAsyncSwap()) |
| 230 | LOG(FATAL) << "GL surface must support SwapBuffersAsync"; |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 231 | if (surface->IsSurfaceless()) |
ricea | eb5cdbe | 2016-08-22 02:47:27 | [diff] [blame] | 232 | return base::MakeUnique<ui::SurfacelessGlRenderer>(widget, surface, |
| 233 | size); |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 234 | else |
ricea | eb5cdbe | 2016-08-22 02:47:27 | [diff] [blame] | 235 | return base::MakeUnique<ui::GlRenderer>(widget, surface, size); |
spang | cb6a15f | 2015-09-16 22:48:55 | [diff] [blame] | 236 | } |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 237 | case SOFTWARE: |
ricea | eb5cdbe | 2016-08-22 02:47:27 | [diff] [blame] | 238 | return base::MakeUnique<ui::SoftwareRenderer>(widget, size); |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | return nullptr; |
| 242 | } |
| 243 | |
| 244 | /////////////////////////////////////////////////////////////////////////////// |
| 245 | // WindowManager implementation: |
| 246 | |
| 247 | WindowManager::WindowManager(const base::Closure& quit_closure) |
| 248 | : delegate_( |
| 249 | ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate()), |
spang | 6f2e80c | 2015-06-17 17:41:04 | [diff] [blame] | 250 | quit_closure_(quit_closure) { |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 251 | if (!renderer_factory_.Initialize()) |
| 252 | LOG(FATAL) << "Failed to initialize renderer factory"; |
| 253 | |
| 254 | if (delegate_) { |
| 255 | delegate_->AddObserver(this); |
| 256 | delegate_->Initialize(); |
| 257 | OnConfigurationChanged(); |
| 258 | } else { |
| 259 | LOG(WARNING) << "No display delegate; falling back to test window"; |
| 260 | int width = kTestWindowWidth; |
| 261 | int height = kTestWindowHeight; |
| 262 | sscanf(base::CommandLine::ForCurrentProcess() |
| 263 | ->GetSwitchValueASCII(kWindowSize) |
| 264 | .c_str(), |
| 265 | "%dx%d", &width, &height); |
| 266 | |
| 267 | DemoWindow* window = new DemoWindow(this, &renderer_factory_, |
| 268 | gfx::Rect(gfx::Size(width, height))); |
| 269 | window->Start(); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | WindowManager::~WindowManager() { |
| 274 | if (delegate_) |
| 275 | delegate_->RemoveObserver(this); |
| 276 | } |
| 277 | |
| 278 | void WindowManager::Quit() { |
| 279 | quit_closure_.Run(); |
| 280 | } |
| 281 | |
| 282 | void WindowManager::OnConfigurationChanged() { |
| 283 | if (is_configuring_) { |
| 284 | should_configure_ = true; |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | is_configuring_ = true; |
| 289 | delegate_->GrabServer(); |
| 290 | delegate_->GetDisplays( |
| 291 | base::Bind(&WindowManager::OnDisplaysAquired, base::Unretained(this))); |
| 292 | } |
| 293 | |
kylechar | 3f0ff6fe9 | 2016-12-14 15:16:19 | [diff] [blame] | 294 | void WindowManager::OnDisplaySnapshotsInvalidated() {} |
| 295 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 296 | void WindowManager::OnDisplaysAquired( |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 297 | const std::vector<display::DisplaySnapshot*>& displays) { |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 298 | windows_.clear(); |
| 299 | |
| 300 | gfx::Point origin; |
tonikitoo | f24d368 | 2017-02-25 05:16:55 | [diff] [blame] | 301 | for (auto* display : displays) { |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 302 | if (!display->native_mode()) { |
| 303 | LOG(ERROR) << "Display " << display->display_id() |
| 304 | << " doesn't have a native mode"; |
| 305 | continue; |
| 306 | } |
| 307 | |
| 308 | delegate_->Configure( |
| 309 | *display, display->native_mode(), origin, |
| 310 | base::Bind(&WindowManager::OnDisplayConfigured, base::Unretained(this), |
| 311 | gfx::Rect(origin, display->native_mode()->size()))); |
| 312 | origin.Offset(display->native_mode()->size().width(), 0); |
| 313 | } |
| 314 | delegate_->UngrabServer(); |
| 315 | is_configuring_ = false; |
| 316 | |
| 317 | if (should_configure_) { |
| 318 | should_configure_ = false; |
| 319 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 320 | FROM_HERE, base::Bind(&WindowManager::OnConfigurationChanged, |
| 321 | base::Unretained(this))); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | void WindowManager::OnDisplayConfigured(const gfx::Rect& bounds, bool success) { |
| 326 | if (success) { |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 327 | std::unique_ptr<DemoWindow> window( |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 328 | new DemoWindow(this, &renderer_factory_, bounds)); |
| 329 | window->Start(); |
martina.kollarova | c0f8a96 | 2015-12-21 09:09:00 | [diff] [blame] | 330 | windows_.push_back(std::move(window)); |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 331 | } else { |
| 332 | LOG(ERROR) << "Failed to configure display at " << bounds.ToString(); |
| 333 | } |
| 334 | } |
| 335 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 336 | int main(int argc, char** argv) { |
avi | 6b10fd0 | 2014-12-23 05:51:23 | [diff] [blame] | 337 | base::CommandLine::Init(argc, argv); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 338 | base::AtExitManager exit_manager; |
| 339 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 340 | // Initialize logging so we can enable VLOG messages. |
| 341 | logging::LoggingSettings settings; |
| 342 | logging::InitLogging(settings); |
| 343 | |
Robert Kroeger | b0c2e45 | 2017-06-19 21:36:19 | [diff] [blame^] | 344 | // Initialize tracing. |
| 345 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 346 | switches::kTraceToConsole)) { |
| 347 | base::trace_event::TraceConfig trace_config = |
| 348 | tracing::GetConfigForTraceToConsole(); |
| 349 | base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 350 | trace_config, base::trace_event::TraceLog::RECORDING_MODE); |
| 351 | } |
| 352 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 353 | // Build UI thread message loop. This is used by platform |
| 354 | // implementations for event polling & running background tasks. |
| 355 | base::MessageLoopForUI message_loop; |
fdoray | f264f1a | 2017-04-26 21:54:58 | [diff] [blame] | 356 | base::TaskScheduler::CreateAndStartWithDefaultParams("OzoneDemo"); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 357 | |
| 358 | ui::OzonePlatform::InitializeForUI(); |
dnicoara | 6e408ee8 | 2015-01-14 03:55:27 | [diff] [blame] | 359 | ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() |
| 360 | ->SetCurrentLayoutByName("us"); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 361 | |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 362 | base::RunLoop run_loop; |
spang | bb91b33b | 2015-01-09 23:06:17 | [diff] [blame] | 363 | |
dnicoara | 655c4e6 | 2015-02-11 18:25:56 | [diff] [blame] | 364 | WindowManager window_manager(run_loop.QuitClosure()); |
spang | bb91b33b | 2015-01-09 23:06:17 | [diff] [blame] | 365 | |
| 366 | run_loop.Run(); |
spang@chromium.org | 85905ed | 2014-07-24 18:48:41 | [diff] [blame] | 367 | |
| 368 | return 0; |
| 369 | } |