-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add minimal Ozone implementation for Starboard (#4396)
Create a skeleton of an Ozone implementation as a starter. We'll build on top of this in future commits. b/371272304
- Loading branch information
Showing
14 changed files
with
714 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import("//build/config/ozone.gni") | ||
|
||
source_set("starboard") { | ||
visibility = [ "//ui/ozone/*" ] | ||
|
||
defines = [ "OZONE_IMPLEMENTATION" ] | ||
|
||
sources = [ | ||
"client_native_pixmap_factory_starboard.cc", | ||
"client_native_pixmap_factory_starboard.h", | ||
"ozone_platform_starboard.cc", | ||
"ozone_platform_starboard.h", | ||
"platform_screen_starboard.cc", | ||
"platform_screen_starboard.h", | ||
"platform_window_starboard.cc", | ||
"platform_window_starboard.h", | ||
"surface_factory_starboard.cc", | ||
"surface_factory_starboard.h", | ||
] | ||
|
||
deps = [ | ||
"//ui/base/ime", | ||
"//ui/display", | ||
"//ui/display/fake", | ||
"//ui/gfx:native_widget_types", | ||
"//ui/ozone:ozone_base", | ||
"//ui/ozone/common", | ||
"//ui/platform_window", | ||
"//ui/platform_window/stub", | ||
] | ||
} | ||
|
||
source_set("test_support") { | ||
visibility = [ "//ui/ozone/*" ] | ||
|
||
testonly = true | ||
|
||
sources = [ | ||
"ozone_ui_controls_test_helper_starboard.cc", | ||
"ozone_ui_controls_test_helper_starboard.h", | ||
] | ||
|
||
deps = [ "//ui/base/x" ] | ||
} |
25 changes: 25 additions & 0 deletions
25
ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.h" | ||
|
||
#include "ui/ozone/common/stub_client_native_pixmap_factory.h" | ||
|
||
namespace ui { | ||
|
||
gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryStarboard() { | ||
return CreateStubClientNativePixmapFactory(); | ||
} | ||
|
||
} // namespace ui |
28 changes: 28 additions & 0 deletions
28
ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef UI_OZONE_PLATFORM_STARBOARD_CLIENT_NATIVE_PIXMAP_FACTORY_STARBOARD_H_ | ||
#define UI_OZONE_PLATFORM_STARBOARD_CLIENT_NATIVE_PIXMAP_FACTORY_STARBOARD_H_ | ||
|
||
namespace gfx { | ||
class ClientNativePixmapFactory; | ||
} | ||
|
||
namespace ui { | ||
|
||
gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryStarboard(); | ||
|
||
} // namespace ui | ||
|
||
#endif // UI_OZONE_PLATFORM_STARBOARD_CLIENT_NATIVE_PIXMAP_FACTORY_STARBOARD_H_ |
158 changes: 158 additions & 0 deletions
158
ui/ozone/platform/starboard/ozone_platform_starboard.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "ui/ozone/platform/starboard/ozone_platform_starboard.h" | ||
|
||
#include "base/logging.h" | ||
#include "ui/base/ime/input_method_minimal.h" | ||
#include "ui/display/fake/fake_display_delegate.h" | ||
#include "ui/ozone/common/bitmap_cursor_factory.h" | ||
#include "ui/ozone/common/stub_overlay_manager.h" | ||
#include "ui/ozone/platform/starboard/platform_screen_starboard.h" | ||
#include "ui/ozone/platform/starboard/platform_window_starboard.h" | ||
#include "ui/ozone/platform/starboard/surface_factory_starboard.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/platform_window/platform_window_init_properties.h" | ||
|
||
namespace ui { | ||
namespace { | ||
|
||
// Ozone platform implementation for Starboard, an OS abstraction and porting | ||
// layer for Cobalt (https://github.com/youtube/cobalt). Platform specific | ||
// implementation details are abstracted out using Starboard. | ||
// - TODO(tholcombe): fill out implementation details as they're added. | ||
class OzonePlatformStarboard : public OzonePlatform { | ||
public: | ||
OzonePlatformStarboard() {} | ||
|
||
OzonePlatformStarboard(const OzonePlatformStarboard&) = delete; | ||
OzonePlatformStarboard& operator=(const OzonePlatformStarboard&) = delete; | ||
|
||
~OzonePlatformStarboard() override {} | ||
|
||
ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { | ||
if (!surface_factory_) { | ||
LOG(WARNING) << "GetSurfaceFactoryOzone(): surface_factory_ is expected " | ||
"to be initialized in InitializeGPU " | ||
"or InitializeUI, but no graphics context was found."; | ||
surface_factory_ = std::make_unique<SurfaceFactoryStarboard>(); | ||
} | ||
return surface_factory_.get(); | ||
} | ||
|
||
ui::OverlayManagerOzone* GetOverlayManager() override { | ||
return overlay_manager_.get(); | ||
} | ||
|
||
ui::CursorFactory* GetCursorFactory() override { | ||
return cursor_factory_.get(); | ||
} | ||
|
||
ui::InputController* GetInputController() override { | ||
return input_controller_.get(); | ||
} | ||
|
||
ui::GpuPlatformSupportHost* GetGpuPlatformSupportHost() override { | ||
return gpu_platform_support_host_.get(); | ||
} | ||
|
||
std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override { | ||
// TODO(b/371272304): Implement a system input injector for Starboard. This | ||
// will likely be part of an event factory/dispatcher. | ||
return nullptr; | ||
} | ||
|
||
std::unique_ptr<PlatformWindow> CreatePlatformWindow( | ||
PlatformWindowDelegate* delegate, | ||
PlatformWindowInitProperties properties) override { | ||
return std::make_unique<PlatformWindowStarboard>(delegate, | ||
properties.bounds); | ||
} | ||
|
||
std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() | ||
override { | ||
// TODO(b/371272304): Implement a native display delegate to allow display | ||
// configuration and hotplug (adding a new display while the process is | ||
// running). | ||
return std::make_unique<display::FakeDisplayDelegate>(); | ||
} | ||
|
||
std::unique_ptr<PlatformScreen> CreateScreen() override { | ||
return std::make_unique<PlatformScreenStarboard>(); | ||
} | ||
// This function must be called immediately after CreateScreen with the | ||
// `screen` that was returned from CreateScreen. They are separated to avoid | ||
// observer recursion into display::Screen from inside CreateScreen. | ||
void InitScreen(PlatformScreen* screen) override {} | ||
|
||
std::unique_ptr<InputMethod> CreateInputMethod( | ||
ImeKeyEventDispatcher* ime_key_event_dispatcher, | ||
gfx::AcceleratedWidget widget) override { | ||
return std::make_unique<InputMethodMinimal>(ime_key_event_dispatcher); | ||
} | ||
|
||
bool InitializeUI(const InitParams& params) override { | ||
// TODO(b/371272304): Investigate if we need a more robust cursor factory or | ||
// if we can continue using BitmapCursorFactory. | ||
cursor_factory_ = std::make_unique<BitmapCursorFactory>(); | ||
// TODO(b/371272304): GpuPlatformSupportHost seems to be mainly for IPC | ||
// between the Browser and GPU processes. Since Cobalt will be running as a | ||
// single process, investigate if this is needed or if there's any | ||
// additional features we might need to implement from there. | ||
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); | ||
// TODO(b/371272304): Investigate if we need our own implementation of | ||
// InputController for things like gamepads or other atypical input devices. | ||
input_controller_ = CreateStubInputController(); | ||
// TODO(b/371272304): Investigate if we need our own implementation of | ||
// OverlayManager. | ||
// It doesn't matter which of the UI or GPU creates | overlay_manager_ | and | ||
// | surface_factory_ | in single-process mode. | ||
if (!overlay_manager_) { | ||
overlay_manager_ = std::make_unique<StubOverlayManager>(); | ||
} | ||
if (!surface_factory_) { | ||
surface_factory_ = std::make_unique<SurfaceFactoryStarboard>(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void InitializeGPU(const InitParams& params) override { | ||
// It doesn't matter which of the UI or GPU creates | overlay_manager_ | and | ||
// | surface_factory_ | in single-process mode. | ||
if (!overlay_manager_) { | ||
overlay_manager_ = std::make_unique<StubOverlayManager>(); | ||
} | ||
if (!surface_factory_) { | ||
surface_factory_ = std::make_unique<SurfaceFactoryStarboard>(); | ||
} | ||
} | ||
|
||
private: | ||
std::unique_ptr<CursorFactory> cursor_factory_; | ||
std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; | ||
std::unique_ptr<InputController> input_controller_; | ||
std::unique_ptr<OverlayManagerOzone> overlay_manager_; | ||
std::unique_ptr<SurfaceFactoryStarboard> surface_factory_; | ||
}; | ||
|
||
} // namespace | ||
|
||
OzonePlatform* CreateOzonePlatformStarboard() { | ||
return new OzonePlatformStarboard(); | ||
} | ||
|
||
} // namespace ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef UI_OZONE_PLATFORM_STARBOARD_OZONE_PLATFORM_STARBOARD_H_ | ||
#define UI_OZONE_PLATFORM_STARBOARD_OZONE_PLATFORM_STARBOARD_H_ | ||
|
||
namespace ui { | ||
|
||
class OzonePlatform; | ||
|
||
// Constructor hook for use in ozone_platform_list.cc | ||
OzonePlatform* CreateOzonePlatformStarboard(); | ||
|
||
} // namespace ui | ||
|
||
#endif // UI_OZONE_PLATFORM_STARBOARD_OZONE_PLATFORM_STARBOARD_H_ |
Oops, something went wrong.