blob: 0fc1f19c32d3bab586d7963118529f0ef040c7a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/headless/ozone_platform_headless.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/ozone/common/native_display_delegate_ozone.h"
#include "ui/ozone/common/stub_overlay_manager.h"
#include "ui/ozone/platform/headless/headless_surface_factory.h"
#include "ui/ozone/platform/headless/headless_window.h"
#include "ui/ozone/platform/headless/headless_window_manager.h"
#include "ui/ozone/public/cursor_factory_ozone.h"
#include "ui/ozone/public/gpu_platform_support.h"
#include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/input_controller.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ozone_switches.h"
#include "ui/ozone/public/system_input_injector.h"
namespace ui {
namespace {
// A headless implementation of PlatformEventSource that we can instantiate to
// make
// sure that the PlatformEventSource has an instance while in unit tests.
class HeadlessPlatformEventSource : public ui::PlatformEventSource {
public:
HeadlessPlatformEventSource() {}
~HeadlessPlatformEventSource() override {}
private:
DISALLOW_COPY_AND_ASSIGN(HeadlessPlatformEventSource);
};
// OzonePlatform for headless mode
class OzonePlatformHeadless : public OzonePlatform {
public:
OzonePlatformHeadless(const base::FilePath& dump_file)
: file_path_(dump_file) {}
~OzonePlatformHeadless() override {}
// OzonePlatform:
ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
return surface_factory_.get();
}
OverlayManagerOzone* GetOverlayManager() override {
return overlay_manager_.get();
}
CursorFactoryOzone* GetCursorFactoryOzone() override {
return cursor_factory_ozone_.get();
}
InputController* GetInputController() override {
return input_controller_.get();
}
GpuPlatformSupport* GetGpuPlatformSupport() override {
return gpu_platform_support_.get();
}
GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
return gpu_platform_support_host_.get();
}
scoped_ptr<SystemInputInjector> CreateSystemInputInjector() override {
return nullptr; // no input injection support.
}
scoped_ptr<PlatformWindow> CreatePlatformWindow(
PlatformWindowDelegate* delegate,
const gfx::Rect& bounds) override {
return make_scoped_ptr<PlatformWindow>(
new HeadlessWindow(delegate, window_manager_.get(), bounds));
}
scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
return make_scoped_ptr(new NativeDisplayDelegateOzone());
}
base::ScopedFD OpenClientNativePixmapDevice() const override {
return base::ScopedFD();
}
void InitializeUI() override {
window_manager_.reset(new HeadlessWindowManager(file_path_));
window_manager_->Initialize();
surface_factory_.reset(new HeadlessSurfaceFactory(window_manager_.get()));
// This unbreaks tests that create their own.
if (!PlatformEventSource::GetInstance())
platform_event_source_.reset(new HeadlessPlatformEventSource);
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
make_scoped_ptr(new StubKeyboardLayoutEngine()));
overlay_manager_.reset(new StubOverlayManager());
input_controller_ = CreateStubInputController();
cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
}
void InitializeGPU() override {
if (!surface_factory_)
surface_factory_.reset(new HeadlessSurfaceFactory());
gpu_platform_support_.reset(CreateStubGpuPlatformSupport());
}
private:
scoped_ptr<HeadlessWindowManager> window_manager_;
scoped_ptr<HeadlessSurfaceFactory> surface_factory_;
scoped_ptr<PlatformEventSource> platform_event_source_;
scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_;
scoped_ptr<InputController> input_controller_;
scoped_ptr<GpuPlatformSupport> gpu_platform_support_;
scoped_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
scoped_ptr<OverlayManagerOzone> overlay_manager_;
base::FilePath file_path_;
DISALLOW_COPY_AND_ASSIGN(OzonePlatformHeadless);
};
} // namespace
OzonePlatform* CreateOzonePlatformHeadless() {
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
base::FilePath location;
if (cmd->HasSwitch(switches::kOzoneDumpFile))
location = cmd->GetSwitchValuePath(switches::kOzoneDumpFile);
return new OzonePlatformHeadless(location);
}
} // namespace ui
|