Skip to content

Commit

Permalink
Convert hybrid nav ( ui_navigation.h ) to a Starboard extension
Browse files Browse the repository at this point in the history
b/299481829

Change-Id: I4d1d49942b1dbdafec06da6cefe9e47f9a833125
  • Loading branch information
iuriionishchenko authored and Iurii Onishchenko committed Dec 26, 2023
1 parent e25a331 commit 0099e9f
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 5 deletions.
40 changes: 39 additions & 1 deletion cobalt/ui_navigation/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "cobalt/ui_navigation/interface.h"

#include "starboard/common/spin_lock.h"
#if SB_API_VERSION >= 16
#include <string.h>

#include "starboard/system.h"
#endif // SB_API_VERSION

namespace cobalt {
namespace ui_navigation {
Expand Down Expand Up @@ -138,6 +143,7 @@ void DoBatchUpdate(void (*update_function)(void*), void* context) {

NativeInterface InitializeInterface() {
NativeInterface interface = {0};
#if SB_API_VERSION < 16
SbUiNavInterface sb_ui_interface = {0};
if (SbUiNavGetInterface(&sb_ui_interface)) {
interface.create_item = sb_ui_interface.create_item;
Expand All @@ -161,7 +167,39 @@ NativeInterface InitializeInterface() {
interface.do_batch_update = sb_ui_interface.do_batch_update;
return interface;
}

#else // SB_API_VERSION < 16
const SbUiNavInterface* sb_ui_interface =
static_cast<const SbUiNavInterface*>(
SbSystemGetExtension(kCobaltExtensionUiNavigationName));
if (sb_ui_interface &&
strcmp(sb_ui_interface->name, kCobaltExtensionUiNavigationName) == 0 &&
sb_ui_interface->version >= 1) {
interface.create_item = sb_ui_interface->create_item;
interface.destroy_item = sb_ui_interface->destroy_item;
interface.set_item_bounds = nullptr;
interface.get_item_bounds = nullptr;
interface.set_focus = sb_ui_interface->set_focus;
interface.set_item_enabled = sb_ui_interface->set_item_enabled;
interface.set_item_dir = sb_ui_interface->set_item_dir;
interface.set_item_size = sb_ui_interface->set_item_size;
interface.set_item_transform = sb_ui_interface->set_item_transform;
interface.get_item_focus_transform =
sb_ui_interface->get_item_focus_transform;
interface.get_item_focus_vector = sb_ui_interface->get_item_focus_vector;
interface.set_item_container_window =
sb_ui_interface->set_item_container_window;
interface.set_item_container_item =
sb_ui_interface->set_item_container_item;
interface.set_item_content_offset =
sb_ui_interface->set_item_content_offset;
interface.get_item_content_offset =
sb_ui_interface->get_item_content_offset;
interface.set_item_focus_duration =
sb_ui_interface->set_item_focus_duration;
interface.do_batch_update = sb_ui_interface->do_batch_update;
return interface;
}
#endif // SB_API_VERSION < 16
interface.create_item = &CreateItem;
interface.destroy_item = &DestroyItem;
interface.set_item_bounds = &SetItemBounds;
Expand Down
4 changes: 4 additions & 0 deletions cobalt/ui_navigation/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
#define COBALT_UI_NAVIGATION_INTERFACE_H_

#include "starboard/configuration.h"
#if SB_API_VERSION < 16
#include "starboard/ui_navigation.h"
#else
#include "starboard/extension/ui_navigation.h"
#endif // SB_API_VERSION

namespace cobalt {
namespace ui_navigation {
Expand Down
4 changes: 2 additions & 2 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
#include "starboard/system.h"
#include "starboard/thread.h"
#include "starboard/time_zone.h"
#include "starboard/ui_navigation.h"
#if SB_API_VERSION < 16
#include "starboard/ui_navigation.h"
#include "starboard/user.h"
#endif // SB_API_VERSION < 16
#include "starboard/window.h"
Expand Down Expand Up @@ -383,8 +383,8 @@ ExportedSymbols::ExportedSymbols() {
#endif // SB_API_VERSION < 16
REGISTER_SYMBOL(SbTimeZoneGetCurrent);
REGISTER_SYMBOL(SbTimeZoneGetName);
REGISTER_SYMBOL(SbUiNavGetInterface);
#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbUiNavGetInterface);
REGISTER_SYMBOL(SbUserGetCurrent);
REGISTER_SYMBOL(SbUserGetProperty);
REGISTER_SYMBOL(SbUserGetPropertySize);
Expand Down
Loading

0 comments on commit 0099e9f

Please sign in to comment.