Skip to content

Commit

Permalink
Enable Skia through persistent setting (#3592)
Browse files Browse the repository at this point in the history
Using h5vcc.settings.set("SkiaRasterizer", 1/0) to enable or disable
skia rasterizer.

b/184042925
  • Loading branch information
sherryzy authored Jul 3, 2024
1 parent dae1fb9 commit 3d783ce
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 69 deletions.
16 changes: 16 additions & 0 deletions cobalt/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ source_set("browser_switches") {
public_deps = [ "//starboard:starboard_headers_only" ]
}

source_set("browser_rasterizer_settings") {
has_pedantic_warnings = true
sources = [
"resolve_rasterizer_settings.cc",
"resolve_rasterizer_settings.h",
]
deps = [
":browser_switches",
"//cobalt/base",
"//cobalt/configuration",
"//cobalt/persistent_storage:persistent_settings",
]
}

static_library("browser") {
has_pedantic_warnings = true

Expand Down Expand Up @@ -152,6 +166,7 @@ static_library("browser") {

deps = [
":bindings",
":browser_rasterizer_settings",
":browser_switches",
":cpu_usage_tracker",
":generated_bindings",
Expand Down Expand Up @@ -268,6 +283,7 @@ target(gtest_target_type, "browser_test") {

deps = [
":browser",
":browser_rasterizer_settings",
":browser_switches",
"//cobalt/base",
"//cobalt/browser/memory_settings:browser_memory_settings",
Expand Down
28 changes: 11 additions & 17 deletions cobalt/browser/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "cobalt/browser/loader_app_metrics.h"
#include "cobalt/browser/memory_settings/auto_mem_settings.h"
#include "cobalt/browser/metrics/cobalt_metrics_services_manager.h"
#include "cobalt/browser/resolve_rasterizer_settings.h"
#include "cobalt/browser/switches.h"
#include "cobalt/browser/user_agent_platform_info.h"
#include "cobalt/browser/user_agent_string.h"
Expand Down Expand Up @@ -106,8 +107,6 @@ const char kDefaultURL[] = "https://www.youtube.com/tv";
const char kAboutBlankURL[] = "about:blank";
#endif // defined(ENABLE_ABOUT_SCHEME)

const char kPersistentSettingsJson[] = "settings.json";

// The watchdog client name used to represent Stats.
const char kWatchdogName[] = "stats";
// The watchdog time interval in microseconds allowed between pings before
Expand Down Expand Up @@ -687,7 +686,7 @@ Application::Application(const base::Closure& quit_closure, bool should_preload,
// Initializes persistent settings.
persistent_settings_ =
std::make_unique<persistent_storage::PersistentSettings>(
kPersistentSettingsJson);
configuration::Configuration::kPersistentSettingsJson);

// Initialize telemetry/metrics.
InitMetrics();
Expand Down Expand Up @@ -732,18 +731,13 @@ Application::Application(const base::Closure& quit_closure, bool should_preload,
options.renderer_module_options.enable_fps_overlay = true;
}

if (command_line->HasSwitch(browser::switches::kEnableSkiaRasterizer)) {
int enable_skia = 0;
base::StringToInt(command_line->GetSwitchValueASCII(
browser::switches::kEnableSkiaRasterizer),
&enable_skia);
if (enable_skia) {
options.renderer_module_options.rasterizer_type_setting =
configuration::Configuration::kSkiaRasterizer;
} else {
options.renderer_module_options.rasterizer_type_setting =
configuration::Configuration::kGlesRasterizer;
}
bool enable_skia_rasterizer = false;
options.renderer_module_options.rasterizer_type_setting =
browser::GetRasterizerType(persistent_settings_.get());
if (options.renderer_module_options.rasterizer_type_setting ==
configuration::Configuration::kSkiaRasterizer) {
loader::image::ImageDecoder::EnableSkiaRasterizer();
enable_skia_rasterizer = true;
}

ApplyCommandLineSettingsToRendererOptions(&options.renderer_module_options);
Expand Down Expand Up @@ -895,7 +889,7 @@ Application::Application(const base::Closure& quit_closure, bool should_preload,
options.web_module_options.collect_unload_event_time_callback = base::Bind(
&Application::CollectUnloadEventTimingInfo, base::Unretained(this));

cobalt::browser::UserAgentPlatformInfo platform_info;
cobalt::browser::UserAgentPlatformInfo platform_info(enable_skia_rasterizer);

network_module_.reset(new network::NetworkModule(
CreateUserAgentString(platform_info), GetClientHintHeaders(platform_info),
Expand Down Expand Up @@ -938,7 +932,7 @@ Application::Application(const base::Closure& quit_closure, bool should_preload,
#if SB_IS(EVERGREEN)
updater_module_.get(),
#endif
options));
options, enable_skia_rasterizer));

UpdateUserAgent();

Expand Down
15 changes: 9 additions & 6 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ BrowserModule::BrowserModule(const GURL& url,
#if SB_IS(EVERGREEN)
updater::UpdaterModule* updater_module,
#endif
const Options& options)
const Options& options,
bool enable_skia_rasterizer)
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(
weak_this_(weak_ptr_factory_.GetWeakPtr())),
Expand Down Expand Up @@ -252,7 +253,8 @@ BrowserModule::BrowserModule(const GURL& url,
main_web_module_generation_(0),
next_timeline_id_(1),
current_splash_screen_timeline_id_(-1),
current_main_web_module_timeline_id_(-1) {
current_main_web_module_timeline_id_(-1),
enable_skia_rasterizer_(enable_skia_rasterizer) {
TRACE_EVENT0("cobalt::browser", "BrowserModule::BrowserModule()");

if (options.enable_on_screen_keyboard) {
Expand All @@ -272,7 +274,8 @@ BrowserModule::BrowserModule(const GURL& url,
// Apply platform memory setting adjustments and defaults.
ApplyAutoMemSettings();

platform_info_.reset(new browser::UserAgentPlatformInfo());
platform_info_.reset(
new browser::UserAgentPlatformInfo(enable_skia_rasterizer_));
service_worker_registry_.reset(new ServiceWorkerRegistry(
&web_settings_, network_module, platform_info_.get()));

Expand Down Expand Up @@ -1971,9 +1974,9 @@ ViewportSize BrowserModule::GetViewportSize() {

void BrowserModule::ApplyAutoMemSettings() {
TRACE_EVENT0("cobalt::browser", "BrowserModule::ApplyAutoMemSettings()");
auto_mem_.ConstructSettings(GetViewportSize().width_height(),
options_.command_line_auto_mem_settings,
options_.config_api_auto_mem_settings);
auto_mem_.ConstructSettings(
GetViewportSize().width_height(), options_.command_line_auto_mem_settings,
options_.config_api_auto_mem_settings, enable_skia_rasterizer_);

// Web Module options.
options_.web_module_options.encoded_image_cache_capacity =
Expand Down
4 changes: 3 additions & 1 deletion cobalt/browser/browser_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class BrowserModule {
#if SB_IS(EVERGREEN)
updater::UpdaterModule* updater_module,
#endif
const Options& options);
const Options& options, bool enable_skia_rasterizer = false);
~BrowserModule();

std::string GetUserAgent() { return network_module_->GetUserAgent(); }
Expand Down Expand Up @@ -748,6 +748,8 @@ class BrowserModule {

// Manages the Service Workers.
std::unique_ptr<ServiceWorkerRegistry> service_worker_registry_;

bool enable_skia_rasterizer_;
};

} // namespace browser
Expand Down
16 changes: 4 additions & 12 deletions cobalt/browser/memory_settings/auto_mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ int64_t AutoMem::SumAllMemoryOfType(

void AutoMem::ConstructSettings(const math::Size& ui_resolution,
const AutoMemSettings& command_line_settings,
const AutoMemSettings& config_api_settings) {
const AutoMemSettings& config_api_settings,
bool enable_skia_rasterizer) {
TRACE_EVENT0("cobalt::browser", "AutoMem::ConstructSettings()");
max_cpu_bytes_ = CreateCpuSetting(command_line_settings);
max_gpu_bytes_ = CreateGpuSetting(command_line_settings);
Expand Down Expand Up @@ -411,19 +412,10 @@ void AutoMem::ConstructSettings(const math::Size& ui_resolution,
offscreen_target_cache_size_in_bytes_->set_memory_scaling_function(
MakeLinearMemoryScaler(0.25, 1.0));

base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
std::string rasterizer_type =
configuration::Configuration::GetInstance()->CobaltRasterizerType();
if (command_line->HasSwitch(browser::switches::kEnableSkiaRasterizer)) {
int enable_skia = 0;
base::StringToInt(command_line->GetSwitchValueASCII(
browser::switches::kEnableSkiaRasterizer),
&enable_skia);
if (enable_skia) {
rasterizer_type = configuration::Configuration::kSkiaRasterizer;
} else {
rasterizer_type = configuration::Configuration::kGlesRasterizer;
}
if (enable_skia_rasterizer) {
rasterizer_type = configuration::Configuration::kSkiaRasterizer;
}
if (rasterizer_type == configuration::Configuration::kGlesRasterizer) {
offscreen_target_cache_size_in_bytes_->set_memory_type(MemorySetting::kGPU);
Expand Down
3 changes: 2 additions & 1 deletion cobalt/browser/memory_settings/auto_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class AutoMem {

void ConstructSettings(const math::Size& ui_resolution,
const AutoMemSettings& command_line_settings,
const AutoMemSettings& config_api_settings);
const AutoMemSettings& config_api_settings,
bool enable_skia_rasterizer = false);

const IntSetting* encoded_image_cache_size_in_bytes() const;
const IntSetting* image_cache_size_in_bytes() const;
Expand Down
83 changes: 83 additions & 0 deletions cobalt/browser/resolve_rasterizer_settings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 "cobalt/browser/resolve_rasterizer_settings.h"

#include <memory>

#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "cobalt/browser/switches.h"
#include "cobalt/configuration/configuration.h"
#include "cobalt/persistent_storage/persistent_settings.h"

namespace cobalt {
namespace browser {

namespace {
std::string GetRasterizerTypeFromPersistentSettings(
persistent_storage::PersistentSettings* persistent_settings) {
std::string rasterizer_type = "";
if (persistent_settings != nullptr) {
base::Value value;
persistent_settings->Get(
configuration::Configuration::kEnableSkiaRasterizerPersistentSettingKey,
&value);
if (!value.is_none() && value.is_bool()) {
bool enable_skia = 0;
enable_skia = value.GetBool();
rasterizer_type = enable_skia
? configuration::Configuration::kSkiaRasterizer
: configuration::Configuration::kGlesRasterizer;
}
}
return rasterizer_type;
}

std::string GetRasterizerTypeFromCommandline() {
std::string rasterizer_type = "";
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(browser::switches::kEnableSkiaRasterizer)) {
int enable_skia = 0;
base::StringToInt(command_line->GetSwitchValueASCII(
browser::switches::kEnableSkiaRasterizer),
&enable_skia);
rasterizer_type = enable_skia
? configuration::Configuration::kSkiaRasterizer
: configuration::Configuration::kGlesRasterizer;
}
return rasterizer_type;
}

} // namespace

std::string GetRasterizerType(
persistent_storage::PersistentSettings* persistent_settings) {
std::string rasterizer_type = GetRasterizerTypeFromCommandline();
if (rasterizer_type != "") {
return rasterizer_type;
}

rasterizer_type =
GetRasterizerTypeFromPersistentSettings(persistent_settings);
if (rasterizer_type != "") {
return rasterizer_type;
}

return configuration::Configuration::GetInstance()->CobaltRasterizerType();
}

} // namespace browser
} // namespace cobalt
31 changes: 31 additions & 0 deletions cobalt/browser/resolve_rasterizer_settings.h
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.

#ifndef COBALT_BROWSER_RESOLVE_RASTERIZER_SETTINGS_H_
#define COBALT_BROWSER_RESOLVE_RASTERIZER_SETTINGS_H_

#include <string>

#include "cobalt/persistent_storage/persistent_settings.h"

namespace cobalt {
namespace browser {

std::string GetRasterizerType(
persistent_storage::PersistentSettings* persistent_settings = nullptr);

} // namespace browser
} // namespace cobalt

#endif // COBALT_BROWSER_RESOLVE_RASTERIZER_SETTINGS_H_
22 changes: 6 additions & 16 deletions cobalt/browser/user_agent_platform_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,10 @@ void InitializeUserAgentPlatformInfoFields(UserAgentPlatformInfo& info) {
info.set_javascript_engine_version(
script::GetJavaScriptEngineNameAndVersion());

std::string rasterizer_type_setting = "";
if (base::CommandLine::InitializedForCurrentProcess()) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(browser::switches::kEnableSkiaRasterizer)) {
int enable_skia = 0;
base::StringToInt(command_line->GetSwitchValueASCII(
browser::switches::kEnableSkiaRasterizer),
&enable_skia);
if (enable_skia) {
rasterizer_type_setting = configuration::Configuration::kSkiaRasterizer;
} else {
rasterizer_type_setting = configuration::Configuration::kGlesRasterizer;
}
}
}
std::string rasterizer_type_setting =
info.enable_skia_rasterizer()
? configuration::Configuration::kSkiaRasterizer
: "";
std::string rasterizer_type =
renderer::GetDefaultRasterizerForPlatform(rasterizer_type_setting)
.rasterizer_name;
Expand Down Expand Up @@ -464,7 +453,8 @@ void InitializeUserAgentPlatformInfoFields(UserAgentPlatformInfo& info) {
}
} // namespace

UserAgentPlatformInfo::UserAgentPlatformInfo() {
UserAgentPlatformInfo::UserAgentPlatformInfo(bool enable_skia_rasterizer)
: enable_skia_rasterizer_(enable_skia_rasterizer) {
InitializeUserAgentPlatformInfoFields(*this);
}

Expand Down
8 changes: 6 additions & 2 deletions cobalt/browser/user_agent_platform_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void GetUserAgentInputMap(

class UserAgentPlatformInfo : public web::UserAgentPlatformInfo {
public:
UserAgentPlatformInfo();
~UserAgentPlatformInfo() override{};
explicit UserAgentPlatformInfo(bool enable_skia_rasterizer = false);
~UserAgentPlatformInfo() override {};

// From: dom:UserAgentPlatformInfo
//
Expand Down Expand Up @@ -90,6 +90,8 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo {
return build_configuration_;
}

bool enable_skia_rasterizer() { return enable_skia_rasterizer_; }

// Other: Setters that sanitize the strings where needed.
//
void set_starboard_version(const std::string& starboard_version);
Expand Down Expand Up @@ -146,6 +148,8 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo {
std::string cobalt_version_;
std::string cobalt_build_version_number_;
std::string build_configuration_;

bool enable_skia_rasterizer_ = false;
};

} // namespace browser
Expand Down
Loading

0 comments on commit 3d783ce

Please sign in to comment.