Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/webgl/WebGLContextGroup.h" | 26 #include "modules/webgl/WebGLContextGroup.h" |
| 27 | 27 |
| 28 #include "modules/webgl/WebGLSharedObject.h" | |
| 29 | |
| 30 namespace blink { | 28 namespace blink { |
| 31 | 29 |
| 32 PassRefPtr<WebGLContextGroup> WebGLContextGroup::create() { | 30 WebGLContextGroup::WebGLContextGroup() : m_numberOfContextLosses(0) {} |
| 33 RefPtr<WebGLContextGroup> contextGroup = adoptRef(new WebGLContextGroup()); | |
| 34 return contextGroup.release(); | |
| 35 } | |
| 36 | |
| 37 WebGLContextGroup::WebGLContextGroup() {} | |
| 38 | |
| 39 WebGLContextGroup::~WebGLContextGroup() { | |
| 40 detachAndRemoveAllObjects(); | |
| 41 } | |
| 42 | 31 |
| 43 gpu::gles2::GLES2Interface* WebGLContextGroup::getAGLInterface() { | 32 gpu::gles2::GLES2Interface* WebGLContextGroup::getAGLInterface() { |
| 44 ASSERT(!m_contexts.isEmpty()); | 33 ASSERT(!m_contexts.isEmpty()); |
| 34 // Weak processing removes dead entries from the HeapHashSet, so it's | |
| 35 // guaranteed that this will not return null for the reason that a | |
| 36 // WeakMember was nulled out. | |
| 45 return (*m_contexts.begin())->contextGL(); | 37 return (*m_contexts.begin())->contextGL(); |
| 46 } | 38 } |
| 47 | 39 |
| 48 void WebGLContextGroup::addContext(WebGLRenderingContextBase* context) { | 40 void WebGLContextGroup::addContext(WebGLRenderingContextBase* context) { |
| 49 m_contexts.add(context); | 41 m_contexts.add(context); |
|
haraken
2016/12/05 05:15:59
You need to add a write barrier here.
Ken Russell (switch to Gerrit)
2016/12/05 06:03:40
What should it read?
ScriptWrappableVisitor::writ
haraken
2016/12/05 06:08:39
ScriptWrappableVisitor::writeBarrier(this, context
Ken Russell (switch to Gerrit)
2016/12/05 06:36:20
Thanks, will add.
| |
| 50 } | 42 } |
| 51 | 43 |
| 52 void WebGLContextGroup::removeContext(WebGLRenderingContextBase* context) { | |
| 53 // We must call detachAndRemoveAllObjects before removing the last context. | |
| 54 if (m_contexts.size() == 1 && m_contexts.contains(context)) | |
| 55 detachAndRemoveAllObjects(); | |
| 56 | |
| 57 m_contexts.remove(context); | |
| 58 } | |
| 59 | |
| 60 void WebGLContextGroup::removeObject(WebGLSharedObject* object) { | |
| 61 m_groupObjects.remove(object); | |
| 62 } | |
| 63 | |
| 64 void WebGLContextGroup::addObject(WebGLSharedObject* object) { | |
| 65 m_groupObjects.add(object); | |
| 66 } | |
| 67 | |
| 68 void WebGLContextGroup::detachAndRemoveAllObjects() { | |
| 69 while (!m_groupObjects.isEmpty()) { | |
| 70 (*m_groupObjects.begin())->detachContextGroup(); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 void WebGLContextGroup::loseContextGroup( | 44 void WebGLContextGroup::loseContextGroup( |
| 75 WebGLRenderingContextBase::LostContextMode mode, | 45 WebGLRenderingContextBase::LostContextMode mode, |
| 76 WebGLRenderingContextBase::AutoRecoveryMethod autoRecoveryMethod) { | 46 WebGLRenderingContextBase::AutoRecoveryMethod autoRecoveryMethod) { |
| 77 // Detach must happen before loseContextImpl, which destroys the | 47 ++m_numberOfContextLosses; |
|
haraken
2016/12/05 05:15:59
Shall we add CHECK(m_numberOfContextLosses > 0) to
Ken Russell (switch to Gerrit)
2016/12/05 06:03:40
I don't think it's necessary. In the very unlikely
| |
| 78 // GraphicsContext3D and prevents groupObjects from being properly deleted. | |
| 79 detachAndRemoveAllObjects(); | |
| 80 | |
| 81 for (WebGLRenderingContextBase* const context : m_contexts) | 48 for (WebGLRenderingContextBase* const context : m_contexts) |
| 82 context->loseContextImpl(mode, autoRecoveryMethod); | 49 context->loseContextImpl(mode, autoRecoveryMethod); |
| 83 } | 50 } |
| 84 | 51 |
| 52 uint32_t WebGLContextGroup::numberOfContextLosses() const { | |
| 53 return m_numberOfContextLosses; | |
| 54 } | |
| 55 | |
| 56 DEFINE_TRACE_WRAPPERS(WebGLContextGroup) { | |
| 57 // TODO(kbr, mlippautz): need to use the manual write barrier since we | |
| 58 // need to use weak members to get the desired semantics in Oilpan, but | |
| 59 // no such TraceWrapperMember (like TraceWrapperWeakMember) exists yet. | |
|
haraken
2016/12/05 05:15:59
You need to add the write barrier to line 41.
Ken Russell (switch to Gerrit)
2016/12/05 06:03:40
Please see question above.
| |
| 60 for (auto context : m_contexts) { | |
| 61 visitor->traceWrappersWithManualWriteBarrier(context); | |
| 62 } | |
| 63 } | |
| 64 | |
| 85 } // namespace blink | 65 } // namespace blink |
| OLD | NEW |