| 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> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return std::move(window); | 79 return std::move(window); |
| 80 } | 80 } |
| 81 | 81 |
| 82 std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() | 82 std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() |
| 83 override { | 83 override { |
| 84 return base::MakeUnique<display::FakeDisplayDelegate>(); | 84 return base::MakeUnique<display::FakeDisplayDelegate>(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void InitializeUI(const InitParams& params) override { | 87 void InitializeUI(const InitParams& params) override { |
| 88 InitializeCommon(params); | 88 InitializeCommon(params); |
| 89 window_manager_.reset(new X11WindowManagerOzone); | 89 CreatePlatformEventSource(); |
| 90 overlay_manager_.reset(new StubOverlayManager()); | 90 window_manager_ = base::MakeUnique<X11WindowManagerOzone>(); |
| 91 overlay_manager_ = base::MakeUnique<StubOverlayManager>(); |
| 91 input_controller_ = CreateStubInputController(); | 92 input_controller_ = CreateStubInputController(); |
| 92 cursor_factory_ozone_.reset(new X11CursorFactoryOzone()); | 93 cursor_factory_ozone_ = base::MakeUnique<X11CursorFactoryOzone>(); |
| 93 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); | 94 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void InitializeUI() override { NOTREACHED(); } | 97 void InitializeUI() override { NOTREACHED(); } |
| 97 | 98 |
| 98 void InitializeGPU(const InitParams& params) override { | 99 void InitializeGPU(const InitParams& params) override { |
| 99 InitializeCommon(params); | 100 InitializeCommon(params); |
| 100 surface_factory_ozone_.reset(new X11SurfaceFactory()); | 101 |
| 102 // In single process mode either the UI thread will create an event source |
| 103 // or it's a test and an event source isn't desired. |
| 104 if (!params.single_process && !RunningInsideMus()) |
| 105 CreatePlatformEventSource(); |
| 106 |
| 107 surface_factory_ozone_ = base::MakeUnique<X11SurfaceFactory>(); |
| 101 } | 108 } |
| 102 | 109 |
| 103 void InitializeGPU() override { NOTREACHED(); } | 110 void InitializeGPU() override { NOTREACHED(); } |
| 104 | 111 |
| 105 base::MessageLoop::Type GetMessageLoopTypeForGpu() override { | 112 base::MessageLoop::Type GetMessageLoopTypeForGpu() override { |
| 106 // When Ozone X11 backend is running use an UI loop to grab Expose events. | 113 // When Ozone X11 backend is running use an UI loop to grab Expose events. |
| 107 // See GLSurfaceGLX and https://crbug.com/326995. | 114 // See GLSurfaceGLX and https://crbug.com/326995. |
| 108 return base::MessageLoop::TYPE_UI; | 115 return base::MessageLoop::TYPE_UI; |
| 109 } | 116 } |
| 110 | 117 |
| 111 private: | 118 private: |
| 112 // Performs initialization steps need by both UI and GPU. | 119 // Performs initialization steps need by both UI and GPU. |
| 113 void InitializeCommon(const InitParams& params) { | 120 void InitializeCommon(const InitParams& params) { |
| 114 // TODO(kylechar): Add DCHECK we only enter InitializeCommon() twice for | 121 // TODO(kylechar): Add DCHECK we only enter InitializeCommon() twice for |
| 115 // single process mode. | 122 // single process mode. |
| 116 if (common_initialized_) | 123 if (common_initialized_) |
| 117 return; | 124 return; |
| 118 | 125 |
| 119 // If both UI and GPU are running in the same process then XInitThreads() | 126 // In single process mode XInitThreads() must be the first Xlib call. |
| 120 // must be the first Xlib call. | |
| 121 if (params.single_process || RunningInsideMus()) | 127 if (params.single_process || RunningInsideMus()) |
| 122 XInitThreads(); | 128 XInitThreads(); |
| 123 | 129 |
| 124 ui::SetDefaultX11ErrorHandlers(); | 130 ui::SetDefaultX11ErrorHandlers(); |
| 125 event_source_.reset(new X11EventSourceLibevent(gfx::GetXDisplay())); | |
| 126 | 131 |
| 127 common_initialized_ = true; | 132 common_initialized_ = true; |
| 128 } | 133 } |
| 129 | 134 |
| 135 // Creates |event_source_| if it doesn't already exist. |
| 136 void CreatePlatformEventSource() { |
| 137 if (event_source_) |
| 138 return; |
| 139 |
| 140 XDisplay* display = gfx::GetXDisplay(); |
| 141 event_source_ = base::MakeUnique<X11EventSourceLibevent>(display); |
| 142 } |
| 143 |
| 130 bool common_initialized_ = false; | 144 bool common_initialized_ = false; |
| 131 | 145 |
| 132 // Objects in the UI process. | 146 // Objects in the UI process. |
| 133 std::unique_ptr<X11WindowManagerOzone> window_manager_; | 147 std::unique_ptr<X11WindowManagerOzone> window_manager_; |
| 134 std::unique_ptr<OverlayManagerOzone> overlay_manager_; | 148 std::unique_ptr<OverlayManagerOzone> overlay_manager_; |
| 135 std::unique_ptr<InputController> input_controller_; | 149 std::unique_ptr<InputController> input_controller_; |
| 136 std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_; | 150 std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_; |
| 137 std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; | 151 std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; |
| 138 | 152 |
| 139 // Objects in the GPU process. | 153 // Objects in the GPU process. |
| 140 std::unique_ptr<X11SurfaceFactory> surface_factory_ozone_; | 154 std::unique_ptr<X11SurfaceFactory> surface_factory_ozone_; |
| 141 | 155 |
| 142 // Objects in both UI and GPU process. | 156 // Objects in both UI and GPU process. |
| 143 std::unique_ptr<X11EventSourceLibevent> event_source_; | 157 std::unique_ptr<X11EventSourceLibevent> event_source_; |
| 144 | 158 |
| 145 DISALLOW_COPY_AND_ASSIGN(OzonePlatformX11); | 159 DISALLOW_COPY_AND_ASSIGN(OzonePlatformX11); |
| 146 }; | 160 }; |
| 147 | 161 |
| 148 } // namespace | 162 } // namespace |
| 149 | 163 |
| 150 OzonePlatform* CreateOzonePlatformX11() { | 164 OzonePlatform* CreateOzonePlatformX11() { |
| 151 return new OzonePlatformX11; | 165 return new OzonePlatformX11; |
| 152 } | 166 } |
| 153 | 167 |
| 154 } // namespace ui | 168 } // namespace ui |
| OLD | NEW |