Title: [92430] trunk/Source/WebCore
- Revision
- 92430
- Author
- [email protected]
- Date
- 2011-08-04 16:46:59 -0700 (Thu, 04 Aug 2011)
Log Message
[chromium] Implement a global resource limit for DrawingBuffer to limit the amount of GPU memory used by 2d canvas backing stores
https://bugs.webkit.org/show_bug.cgi?id=65655
Patch by James Robinson <[email protected]> on 2011-08-04
Reviewed by Kenneth Russell.
* platform/graphics/gpu/DrawingBuffer.cpp:
(WebCore::DrawingBuffer::setResourceLimit):
(WebCore::DrawingBuffer::clear):
(WebCore::DrawingBuffer::reset):
* platform/graphics/gpu/DrawingBuffer.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (92429 => 92430)
--- trunk/Source/WebCore/ChangeLog 2011-08-04 23:25:41 UTC (rev 92429)
+++ trunk/Source/WebCore/ChangeLog 2011-08-04 23:46:59 UTC (rev 92430)
@@ -1,3 +1,16 @@
+2011-08-04 James Robinson <[email protected]>
+
+ [chromium] Implement a global resource limit for DrawingBuffer to limit the amount of GPU memory used by 2d canvas backing stores
+ https://bugs.webkit.org/show_bug.cgi?id=65655
+
+ Reviewed by Kenneth Russell.
+
+ * platform/graphics/gpu/DrawingBuffer.cpp:
+ (WebCore::DrawingBuffer::setResourceLimit):
+ (WebCore::DrawingBuffer::clear):
+ (WebCore::DrawingBuffer::reset):
+ * platform/graphics/gpu/DrawingBuffer.h:
+
2011-08-04 Kenichi Ishibashi <[email protected]>
[Chromium] Reduce memory consumption of HarfbuzzFace
Modified: trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp (92429 => 92430)
--- trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp 2011-08-04 23:25:41 UTC (rev 92429)
+++ trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp 2011-08-04 23:46:59 UTC (rev 92430)
@@ -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) {
Modified: trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.h (92429 => 92430)
--- trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.h 2011-08-04 23:25:41 UTC (rev 92429)
+++ trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.h 2011-08-04 23:46:59 UTC (rev 92430)
@@ -58,7 +58,7 @@
class DrawingBuffer : public RefCounted<DrawingBuffer> {
public:
friend class GraphicsContext3D;
-
+
~DrawingBuffer();
void clearFramebuffer();
@@ -114,7 +114,7 @@
static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&);
DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionSupported, bool packedDepthStencilExtensionSupported);
-
+
// Platform specific function called after reset() so each platform can do extra work if needed
void didReset();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes