Bug 1417310 - Don't attempt to create buffers of unreasonable sizes. r=bas
authorJamie Nicol <jnicol@mozilla.com>
Wed, 13 Dec 2017 15:49:41 -0600
changeset 448045 6b52d9870d2d16a29e3075627953304c574f11ed
parent 448044 ccd7b237c4337a00e45bf18ac2d0218c61e1134d
child 448046 b949944f17b0cae7d3d24c2cf9f8a177fe571956
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1417310
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1417310 - Don't attempt to create buffers of unreasonable sizes. r=bas Currently ContentClient will attempt to create a buffer of any size that Layers requires it to. If that fails it will then warn if the requested buffer was an unreasonable size. This change makes it so that we check whether the size is reasonable first, and do not attempt to create the buffer if it is unreasonable. Previously the operating system would have managed to allocate some buffers that we deem unreasonable, but at the cost of the system becoming unresponsive. Now, some large buffers which would previously have been created won't be, but the chances of the system becoming unresponsive should decrease. Ideally Layers wouldn't request buffers of these sizes in the first place - there are measures in place to try to prevent it, and more work is certainly required. However, this will act as a last ditch defence. MozReview-Commit-ID: 7WCqEwkmViy
gfx/layers/client/ContentClient.cpp
--- a/gfx/layers/client/ContentClient.cpp
+++ b/gfx/layers/client/ContentClient.cpp
@@ -238,28 +238,30 @@ ContentClient::BeginPaint(PaintedLayer* 
   // types, or we failed to unrotate the buffer when requested. In any case,
   // we need to allocate a new one and prepare it for drawing.
   if (!dest.mCanReuseBuffer) {
     uint32_t bufferFlags = 0;
     if (dest.mBufferMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) {
       bufferFlags |= BUFFER_COMPONENT_ALPHA;
     }
 
-    RefPtr<RotatedBuffer> newBuffer = CreateBuffer(result.mContentType,
-                                                   dest.mBufferRect,
-                                                   bufferFlags);
+    RefPtr<RotatedBuffer> newBuffer;
+    if (Factory::ReasonableSurfaceSize(IntSize(dest.mBufferRect.Width(), dest.mBufferRect.Height()))) {
+      newBuffer = CreateBuffer(result.mContentType, dest.mBufferRect, bufferFlags);
 
-    if (!newBuffer) {
-      if (Factory::ReasonableSurfaceSize(IntSize(dest.mBufferRect.Width(), dest.mBufferRect.Height()))) {
+      if (!newBuffer) {
         gfxCriticalNote << "Failed buffer for "
                         << dest.mBufferRect.x << ", "
                         << dest.mBufferRect.y << ", "
                         << dest.mBufferRect.Width() << ", "
                         << dest.mBufferRect.Height();
       }
+    }
+
+    if (!newBuffer) {
       Clear();
       return result;
     }
 
     if (!newBuffer->Lock(lockMode)) {
       gfxCriticalNote << "Failed to lock new back buffer.";
       Clear();
       return result;