Chromium Code Reviews| 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..54d9bc4942cae9d26ac0649b79cd36cd4ab6ef13 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| @@ -89,6 +89,14 @@ 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 = 20; |
| +#else |
| +const int MaxGlobalAcceleratedImageBufferCount = 80; |
| +#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 |
| @@ -96,13 +104,7 @@ const int MaxSkiaDim = 32767; // Maximum width/height in CSS pixels. |
| // 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,13 @@ bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const |
| if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage) |
| return false; |
| + // When GPU allocated memory runs low (due to having created too many |
|
xlai (Olivia)
2016/06/15 18:54:06
Hmmm...duplicate comments?
Justin Novosad
2016/06/15 19:17:34
Done.
|
| + // accelerated canvases), the compositor starves and browser becomes laggy. |
| + // Thus, we should stop allocating more GPU memory to new canvases created |
| + // when the current memory usage exceeds the threshold. |
| + if (ImageBuffer::getGlobalAcceleratedImageBufferCount() >= MaxGlobalAcceleratedImageBufferCount) |
| + return false; |
| + |
| return true; |
| } |
| @@ -1081,7 +1090,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(); |