| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/platform/x11/ozone_platform_x11.h" | 5 #include "ui/ozone/platform/x11/ozone_platform_x11.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "ui/base/x/x11_util.h" |
| 15 #include "ui/display/fake_display_delegate.h" | 16 #include "ui/display/fake_display_delegate.h" |
| 16 #include "ui/events/platform/x11/x11_event_source_libevent.h" | 17 #include "ui/events/platform/x11/x11_event_source_libevent.h" |
| 17 #include "ui/ozone/common/stub_overlay_manager.h" | 18 #include "ui/ozone/common/stub_overlay_manager.h" |
| 18 #include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h" | 19 #include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h" |
| 19 #include "ui/ozone/platform/x11/x11_surface_factory.h" | 20 #include "ui/ozone/platform/x11/x11_surface_factory.h" |
| 20 #include "ui/ozone/public/gpu_platform_support_host.h" | 21 #include "ui/ozone/public/gpu_platform_support_host.h" |
| 21 #include "ui/ozone/public/input_controller.h" | 22 #include "ui/ozone/public/input_controller.h" |
| 22 #include "ui/ozone/public/ozone_platform.h" | 23 #include "ui/ozone/public/ozone_platform.h" |
| 23 #include "ui/ozone/public/system_input_injector.h" | 24 #include "ui/ozone/public/system_input_injector.h" |
| 24 #include "ui/platform_window/platform_window.h" | 25 #include "ui/platform_window/platform_window.h" |
| 25 #include "ui/platform_window/x11/x11_window_manager_ozone.h" | 26 #include "ui/platform_window/x11/x11_window_manager_ozone.h" |
| 26 #include "ui/platform_window/x11/x11_window_ozone.h" | 27 #include "ui/platform_window/x11/x11_window_ozone.h" |
| 27 | 28 |
| 28 namespace ui { | 29 namespace ui { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // Returns true if we should operate in Mus mode. | 33 // Returns true if Ozone is running inside the mus process. |
| 33 bool RunningInsideMus() { | 34 bool RunningInsideMus() { |
| 34 bool has_channel_handle = base::CommandLine::ForCurrentProcess()->HasSwitch( | 35 bool has_channel_handle = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 35 "mojo-platform-channel-handle"); | 36 "mojo-platform-channel-handle"); |
| 36 return has_channel_handle; | 37 return has_channel_handle; |
| 37 } | 38 } |
| 38 | 39 |
| 39 // Singleton OzonePlatform implementation for Linux X11 platform. | 40 // Singleton OzonePlatform implementation for X11 platform. |
| 40 class OzonePlatformX11 : public OzonePlatform { | 41 class OzonePlatformX11 : public OzonePlatform { |
| 41 public: | 42 public: |
| 42 OzonePlatformX11() { | 43 OzonePlatformX11() {} |
| 43 // If we're running in Mus mode both the UI and GPU components of Ozone will | |
| 44 // be running in the same process. Enable X11 concurrent thread support. | |
| 45 if (RunningInsideMus()) | |
| 46 XInitThreads(); | |
| 47 } | |
| 48 | 44 |
| 49 ~OzonePlatformX11() override {} | 45 ~OzonePlatformX11() override {} |
| 50 | 46 |
| 51 // OzonePlatform: | 47 // OzonePlatform: |
| 52 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { | 48 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { |
| 53 return surface_factory_ozone_.get(); | 49 return surface_factory_ozone_.get(); |
| 54 } | 50 } |
| 55 | 51 |
| 56 ui::OverlayManagerOzone* GetOverlayManager() override { | 52 ui::OverlayManagerOzone* GetOverlayManager() override { |
| 57 return overlay_manager_.get(); | 53 return overlay_manager_.get(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 81 window->Create(); | 77 window->Create(); |
| 82 window->SetTitle(base::ASCIIToUTF16("Ozone X11")); | 78 window->SetTitle(base::ASCIIToUTF16("Ozone X11")); |
| 83 return std::move(window); | 79 return std::move(window); |
| 84 } | 80 } |
| 85 | 81 |
| 86 std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() | 82 std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() |
| 87 override { | 83 override { |
| 88 return base::MakeUnique<display::FakeDisplayDelegate>(); | 84 return base::MakeUnique<display::FakeDisplayDelegate>(); |
| 89 } | 85 } |
| 90 | 86 |
| 91 void InitializeUI() override { | 87 void InitializeUI(const InitParams& params) override { |
| 88 InitializeCommon(params); |
| 92 window_manager_.reset(new X11WindowManagerOzone); | 89 window_manager_.reset(new X11WindowManagerOzone); |
| 93 if (!event_source_) | |
| 94 event_source_.reset(new X11EventSourceLibevent(gfx::GetXDisplay())); | |
| 95 overlay_manager_.reset(new StubOverlayManager()); | 90 overlay_manager_.reset(new StubOverlayManager()); |
| 96 input_controller_ = CreateStubInputController(); | 91 input_controller_ = CreateStubInputController(); |
| 97 cursor_factory_ozone_.reset(new X11CursorFactoryOzone()); | 92 cursor_factory_ozone_.reset(new X11CursorFactoryOzone()); |
| 98 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); | 93 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); |
| 99 } | 94 } |
| 100 | 95 |
| 101 void InitializeGPU() override { | 96 void InitializeUI() override { NOTREACHED(); } |
| 102 if (!event_source_) | 97 |
| 103 event_source_.reset(new X11EventSourceLibevent(gfx::GetXDisplay())); | 98 void InitializeGPU(const InitParams& params) override { |
| 99 InitializeCommon(params); |
| 104 surface_factory_ozone_.reset(new X11SurfaceFactory()); | 100 surface_factory_ozone_.reset(new X11SurfaceFactory()); |
| 105 } | 101 } |
| 106 | 102 |
| 103 void InitializeGPU() override { NOTREACHED(); } |
| 104 |
| 107 base::MessageLoop::Type GetMessageLoopTypeForGpu() override { | 105 base::MessageLoop::Type GetMessageLoopTypeForGpu() override { |
| 108 // When Ozone X11 backend is running use an UI loop to grab Expose events. | 106 // When Ozone X11 backend is running use an UI loop to grab Expose events. |
| 109 // See GLSurfaceGLX and https://crbug.com/326995. | 107 // See GLSurfaceGLX and https://crbug.com/326995. |
| 110 return base::MessageLoop::TYPE_UI; | 108 return base::MessageLoop::TYPE_UI; |
| 111 } | 109 } |
| 112 | 110 |
| 113 private: | 111 private: |
| 114 // Objects in the browser process. | 112 // Performs initialization steps need by both UI and GPU. |
| 113 void InitializeCommon(const InitParams& params) { |
| 114 // TODO(kylechar): Add DCHECK we only enter InitializeCommon() twice for |
| 115 // single process mode. |
| 116 if (common_initialized_) |
| 117 return; |
| 118 |
| 119 // If both UI and GPU are running in the same process then XInitThreads() |
| 120 // must be the first Xlib call. |
| 121 if (params.single_process || RunningInsideMus()) |
| 122 XInitThreads(); |
| 123 |
| 124 ui::SetDefaultX11ErrorHandlers(); |
| 125 event_source_.reset(new X11EventSourceLibevent(gfx::GetXDisplay())); |
| 126 |
| 127 common_initialized_ = true; |
| 128 } |
| 129 |
| 130 bool common_initialized_ = false; |
| 131 |
| 132 // Objects in the UI process. |
| 115 std::unique_ptr<X11WindowManagerOzone> window_manager_; | 133 std::unique_ptr<X11WindowManagerOzone> window_manager_; |
| 116 std::unique_ptr<OverlayManagerOzone> overlay_manager_; | 134 std::unique_ptr<OverlayManagerOzone> overlay_manager_; |
| 117 std::unique_ptr<InputController> input_controller_; | 135 std::unique_ptr<InputController> input_controller_; |
| 118 std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_; | 136 std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_; |
| 119 std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; | 137 std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; |
| 120 | 138 |
| 121 // Objects in the GPU process. | 139 // Objects in the GPU process. |
| 122 std::unique_ptr<X11SurfaceFactory> surface_factory_ozone_; | 140 std::unique_ptr<X11SurfaceFactory> surface_factory_ozone_; |
| 123 | 141 |
| 124 // Objects in both browser and GPU process. | 142 // Objects in both UI and GPU process. |
| 125 std::unique_ptr<X11EventSourceLibevent> event_source_; | 143 std::unique_ptr<X11EventSourceLibevent> event_source_; |
| 126 | 144 |
| 127 DISALLOW_COPY_AND_ASSIGN(OzonePlatformX11); | 145 DISALLOW_COPY_AND_ASSIGN(OzonePlatformX11); |
| 128 }; | 146 }; |
| 129 | 147 |
| 130 } // namespace | 148 } // namespace |
| 131 | 149 |
| 132 OzonePlatform* CreateOzonePlatformX11() { | 150 OzonePlatform* CreateOzonePlatformX11() { |
| 133 return new OzonePlatformX11; | 151 return new OzonePlatformX11; |
| 134 } | 152 } |
| 135 | 153 |
| 136 } // namespace ui | 154 } // namespace ui |
| OLD | NEW |