Add skia_enable_discrete_gpu argument to GN
This forces all of our testing tools to run with the discrete GPU in
laptop systems that have that option.
BUG=skia:
Change-Id: Ibd7629d6de5f063cdf219b3c7469210af5085d90
Reviewed-on: https://skia-review.googlesource.com/6474
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 102b785..24651c7 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -26,6 +26,7 @@
skia_use_zlib = true
skia_enable_android_framework_defines = false
+ skia_enable_discrete_gpu = true
skia_enable_gpu = true
skia_enable_tools = is_skia_standalone
skia_enable_vulkan_debug_layers = is_skia_standalone && is_debug
@@ -148,6 +149,9 @@
if (skia_use_angle) {
defines += [ "SK_ANGLE" ]
}
+ if (skia_enable_discrete_gpu) {
+ defines += [ "SK_ENABLE_DISCRETE_GPU" ]
+ }
}
# Any code that's linked into Skia-the-library should use this config via += skia_library_configs.
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index 8d9bd41..bd745bc 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -24,6 +24,20 @@
#include "gl/GrGLGpu.h"
#include "GrCaps.h"
+#if defined(SK_BUILD_FOR_WIN32) && defined(SK_ENABLE_DISCRETE_GPU)
+extern "C" {
+ // NVIDIA documents that the presence and value of this symbol programmatically enable the high
+ // performance GPU in laptops with switchable graphics.
+ // https://docs.nvidia.com/gameworks/content/technologies/desktop/optimus.htm
+ // From testing, including this symbol, even if it is set to 0, we still get the NVIDIA GPU.
+ _declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
+
+ // AMD has a similar mechanism, although I don't have an AMD laptop, so this is untested.
+ // https://community.amd.com/thread/169965
+ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
+}
+#endif
+
namespace sk_gpu_test {
GrContextFactory::GrContextFactory() { }