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

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

Issue 14217005: Limit the number of WebGL contexts that are active at any given time (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated and rebased on DrawingBuffer refactor Created 7 years, 8 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/core/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/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
« no previous file with comments | « Source/core/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698