From 95f38740b8a4a4cdc15197f6a721336c7b6500e6 Mon Sep 17 00:00:00 2001 From: Marek Biolik Date: Mon, 25 Nov 2024 08:58:23 +0100 Subject: [PATCH] [xb1] Implement closed captioning system settings --- starboard/xb1/BUILD.gn | 2 + .../xb1/shared/accessibility_extension.cc | 53 +++++ .../xb1/shared/accessibility_extension.h | 36 ++++ .../accessibility_get_caption_settings.cc | 194 ++++++++++++++++++ starboard/xb1/shared/system_get_extensions.cc | 4 + 5 files changed, 289 insertions(+) create mode 100644 starboard/xb1/shared/accessibility_extension.cc create mode 100644 starboard/xb1/shared/accessibility_extension.h create mode 100644 starboard/xb1/shared/accessibility_get_caption_settings.cc diff --git a/starboard/xb1/BUILD.gn b/starboard/xb1/BUILD.gn index e4137bc401b..dfb13c15e4d 100644 --- a/starboard/xb1/BUILD.gn +++ b/starboard/xb1/BUILD.gn @@ -186,6 +186,8 @@ static_library("starboard_platform") { "//starboard/shared/win32/win32_audio_decoder.h", "//starboard/shared/win32/wrm_header.cc", "//starboard/shared/win32/wrm_header.h", + "//starboard/xb1/shared/accessibility_extension.cc", + "//starboard/xb1/shared/accessibility_get_caption_settings.cc", "//starboard/xb1/shared/gpu_base_video_decoder.cc", "//starboard/xb1/shared/gpu_base_video_decoder.h", "//starboard/xb1/shared/internal_shims.h", diff --git a/starboard/xb1/shared/accessibility_extension.cc b/starboard/xb1/shared/accessibility_extension.cc new file mode 100644 index 00000000000..05c8998939b --- /dev/null +++ b/starboard/xb1/shared/accessibility_extension.cc @@ -0,0 +1,53 @@ +// 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/xb1/shared/accessibility_extension.h" +#include "starboard/extension/accessibility.h" + +namespace starboard { +namespace xb1 { +namespace shared { + +namespace accessibility { + +// The rest of the accessibility extension is not implemented on XB1 +bool GetTextToSpeechSettings(SbAccessibilityTextToSpeechSettings* out_setting) { + return false; +} + +bool GetDisplaySettings(SbAccessibilityDisplaySettings* out_setting) { + return false; +} + +bool SetCaptionsEnabled(bool enabled) { + return false; +} + +} // namespace accessibility + +const StarboardExtensionAccessibilityApi kAccessibilityAPI = { + kStarboardExtensionAccessibilityName, + 1, + &accessibility::GetTextToSpeechSettings, + &accessibility::GetDisplaySettings, + &accessibility::GetCaptionSettings, + &accessibility::SetCaptionsEnabled}; + +const void* GetAccessibilityApi() { + return &kAccessibilityAPI; +} + +} // namespace shared +} // namespace xb1 +} // namespace starboard diff --git a/starboard/xb1/shared/accessibility_extension.h b/starboard/xb1/shared/accessibility_extension.h new file mode 100644 index 00000000000..8c81c16d9d9 --- /dev/null +++ b/starboard/xb1/shared/accessibility_extension.h @@ -0,0 +1,36 @@ +// 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 STARBOARD_XB1_SHARED_ACCESSIBILITY_EXTENSION_H_ +#define STARBOARD_XB1_SHARED_ACCESSIBILITY_EXTENSION_H_ + +#include "starboard/extension/accessibility.h" + +namespace starboard { +namespace xb1 { +namespace shared { + +namespace accessibility { +bool GetTextToSpeechSettings(SbAccessibilityTextToSpeechSettings* out_setting); +bool GetDisplaySettings(SbAccessibilityDisplaySettings* out_setting); +bool GetCaptionSettings(SbAccessibilityCaptionSettings* caption_settings); +bool SetCaptionsEnabled(bool enabled); +} // namespace accessibility + +const void* GetAccessibilityApi(); +} // namespace shared +} // namespace xb1 +} // namespace starboard + +#endif // STARBOARD_XB1_SHARED_ACCESSIBILITY_EXTENSION_H_ diff --git a/starboard/xb1/shared/accessibility_get_caption_settings.cc b/starboard/xb1/shared/accessibility_get_caption_settings.cc new file mode 100644 index 00000000000..03e2b5e38f5 --- /dev/null +++ b/starboard/xb1/shared/accessibility_get_caption_settings.cc @@ -0,0 +1,194 @@ +// 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 + +#include "starboard/common/memory.h" +#include "starboard/shared/starboard/accessibility_internal.h" +#include "starboard/xb1/shared/accessibility_extension.h" + +namespace starboard { +namespace xb1 { +namespace shared { +namespace accessibility { + +namespace { + +using namespace Windows::Media::ClosedCaptioning; + +SbAccessibilityCaptionCharacterEdgeStyle +ClosedCaptionEdgeEffectToSbAccessibilityCaptionCharacterEdgeStyle( + ClosedCaptionEdgeEffect edgeStyle) { + switch (edgeStyle) { + case ClosedCaptionEdgeEffect::Default: + return kSbAccessibilityCaptionCharacterEdgeStyleNone; + case ClosedCaptionEdgeEffect::None: + return kSbAccessibilityCaptionCharacterEdgeStyleNone; + case ClosedCaptionEdgeEffect::Raised: + return kSbAccessibilityCaptionCharacterEdgeStyleRaised; + case ClosedCaptionEdgeEffect::Depressed: + return kSbAccessibilityCaptionCharacterEdgeStyleDepressed; + case ClosedCaptionEdgeEffect::Uniform: + return kSbAccessibilityCaptionCharacterEdgeStyleUniform; + case ClosedCaptionEdgeEffect::DropShadow: + return kSbAccessibilityCaptionCharacterEdgeStyleDropShadow; + } +} + +SbAccessibilityCaptionColor ClosedCaptionColorToSbAccessibilityCaptionColor( + ClosedCaptionColor color) { + switch (color) { + case ClosedCaptionColor::Default: + return kSbAccessibilityCaptionColorWhite; + case ClosedCaptionColor::White: + return kSbAccessibilityCaptionColorWhite; + case ClosedCaptionColor::Black: + return kSbAccessibilityCaptionColorBlack; + case ClosedCaptionColor::Red: + return kSbAccessibilityCaptionColorRed; + case ClosedCaptionColor::Green: + return kSbAccessibilityCaptionColorGreen; + case ClosedCaptionColor::Blue: + return kSbAccessibilityCaptionColorBlue; + case ClosedCaptionColor::Yellow: + return kSbAccessibilityCaptionColorYellow; + case ClosedCaptionColor::Magenta: + return kSbAccessibilityCaptionColorMagenta; + case ClosedCaptionColor::Cyan: + return kSbAccessibilityCaptionColorCyan; + } +} + +SbAccessibilityCaptionFontFamily +ClosedCaptionStyleToSbAccessibilityCaptionFontFamily(ClosedCaptionStyle style) { + switch (style) { + case ClosedCaptionStyle::Default: + return kSbAccessibilityCaptionFontFamilyCasual; + case ClosedCaptionStyle::MonospacedWithSerifs: + return kSbAccessibilityCaptionFontFamilyMonospaceSerif; + case ClosedCaptionStyle::ProportionalWithSerifs: + return kSbAccessibilityCaptionFontFamilyProportionalSerif; + case ClosedCaptionStyle::MonospacedWithoutSerifs: + return kSbAccessibilityCaptionFontFamilyMonospaceSansSerif; + case ClosedCaptionStyle::ProportionalWithoutSerifs: + return kSbAccessibilityCaptionFontFamilyProportionalSansSerif; + case ClosedCaptionStyle::Casual: + return kSbAccessibilityCaptionFontFamilyCasual; + case ClosedCaptionStyle::Cursive: + return kSbAccessibilityCaptionFontFamilyCursive; + case ClosedCaptionStyle::SmallCapitals: + return kSbAccessibilityCaptionFontFamilySmallCapitals; + } +} + +SbAccessibilityCaptionFontSizePercentage +ClosedCaptionSizeToSbAccessibilityCaptionFontSizePercentage( + ClosedCaptionSize opacity) { + switch (opacity) { + case ClosedCaptionSize::Default: + return kSbAccessibilityCaptionFontSizePercentage100; + case ClosedCaptionSize::FiftyPercent: + return kSbAccessibilityCaptionFontSizePercentage50; + case ClosedCaptionSize::OneHundredPercent: + return kSbAccessibilityCaptionFontSizePercentage100; + case ClosedCaptionSize::OneHundredFiftyPercent: + return kSbAccessibilityCaptionFontSizePercentage150; + case ClosedCaptionSize::TwoHundredPercent: + return kSbAccessibilityCaptionFontSizePercentage200; + } +} + +SbAccessibilityCaptionOpacityPercentage +ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage( + ClosedCaptionOpacity opacity) { + switch (opacity) { + case ClosedCaptionOpacity::Default: + return kSbAccessibilityCaptionOpacityPercentage100; + case ClosedCaptionOpacity::OneHundredPercent: + return kSbAccessibilityCaptionOpacityPercentage100; + case ClosedCaptionOpacity::SeventyFivePercent: + return kSbAccessibilityCaptionOpacityPercentage75; + case ClosedCaptionOpacity::TwentyFivePercent: + return kSbAccessibilityCaptionOpacityPercentage25; + case ClosedCaptionOpacity::ZeroPercent: + return kSbAccessibilityCaptionOpacityPercentage0; + } +} + +} // namespace. + +bool GetCaptionSettings(SbAccessibilityCaptionSettings* caption_settings) { + if (!caption_settings || + !starboard::common::MemoryIsZero( + caption_settings, sizeof(SbAccessibilityCaptionSettings))) { + return false; + } + + caption_settings->background_color = + ClosedCaptionColorToSbAccessibilityCaptionColor( + ClosedCaptionProperties::BackgroundColor); + caption_settings->background_color_state = kSbAccessibilityCaptionStateSet; + + caption_settings->background_opacity = + ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage( + ClosedCaptionProperties::BackgroundOpacity); + caption_settings->background_opacity_state = kSbAccessibilityCaptionStateSet; + + caption_settings->character_edge_style = + ClosedCaptionEdgeEffectToSbAccessibilityCaptionCharacterEdgeStyle( + ClosedCaptionProperties::FontEffect); + caption_settings->character_edge_style_state = + kSbAccessibilityCaptionStateSet; + + caption_settings->font_color = + ClosedCaptionColorToSbAccessibilityCaptionColor( + ClosedCaptionProperties::FontColor); + caption_settings->font_color_state = kSbAccessibilityCaptionStateSet; + + caption_settings->font_family = + ClosedCaptionStyleToSbAccessibilityCaptionFontFamily( + ClosedCaptionProperties::FontStyle); + caption_settings->font_family_state = kSbAccessibilityCaptionStateSet; + + caption_settings->font_opacity = + ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage( + ClosedCaptionProperties::FontOpacity); + caption_settings->font_opacity_state = kSbAccessibilityCaptionStateSet; + + caption_settings->font_size = + ClosedCaptionSizeToSbAccessibilityCaptionFontSizePercentage( + ClosedCaptionProperties::FontSize); + caption_settings->font_size_state = kSbAccessibilityCaptionStateSet; + + caption_settings->window_color = + ClosedCaptionColorToSbAccessibilityCaptionColor( + ClosedCaptionProperties::RegionColor); + caption_settings->window_color_state = kSbAccessibilityCaptionStateSet; + + caption_settings->window_opacity = + ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage( + ClosedCaptionProperties::RegionOpacity); + caption_settings->window_opacity_state = kSbAccessibilityCaptionStateSet; + + caption_settings->is_enabled = true; // TODO: check it + caption_settings->supports_is_enabled = true; + caption_settings->supports_set_enabled = false; + caption_settings->supports_override = true; + return true; +} + +} // namespace accessibility +} // namespace shared +} // namespace xb1 +} // namespace starboard diff --git a/starboard/xb1/shared/system_get_extensions.cc b/starboard/xb1/shared/system_get_extensions.cc index 009b8d78ff2..e7755e4267c 100644 --- a/starboard/xb1/shared/system_get_extensions.cc +++ b/starboard/xb1/shared/system_get_extensions.cc @@ -20,6 +20,7 @@ #include "starboard/extension/media_session.h" #include "starboard/shared/uwp/xb1_media_session_client.h" #include "starboard/shared/win32/graphics.h" +#include "starboard/xb1/shared/accessibility_extension.h" #include "starboard/xb1/shared/configuration.h" const void* SbSystemGetExtension(const char* name) { @@ -32,5 +33,8 @@ const void* SbSystemGetExtension(const char* name) { if (strcmp(name, kCobaltExtensionMediaSessionName) == 0) { return starboard::shared::uwp::GetMediaSessionApi(); } + if (strcmp(name, kStarboardExtensionAccessibilityName) == 0) { + return starboard::xb1::shared::GetAccessibilityApi(); + } return NULL; }