diff --git a/build/config/ozone_extra.gni b/build/config/ozone_extra.gni index cbbca1efe223..8f91f5cf7064 100644 --- a/build/config/ozone_extra.gni +++ b/build/config/ozone_extra.gni @@ -31,3 +31,9 @@ ozone_external_platform_ui_test_support_deps = [] # source_set can be listed here so that they can included into # interactive_ui_tests. ozone_external_interactive_ui_tests_deps = [] + +if (defined(is_starboard) && is_starboard) { + ozone_external_platforms += ["starboard"] + ozone_external_platform_deps += ["platform/starboard"] + ozone_external_platform_ui_test_support_deps += ["platform/starboard:test_support"] +} diff --git a/ui/ozone/platform/starboard/BUILD.gn b/ui/ozone/platform/starboard/BUILD.gn new file mode 100644 index 000000000000..271c16688f7d --- /dev/null +++ b/ui/ozone/platform/starboard/BUILD.gn @@ -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" ] +} diff --git a/ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.cc b/ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.cc new file mode 100644 index 000000000000..8a2575c6bcce --- /dev/null +++ b/ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.cc @@ -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 diff --git a/ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.h b/ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.h new file mode 100644 index 000000000000..14167b2df385 --- /dev/null +++ b/ui/ozone/platform/starboard/client_native_pixmap_factory_starboard.h @@ -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_ diff --git a/ui/ozone/platform/starboard/ozone_platform_starboard.cc b/ui/ozone/platform/starboard/ozone_platform_starboard.cc new file mode 100644 index 000000000000..2f831b8bfb06 --- /dev/null +++ b/ui/ozone/platform/starboard/ozone_platform_starboard.cc @@ -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(); + } + 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 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 CreatePlatformWindow( + PlatformWindowDelegate* delegate, + PlatformWindowInitProperties properties) override { + return std::make_unique(delegate, + properties.bounds); + } + + std::unique_ptr 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(); + } + + std::unique_ptr CreateScreen() override { + return std::make_unique(); + } + // 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 CreateInputMethod( + ImeKeyEventDispatcher* ime_key_event_dispatcher, + gfx::AcceleratedWidget widget) override { + return std::make_unique(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(); + // 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(); + } + if (!surface_factory_) { + surface_factory_ = std::make_unique(); + } + + 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(); + } + if (!surface_factory_) { + surface_factory_ = std::make_unique(); + } + } + + private: + std::unique_ptr cursor_factory_; + std::unique_ptr gpu_platform_support_host_; + std::unique_ptr input_controller_; + std::unique_ptr overlay_manager_; + std::unique_ptr surface_factory_; +}; + +} // namespace + +OzonePlatform* CreateOzonePlatformStarboard() { + return new OzonePlatformStarboard(); +} + +} // namespace ui diff --git a/ui/ozone/platform/starboard/ozone_platform_starboard.h b/ui/ozone/platform/starboard/ozone_platform_starboard.h new file mode 100644 index 000000000000..a5d8f3de48c8 --- /dev/null +++ b/ui/ozone/platform/starboard/ozone_platform_starboard.h @@ -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_ diff --git a/ui/ozone/platform/starboard/ozone_ui_controls_test_helper_starboard.cc b/ui/ozone/platform/starboard/ozone_ui_controls_test_helper_starboard.cc new file mode 100644 index 000000000000..0e09e67a0bdb --- /dev/null +++ b/ui/ozone/platform/starboard/ozone_ui_controls_test_helper_starboard.cc @@ -0,0 +1,90 @@ +// 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_ui_controls_test_helper_starboard.h" + +#include "base/functional/callback.h" + +namespace ui { + +OzoneUIControlsTestHelperStarboard::OzoneUIControlsTestHelperStarboard() {} + +OzoneUIControlsTestHelperStarboard::~OzoneUIControlsTestHelperStarboard() {} + +void OzoneUIControlsTestHelperStarboard::Reset() {} + +bool OzoneUIControlsTestHelperStarboard::SupportsScreenCoordinates() const { + // TODO(b/371272304): Once PlatformWindowStarboard is fully implemented change + // this to return true. + return false; +} + +unsigned OzoneUIControlsTestHelperStarboard::ButtonDownMask() const { + // TODO(b/371272304): This is only called after checking + // !MustUseUiControlsForMoveCursorTo(). Re-examine how we want tests to handle + // cursor movement and determine if this should be NOTREACHED() instead of + // return 0. + return 0; +} + +void OzoneUIControlsTestHelperStarboard::SendKeyEvents( + gfx::AcceleratedWidget widget, + ui::KeyboardCode key, + int key_event_types, + int accelerator_state, + base::OnceClosure closure) { + // TODO(b/371272304): Once PlatformWindowStarboard has an event handler added, + // update this to send events. + return; +} + +void OzoneUIControlsTestHelperStarboard::SendMouseMotionNotifyEvent( + gfx::AcceleratedWidget widget, + const gfx::Point& mouse_loc, + const gfx::Point& mouse_loc_in_screen, + base::OnceClosure closure) { + // TODO(b/371272304): Once PlatformWindowStarboard has an event handler added, + // update this to send events. + return; +} + +void OzoneUIControlsTestHelperStarboard::SendMouseEvent( + gfx::AcceleratedWidget widget, + ui_controls::MouseButton type, + int button_state, + int accelerator_state, + const gfx::Point& mouse_loc, + const gfx::Point& mouse_loc_in_screen, + base::OnceClosure closure) { + // TODO(b/371272304): Once PlatformWindowStarboard has an event handler added, + // update this to send events. + return; +} + +void OzoneUIControlsTestHelperStarboard::RunClosureAfterAllPendingUIEvents( + base::OnceClosure closure) { + // TODO(b/371272304): Once PlatformWindowStarboard has an event handler added, + // update this to send events. + return; +} + +bool OzoneUIControlsTestHelperStarboard::MustUseUiControlsForMoveCursorTo() { + return false; +} + +OzoneUIControlsTestHelper* CreateOzoneUIControlsTestHelperStarboard() { + return new OzoneUIControlsTestHelperStarboard(); +} + +} // namespace ui diff --git a/ui/ozone/platform/starboard/ozone_ui_controls_test_helper_starboard.h b/ui/ozone/platform/starboard/ozone_ui_controls_test_helper_starboard.h new file mode 100644 index 000000000000..d38531790511 --- /dev/null +++ b/ui/ozone/platform/starboard/ozone_ui_controls_test_helper_starboard.h @@ -0,0 +1,67 @@ +// 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_UI_CONTROLS_TEST_HELPER_STARBOARD_H_ +#define UI_OZONE_PLATFORM_STARBOARD_OZONE_UI_CONTROLS_TEST_HELPER_STARBOARD_H_ + +#include "ui/ozone/public/ozone_ui_controls_test_helper.h" + +namespace ui { + +class OzoneUIControlsTestHelperStarboard : public OzoneUIControlsTestHelper { + public: + OzoneUIControlsTestHelperStarboard(); + + OzoneUIControlsTestHelperStarboard( + const OzoneUIControlsTestHelperStarboard&) = delete; + OzoneUIControlsTestHelperStarboard& operator=( + const OzoneUIControlsTestHelperStarboard&) = delete; + + ~OzoneUIControlsTestHelperStarboard() override; + + void Reset() override; + + bool SupportsScreenCoordinates() const override; + + unsigned ButtonDownMask() const override; + + void SendKeyEvents(gfx::AcceleratedWidget widget, + ui::KeyboardCode key, + int key_event_types, + int accelerator_state, + base::OnceClosure closure) override; + + void SendMouseMotionNotifyEvent(gfx::AcceleratedWidget widget, + const gfx::Point& mouse_loc, + const gfx::Point& mouse_loc_in_screen, + base::OnceClosure closure) override; + + void SendMouseEvent(gfx::AcceleratedWidget widget, + ui_controls::MouseButton type, + int button_state, + int accelerator_state, + const gfx::Point& mouse_loc, + const gfx::Point& mouse_loc_in_screen, + base::OnceClosure closure) override; + + void RunClosureAfterAllPendingUIEvents(base::OnceClosure closure) override; + + bool MustUseUiControlsForMoveCursorTo() override; +}; + +OzoneUIControlsTestHelper* CreateOzoneUIControlsTestHelperStarboard(); + +} // namespace ui + +#endif // UI_OZONE_PLATFORM_STARBOARD_OZONE_UI_CONTROLS_TEST_HELPER_STARBOARD_H_ diff --git a/ui/ozone/platform/starboard/platform_screen_starboard.cc b/ui/ozone/platform/starboard/platform_screen_starboard.cc new file mode 100644 index 000000000000..e4b6012a4650 --- /dev/null +++ b/ui/ozone/platform/starboard/platform_screen_starboard.cc @@ -0,0 +1,74 @@ +// 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/platform_screen_starboard.h" + +#include "ui/display/display.h" + +namespace ui { + +PlatformScreenStarboard::PlatformScreenStarboard() {} + +PlatformScreenStarboard::~PlatformScreenStarboard() = default; + +const std::vector& PlatformScreenStarboard::GetAllDisplays() + const { + // TODO(b/371272304): Initialize display_list_ in the constructor. + return display_list_.displays(); +} + +display::Display PlatformScreenStarboard::GetPrimaryDisplay() const { + // TODO(b/371272304): Get the actual primary display from display_list_. + return display::Display(); +} +display::Display PlatformScreenStarboard::GetDisplayForAcceleratedWidget( + gfx::AcceleratedWidget widget) const { + // TODO(b/371272304): Check if the widget exists within the current window and + // maps to a display. If not, return primary display. + return GetPrimaryDisplay(); +} +display::Display PlatformScreenStarboard::GetDisplayNearestPoint( + const gfx::Point& point_in_dip) const { + // TODO(b/371272304): Iterate a display list and find the one nearest the + // point. + return GetPrimaryDisplay(); +} +display::Display PlatformScreenStarboard::GetDisplayMatching( + const gfx::Rect& match_rect) const { + // TODO(b/371272304): Iterate a display list and find a matching display. + return GetPrimaryDisplay(); +} + +gfx::Point PlatformScreenStarboard::GetCursorScreenPoint() const { + // TODO(b/371272304): Return the actual screen point of the cursor. + return gfx::Point(); +} + +gfx::AcceleratedWidget +PlatformScreenStarboard::GetAcceleratedWidgetAtScreenPoint( + const gfx::Point& point_in_dip) const { + // TODO(b/371272304): Check if a widget exists within the current window and + // return that, otherwise return kNullAcceleratedWidget. + return gfx::kNullAcceleratedWidget; +} + +void PlatformScreenStarboard::AddObserver(display::DisplayObserver* observer) { + // TODO(b/371272304): Add Observer to display::DisplayList. +} +void PlatformScreenStarboard::RemoveObserver( + display::DisplayObserver* observer) { + // TODO(b/371272304): Remove Observer from display::DisplayList. +} + +} // namespace ui diff --git a/ui/ozone/platform/starboard/platform_screen_starboard.h b/ui/ozone/platform/starboard/platform_screen_starboard.h new file mode 100644 index 000000000000..6a3d8d536415 --- /dev/null +++ b/ui/ozone/platform/starboard/platform_screen_starboard.h @@ -0,0 +1,54 @@ +// 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_PLATFORM_SCREEN_STARBOARD_H_ +#define UI_OZONE_PLATFORM_STARBOARD_PLATFORM_SCREEN_STARBOARD_H_ + +#include "ui/display/display_list.h" +#include "ui/gfx/geometry/point.h" +#include "ui/ozone/public/platform_screen.h" + +namespace ui { + +class PlatformScreenStarboard : public PlatformScreen { + public: + PlatformScreenStarboard(); + + ~PlatformScreenStarboard() override; + + const std::vector& GetAllDisplays() const override; + + display::Display GetPrimaryDisplay() const override; + display::Display GetDisplayForAcceleratedWidget( + gfx::AcceleratedWidget widget) const override; + display::Display GetDisplayNearestPoint( + const gfx::Point& point_in_dip) const override; + display::Display GetDisplayMatching( + const gfx::Rect& match_rect) const override; + + gfx::Point GetCursorScreenPoint() const override; + + gfx::AcceleratedWidget GetAcceleratedWidgetAtScreenPoint( + const gfx::Point& point_in_dip) const override; + + void AddObserver(display::DisplayObserver* observer) override; + void RemoveObserver(display::DisplayObserver* observer) override; + + private: + display::DisplayList display_list_; +}; + +} // namespace ui + +#endif // UI_OZONE_PLATFORM_STARBOARD_PLATFORM_SCREEN_STARBOARD_H_ diff --git a/ui/ozone/platform/starboard/platform_window_starboard.cc b/ui/ozone/platform/starboard/platform_window_starboard.cc new file mode 100644 index 000000000000..1b8b8cb4cf59 --- /dev/null +++ b/ui/ozone/platform/starboard/platform_window_starboard.cc @@ -0,0 +1,31 @@ +// 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/platform_window_starboard.h" + +#include "ui/gfx/native_widget_types.h" + +namespace ui { + +PlatformWindowStarboard::PlatformWindowStarboard( + PlatformWindowDelegate* delegate, + const gfx::Rect& bounds) + : StubWindow(delegate, /*use_default_accelerated_widget=*/false, bounds) { + gfx::AcceleratedWidget widget = (bounds.width() << 16) + bounds.height(); + delegate->OnAcceleratedWidgetAvailable(widget); +} + +PlatformWindowStarboard::~PlatformWindowStarboard() {} + +} // namespace ui diff --git a/ui/ozone/platform/starboard/platform_window_starboard.h b/ui/ozone/platform/starboard/platform_window_starboard.h new file mode 100644 index 000000000000..0d45665e74e0 --- /dev/null +++ b/ui/ozone/platform/starboard/platform_window_starboard.h @@ -0,0 +1,39 @@ +// 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_PLATFORM_WINDOW_STARBOARD_H_ +#define UI_OZONE_PLATFORM_STARBOARD_PLATFORM_WINDOW_STARBOARD_H_ + +#include "ui/platform_window/platform_window_delegate.h" +#include "ui/platform_window/stub/stub_window.h" + +namespace ui { + +// TODO(b/371272304): Stop extending StubWindow and create a more robust window +// implementation. +// TODO(b/371272304): Add event handling (i.e. extend PlatformEventDispatcher). +class PlatformWindowStarboard : public StubWindow { + public: + PlatformWindowStarboard(PlatformWindowDelegate* delegate, + const gfx::Rect& bounds); + + PlatformWindowStarboard(const PlatformWindowStarboard&) = delete; + PlatformWindowStarboard& operator=(const PlatformWindowStarboard&) = delete; + + ~PlatformWindowStarboard() override; +}; + +} // namespace ui + +#endif // UI_OZONE_PLATFORM_STARBOARD_PLATFORM_WINDOW_STARBOARD_H_ diff --git a/ui/ozone/platform/starboard/surface_factory_starboard.cc b/ui/ozone/platform/starboard/surface_factory_starboard.cc new file mode 100644 index 000000000000..b79f9cfd86af --- /dev/null +++ b/ui/ozone/platform/starboard/surface_factory_starboard.cc @@ -0,0 +1,23 @@ +// 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/surface_factory_starboard.h" + +namespace ui { + +SurfaceFactoryStarboard::SurfaceFactoryStarboard() {} + +SurfaceFactoryStarboard::~SurfaceFactoryStarboard() {} + +} // namespace ui diff --git a/ui/ozone/platform/starboard/surface_factory_starboard.h b/ui/ozone/platform/starboard/surface_factory_starboard.h new file mode 100644 index 000000000000..6c05c43baa2b --- /dev/null +++ b/ui/ozone/platform/starboard/surface_factory_starboard.h @@ -0,0 +1,34 @@ +// 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_SURFACE_FACTORY_STARBOARD_H_ +#define UI_OZONE_PLATFORM_STARBOARD_SURFACE_FACTORY_STARBOARD_H_ + +#include "ui/ozone/public/surface_factory_ozone.h" + +namespace ui { + +class SurfaceFactoryStarboard : public SurfaceFactoryOzone { + public: + SurfaceFactoryStarboard(); + + SurfaceFactoryStarboard(const SurfaceFactoryStarboard&) = delete; + SurfaceFactoryStarboard& operator=(const SurfaceFactoryStarboard&) = delete; + + ~SurfaceFactoryStarboard() override; +}; + +} // namespace ui + +#endif // UI_OZONE_PLATFORM_STARBOARD_SURFACE_FACTORY_STARBOARD_H_