electron/patches/common/chromium/webgl_context_attributes.patch

117 lines
5.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Milan Burda <milan.burda@gmail.com>
Date: Thu, 20 Sep 2018 17:47:01 -0700
Subject: webgl_context_attributes.patch
diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc
index 907fd2f4f8567b828f1a45caa32cbd4dafdcac4e..8eb8b5a763c58da80ab826f629aa33e0d782ad14 100644
--- a/content/renderer/renderer_blink_platform_impl.cc
+++ b/content/renderer/renderer_blink_platform_impl.cc
@@ -1029,8 +1029,10 @@ RendererBlinkPlatformImpl::CreateOffscreenGraphicsContext3DProvider(
attributes.sample_buffers = 0;
attributes.bind_generates_resource = false;
attributes.enable_raster_interface = web_attributes.enable_raster_interface;
- // Prefer discrete GPU for WebGL.
- attributes.gpu_preference = gl::PreferDiscreteGpu;
+
+ attributes.gpu_preference = web_attributes.prefer_integrated_gpu
+ ? gl::PreferIntegratedGpu
+ : gl::PreferDiscreteGpu;
attributes.fail_if_major_perf_caveat =
web_attributes.fail_if_major_performance_caveat;
diff --git a/third_party/blink/public/platform/platform.h b/third_party/blink/public/platform/platform.h
index 2f57bdd1ef3ee4f81d248fffc6e1e512ed83bb27..f016cfb6d31d0feeb32800fe6bc1c0421bad66e0 100644
--- a/third_party/blink/public/platform/platform.h
+++ b/third_party/blink/public/platform/platform.h
@@ -550,6 +550,7 @@ class BLINK_PLATFORM_EXPORT Platform {
kWebGPUContextType, // WebGPU context
};
struct ContextAttributes {
+ bool prefer_integrated_gpu = false;
bool fail_if_major_performance_caveat = false;
ContextType context_type = kGLES2ContextType;
// Offscreen contexts usually share a surface for the default frame buffer
diff --git a/third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h b/third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h
index a6f46ede75f84294d34ad042a1fb103d106a0543..c62399bde32c6296d7bdede710e63f30cef50833 100644
--- a/third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h
+++ b/third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h
@@ -30,6 +30,7 @@ class CORE_EXPORT CanvasContextCreationAttributesCore {
String pixel_format = "uint8";
bool premultiplied_alpha = true;
bool preserve_drawing_buffer = false;
+ String power_preference = "default";
bool stencil = false;
// This attribute is of type XRDevice, defined in modules/xr/xr_device.h
diff --git a/third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_module.idl b/third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_module.idl
index 98875e974f51ea77a0adf6f6f304ff97f1f62102..36739547ce2ffda7e6f243f50dab5a63a1fc6a4f 100644
--- a/third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_module.idl
+++ b/third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_module.idl
@@ -28,6 +28,12 @@ enum CanvasPixelFormat {
"float16",
};
+enum CanvasPowerPreference {
+ "default",
+ "low-power",
+ "high-performance",
+};
+
[PermissiveDictionaryConversion]
dictionary CanvasContextCreationAttributesModule {
// This is an experimental feature, but it is not hidden behind a flag in
@@ -47,6 +53,7 @@ dictionary CanvasContextCreationAttributesModule {
boolean antialias = true;
boolean premultipliedAlpha = true;
boolean preserveDrawingBuffer = false;
+ CanvasPowerPreference powerPreference = "default";
boolean failIfMajorPerformanceCaveat = false;
[OriginTrialEnabled=WebXR] XRDevice compatibleXRDevice = null;
};
diff --git a/third_party/blink/renderer/modules/webgl/webgl_context_attribute_helpers.cc b/third_party/blink/renderer/modules/webgl/webgl_context_attribute_helpers.cc
index 26b4610c87c2a2c38e45e0c3d26b5b52ef1097e4..fa6923ed17aee8d85f4d1d7e27dd17fae619da85 100644
--- a/third_party/blink/renderer/modules/webgl/webgl_context_attribute_helpers.cc
+++ b/third_party/blink/renderer/modules/webgl/webgl_context_attribute_helpers.cc
@@ -18,6 +18,7 @@ WebGLContextAttributes ToWebGLContextAttributes(
result.setAntialias(attrs.antialias);
result.setPremultipliedAlpha(attrs.premultiplied_alpha);
result.setPreserveDrawingBuffer(attrs.preserve_drawing_buffer);
+ result.setPowerPreference(attrs.power_preference);
result.setFailIfMajorPerformanceCaveat(
attrs.fail_if_major_performance_caveat);
result.setCompatibleXRDevice(
@@ -31,6 +32,7 @@ Platform::ContextAttributes ToPlatformContextAttributes(
Platform::ContextType context_type,
bool support_own_offscreen_surface) {
Platform::ContextAttributes result;
+ result.prefer_integrated_gpu = attrs.power_preference == "low-power";
result.fail_if_major_performance_caveat =
attrs.fail_if_major_performance_caveat;
result.context_type = context_type;
diff --git a/third_party/blink/renderer/modules/webgl/webgl_context_attributes.idl b/third_party/blink/renderer/modules/webgl/webgl_context_attributes.idl
index 39092f2acab0996dc4f29c3687f92fcd4b8b090f..256beda2da43bf02391943c6ca337fed141bc2a3 100644
--- a/third_party/blink/renderer/modules/webgl/webgl_context_attributes.idl
+++ b/third_party/blink/renderer/modules/webgl/webgl_context_attributes.idl
@@ -26,6 +26,12 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.2
+enum WebGLPowerPreference {
+ "default",
+ "low-power",
+ "high-performance",
+};
+
dictionary WebGLContextAttributes {
boolean alpha = true;
boolean depth = true;
@@ -33,6 +39,7 @@ dictionary WebGLContextAttributes {
boolean antialias = true;
boolean premultipliedAlpha = true;
boolean preserveDrawingBuffer = false;
+ WebGLPowerPreference powerPreference = "default";
boolean failIfMajorPerformanceCaveat = false;
[OriginTrialEnabled=WebXR] XRDevice compatibleXRDevice = null;
// TODO(crbug.com/788439): remove OriginTrialEnabled.