From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Milan Burda 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 a9b86c68fe5098be3f2b2c902dccd38f893c8800..46931503ec2bdeed0667defaee7593249d887bbf 100644 --- a/content/renderer/renderer_blink_platform_impl.cc +++ b/content/renderer/renderer_blink_platform_impl.cc @@ -997,8 +997,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 f927253a7e0b2ddb2fbcc0958634e7a41b988be9..12ada20ec3a3c9cffb9c95d56d379b93efe38580 100644 --- a/third_party/blink/public/platform/platform.h +++ b/third_party/blink/public/platform/platform.h @@ -500,6 +500,7 @@ class BLINK_PLATFORM_EXPORT Platform { kGLES3ContextType, // GLES 3.0 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 03da0840b0e398fa0826fb36b55ff41bd95af77d..9551675de44d1475714726d9b58f4d1b7863d98f 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 = "8-8-8-8"; 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/XRDevice.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 7b655dd12a77d701453988d949295ead0b7dbf4d..8969eb7d98f3a7bf2e431a398a2156499d1be326 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 3846b2a179d963a99c3785c4b9b41f346403eeb2..bf7c63a8139152c4e6a01f52965da09f6ed0b48e 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( @@ -30,6 +31,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 38ca0f6b6a0c4bcb042887cd168ba8040435875d..90cfe8497daf2db6c3022826b5f1ab4e854e9955 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; };