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 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 | 27 |
28 #include "core/html/canvas/WebGLContextGroup.h" | 28 #include "core/html/canvas/WebGLContextGroup.h" |
29 | 29 |
30 #include "core/html/canvas/WebGLSharedObject.h" | 30 #include "core/html/canvas/WebGLSharedObject.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 PassRefPtr<WebGLContextGroup> WebGLContextGroup::create() | 34 PassRefPtrWillBeRawPtr<WebGLContextGroup> WebGLContextGroup::create() |
35 { | 35 { |
36 RefPtr<WebGLContextGroup> contextGroup = adoptRef(new WebGLContextGroup()); | 36 RefPtrWillBeRawPtr<WebGLContextGroup> contextGroup = adoptRefWillBeNoop(new WebGLContextGroup()); |
37 return contextGroup.release(); | 37 return contextGroup.release(); |
haraken
2014/07/02 07:47:37
return adoptRefWillBeNoop(new WebGLContextGroup())
sof
2014/07/02 11:43:52
I've switched this back to returning PassRefPtr<>
| |
38 } | 38 } |
39 | 39 |
40 WebGLContextGroup::WebGLContextGroup() | 40 WebGLContextGroup::WebGLContextGroup() |
41 #if ENABLE(OILPAN) | |
42 : m_savedContext(0) | |
43 #endif | |
41 { | 44 { |
42 } | 45 } |
43 | 46 |
47 #if !ENABLE(OILPAN) | |
44 WebGLContextGroup::~WebGLContextGroup() | 48 WebGLContextGroup::~WebGLContextGroup() |
45 { | 49 { |
46 detachAndRemoveAllObjects(); | 50 detachAndRemoveAllObjects(); |
47 } | 51 } |
52 #endif | |
48 | 53 |
49 blink::WebGraphicsContext3D* WebGLContextGroup::getAWebGraphicsContext3D() | 54 blink::WebGraphicsContext3D* WebGLContextGroup::getAWebGraphicsContext3D() |
50 { | 55 { |
56 #if ENABLE(OILPAN) | |
57 ASSERT(!m_contexts.isEmpty() || m_savedContext); | |
58 if (m_savedContext) | |
haraken
2014/07/02 07:47:38
Just help me understand: This branch hits only whe
sof
2014/07/02 11:43:52
Yes (to the last point), that's what I ended up wi
| |
59 return m_savedContext; | |
60 #else | |
51 ASSERT(!m_contexts.isEmpty()); | 61 ASSERT(!m_contexts.isEmpty()); |
52 HashSet<WebGLRenderingContextBase*>::iterator it = m_contexts.begin(); | 62 #endif |
63 WillBeHeapHashSet<RawPtrWillBeWeakMember<WebGLRenderingContextBase> >::itera tor it = m_contexts.begin(); | |
53 return (*it)->webContext(); | 64 return (*it)->webContext(); |
54 } | 65 } |
55 | 66 |
56 void WebGLContextGroup::addContext(WebGLRenderingContextBase* context) | 67 void WebGLContextGroup::addContext(WebGLRenderingContextBase* context) |
57 { | 68 { |
58 m_contexts.add(context); | 69 m_contexts.add(context); |
59 } | 70 } |
60 | 71 |
61 void WebGLContextGroup::removeContext(WebGLRenderingContextBase* context) | 72 void WebGLContextGroup::removeContext(WebGLRenderingContextBase* context) |
62 { | 73 { |
63 // We must call detachAndRemoveAllObjects before removing the last context. | 74 // We must call detachAndRemoveAllObjects before removing the last context. |
64 if (m_contexts.size() == 1 && m_contexts.contains(context)) | 75 if (m_contexts.size() == 1 && m_contexts.contains(context)) |
65 detachAndRemoveAllObjects(); | 76 detachAndRemoveAllObjects(); |
66 | 77 |
67 m_contexts.remove(context); | 78 m_contexts.remove(context); |
68 } | 79 } |
69 | 80 |
70 void WebGLContextGroup::removeObject(WebGLSharedObject* object) | 81 void WebGLContextGroup::removeObject(WebGLSharedObject* object) |
71 { | 82 { |
83 #if ENABLE(OILPAN) | |
84 // Oilpan: if removal happens during weak callback processing, ignore. | |
haraken
2014/07/02 07:47:38
Specifically, when can the removal happen during w
sof
2014/07/02 11:43:52
It happens when tracing has determined that no con
| |
85 // Done so as to prevent re-allocation of the backing store; the table | |
86 // is cleared afterwards instead. | |
87 if (m_savedContext) | |
88 return; | |
89 #endif | |
72 m_groupObjects.remove(object); | 90 m_groupObjects.remove(object); |
73 } | 91 } |
74 | 92 |
75 void WebGLContextGroup::addObject(WebGLSharedObject* object) | 93 void WebGLContextGroup::addObject(WebGLSharedObject* object) |
76 { | 94 { |
77 m_groupObjects.add(object); | 95 m_groupObjects.add(object); |
78 } | 96 } |
79 | 97 |
80 void WebGLContextGroup::detachAndRemoveAllObjects() | 98 void WebGLContextGroup::detachAndRemoveAllObjects() |
81 { | 99 { |
82 while (!m_groupObjects.isEmpty()) { | 100 while (!m_groupObjects.isEmpty()) { |
83 HashSet<WebGLSharedObject*>::iterator it = m_groupObjects.begin(); | 101 WillBeHeapHashSet<RawPtrWillBeWeakMember<WebGLSharedObject> >::iterator it = m_groupObjects.begin(); |
84 (*it)->detachContextGroup(); | 102 (*it)->detachContextGroup(); |
85 } | 103 } |
86 } | 104 } |
87 | 105 |
88 void WebGLContextGroup::loseContextGroup(WebGLRenderingContextBase::LostContextM ode mode) | 106 void WebGLContextGroup::loseContextGroup(WebGLRenderingContextBase::LostContextM ode mode) |
89 { | 107 { |
90 // Detach must happen before loseContextImpl, which destroys the GraphicsCon text3D | 108 // Detach must happen before loseContextImpl, which destroys the GraphicsCon text3D |
91 // and prevents groupObjects from being properly deleted. | 109 // and prevents groupObjects from being properly deleted. |
92 detachAndRemoveAllObjects(); | 110 detachAndRemoveAllObjects(); |
93 | 111 |
94 for (HashSet<WebGLRenderingContextBase*>::iterator it = m_contexts.begin(); it != m_contexts.end(); ++it) | 112 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<WebGLRenderingContextBase> >:: iterator it = m_contexts.begin(); it != m_contexts.end(); ++it) |
95 (*it)->loseContextImpl(mode); | 113 (*it)->loseContextImpl(mode); |
96 } | 114 } |
97 | 115 |
116 void WebGLContextGroup::clearWeakMembers(Visitor*) | |
117 { | |
118 #if ENABLE(OILPAN) | |
119 // We must call detachAndRemoveAllObjects when there are no contexts left. | |
120 // In order to be able to provide the group objects with the WebGraphicsCont ext3D | |
121 // object they need on detach, one is saved away during tracing. | |
122 if (!m_contexts.size() && m_savedContext) { | |
123 detachAndRemoveAllObjects(); | |
124 m_groupObjects.clear(); | |
125 } | |
126 m_savedContext = 0; | |
127 #endif | |
128 } | |
129 | |
130 void WebGLContextGroup::trace(Visitor* visitor) | |
131 { | |
132 #if ENABLE(OILPAN) | |
133 // See clearWeakMembers() comment. | |
134 if (m_contexts.size() && m_groupObjects.size()) { | |
135 m_savedContext = getAWebGraphicsContext3D(); | |
haraken
2014/07/02 07:47:37
It looks dangerous to do something non-trivial in
| |
136 ASSERT(m_savedContext); | |
137 } | |
138 #endif | |
139 visitor->trace(m_contexts); | |
140 visitor->trace(m_groupObjects); | |
141 visitor->registerWeakMembers<WebGLContextGroup, &WebGLContextGroup::clearWea kMembers>(this); | |
142 } | |
143 | |
98 } // namespace WebCore | 144 } // namespace WebCore |
OLD | NEW |