| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 #include <wtf/OwnArrayPtr.h> | 77 #include <wtf/OwnArrayPtr.h> |
| 78 #include <wtf/PassOwnArrayPtr.h> | 78 #include <wtf/PassOwnArrayPtr.h> |
| 79 #include <wtf/Uint16Array.h> | 79 #include <wtf/Uint16Array.h> |
| 80 #include <wtf/Uint32Array.h> | 80 #include <wtf/Uint32Array.h> |
| 81 #include <wtf/text/StringBuilder.h> | 81 #include <wtf/text/StringBuilder.h> |
| 82 | 82 |
| 83 namespace WebCore { | 83 namespace WebCore { |
| 84 | 84 |
| 85 const double secondsBetweenRestoreAttempts = 1.0; | 85 const double secondsBetweenRestoreAttempts = 1.0; |
| 86 const int maxGLErrorsAllowedToConsole = 256; | 86 const int maxGLErrorsAllowedToConsole = 256; |
| 87 const int maxGLActiveContexts = 20; |
| 88 |
| 89 Vector<WebGLRenderingContext*>& WebGLRenderingContext::activeContexts() |
| 90 { |
| 91 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContext*>, activeContexts, ()); |
| 92 return activeContexts; |
| 93 } |
| 94 |
| 95 Vector<WebGLRenderingContext*>& WebGLRenderingContext::forciblyEvictedContexts() |
| 96 { |
| 97 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContext*>, forciblyEvictedContexts,
()); |
| 98 return forciblyEvictedContexts; |
| 99 } |
| 100 |
| 101 void WebGLRenderingContext::forciblyLoseOldestContext() |
| 102 { |
| 103 if (activeContexts().size()) { |
| 104 WebGLRenderingContext* oldestActiveContext = activeContexts().first(); |
| 105 activeContexts().remove(0); |
| 106 |
| 107 // This will call deactivateContext once the context has actually been l
ost |
| 108 oldestActiveContext->forceLostContext(WebGLRenderingContext::SyntheticLo
stContext); |
| 109 } |
| 110 } |
| 111 |
| 112 IntSize WebGLRenderingContext::oldestContextSize() |
| 113 { |
| 114 IntSize size; |
| 115 |
| 116 if (activeContexts().size()) { |
| 117 WebGLRenderingContext* oldestActiveContext = activeContexts().first(); |
| 118 size.setWidth(oldestActiveContext->drawingBufferWidth()); |
| 119 size.setHeight(oldestActiveContext->drawingBufferHeight()); |
| 120 } |
| 121 |
| 122 return size; |
| 123 } |
| 124 |
| 125 void WebGLRenderingContext::activateContext(WebGLRenderingContext* context) |
| 126 { |
| 127 if (!activeContexts().contains(context)) |
| 128 activeContexts().append(context); |
| 129 |
| 130 if (activeContexts().size() > maxGLActiveContexts) |
| 131 forciblyLoseOldestContext(); |
| 132 } |
| 133 |
| 134 void WebGLRenderingContext::deactivateContext(WebGLRenderingContext* context, bo
ol addToEvictedList) |
| 135 { |
| 136 size_t position = activeContexts().find(context); |
| 137 if (position != WTF::notFound) |
| 138 activeContexts().remove(position); |
| 139 |
| 140 if (addToEvictedList && !forciblyEvictedContexts().contains(context)) |
| 141 forciblyEvictedContexts().append(context); |
| 142 } |
| 143 |
| 144 void WebGLRenderingContext::willDestroyContext(WebGLRenderingContext* context) |
| 145 { |
| 146 size_t position = forciblyEvictedContexts().find(context); |
| 147 if (position != WTF::notFound) |
| 148 forciblyEvictedContexts().remove(position); |
| 149 |
| 150 deactivateContext(context, false); |
| 151 |
| 152 // Try to re-enable the oldest inactive contexts |
| 153 while(activeContexts().size() < maxGLActiveContexts && forciblyEvictedContex
ts().size()) { |
| 154 WebGLRenderingContext* evictedContext = forciblyEvictedContexts().first(
); |
| 155 if (!evictedContext->m_restoreAllowed) { |
| 156 forciblyEvictedContexts().remove(0); |
| 157 continue; |
| 158 } |
| 159 |
| 160 IntSize desiredSize = evictedContext->m_drawingBuffer->adjustSize(evicte
dContext->clampedCanvasSize()); |
| 161 |
| 162 // If there's room in the pixel budget for this context, restore it! |
| 163 if (!desiredSize.isEmpty()) { |
| 164 forciblyEvictedContexts().remove(0); |
| 165 evictedContext->forceRestoreContext(); |
| 166 activeContexts().append(evictedContext); |
| 167 } |
| 168 break; |
| 169 } |
| 170 } |
| 87 | 171 |
| 88 namespace { | 172 namespace { |
| 89 | 173 |
| 90 class ScopedDrawingBufferBinder { | 174 class ScopedDrawingBufferBinder { |
| 91 public: | 175 public: |
| 92 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer
* framebufferBinding) | 176 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer
* framebufferBinding) |
| 93 : m_drawingBuffer(drawingBuffer) | 177 : m_drawingBuffer(drawingBuffer) |
| 94 , m_framebufferBinding(framebufferBinding) | 178 , m_framebufferBinding(framebufferBinding) |
| 95 { | 179 { |
| 96 // Commit DrawingBuffer if needed (e.g., for multisampling) | 180 // Commit DrawingBuffer if needed (e.g., for multisampling) |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 640 |
| 557 IntSize canvasSize = clampedCanvasSize(); | 641 IntSize canvasSize = clampedCanvasSize(); |
| 558 m_drawingBuffer->reset(canvasSize); | 642 m_drawingBuffer->reset(canvasSize); |
| 559 | 643 |
| 560 m_context->reshape(canvasSize.width(), canvasSize.height()); | 644 m_context->reshape(canvasSize.width(), canvasSize.height()); |
| 561 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height()); | 645 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height()); |
| 562 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height()); | 646 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height()); |
| 563 | 647 |
| 564 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall
back(this))); | 648 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall
back(this))); |
| 565 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe
ssageCallback(this))); | 649 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe
ssageCallback(this))); |
| 650 |
| 651 activateContext(this); |
| 566 } | 652 } |
| 567 | 653 |
| 568 void WebGLRenderingContext::setupFlags() | 654 void WebGLRenderingContext::setupFlags() |
| 569 { | 655 { |
| 570 ASSERT(m_context); | 656 ASSERT(m_context); |
| 571 | 657 |
| 572 Page* p = canvas()->document()->page(); | 658 Page* p = canvas()->document()->page(); |
| 573 if (p) | 659 if (p) |
| 574 m_synthesizedErrorsToConsole = p->settings()->webGLErrorsToConsoleEnable
d(); | 660 m_synthesizedErrorsToConsole = p->settings()->webGLErrorsToConsoleEnable
d(); |
| 575 | 661 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 m_textureUnits[i].m_texture2DBinding = 0; | 702 m_textureUnits[i].m_texture2DBinding = 0; |
| 617 m_textureUnits[i].m_textureCubeMapBinding = 0; | 703 m_textureUnits[i].m_textureCubeMapBinding = 0; |
| 618 } | 704 } |
| 619 | 705 |
| 620 m_blackTexture2D = 0; | 706 m_blackTexture2D = 0; |
| 621 m_blackTextureCubeMap = 0; | 707 m_blackTextureCubeMap = 0; |
| 622 | 708 |
| 623 detachAndRemoveAllObjects(); | 709 detachAndRemoveAllObjects(); |
| 624 destroyGraphicsContext3D(); | 710 destroyGraphicsContext3D(); |
| 625 m_contextGroup->removeContext(this); | 711 m_contextGroup->removeContext(this); |
| 712 |
| 713 willDestroyContext(this); |
| 626 } | 714 } |
| 627 | 715 |
| 628 void WebGLRenderingContext::destroyGraphicsContext3D() | 716 void WebGLRenderingContext::destroyGraphicsContext3D() |
| 629 { | 717 { |
| 630 // The drawing buffer holds a context reference. It must also be destroyed | 718 // The drawing buffer holds a context reference. It must also be destroyed |
| 631 // in order for the context to be released. | 719 // in order for the context to be released. |
| 632 m_drawingBuffer.clear(); | 720 m_drawingBuffer.clear(); |
| 633 | 721 |
| 634 if (m_context) { | 722 if (m_context) { |
| 635 m_context->setContextLostCallback(nullptr); | 723 m_context->setContextLostCallback(nullptr); |
| (...skipping 5112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5748 m_context->vertexAttribPointer(0, state.size, state.type, state.normaliz
ed, state.originalStride, state.offset); | 5836 m_context->vertexAttribPointer(0, state.size, state.type, state.normaliz
ed, state.originalStride, state.offset); |
| 5749 } | 5837 } |
| 5750 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(m_boundA
rrayBuffer.get())); | 5838 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(m_boundA
rrayBuffer.get())); |
| 5751 } | 5839 } |
| 5752 | 5840 |
| 5753 void WebGLRenderingContext::dispatchContextLostEvent(Timer<WebGLRenderingContext
>*) | 5841 void WebGLRenderingContext::dispatchContextLostEvent(Timer<WebGLRenderingContext
>*) |
| 5754 { | 5842 { |
| 5755 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().web
glcontextlostEvent, false, true, ""); | 5843 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().web
glcontextlostEvent, false, true, ""); |
| 5756 canvas()->dispatchEvent(event); | 5844 canvas()->dispatchEvent(event); |
| 5757 m_restoreAllowed = event->defaultPrevented(); | 5845 m_restoreAllowed = event->defaultPrevented(); |
| 5846 deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAll
owed); |
| 5758 if (m_contextLostMode == RealLostContext && m_restoreAllowed) | 5847 if (m_contextLostMode == RealLostContext && m_restoreAllowed) |
| 5759 m_restoreTimer.startOneShot(0); | 5848 m_restoreTimer.startOneShot(0); |
| 5760 } | 5849 } |
| 5761 | 5850 |
| 5762 void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) | 5851 void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) |
| 5763 { | 5852 { |
| 5764 ASSERT(m_contextLost); | 5853 ASSERT(m_contextLost); |
| 5765 if (!m_contextLost) | 5854 if (!m_contextLost) |
| 5766 return; | 5855 return; |
| 5767 | 5856 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6002 bool WebGLRenderingContext::supportsDrawBuffers() | 6091 bool WebGLRenderingContext::supportsDrawBuffers() |
| 6003 { | 6092 { |
| 6004 if (!m_drawBuffersWebGLRequirementsChecked) { | 6093 if (!m_drawBuffersWebGLRequirementsChecked) { |
| 6005 m_drawBuffersWebGLRequirementsChecked = true; | 6094 m_drawBuffersWebGLRequirementsChecked = true; |
| 6006 m_drawBuffersSupported = EXTDrawBuffers::supported(this); | 6095 m_drawBuffersSupported = EXTDrawBuffers::supported(this); |
| 6007 } | 6096 } |
| 6008 return m_drawBuffersSupported; | 6097 return m_drawBuffersSupported; |
| 6009 } | 6098 } |
| 6010 | 6099 |
| 6011 } // namespace WebCore | 6100 } // namespace WebCore |
| OLD | NEW |