Skip to content

Commit

Permalink
Support hidpiScreenSize setting in getGPUTier()
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Kovelenov committed Nov 23, 2023
1 parent e2be2ce commit dad7c20
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ getGPUTier({
* @defaultValue [0, 15, 30, 60]
*/
desktopTiers,
/**
* Use HiDPI (Retina) resolution to find benchmark results.
*
* @defaultValue true
*/
hidpiScreenSize,
/**
* Optionally override specific parameters. Used mainly for testing.
*/
Expand All @@ -97,9 +103,9 @@ getGPUTier({
/**
* Override device screen size.
*/
screenSize: { width, height };
screenSize: { width, height },
/**
* Override how benchmark data is loaded
* Override how benchmark data is loaded.
*/
loadBenchmarks
};
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const getGPUTier = async ({
glContext,
failIfMajorPerformanceCaveat = false,
benchmarksURL = `https://unpkg.com/detect-gpu-js@${version}/dist/benchmarks`,
hidpiScreenSize = true,
} = {}) => {

const queryCache = {};
Expand Down Expand Up @@ -128,9 +129,11 @@ export const getGPUTier = async ({

let minDistance = Number.MAX_VALUE;
let closest;
const { devicePixelRatio } = window;

const pixelCount = screenSize.width * devicePixelRatio * screenSize.height * devicePixelRatio;
let pixelCount = screenSize.width * screenSize.height;

if (hidpiScreenSize)
pixelCount = pixelCount * window.devicePixelRatio * window.devicePixelRatio;

for (const match of fpsesByPixelCount) {
const [width, height] = match;
Expand Down

0 comments on commit dad7c20

Please sign in to comment.