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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLContextGroup.cpp

Issue 2547813002: Remove WebGLObject maps from WebGLRenderingContextBase and WebGLContextGroup. (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
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 // TODO(kbr): is it guaranteed that we won't return null here
35 // because the WeakMember was nulled out but its entry wasn't
36 // removed from the HeapHashSet?
Ken Russell (switch to Gerrit) 2016/12/02 09:58:48 haraken@ and sigbjornf@: could you answer this que
haraken 2016/12/02 10:14:34 The weak processing removes the dead entry from th
sof 2016/12/02 10:39:06 https://cs.chromium.org/chromium/src/third_party/W
Ken Russell (switch to Gerrit) 2016/12/02 20:38:49 Thanks for the feedback. I'll include this informa
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);
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;
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
Ken Russell (switch to Gerrit) 2016/12/02 09:58:48 mlippautz: am I correct in my thinking here?
58 // need to use weak members, but no such TraceWrapperMember exists yet.
59 for (auto context : m_contexts) {
60 visitor->traceWrappersWithManualWriteBarrier(context);
61 }
62 }
63
85 } // namespace blink 64 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698