Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52690199 authored by Steven Thomas's avatar Steven Thomas Committed by Alex Vakulenko
Browse files

Add gvr_is_feature_supported()

A new gvr function gvr_is_feature_supported() was added in
https://critique.corp.google.com/#review/145712807.

Implement the function to bring our gvr library up to date.

Bug: 34742071
Test: Confirmed I can once again load TreasureHunt built from google3.
Change-Id: Ib6a9802812a514ee54564f8572be9f6f4820ed01
parent 7fe71e59
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -338,6 +338,15 @@ void gvr_distort_to_screen(gvr_context* gvr, int32_t texture_id,
                           const gvr_buffer_viewport_list* viewport_list,
                           gvr_mat4f head_space_from_start_space,
                           gvr_clock_time_point target_presentation_time);

/// Queries whether a particular GVR feature is supported by the underlying
/// platform.
///
/// @param gvr The context to query against.
/// @param feature The gvr_feature type being queried.
/// @return true if feature is supported, false otherwise.
bool gvr_is_feature_supported(const gvr_context* gvr, int32_t feature);

/// @}

/////////////////////////////////////////////////////////////////////////////
@@ -743,7 +752,7 @@ gvr_mat4f gvr_get_head_space_from_start_space_rotation(
/// scenarios, e.g., when tracking is non-biological.
///
/// @param gvr Pointer to the context instance from which the pose was obtained.
/// @param head_rotation_in_start_space The head rotation as returned by
/// @param head_space_from_start_space_rotation The head rotation as returned by
///     gvr_get_head_space_from_start_space_rotation().
/// @param factor A scaling factor for the neck model offset, clamped from 0 to
///     1. This should be 1 for most scenarios, while 0 will effectively disable
@@ -1589,6 +1598,11 @@ class GvrApi {
                          texture_presentation_time);
  }

  /// For more information, see gvr_is_feature_supported().
  bool IsFeatureSupported(int32_t feature) {
    return gvr_is_feature_supported(context_, feature);
  }

  /// For more information, see gvr_buffer_spec_create().
  BufferSpec CreateBufferSpec() {
    return BufferSpec(context_);
+5 −7
Original line number Diff line number Diff line
@@ -549,7 +549,6 @@ void gvr_audio_set_sound_object_distance_rolloff_model(
    gvr_audio_context* api, gvr_audio_source_id sound_object_id,
    int32_t rolloff_model, float min_distance, float max_distance);


/// Changes the master volume.
///
/// @param api Pointer to a gvr_audio_context.
@@ -707,7 +706,7 @@ class AudioApi {
    return gvr_audio_create_soundfield(context_, filename.c_str());
  }

  /// Returns a new stereo soound.
  /// Returns a new stereo sound.
  /// For more information, see gvr_audio_create_stereo_sound().
  AudioSourceId CreateStereoSound(const std::string& filename) {
    return gvr_audio_create_stereo_sound(context_, filename.c_str());
@@ -824,8 +823,7 @@ class AudioApi {
  /// @name Wrapper manipulation
  /// @{
  /// Creates a C++ wrapper for a C object and takes ownership.
  explicit AudioApi(gvr_audio_context* context)
      : context_(context) {}
  explicit AudioApi(gvr_audio_context* context) : context_(context) {}

  /// Returns the wrapped C object. Does not affect ownership.
  gvr_audio_context* cobj() { return context_; }
+41 −0
Original line number Diff line number Diff line
@@ -414,6 +414,27 @@ gvr_vec3f gvr_controller_state_get_position(const gvr_controller_state* state);
int64_t gvr_controller_state_get_last_position_timestamp(
    const gvr_controller_state* state);

/// Returns whether the controller battery is currently charging.
/// This may not be real time information and may be slow to be updated.
bool gvr_controller_state_get_battery_charging(
    const gvr_controller_state* state);

/// Returns the bucketed controller battery level.
/// Note this is a gvr_controller_battery_level and not a percent.
int32_t gvr_controller_state_get_battery_level(
    const gvr_controller_state* state);

/// Returns the timestamp (nanos) when the last battery event was received.
int64_t gvr_controller_state_get_last_battery_timestamp(
    const gvr_controller_state* state);

/// Convenience to convert a battery level to string. The returned pointer
/// is static and valid throughout the lifetime of the application.
///
/// @param level The gvr_controller_battery_level to convert to string.
/// @return A pointer to a string that describes the value.
const char* gvr_controller_battery_level_to_string(int32_t level);

/// @}

#ifdef __cplusplus
@@ -572,6 +593,10 @@ class ControllerApi {
    return gvr_controller_button_to_string(button);
  }

  static const char* ToString(ControllerBatteryLevel level) {
    return gvr_controller_battery_level_to_string(level);
  }

  /// @name Wrapper manipulation
  /// @{
  /// Creates a C++ wrapper for a C object and takes ownership.
@@ -724,6 +749,22 @@ class ControllerState {
    return gvr_controller_state_get_last_position_timestamp(state_);
  }

  /// For more information, see gvr_controller_state_get_battery_charging
  bool GetBatteryCharging() const {
    return gvr_controller_state_get_battery_charging(state_);
  }

  /// For more information, see gvr_controller_state_get_battery_level
  ControllerBatteryLevel GetBatteryLevel() const {
    return static_cast<ControllerBatteryLevel>(
        gvr_controller_state_get_battery_level(state_));
  }

  /// For more information, see gvr_controller_state_get_last_battery_timestamp
  int64_t GetLastBatteryTimestamp() const {
    return gvr_controller_state_get_last_battery_timestamp(state_);
  }

  /// @name Wrapper manipulation
  /// @{
  /// Creates a C++ wrapper for a C object and takes ownership.
+83 −0
Original line number Diff line number Diff line
@@ -50,6 +50,14 @@ typedef enum {
  GVR_VIEWER_TYPE_DAYDREAM = 1,
} gvr_viewer_type;

// Types of VR-specific features which may or may not be supported on the
// underlying platform.
typedef enum {
  // Asynchronous reprojection warps the app's rendered frame using the most
  // recent head pose just before pushing the frame to the display.
  GVR_FEATURE_ASYNC_REPROJECTION = 0,
} gvr_feature;

/// @}

/// Version information for the Google VR API.
@@ -185,6 +193,8 @@ enum {
  GVR_CONTROLLER_ENABLE_POSE_PREDICTION = 1 << 5,
  /// Indicates that controller position data should be reported.
  GVR_CONTROLLER_ENABLE_POSITION = 1 << 6,
  /// Indicates that controller battery data should be reported.
  GVR_CONTROLLER_ENABLE_BATTERY = 1 << 7,
};

/// Constants that represent the status of the controller API.
@@ -239,6 +249,21 @@ typedef enum {
  GVR_CONTROLLER_BUTTON_COUNT = 6,
} gvr_controller_button;

/// Controller battery states.
typedef enum {
  GVR_CONTROLLER_BATTERY_LEVEL_UNKNOWN = 0,
  GVR_CONTROLLER_BATTERY_LEVEL_CRITICAL_LOW = 1,
  GVR_CONTROLLER_BATTERY_LEVEL_LOW = 2,
  GVR_CONTROLLER_BATTERY_LEVEL_MEDIUM = 3,
  GVR_CONTROLLER_BATTERY_LEVEL_ALMOST_FULL = 4,
  GVR_CONTROLLER_BATTERY_LEVEL_FULL = 5,

  /// Note: there are 5 distinct levels, but there are 6 due to the inclusion
  /// of an UNKNOWN state before any battery information is collected, etc.
  GVR_CONTROLLER_BATTERY_LEVEL_COUNT = 6,
} gvr_controller_battery_level;


/// @}

/// Opaque handle to controller state.
@@ -322,6 +347,41 @@ typedef enum {
/// Sound object and sound field identifier.
typedef int32_t gvr_audio_source_id;

/// Supported surround sound formats.
typedef enum {
  // Enables to initialize a yet undefined rendering mode.
  GVR_AUDIO_SURROUND_FORMAT_INVALID = 0,

  // Virtual stereo speakers at -30 degrees and +30 degrees.
  GVR_AUDIO_SURROUND_FORMAT_SURROUND_STEREO = 1,

  // 5.1 surround sound according to the ITU-R BS 775 speaker configuration
  // recommendation:
  //   - Front left (FL) at 30 degrees.
  //   - Front right (FR) at -30 degrees.
  //   - Front center (FC) at 0 degrees.
  //   - Low frequency effects (LFE) at front center at 0 degrees.
  //   - Left side (LS) at 110 degrees.
  //   - Right side (RS) at -110 degrees.
  //
  // The 5.1 channel input layout must matches AAC: FL, FR, FC, LFE, LS, RS.
  // Note that this differs from the Vorbis/Opus 5.1 channel layout, which
  // is: FL, FC, FR, LS, RS, LFE.
  GVR_AUDIO_SURROUND_FORMAT_SURROUND_FIVE_DOT_ONE = 2,

  // First-order ambisonics (AmbiX format: 4 channels, ACN channel ordering,
  // SN3D normalization).
  GVR_AUDIO_SURROUND_FORMAT_FIRST_ORDER_AMBISONICS = 3,

  // Second-order ambisonics (AmbiX format: 9 channels, ACN channel ordering,
  // SN3D normalization).
  GVR_AUDIO_SURROUND_FORMAT_SECOND_ORDER_AMBISONICS = 4,

  // Third-order ambisonics (AmbiX format: 16 channels, ACN channel ordering,
  // SN3D normalization).
  GVR_AUDIO_SURROUND_FORMAT_THIRD_ORDER_AMBISONICS = 5,
} gvr_audio_surround_format_type;

/// Valid color formats for swap chain buffers.
typedef enum {
  /// Equivalent to GL_RGBA8
@@ -400,6 +460,8 @@ const int32_t kControllerEnablePosePrediction =
    static_cast<int32_t>(GVR_CONTROLLER_ENABLE_POSE_PREDICTION);
const int32_t kControllerEnablePosition =
    static_cast<int32_t>(GVR_CONTROLLER_ENABLE_POSITION);
const int32_t kControllerEnableBattery =
    static_cast<int32_t>(GVR_CONTROLLER_ENABLE_BATTERY);

typedef gvr_controller_api_status ControllerApiStatus;
const ControllerApiStatus kControllerApiOk =
@@ -443,6 +505,26 @@ const ControllerButton kControllerButtonVolumeDown =
const ControllerButton kControllerButtonCount =
    static_cast<ControllerButton>(GVR_CONTROLLER_BUTTON_COUNT);

typedef gvr_controller_battery_level ControllerBatteryLevel;
const ControllerBatteryLevel kControllerBatteryLevelUnknown =
    static_cast<ControllerBatteryLevel>(
        GVR_CONTROLLER_BATTERY_LEVEL_UNKNOWN);
const ControllerBatteryLevel kControllerBatteryLevelCriticalLow =
    static_cast<ControllerBatteryLevel>(
        GVR_CONTROLLER_BATTERY_LEVEL_CRITICAL_LOW);
const ControllerBatteryLevel kControllerBatteryLevelLow =
    static_cast<ControllerBatteryLevel>(
        GVR_CONTROLLER_BATTERY_LEVEL_LOW);
const ControllerBatteryLevel kControllerBatteryLevelMedium =
    static_cast<ControllerBatteryLevel>(
        GVR_CONTROLLER_BATTERY_LEVEL_MEDIUM);
const ControllerBatteryLevel kControllerBatteryLevelAlmostFull =
    static_cast<ControllerBatteryLevel>(
        GVR_CONTROLLER_BATTERY_LEVEL_ALMOST_FULL);
const ControllerBatteryLevel kControllerBatteryLevelFull =
    static_cast<ControllerBatteryLevel>(
        GVR_CONTROLLER_BATTERY_LEVEL_FULL);

/// An uninitialized external surface ID.
const int32_t kUninitializedExternalSurface = GVR_BUFFER_INDEX_EXTERNAL_SURFACE;
/// The default source buffer index for viewports.
@@ -474,6 +556,7 @@ typedef gvr_audio_rendering_mode AudioRenderingMode;
typedef gvr_audio_material_type AudioMaterialName;
typedef gvr_audio_distance_rolloff_type AudioRolloffMethod;
typedef gvr_audio_source_id AudioSourceId;
typedef gvr_audio_surround_format_type AudioSurroundFormat;

typedef gvr_color_format_type ColorFormat;
const ColorFormat kColorFormatRgba8888 =
+0 −9
Original line number Diff line number Diff line
@@ -86,15 +86,6 @@ void* gvr_external_surface_get_surface(const gvr_external_surface* surface);
int32_t gvr_external_surface_get_surface_id(
    const gvr_external_surface* surface);

/// Queries whether a particular GVR feature is supported by the underlying
/// platform.
///
/// @param gvr The context to query against.
/// @param feature The gvr_feature type being queried.
/// @return true if feature is supported, false otherwise.
bool gvr_experimental_is_feature_supported(const gvr_context* gvr,
                                           int32_t feature);

/// Sets the z order of the layer to be created.
/// Note that this API is a short-term workaround for SysUI work and is never
/// meant to graduate as is to either gvr.h or gvr_private.h. The proper
Loading