Chromium Code Reviews| Index: Source/core/platform/graphics/gpu/DrawingBuffer.cpp |
| diff --git a/Source/core/platform/graphics/gpu/DrawingBuffer.cpp b/Source/core/platform/graphics/gpu/DrawingBuffer.cpp |
| index 33855a04085adb6d95aa2ea8dc6a223ff0b7cb64..64ea9a424d0341963ca99638bebf3697768280c8 100644 |
| --- a/Source/core/platform/graphics/gpu/DrawingBuffer.cpp |
| +++ b/Source/core/platform/graphics/gpu/DrawingBuffer.cpp |
| @@ -39,6 +39,7 @@ |
| #include "GraphicsLayerChromium.h" |
| #include "ImageData.h" |
| #include "TraceEvent.h" |
| +#include "WebGLRenderingContext.h" |
|
bajones
2013/04/20 05:19:59
Ken already pointed out in a different patch revie
|
| #include <algorithm> |
| #include <public/Platform.h> |
| #include <public/WebCompositorSupport.h> |
| @@ -58,6 +59,9 @@ static const int s_maximumResourceUsePixels = 16 * 1024 * 1024; |
| static int s_currentResourceUsePixels = 0; |
| static const float s_resourceAdjustedRatio = 0.5; |
| +static const bool s_allowContextEvictionOnCreate = true; |
| +static const int s_maxScaleAttempts = 3; |
| + |
| class ScopedTextureUnit0BindingRestorer { |
| public: |
| ScopedTextureUnit0BindingRestorer(GraphicsContext3D* context, GC3Denum activeTextureUnit, Platform3DObject textureUnitZeroId) |
| @@ -577,6 +581,8 @@ void DrawingBuffer::resizeDepthStencil(const IntSize& size, int sampleCount) |
| m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, 0); |
| } |
| + |
| + |
| void DrawingBuffer::clearFramebuffers(GC3Dbitfield clearMask) |
| { |
| m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo); |
| @@ -648,21 +654,56 @@ IntSize DrawingBuffer::adjustSize(const IntSize& size) { |
| adjustedSize.setWidth(maxTextureSize); |
| // Try progressively smaller sizes until we find a size that fits or reach a scale limit. |
| + int scaleAttempts = 0; |
| while ((s_currentResourceUsePixels + pixelDelta(adjustedSize)) > s_maximumResourceUsePixels) { |
| + scaleAttempts++; |
| + if(s_maxScaleAttempts > -1 && scaleAttempts > s_maxScaleAttempts) |
| + return IntSize(); |
| + |
| adjustedSize.scale(s_resourceAdjustedRatio); |
| if (adjustedSize.isEmpty()) |
| return IntSize(); |
| } |
| + |
| + return adjustedSize; |
| +} |
| + |
| +IntSize DrawingBuffer::adjustSizeWithContextEviction(const IntSize& size, bool& evictContext) { |
| + IntSize adjustedSize = adjustSize(size); |
| + if(!adjustedSize.isEmpty()) { |
| + evictContext = false; |
| + return adjustedSize; // Buffer fits without evicting a context |
| + } |
| + |
| + // Speculatively adjust the pixel budget to see if the buffer would fit should the oldest context be evicted |
| + IntSize oldestSize = WebGLRenderingContext::oldestContextSize(); |
| + int pixelDelta = oldestSize.width() * oldestSize.height(); |
| + |
| + s_currentResourceUsePixels -= pixelDelta; |
| + adjustedSize = adjustSize(size); |
| + s_currentResourceUsePixels += pixelDelta; |
| + |
| + evictContext = !adjustedSize.isEmpty(); |
| return adjustedSize; |
| } |
| void DrawingBuffer::reset(const IntSize& newSize) |
| { |
| - IntSize adjustedSize = adjustSize(newSize); |
| + IntSize adjustedSize; |
| + bool evictContext = false; |
| + bool isNewContext = m_size.isEmpty(); |
| + if (s_allowContextEvictionOnCreate && isNewContext) |
| + adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); |
| + else |
| + adjustSize(newSize); |
| + |
| if (adjustedSize.isEmpty()) |
| return; |
| + if (evictContext) |
| + WebGLRenderingContext::forciblyLoseOldestContext(); |
| + |
| if (adjustedSize != m_size) { |
| do { |
| // resize multisample FBO |