Commit a378a8f4 authored by Mohsen Izadi's avatar Mohsen Izadi Committed by Commit Bot

Use OzonePlatform::PlatformProperties::requires_mojo only after init

Some ozone platforms (e.g. Wayland) require mojo communication while
others either don't use mojo or use it only if OzoneDrmMojo feature is
enabled. |requires_mojo| shows whether a platform requires mojo or not.

|requires_mojo| is used in some places before OzonePlatform is
initialized.

Part of this usage is for populating InitParams used for OzonePlatform
initialization. These can easily be removed as each type of
OzonePlatform knows whether it requires mojo or not when it is being
initialized. There is no need to pass this value to the initialization
codes.

Other cases use this and other info to check whether mojo is actually
used or not. None of these cases really need to happen before
initialization and can be moved to after initialization.

This change is part of a larger effort to remove the need for
OzonePlatform instance before it is initialized.

This CL also cleans up some code in OzonePlatform implementations,
mostly using std::make_unique<> instead of new operator.

BUG=958387

Change-Id: Ie44c6e441389e1f119f6458bc4e1c15bdc1d83e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1604112Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Mohsen Izadi <mohsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683452}
parent acda9c06
......@@ -55,7 +55,7 @@ class InteractiveUITestSuite : public ChromeTestSuite {
#elif defined(USE_OZONE) && defined(OS_LINUX)
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::EnsureInstance()->InitializeForUI(std::move(params));
ui::OzonePlatform::InitializeForUI(params);
#elif defined(OS_LINUX)
ui_controls::InstallUIControlsAura(
views::test::CreateUIControlsDesktopAura());
......
......@@ -272,6 +272,7 @@ mojom::GpuService* GpuHostImpl::gpu_service() {
}
#if defined(USE_OZONE)
void GpuHostImpl::InitOzone() {
// Ozone needs to send the primary DRM device to GPU service as early as
// possible to ensure the latter always has a valid device.
......@@ -280,9 +281,8 @@ void GpuHostImpl::InitOzone() {
// The Ozone/Wayland requires mojo communication to be established to be
// functional with a separate gpu process. Thus, using the PlatformProperties,
// check if there is such a requirement.
if (features::IsOzoneDrmMojo() || ui::OzonePlatform::EnsureInstance()
->GetPlatformProperties()
.requires_mojo) {
if (features::IsOzoneDrmMojo() ||
ui::OzonePlatform::GetInstance()->GetPlatformProperties().requires_mojo) {
// TODO(rjkroege): Remove the legacy IPC code paths when no longer
// necessary. https://crbug.com/806092
auto interface_binder = base::BindRepeating(&GpuHostImpl::BindInterface,
......
......@@ -246,10 +246,7 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
// may also have started at this point.
ui::OzonePlatform::InitParams params;
params.single_process = false;
params.using_mojo =
features::IsOzoneDrmMojo() || ui::OzonePlatform::EnsureInstance()
->GetPlatformProperties()
.requires_mojo;
params.using_mojo = features::IsOzoneDrmMojo();
params.viz_display_compositor = features::IsVizDisplayCompositorEnabled();
ui::OzonePlatform::InitializeForGPU(params);
const std::vector<gfx::BufferFormat> supported_buffer_formats_for_texturing =
......@@ -481,10 +478,7 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line,
#if defined(USE_OZONE)
ui::OzonePlatform::InitParams params;
params.single_process = true;
params.using_mojo =
features::IsOzoneDrmMojo() || ui::OzonePlatform::EnsureInstance()
->GetPlatformProperties()
.requires_mojo;
params.using_mojo = features::IsOzoneDrmMojo();
params.viz_display_compositor = features::IsVizDisplayCompositorEnabled();
ui::OzonePlatform::InitializeForGPU(params);
const std::vector<gfx::BufferFormat> supported_buffer_formats_for_texturing =
......
......@@ -60,7 +60,8 @@ void VideoTestEnvironment::SetUp() {
// video decode acceleration.
LOG(WARNING) << "Initializing Ozone Platform...\n"
"If this hangs indefinitely please call 'stop ui' first!";
ui::OzonePlatform::InitParams params = {.single_process = false};
ui::OzonePlatform::InitParams params;
params.single_process = false;
ui::OzonePlatform::InitializeForUI(params);
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
......
......@@ -76,9 +76,6 @@ int main(int argc, char** argv) {
ui::OzonePlatform::InitParams params;
params.single_process = true;
params.using_mojo = ui::OzonePlatform::EnsureInstance()
->GetPlatformProperties()
.requires_mojo;
ui::OzonePlatform::InitializeForUI(params);
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()
->SetCurrentLayoutByName("us");
......@@ -87,7 +84,9 @@ int main(int argc, char** argv) {
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper;
if (!params.using_mojo) {
if (!ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.requires_mojo) {
// OzoneGpuTestHelper transports Chrome IPC messages between host & gpu code
// in single process mode. We don't use both Chrome IPC and mojo, so only
// initialize it for non-mojo platforms.
......
......@@ -51,9 +51,6 @@ int main(int argc, char** argv) {
ui::OzonePlatform::InitParams params;
params.single_process = true;
params.using_mojo = ui::OzonePlatform::EnsureInstance()
->GetPlatformProperties()
.requires_mojo;
ui::OzonePlatform::InitializeForUI(params);
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()
->SetCurrentLayoutByName("us");
......@@ -62,7 +59,9 @@ int main(int argc, char** argv) {
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper;
if (!params.using_mojo) {
if (!ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.requires_mojo) {
// OzoneGpuTestHelper transports Chrome IPC messages between host & gpu code
// in single process mode. We don't use both Chrome IPC and mojo, so only
// initialize it for non-mojo platforms.
......
......@@ -69,7 +69,7 @@ class OzonePlatformCast : public OzonePlatform {
"allow-dummy-software-rendering");
if (allow_dummy_software_rendering) {
LOG(INFO) << "Using dummy SurfaceFactoryCast";
surface_factory_.reset(new SurfaceFactoryCast());
surface_factory_ = std::make_unique<SurfaceFactoryCast>();
return surface_factory_.get();
}
......@@ -96,8 +96,7 @@ class OzonePlatformCast : public OzonePlatform {
std::unique_ptr<PlatformWindow> CreatePlatformWindow(
PlatformWindowDelegate* delegate,
PlatformWindowInitProperties properties) override {
return base::WrapUnique<PlatformWindow>(
new PlatformWindowCast(delegate, properties.bounds));
return std::make_unique<PlatformWindowCast>(delegate, properties.bounds);
}
std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate()
override {
......@@ -117,8 +116,8 @@ class OzonePlatformCast : public OzonePlatform {
void InitializeUI(const InitParams& params) override {
device_manager_ = CreateDeviceManager();
overlay_manager_.reset(new OverlayManagerCast());
cursor_factory_.reset(new CursorFactoryOzone());
overlay_manager_ = std::make_unique<OverlayManagerCast>();
cursor_factory_ = std::make_unique<CursorFactoryOzone>();
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
// Enable dummy software rendering support if GPU process disabled
......@@ -134,15 +133,16 @@ class OzonePlatformCast : public OzonePlatform {
std::make_unique<StubKeyboardLayoutEngine>());
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()
->SetCurrentLayoutByName("us");
event_factory_ozone_.reset(new EventFactoryEvdev(
event_factory_ozone_ = std::make_unique<EventFactoryEvdev>(
nullptr, device_manager_.get(),
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine());
if (enable_dummy_software_rendering)
surface_factory_.reset(new SurfaceFactoryCast());
surface_factory_ = std::make_unique<SurfaceFactoryCast>();
}
void InitializeGPU(const InitParams& params) override {
surface_factory_.reset(new SurfaceFactoryCast(std::move(egl_platform_)));
surface_factory_ =
std::make_unique<SurfaceFactoryCast>(std::move(egl_platform_));
}
private:
......
......@@ -190,8 +190,8 @@ class OzonePlatformGbm : public OzonePlatform {
host_thread_ = base::PlatformThread::CurrentRef();
device_manager_ = CreateDeviceManager();
window_manager_.reset(new DrmWindowHostManager());
cursor_.reset(new DrmCursor(window_manager_.get()));
window_manager_ = std::make_unique<DrmWindowHostManager>();
cursor_ = std::make_unique<DrmCursor>(window_manager_.get());
#if BUILDFLAG(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
......@@ -201,9 +201,9 @@ class OzonePlatformGbm : public OzonePlatform {
std::make_unique<StubKeyboardLayoutEngine>());
#endif
event_factory_ozone_.reset(new EventFactoryEvdev(
event_factory_ozone_ = std::make_unique<EventFactoryEvdev>(
cursor_.get(), device_manager_.get(),
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine());
GpuThreadAdapter* adapter;
......@@ -213,8 +213,8 @@ class OzonePlatformGbm : public OzonePlatform {
std::make_unique<DrmDeviceConnector>(host_drm_device_);
adapter = host_drm_device_.get();
} else {
gpu_platform_support_host_.reset(
new DrmGpuPlatformSupportHost(cursor_.get()));
gpu_platform_support_host_ =
std::make_unique<DrmGpuPlatformSupportHost>(cursor_.get());
adapter = gpu_platform_support_host_.get();
}
......@@ -227,7 +227,7 @@ class OzonePlatformGbm : public OzonePlatform {
display_manager_ = std::make_unique<DrmDisplayHostManager>(
adapter, device_manager_.get(), &host_properties_,
overlay_manager_host.get(), event_factory_ozone_->input_controller());
cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
cursor_factory_ozone_ = std::make_unique<BitmapCursorFactoryOzone>();
if (using_mojo_) {
host_drm_device_->ProvideManagers(display_manager_.get(),
......@@ -251,9 +251,10 @@ class OzonePlatformGbm : public OzonePlatform {
// NOTE: Can't start the thread here since this is called before sandbox
// initialization in multi-process Chrome.
drm_thread_proxy_.reset(new DrmThreadProxy());
drm_thread_proxy_ = std::make_unique<DrmThreadProxy>();
surface_factory_.reset(new GbmSurfaceFactory(drm_thread_proxy_.get()));
surface_factory_ =
std::make_unique<GbmSurfaceFactory>(drm_thread_proxy_.get());
if (!using_mojo_) {
drm_thread_proxy_->BindThreadIntoMessagingProxy(itmp);
}
......
......@@ -61,7 +61,7 @@ class OzonePlatformScenic
: public OzonePlatform,
public base::MessageLoopCurrent::DestructionObserver {
public:
OzonePlatformScenic() {}
OzonePlatformScenic() = default;
~OzonePlatformScenic() override = default;
// OzonePlatform implementation.
......
......@@ -132,9 +132,10 @@ class OzonePlatformWayland : public OzonePlatform {
// it is set at this point if none exists
if (!LinuxInputMethodContextFactory::instance() &&
!input_method_context_factory_) {
auto* factory = new WaylandInputMethodContextFactory(connection_.get());
input_method_context_factory_.reset(factory);
LinuxInputMethodContextFactory::SetInstance(factory);
input_method_context_factory_ =
std::make_unique<WaylandInputMethodContextFactory>(connection_.get());
LinuxInputMethodContextFactory::SetInstance(
input_method_context_factory_.get());
}
return std::make_unique<InputMethodAuraLinux>(delegate);
......
......@@ -35,11 +35,10 @@ OzonePlatform::~OzonePlatform() = default;
// static
void OzonePlatform::InitializeForUI(const InitParams& args) {
EnsureInstance();
if (g_platform_initialized_ui)
return;
g_platform_initialized_ui = true;
g_instance->InitializeUI(args);
EnsureInstance()->InitializeUI(args);
// This is deliberately created after initializing so that the platform can
// create its own version of DDM.
DeviceDataManager::CreateInstance();
......@@ -47,11 +46,10 @@ void OzonePlatform::InitializeForUI(const InitParams& args) {
// static
void OzonePlatform::InitializeForGPU(const InitParams& args) {
EnsureInstance();
if (g_platform_initialized_gpu)
return;
g_platform_initialized_gpu = true;
g_instance->InitializeGPU(args);
EnsureInstance()->InitializeGPU(args);
}
// static
......
......@@ -72,7 +72,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
// Setting this to true indicates that the platform implementation should
// use mojo. Setting this to true requires calling |AddInterfaces|
// afterwards in the Viz process and providing a connector as part.
// afterwards in the Viz process. Note that this param is only checked in
// Ozone DRM. Other platforms either never use mojo or always use mojo
// regardless of this param.
// TODO(crbug.com/806092): Remove after legacy IPC-based Ozone is removed.
bool using_mojo = false;
// Setting this to true indicates the display compositor will run in the GPU
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment