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

Unified Diff: Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp

Issue 7670046: Merge 92430 - [chromium] Implement a global resource limit for DrawingBuffer to limit the amount ... (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 4 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 | « Source/WebCore/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
===================================================================
--- Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp (revision 93251)
+++ Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp (working copy)
@@ -38,6 +38,16 @@
namespace WebCore {
+// Global resource ceiling (expressed in terms of pixels) for DrawingBuffer creation and resize.
+// When this limit is set, DrawingBuffer::create() and DrawingBuffer::reset() calls that would
+// exceed the global cap will instead clear the buffer.
+#if PLATFORM(CHROMIUM) // Currently, this cap only exists for chromium.
+static int s_maximumResourceUsePixels = 16 * 1024 * 1024;
+#else
+static int s_maximumResourceUsePixels = 0;
+#endif
+static int s_currentResourceUsePixels = 0;
+
PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size)
{
Extensions3D* extensions = context->getExtensions();
@@ -60,6 +70,8 @@
return;
m_context->makeContextCurrent();
+ if (!m_size.isEmpty())
+ s_currentResourceUsePixels -= m_size.width() * m_size.height();
if (m_colorBuffer) {
m_context->deleteTexture(m_colorBuffer);
@@ -202,10 +214,20 @@
int maxTextureSize = 0;
m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize);
if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) {
- clear();
- return false;
+ clear();
+ return false;
}
+ int pixelDelta = newSize.width() * newSize.height();
+ if (!m_size.isEmpty())
+ pixelDelta -= m_size.width() * m_size.height();
+
+ if (s_maximumResourceUsePixels && (s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) {
+ clear();
+ return false;
+ }
+ s_currentResourceUsePixels += pixelDelta;
+
const GraphicsContext3D::Attributes& attributes = m_context->getContextAttributes();
if (newSize != m_size) {
« no previous file with comments | « Source/WebCore/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698