Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Unified Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2069143002: Limit the number of accelerated canvases that can exist in a render process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix layout test Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
index ceebfd501035a0a9f250aa662cfd7ee32b70fdf8..40b7e066ec60bfe2f35ff787929c888f34f2b843 100644
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
@@ -89,20 +89,22 @@ const int MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS pixels
// In Skia, we will also limit width/height to 32767.
const int MaxSkiaDim = 32767; // Maximum width/height in CSS pixels.
+#if OS(ANDROID)
+// We estimate that the max limit for android phones is a quarter of that for
+// desktops based on local experimental results on Android One.
+const int MaxGlobalAcceleratedImageBufferCount = 25;
+#else
+const int MaxGlobalAcceleratedImageBufferCount = 100;
+#endif
+
// We estimate the max limit of GPU allocated memory for canvases before Chrome
// becomes laggy by setting the total allocated memory for accelerated canvases
-// to be equivalent to memory used by 80 accelerated canvases, each has a size
+// to be equivalent to memory used by 100 accelerated canvases, each has a size
// of 1000*500 and 2d context.
// Each such canvas occupies 4000000 = 1000 * 500 * 2 * 4 bytes, where 2 is the
// gpuBufferCount in ImageBuffer::updateGPUMemoryUsage() and 4 means four bytes
// per pixel per buffer.
-#if !OS(ANDROID)
-const int MaxGlobalGPUMemoryUsage = 4000000 * 80;
-#else
-// We estimate that the max limit for android phones is a quarter of that for
-// desktops based on local experimental results on Android One.,
-const int MaxGlobalGPUMemoryUsage = 4000000 * 20;
-#endif
+const int MaxGlobalGPUMemoryUsage = 4000000 * MaxGlobalAcceleratedImageBufferCount;
// A default value of quality argument for toDataURL and toBlob
// It is in an invalid range (outside 0.0 - 1.0) so that it will not be
@@ -555,7 +557,7 @@ const AtomicString HTMLCanvasElement::imageSourceURL() const
void HTMLCanvasElement::prepareSurfaceForPaintingIfNeeded() const
{
- ASSERT(m_context && m_context->is2d()); // This function is called by the 2d context
+ DCHECK(m_context && m_context->is2d()); // This function is called by the 2d context
if (buffer())
m_imageBuffer->prepareSurfaceForPaintingIfNeeded();
}
@@ -748,6 +750,12 @@ bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const
if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage)
return false;
+ // Allocating too many GPU resources can makes us run into the driver's
+ // resource limits. So we need to keep the number of texture resources
+ // under tight control
+ if (ImageBuffer::getGlobalAcceleratedImageBufferCount() >= MaxGlobalAcceleratedImageBufferCount)
+ return false;
+
return true;
}
@@ -1081,7 +1089,7 @@ IntSize HTMLCanvasElement::bitmapSourceSize() const
ScriptPromise HTMLCanvasElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState)
{
- ASSERT(eventTarget.toLocalDOMWindow());
+ DCHECK(eventTarget.toLocalDOMWindow());
if (!sw || !sh) {
exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
return ScriptPromise();
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698