-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core(full-page-screenshot): get the MAX_TEXTURE_SIZE from the browser #11847
Changes from all commits
f19d171
09b4027
ce7680a
ab9de8c
8c61f9d
3e9a9a8
93d36fc
17f7f04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,26 @@ function getOuterHTMLSnippet(element, ignoreAttrs = [], snippetCharacterLimit = | |
} | ||
} | ||
|
||
/** | ||
* Get the maximum size of a texture the GPU can handle | ||
* @see https://bugs.chromium.org/p/chromium/issues/detail?id=770769#c13 | ||
*/ | ||
/* istanbul ignore next */ | ||
function getMaxTextureSize() { | ||
try { | ||
let canvas = document.createElement('canvas'); | ||
let gl = canvas.getContext('webgl'); | ||
const maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); | ||
canvas = gl = undefined; // Cleanup for GC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought there might have been a more explicit "destroy" method for a context, but there isn't. As long as the element is not on the DOM, we're good. Can remove the "cleanup" line. sorry for confusion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe i'm overly cautious but memory mgmt with webgl feels like it has some gotchas.. as such, i'm prone to keep the explicit cleanup and not just wait for auto-GC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mathiasbynens we're just two developers who don't know how GC works. wdyt? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neither That said, I’m not familiar with Chromium’s WebGL context lifecycle, and if perhaps there are weird side effects to creating such contexts that I don’t know about. |
||
return maxTextureSize; | ||
} catch (e) { | ||
// If the above fails for any reason we need a fallback number; | ||
// 4096 is the max texture size on a Pixel 2 XL, so to be conservative we'll use a low value like it. | ||
// But we'll subtract 1 just to identify this case later on. | ||
const MAX_TEXTURE_SIZE_FALLBACK = 4095; | ||
return MAX_TEXTURE_SIZE_FALLBACK; | ||
} | ||
} | ||
|
||
/** | ||
* Computes a memory/CPU performance benchmark index to determine rough device class. | ||
|
@@ -521,6 +541,7 @@ module.exports = { | |
getOuterHTMLSnippet: getOuterHTMLSnippet, | ||
computeBenchmarkIndex: computeBenchmarkIndex, | ||
computeBenchmarkIndexString: computeBenchmarkIndex.toString(), | ||
getMaxTextureSize, | ||
getNodeDetailsString, | ||
getNodeDetails, | ||
getNodePathString: getNodePath.toString(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
|
||
const FullPageScreenshotGatherer = require('../../../gather/gatherers/full-page-screenshot.js'); | ||
|
||
// Headless's default value is (1024 * 16), but this varies by device | ||
const maxTextureSizeMock = 1024 * 8; | ||
|
||
/** | ||
* @param {{contentSize: {width: number, height: number}, screenSize: {width?: number, height?: number, dpr: number}, screenshotData: string[]}} | ||
*/ | ||
|
@@ -17,6 +20,8 @@ function createMockDriver({contentSize, screenSize, screenshotData}) { | |
evaluate: async function(fn) { | ||
if (fn.name === 'resolveNodes') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this so much nicer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fn.name is pretty tight. :) good call. |
||
return {}; | ||
} if (fn.name === 'getMaxTextureSize') { | ||
return maxTextureSizeMock; | ||
} else if (fn.name === 'getObservedDeviceMetrics') { | ||
return { | ||
width: screenSize.width, | ||
|
@@ -192,7 +197,7 @@ describe('FullPageScreenshot gatherer', () => { | |
'Emulation.setDeviceMetricsOverride', | ||
expect.objectContaining({ | ||
deviceScaleFactor: 1, | ||
height: FullPageScreenshotGatherer.MAX_SCREENSHOT_HEIGHT, | ||
height: maxTextureSizeMock, | ||
}) | ||
); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why a page function and not local to this module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly because theres a lot of ways in which PFs are very diff than node code and so i'd like to ideally have all PFs live in separate files.
eslint-env browser
instead of our current handcrafted/* global window document Node ShadowRoot */
list.--
but until all are migrated there i'll just place new ones in pf.js. thats my thinking.
i don't care a lot about this particular case tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny, I have the exact opposite thinking. Not speaking to the idea at all, but if we are currently doing "all page functions local if possible", we should keep doing that until we change how we structure things, instead of starting a transitionary thing w/o any discussion.
fwiw i like your bullet points
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
word.
well... looking at the fn's in pf.js, there already are plenty that are one-offs used by gatherrunner & driver. oh and a singleuse for iframe-elements! :)