fix: set supported scale factors on startup (#38836)

This commit is contained in:
Shelley Vohr 2023-06-20 18:24:03 +02:00 committed by GitHub
parent 2b3902e526
commit f6bbc34658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 25 deletions

View file

@ -20,6 +20,7 @@
#include "gin/per_isolate_data.h"
#include "gin/wrappable.h"
#include "net/base/data_url.h"
#include "shell/browser/browser.h"
#include "shell/common/asar/asar_util.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gfx_converter.h"
@ -29,12 +30,14 @@
#include "shell/common/gin_helper/function_template_extensions.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#include "shell/common/process_util.h"
#include "shell/common/skia_util.h"
#include "shell/common/thread_restrictions.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkPixelRef.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h"
@ -53,6 +56,18 @@ namespace electron::api {
namespace {
// This is needed to avoid a hard CHECK when certain aspects of
// ImageSkia are invoked before the browser process is ready,
// since supported scales are normally set by
// ui::ResourceBundle::InitSharedInstance during browser process startup.
void EnsureSupportedScaleFactors() {
if (!electron::IsBrowserProcess())
return;
if (!Browser::Get()->is_ready())
ui::SetSupportedResourceScaleFactors({ui::k100Percent});
}
// Get the scale factor from options object at the first argument
float GetScaleFactorFromOptions(gin::Arguments* args) {
float scale_factor = 1.0f;
@ -108,12 +123,15 @@ base::win::ScopedHICON ReadICOFromPath(int size, const base::FilePath& path) {
NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
: image_(image), isolate_(isolate) {
EnsureSupportedScaleFactors();
UpdateExternalAllocatedMemoryUsage();
}
#if BUILDFLAG(IS_WIN)
NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path)
: hicon_path_(hicon_path), isolate_(isolate) {
EnsureSupportedScaleFactors();
// Use the 256x256 icon as fallback icon.
gfx::ImageSkia image_skia;
electron::util::ReadImageSkiaFromICO(&image_skia, GetHICON(256));