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 3b5b5c4d0c1f043cee3d8dff903fc75d1bff9dfe..e80957a7740de3e4abc1a9d3561315107e91e774 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
@@ -80,6 +80,20 @@ 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. |
+// We estimate the max limit of GPU allocated memory for canvases before Chrome becomes laggy by setting the |
Justin Novosad
2015/12/08 22:15:27
There is no hard rule for this in Blink, but we ge
|
+// total allocated memory for accelerated canvases to be equivalent to memory used by 80 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 MaxTotalGPUMemoryUsage = 4000000 * 80; |
+#else |
+// We estimate that the max limit for android phones is half of that for desktops based on local |
+// experimental results on Android One; though a very slight lagginess on Android One is still expected, |
+// other Android devices should work fine. |
+const int MaxTotalGPUMemoryUsage = 4000000 * 40; |
Justin Novosad
2015/12/08 22:15:27
This limit feels excessive
|
+#endif |
+ |
// 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 misinterpreted as a user-input value |
const int UndefinedQualityValue = -1.0; |
@@ -614,6 +628,12 @@ bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const |
if (!Platform::current()->canAccelerate2dCanvas()) |
return false; |
+ // When GPU allocated memory runs low (due to having created too many accelerated canvases), the |
+ // compositor starves and browser becomes laggy. Thus, we should stop allocating more GPU memory to |
Justin Novosad
2015/12/08 22:15:27
wrapping
|
+ // new canvases created when the current memory usage exceeds the threshold. |
+ if (ImageBuffer::getTotalGPUMemoryUsage() >= MaxTotalGPUMemoryUsage) |
+ return false; |
+ |
return true; |
} |
@@ -762,7 +782,6 @@ void HTMLCanvasElement::updateExternallyAllocatedMemory() const |
if (m_copiedImage) |
bufferCount++; |
- // Four bytes per pixel per buffer. |
Justin Novosad
2015/12/08 22:15:27
Why remove this comment?
|
Checked<intptr_t, RecordOverflow> checkedExternallyAllocatedMemory = 4 * bufferCount; |
if (is3D()) |
checkedExternallyAllocatedMemory += m_context->externallyAllocatedBytesPerPixel(); |