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

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

Issue 169933002: WebGL: Don't destroy mailbox textures in the destructor until they're released. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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
Index: Source/platform/graphics/gpu/DrawingBuffer.cpp
diff --git a/Source/platform/graphics/gpu/DrawingBuffer.cpp b/Source/platform/graphics/gpu/DrawingBuffer.cpp
index 5c470a7d577c0d7145c986c41388acf0ab321eee..cd215dc791f5bd89c5c3ac86b7b4ff02e26ff6a0 100644
--- a/Source/platform/graphics/gpu/DrawingBuffer.cpp
+++ b/Source/platform/graphics/gpu/DrawingBuffer.cpp
@@ -77,10 +77,9 @@ private:
Platform3DObject m_oldTextureUnitZeroId;
};
-PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager)
+PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsContext3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager)
{
- ASSERT(context);
- Extensions3DUtil extensionsUtil(context);
+ Extensions3DUtil extensionsUtil(context.get());
bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_framebuffer_multisample")
&& extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8");
if (multisampleSupported) {
@@ -97,7 +96,7 @@ PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* con
return drawingBuffer.release();
}
-DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context,
+DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context,
bool multisampleExtensionSupported,
bool packedDepthStencilExtensionSupported,
PreserveDrawingBuffer preserve,
@@ -136,7 +135,7 @@ DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context,
DrawingBuffer::~DrawingBuffer()
{
- releaseResources();
+ ASSERT(!m_context);
}
void DrawingBuffer::markContentsChanged()
@@ -158,7 +157,7 @@ void DrawingBuffer::markLayerComposited()
blink::WebGraphicsContext3D* DrawingBuffer::context()
{
- return m_context;
+ return m_context.get();
}
bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, blink::WebExternalBitmap* bitmap)
@@ -184,7 +183,7 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
// We must restore the texture binding since creating new textures,
// consuming and producing mailboxes changes it.
- ScopedTextureUnit0BindingRestorer restorer(m_context, m_activeTextureUnit, m_texture2DBinding);
+ ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureUnit, m_texture2DBinding);
// First try to recycle an old buffer.
RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox();
@@ -231,6 +230,11 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mailbox)
{
+ if (m_selfToWaitForMailboxes) {
+ releaseSelf(mailbox);
Justin Novosad 2014/02/18 18:07:33 naming nit: releaseSelfIfNeeded or releaseSelfIfFi
+ return;
+ }
+
for (size_t i = 0; i < m_textureMailboxes.size(); i++) {
RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[i];
if (!memcmp(mailboxInfo->mailbox.name, mailbox.name, sizeof(mailbox.name))) {
@@ -242,6 +246,27 @@ void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail
ASSERT_NOT_REACHED();
}
+
+void DrawingBuffer::releaseSelf(const blink::WebExternalTextureMailbox& mailbox)
+{
+ ASSERT(!m_textureMailboxes.isEmpty());
+ for (size_t i = 0; i < m_textureMailboxes.size(); i++) {
+ RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[i];
+ if (!memcmp(mailboxInfo->mailbox.name, mailbox.name, sizeof(mailboxInfo->mailbox.name))) {
+ m_context->makeContextCurrent();
+ m_context->deleteTexture(mailboxInfo->textureId);
+ m_textureMailboxes.remove(i);
+ break;
+ }
+ }
+ if (!m_textureMailboxes.isEmpty())
+ return;
+
+ m_context.clear();
+ m_layer.clear();
+ m_selfToWaitForMailboxes.clear();
+}
+
PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox()
{
if (m_recycledMailboxes.isEmpty())
@@ -416,8 +441,18 @@ void DrawingBuffer::releaseResources()
clearPlatformLayer();
- for (size_t i = 0; i < m_textureMailboxes.size(); i++)
- m_context->deleteTexture(m_textureMailboxes[i]->textureId);
+ for (size_t i = 0; i < m_recycledMailboxes.size(); i++) {
+ m_context->deleteTexture(m_recycledMailboxes[i]->textureId);
+
+ for (size_t j = 0; j < m_textureMailboxes.size(); j++) {
+ RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[j];
+ if (mailboxInfo->textureId == m_recycledMailboxes[i]->textureId) {
+ ASSERT(!memcmp(mailboxInfo->mailbox.name, m_recycledMailboxes[i]->mailbox.name, sizeof(mailboxInfo->mailbox.name)));
+ m_textureMailboxes.remove(j);
+ break;
+ }
+ }
+ }
if (m_multisampleColorBuffer)
m_context->deleteRenderbuffer(m_multisampleColorBuffer);
@@ -437,7 +472,7 @@ void DrawingBuffer::releaseResources()
if (m_fbo)
m_context->deleteFramebuffer(m_fbo);
- m_context = 0;
+ setSize(IntSize());
m_colorBuffer = 0;
m_frontColorBuffer = 0;
@@ -450,12 +485,16 @@ void DrawingBuffer::releaseResources()
m_contextEvictionManager.clear();
m_recycledMailboxes.clear();
- m_textureMailboxes.clear();
- if (m_layer) {
+ if (m_layer)
GraphicsLayer::unregisterContentsLayer(m_layer->layer());
+
+ if (m_textureMailboxes.isEmpty()) {
+ m_context.clear();
m_layer.clear();
+ return;
}
+ m_selfToWaitForMailboxes = this;
}
unsigned DrawingBuffer::createColorTexture(const IntSize& size)

Powered by Google App Engine
This is Rietveld 408576698