| Index: Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
|
| diff --git a/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp b/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
|
| index 5fb5f07ea524cc2dceaf05944b0a1dbaf397a9f6..2553465285e39dbb5937884f7f2ef348979a688f 100644
|
| --- a/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
|
| +++ b/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
|
| @@ -39,6 +39,7 @@
|
| #include "GraphicsLayerChromium.h"
|
| #include "ImageData.h"
|
| #include "TraceEvent.h"
|
| +#include "WebGLRenderingContext.h"
|
| #include <algorithm>
|
| #include <public/Platform.h>
|
| #include <public/WebCompositorSupport.h>
|
| @@ -55,6 +56,7 @@ namespace WebCore {
|
| static int s_maximumResourceUsePixels = 16 * 1024 * 1024;
|
| static int s_currentResourceUsePixels = 0;
|
| static const float s_resourceAdjustedRatio = 0.5;
|
| +static const int s_maxScaleAttempts = 3;
|
|
|
| static unsigned generateColorTexture(GraphicsContext3D* context, const IntSize& size)
|
| {
|
| @@ -109,11 +111,11 @@ DrawingBuffer::DrawingBuffer(GraphicsContext3D* context,
|
|
|
| DrawingBuffer::~DrawingBuffer()
|
| {
|
| + clear();
|
| +
|
| if (!m_context)
|
| return;
|
|
|
| - clear();
|
| -
|
| if (m_layer)
|
| GraphicsLayerChromium::unregisterContentsLayer(m_layer->layer());
|
| }
|
| @@ -262,57 +264,49 @@ PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, cons
|
|
|
| void DrawingBuffer::clear()
|
| {
|
| - if (!m_context)
|
| - return;
|
| + if (m_context) {
|
| + m_context->makeContextCurrent();
|
|
|
| - m_context->makeContextCurrent();
|
| + clearPlatformLayer();
|
|
|
| - clearPlatformLayer();
|
| + if (m_colorBuffer)
|
| + m_context->deleteTexture(m_colorBuffer);
|
|
|
| - if (!m_size.isEmpty()) {
|
| - s_currentResourceUsePixels -= m_size.width() * m_size.height();
|
| - m_size = IntSize();
|
| - }
|
| + if (m_frontColorBuffer)
|
| + m_context->deleteTexture(m_frontColorBuffer);
|
|
|
| - if (m_colorBuffer) {
|
| - m_context->deleteTexture(m_colorBuffer);
|
| - m_colorBuffer = 0;
|
| - }
|
| + if (m_multisampleColorBuffer)
|
| + m_context->deleteRenderbuffer(m_multisampleColorBuffer);
|
|
|
| - if (m_frontColorBuffer) {
|
| - m_context->deleteTexture(m_frontColorBuffer);
|
| - m_frontColorBuffer = 0;
|
| - }
|
| + if (m_depthStencilBuffer)
|
| + m_context->deleteRenderbuffer(m_depthStencilBuffer);
|
|
|
| - if (m_multisampleColorBuffer) {
|
| - m_context->deleteRenderbuffer(m_multisampleColorBuffer);
|
| - m_multisampleColorBuffer = 0;
|
| - }
|
| + if (m_depthBuffer)
|
| + m_context->deleteRenderbuffer(m_depthBuffer);
|
|
|
| - if (m_depthStencilBuffer) {
|
| - m_context->deleteRenderbuffer(m_depthStencilBuffer);
|
| - m_depthStencilBuffer = 0;
|
| - }
|
| + if (m_stencilBuffer)
|
| + m_context->deleteRenderbuffer(m_stencilBuffer);
|
|
|
| - if (m_depthBuffer) {
|
| - m_context->deleteRenderbuffer(m_depthBuffer);
|
| - m_depthBuffer = 0;
|
| - }
|
| + if (m_multisampleFBO)
|
| + m_context->deleteFramebuffer(m_multisampleFBO);
|
|
|
| - if (m_stencilBuffer) {
|
| - m_context->deleteRenderbuffer(m_stencilBuffer);
|
| - m_stencilBuffer = 0;
|
| + if (m_fbo)
|
| + m_context->deleteFramebuffer(m_fbo);
|
| }
|
|
|
| - if (m_multisampleFBO) {
|
| - m_context->deleteFramebuffer(m_multisampleFBO);
|
| - m_multisampleFBO = 0;
|
| + if (!m_size.isEmpty()) {
|
| + s_currentResourceUsePixels -= m_size.width() * m_size.height();
|
| + m_size = IntSize();
|
| }
|
|
|
| - if (m_fbo) {
|
| - m_context->deleteFramebuffer(m_fbo);
|
| - m_fbo = 0;
|
| - }
|
| + m_colorBuffer = 0;
|
| + m_frontColorBuffer = 0;
|
| + m_multisampleColorBuffer = 0;
|
| + m_depthStencilBuffer = 0;
|
| + m_depthBuffer = 0;
|
| + m_stencilBuffer = 0;
|
| + m_multisampleFBO = 0;
|
| + m_fbo = 0;
|
| }
|
|
|
| void DrawingBuffer::createSecondaryBuffers()
|
| @@ -420,15 +414,31 @@ bool DrawingBuffer::reset(const IntSize& newSize)
|
|
|
| int pixelDelta = newSize.width() * newSize.height();
|
| int oldSize = 0;
|
| + bool newBuffer = true;
|
| if (!m_size.isEmpty()) {
|
| oldSize = m_size.width() * m_size.height();
|
| pixelDelta -= oldSize;
|
| + newBuffer = false;
|
| + }
|
| +
|
| + if(newBuffer && s_currentResourceUsePixels == s_maximumResourceUsePixels) {
|
| + WebGLRenderingContext::forceLostOldestContext();
|
| + newBuffer = false;
|
| }
|
|
|
| IntSize adjustedSize = newSize;
|
| + int scaleAttempts = 0;
|
| if (s_maximumResourceUsePixels) {
|
| while ((s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) {
|
| adjustedSize.scale(s_resourceAdjustedRatio);
|
| +
|
| + scaleAttempts++;
|
| + if(newBuffer && scaleAttempts >= s_maxScaleAttempts) {
|
| + WebGLRenderingContext::forceLostOldestContext();
|
| + adjustedSize = newSize;
|
| + newBuffer = false;
|
| + }
|
| +
|
| if (adjustedSize.isEmpty()) {
|
| clear();
|
| return false;
|
|
|