Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SbWindowGetDisplayHandle to Starboard Windowing interface #2690

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cobalt/renderer/backend/egl/graphics_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,18 @@ GraphicsSystemEGL::GraphicsSystemEGL(
glimp::SetTraceEventImplementation(&s_glimp_to_base_trace_event_bridge);
#endif // #if defined(ENABLE_GLIMP_TRACING)

#if STARBOARD >= 16
display _ = SbWindowGetDisplayHandle(window_);
// Fall back to SB_EGL_DEFAULT_DISPLAY
if (SB_EGL_NO_DISPLAY != display_) {
display_ = EGL_CALL_SIMPLE(eglGetDisplay(SB_EGL_DEFAULT_DISPLAY));
SB_CHECK(SB_EGL_SUCCESS == EGL_CALL_SIMPLE(eglGetError()));
}
#else
display_ = EGL_CALL_SIMPLE(eglGetDisplay(EGL_DEFAULT_DISPLAY));
CHECK_NE(EGL_NO_DISPLAY, display_);
CHECK_EQ(EGL_SUCCESS, EGL_CALL_SIMPLE(eglGetError()));
#endif
CHECK_NE(EGL_NO_DISPLAY, display_);

{
// Despite eglTerminate() being used in the destructor, the current
Expand Down
8 changes: 8 additions & 0 deletions starboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ since the version previous to it.

## Version 16


### Added SbWindowGetDisplayHandle

The function retrieves native EGL display handle, simplifying correct EGL
context initialization on some platforms. This complements
SbWindowGetPlatformHandle, which retrieves the native window handle.


### Added standard POSIX socket getaddrinfo/freeaddrinfo APIs.
The standard API `getaddrinfo` and `freeaddrinfo`, can be used from
<netdb.h>.
Expand Down
1 change: 1 addition & 0 deletions starboard/android/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ static_library("starboard_platform") {
"//starboard/shared/stub/thread_sampler_is_supported.cc",
"//starboard/shared/stub/thread_sampler_thaw.cc",
"//starboard/shared/stub/ui_nav_get_interface.cc",
"//starboard/shared/stub/window_get_display_handle.cc",
"accessibility_get_caption_settings.cc",
"accessibility_get_display_settings.cc",
"accessibility_get_text_to_speech_settings.cc",
Expand Down
9 changes: 9 additions & 0 deletions starboard/examples/glclear/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,17 @@ Application::Application() {
window_ = SbWindowCreate(&options);
SB_CHECK(SbWindowIsValid(window_));

#if STARBOARD >= 16
display _ = SbWindowGetDisplayHandle(window_);
// Fall back to SB_EGL_DEFAULT_DISPLAY
if (SB_EGL_NO_DISPLAY != display_) {
display_ = EGL_CALL_SIMPLE(eglGetDisplay(SB_EGL_DEFAULT_DISPLAY));
SB_CHECK(SB_EGL_SUCCESS == EGL_CALL_SIMPLE(eglGetError()));
}
#else
display_ = EGL_CALL_SIMPLE(eglGetDisplay(SB_EGL_DEFAULT_DISPLAY));
SB_CHECK(SB_EGL_SUCCESS == EGL_CALL_SIMPLE(eglGetError()));
#endif
SB_CHECK(SB_EGL_NO_DISPLAY != display_);

EGL_CALL(eglInitialize(display_, NULL, NULL));
Expand Down
1 change: 1 addition & 0 deletions starboard/linux/x64x11/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static_library("starboard_platform_sources") {
"//starboard/shared/x11/player_set_bounds.cc",
"//starboard/shared/x11/window_create.cc",
"//starboard/shared/x11/window_destroy.cc",
"//starboard/shared/x11/window_get_display_handle.cc",
"//starboard/shared/x11/window_get_platform_handle.cc",
"//starboard/shared/x11/window_get_size.cc",
"//starboard/shared/x11/window_internal.cc",
Expand Down
1 change: 1 addition & 0 deletions starboard/nplb/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ target(gtest_target_type, "nplb") {
"window_create_test.cc",
"window_destroy_test.cc",
"window_get_diagonal_size_in_inches_test.cc",
"window_get_display_handle_test.cc",
"window_get_platform_handle_test.cc",
"window_get_size_test.cc",
]
Expand Down
44 changes: 44 additions & 0 deletions starboard/nplb/window_get_display_handle_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 <EGL/egl.h>
#include "starboard/configuration.h"
#include "starboard/window.h"
#include "testing/gtest/include/gtest/gtest.h"

#if SB_API_VERSION >= 16
namespace starboard {
namespace nplb {
namespace {

TEST(SbWindowGetDisplayHandleTest, SunnyDay) {
SbWindow window = SbWindowCreate(NULL);
ASSERT_TRUE(SbWindowIsValid(window));
void* handle = SbWindowGetDisplayHandle(window);
// 0 could actually be a valid value here, because we don't know what the
// platform uses as its native window handle type, so we can't do any
// verification here.
ASSERT_TRUE(SbWindowDestroy(window));
}

TEST(SbWindowGetDisplayHandleTest, RainyDay) {
void* handle = SbWindowGetDisplayHandle(kSbWindowInvalid);
ASSERT_EQ(handle, EGL_NO_DISPLAY);
}

} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION >= 16
1 change: 1 addition & 0 deletions starboard/raspi/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ static_library("starboard_platform_sources") {
"//starboard/shared/stub/window_blur_on_screen_keyboard.cc",
"//starboard/shared/stub/window_focus_on_screen_keyboard.cc",
"//starboard/shared/stub/window_get_diagonal_size_in_inches.cc",
"//starboard/shared/stub/window_get_display_handle.cc",
"//starboard/shared/stub/window_get_on_screen_keyboard_bounding_rect.cc",
"//starboard/shared/stub/window_hide_on_screen_keyboard.cc",
"//starboard/shared/stub/window_is_on_screen_keyboard_shown.cc",
Expand Down
20 changes: 20 additions & 0 deletions starboard/shared/stub/window_get_display_handle.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 "starboard/window.h"

void* SbWindowGetDisplayHandle(SbWindow window) {
// Resolves to EGL_NO_DISPLAY
return nullptr;
}
31 changes: 31 additions & 0 deletions starboard/shared/x11/window_get_display_handle.cc
Original file line number Diff line number Diff line change
@@ -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 <EGL/egl.h>
#include "starboard/window.h"

#include "starboard/player.h"
#include "starboard/shared/x11/window_internal.h"

#if SB_API_VERSION >= 16

void* SbWindowGetDisplayHandle(SbWindow window) {
if (!SbWindowIsValid(window)) {
return EGL_NO_DISPLAY;
}

return reinterpret_cast<void*>(window->display);
}

#endif // SB_API_VERSION >= 16
1 change: 1 addition & 0 deletions starboard/stub/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ static_library("stub_sources") {
"//starboard/shared/stub/window_destroy.cc",
"//starboard/shared/stub/window_focus_on_screen_keyboard.cc",
"//starboard/shared/stub/window_get_diagonal_size_in_inches.cc",
"//starboard/shared/stub/window_get_display_handle.cc",
"//starboard/shared/stub/window_get_on_screen_keyboard_bounding_rect.cc",
"//starboard/shared/stub/window_get_platform_handle.cc",
"//starboard/shared/stub/window_get_size.cc",
Expand Down
1 change: 1 addition & 0 deletions starboard/win/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static_library("starboard_platform") {
"//starboard/shared/stub/window_blur_on_screen_keyboard.cc",
"//starboard/shared/stub/window_focus_on_screen_keyboard.cc",
"//starboard/shared/stub/window_get_diagonal_size_in_inches.cc",
"//starboard/shared/stub/window_get_display_handle.cc",
"//starboard/shared/stub/window_get_on_screen_keyboard_bounding_rect.cc",
"//starboard/shared/stub/window_hide_on_screen_keyboard.cc",
"//starboard/shared/stub/window_is_on_screen_keyboard_shown.cc",
Expand Down
10 changes: 10 additions & 0 deletions starboard/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ SB_EXPORT bool SbWindowGetSize(SbWindow window, SbWindowSize* size);
// |window|: The SbWindow to retrieve the platform handle for.
SB_EXPORT void* SbWindowGetPlatformHandle(SbWindow window);

#if SB_API_VERSION >= 16
// Gets the platform-specific handle for |display|, which can be passed as an
// EGLNativeDisplayType to initialize EGL/GLES. This return value is entirely
// platform-specific.
// A return value of EGL_NO_DISPLAY means failure.
//
// |window|: The SbWindow to retrieve the platform display handle for.
SB_EXPORT void* SbWindowGetDisplayHandle(SbWindow window);
#endif

// System-triggered OnScreenKeyboard events have ticket value
// kSbEventOnScreenKeyboardInvalidTicket.
#define kSbEventOnScreenKeyboardInvalidTicket (-1)
Expand Down
Loading