title: Force headless chromium/chrome to use actual gpu instead of Google SwiftShader
body: <p><strong>I'm trying to print html to pdf using headless chromium (using puppeteer)</strong> and everything works fine except if html contains large png images (over 10.000x10.000px) the whole process of rendering page takes extremely long (up to half an hour, but if using non-headless mode it takes only about 10 seconds). After days of investigating and tweaking I came to conclusion that this must be issue with page compositing process.</p>
  <p>Below are dumps from <code>chrome://gpu</code> page in headless and non-headless modes.
  Only significant difference i've noticed is that, when runing chrome headlessly, puppeteer appends by itself <code>--disable-gpu-compositing</code> and <code>--allow-pre-commit-input</code> which i believe are responsible for dramatic performace dropdown.</p>
  <p>Also, in non-headless mode chrome sees 2 gpu units:</p>
  <pre><code>GPU0 VENDOR= 0x10de, DEVICE=0x1d01 *ACTIVE*
  GPU1 VENDOR= 0x8086, DEVICE=0x1912
  </code></pre>
  <p>and in headless mode only one:</p>
  <pre><code>GPU0 VENDOR= 0xffff [Google Inc.], DEVICE=0xffff [Google SwiftShader] *ACTIVE*
  </code></pre>
  <p>which is CPU-based implementation of the Vulkan and OpenGL ES graphics APIs.</p>
  <p>So basicaly my question is:</p>
  <p><strong>Is there any way to run headless chrome/chromium with puppeteer using actual gpu (especialy for gpu-compositing), or is there any way to print page to pdf in non-headless mode?</strong></p>
  <p>Here is my non-headless chrome gpu config (where page rendering is fast):</p>
  <pre><code>Canvas: Hardware accelerated
  Flash: Hardware accelerated
  Flash Stage3D: Hardware accelerated
  Flash Stage3D Baseline profile: Hardware accelerated
  Compositing: Hardware accelerated
  Multiple Raster Threads: Force enabled
  Out-of-process Rasterization: Hardware accelerated
  OpenGL: Enabled
  Hardware Protected Video Decode: Unavailable
  Rasterization: Hardware accelerated on all pages
  Skia Renderer: Enabled
  Video Decode: Unavailable
  Vulkan: Disabled
  WebGL: Hardware accelerated
  WebGL2: Hardware accelerated
  
  Chrome version: Chrome/83.0.4103.0
  Operating system: Linux 4.13.0-46-generic
  2D graphics backend: Skia/83 8ce842d38d0b32149e874d6855c91e8c68ba65a7
  
  Command line:
  /home/wojtas/projects/project-generator/node_modules/puppeteer/.local-
  chromium/linux-756035/chrome-linux/chrome 
  --disable-background-networking 
  --enable-features=NetworkService,NetworkServiceInProcess 
  --disable-background-timer-throttling 
  --disable-backgrounding-occluded-windows 
  --disable-breakpad 
  --disable-client-side-phishing-detection 
  --disable-component-extensions-with-background-pages 
  --disable-default-apps 
  --disable-dev-shm-usage 
  --disable-extensions 
  --disable-features=TranslateUI 
  --disable-hang-monitor 
  --disable-ipc-flooding-protection 
  --disable-popup-blocking 
  --disable-prompt-on-repost 
  --disable-renderer-backgrounding 
  --disable-sync 
  --force-color-profile=srgb 
  --metrics-recording-only 
  --no-first-run
  --enable-automation 
  --password-store=basic 
  --use-mock-keychain 
  --disable-web-security 
  --user-data-dir=/var/www/project-generator/var/chrome-user-data 
  --allow-file-access-from-files 
  --no-sandbox
  --no-sandbox-and-elevated 
  --no-zygote 
  --enable-webgl 
  --use-gl=desktop 
  --use-skia-renderer 
  --enable-gpu-rasterization 
  --enable-zero-copy 
  --disable-gpu-sandbox 
  --enable-native-gpu-memory-buffers 
  --disable-background-timer-throttling 
  --disable-backgrounding-occluded-windows 
  --disable-renderer-backgrounding 
  --ignore-certificate-errors 
  --enable-hardware-overlays 
  --num-raster-threads=4 
  --default-tile-width=512 
  --default-tile-height=512 
  --enable-oop-rasterization 
  --remote-debugging-port=0 
  --flag-switches-begin 
  --flag-switches-end 
  --enable-audio-service-sandbox 
  </code></pre>
  <p>And here is headless chrome gpu config (which is extemely slow)</p>
  <pre><code> Graphics Feature Status
  Canvas: Hardware accelerated
  Flash: Hardware accelerated
  Flash Stage3D: Hardware accelerated
  Flash Stage3D Baseline profile: Hardware accelerated
  Compositing: Software only. Hardware acceleration disabled
  Multiple Raster Threads: Force enabled
  Out-of-process Rasterization: Hardware accelerated
  OpenGL: Enabled
  Hardware Protected Video Decode: Unavailable
  Rasterization: Hardware accelerated on all pages
  Skia Renderer: Enabled
  Video Decode: Unavailable
  Vulkan: Disabled
  WebGL: Hardware accelerated but at reduced performance
  WebGL2: Hardware accelerated but at reduced performance
  
  Chrome version: HeadlessChrome/83.0.4103.0
  Operating system: Linux 4.13.0-46-generic
  2D graphics backend: Skia/83 8ce842d38d0b32149e874d6855c91e8c68ba65a7
  
  Command Line:
  /home/wojtas/projects/project-generator/node_modules/puppeteer/.local-chromium/linux-756035/chrome-linux/chrome 
  --disable-background-networking 
  --enable-features=NetworkService,NetworkServiceInProcess 
  --disable-background-timer-throttling 
  --disable-backgrounding-occluded-windows 
  --disable-breakpad 
  --disable-client-side-phishing-detection 
  --disable-component-extensions-with-background-pages 
  --disable-default-apps 
  --disable-dev-shm-usage 
  --disable-extensions 
  --disable-features=TranslateUI 
  --disable-hang-monitor
  --disable-ipc-flooding-protection 
  --disable-popup-blocking 
  --disable-prompt-on-repost 
  --disable-renderer-backgrounding 
  --disable-sync 
  --force-color-profile=srgb
  --metrics-recording-only 
  --no-first-run 
  --enable-automation 
  --password-store=basic 
  --use-mock-keychain 
  --headless 
  --hide-scrollbars 
  --mute-audio 
  --disable-web-security 
  --user-data-dir=/var/www/project-generator/var/chrome-user-data 
  --allow-file-access-from-files 
  --no-sandbox 
  --no-sandbox-and-elevated 
  --no-zygote 
  --enable-webgl 
  --use-gl=desktop 
  --use-skia-renderer 
  --enable-gpu-rasterization 
  --enable-zero-copy 
  --disable-gpu-sandbox 
  --enable-native-gpu-memory-buffers 
  --disable-background-timer-throttling 
  --disable-backgrounding-occluded-windows 
  --disable-renderer-backgrounding 
  --ignore-certificate-errors 
  --enable-hardware-overlays 
  --num-raster-threads=4 
  --default-tile-width=512 
  --default-tile-height=512
  --enable-oop-rasterization 
  --remote-debugging-port=0 
  --disable-gpu-compositing 
  --allow-pre-commit-input 
  </code></pre>
  <p>Even if i added <code>--disable-webgl</code> and <code>--disable-webgl2</code> still
  <code>VENDOR= 0xffff [Google Inc.], DEVICE=0xffff [Google SwiftShader] *ACTIVE*</code> is being used.</p>
  <p>Additionally:</p>
  <blockquote>
  <p>Gpu compositing has been disabled, either via blacklist, about:flags or the command line. The browser will
  fall back to software compositing and hardware acceleration will be unavailable.
  Disabled Features: gpu_compositing
  WebGL has been disabled via blacklist or the command line.
  Disabled Features: webgl
  WebGL2 has been disabled via blacklist or the command line.
  Disabled Features: webgl2</p>
  </blockquote>
  <p>notice appears on <code>chrome://gpu</code> page</p>
  <p>Graphics Feature Status:</p>
  <pre><code>Canvas: Hardware accelerated
  Flash: Hardware accelerated
  Flash Stage3D: Hardware accelerated
  Flash Stage3D Baseline profile: Hardware accelerated
  Compositing: Software only. Hardware acceleration disabled
  Multiple Raster Threads: Enabled
  Out-of-process Rasterization: Disabled
  OpenGL: Enabled
  Hardware Protected Video Decode: Unavailable
  Rasterization: Hardware accelerated on all pages
  Skia Renderer: Enabled
  Video Decode: Unavailable
  Vulkan: Disabled
  WebGL: Disabled
  WebGL2: Disabled
  </code></pre>