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

Side by Side Diff: Source/core/html/canvas/WebGLContextGroup.cpp

Issue 1151163002: Oilpan: eagerly finalize WebGLRenderingContext objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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 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
(...skipping 10 matching lines...) Expand all
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 "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 #include "platform/heap/Handle.h"
31 32
32 namespace blink { 33 namespace blink {
33 34
34 PassRefPtr<WebGLContextGroup> WebGLContextGroup::create() 35 PassRefPtr<WebGLContextGroup> WebGLContextGroup::create()
35 { 36 {
36 RefPtr<WebGLContextGroup> contextGroup = adoptRef(new WebGLContextGroup()); 37 RefPtr<WebGLContextGroup> contextGroup = adoptRef(new WebGLContextGroup());
37 return contextGroup.release(); 38 return contextGroup.release();
38 } 39 }
39 40
40 WebGLContextGroup::WebGLContextGroup() 41 WebGLContextGroup::WebGLContextGroup()
41 { 42 {
42 } 43 }
43 44
44 WebGLContextGroup::~WebGLContextGroup() 45 WebGLContextGroup::~WebGLContextGroup()
45 { 46 {
46 detachAndRemoveAllObjects(); 47 detachAndRemoveAllObjects();
47 } 48 }
48 49
49 WebGraphicsContext3D* WebGLContextGroup::getAWebGraphicsContext3D() 50 WebGraphicsContext3D* WebGLContextGroup::getAWebGraphicsContext3D()
50 { 51 {
51 ASSERT(!m_contexts.isEmpty()); 52 ASSERT(!m_contexts.isEmpty());
52 HashSet<WebGLRenderingContextBase*>::iterator it = m_contexts.begin(); 53 HashSet<WebGLRenderingContextBase*>::iterator it = m_contexts.begin();
53 return (*it)->webContext(); 54 return (*it)->webContext();
54 } 55 }
55 56
57 #if ENABLE(OILPAN) && defined(ADDRESS_SANITIZER)
58 WebGLContextGroup::UnpoisonScope::UnpoisonScope(WebGLContextGroup* context)
59 : m_context(context)
60 , m_object(nullptr)
61 {
62 m_context->poisonContext(false);
63 }
64
65 WebGLContextGroup::UnpoisonScope::UnpoisonScope(WebGLContextGroup* context, WebG LSharedObject* object)
66 : m_context(context)
67 , m_object(object)
68 {
69 m_context->poisonObject(m_object, false);
70 }
71
72 WebGLContextGroup::UnpoisonScope::~UnpoisonScope()
73 {
74 if (!m_object) {
75 m_context->poisonContext(true);
76 } else {
77 ASSERT(m_object);
78 m_context->poisonObject(m_object, true);
79 }
80 }
81
82 void WebGLContextGroup::poisonContext(bool poisonIt)
83 {
84 HashSet<WebGLRenderingContextBase*>::iterator it = m_contexts.begin();
haraken 2015/05/26 11:23:10 I'd prefer explicitly pass in the WebGLRenderingCo
85 WebGLRenderingContextBase* context = *it;
86 if (!Heap::willObjectBeLazilySwept(context))
haraken 2015/05/26 11:23:10 Can we replace this with Heap::isHeapObjectAlive()
sof 2015/05/26 11:29:47 I'm not sure what you refer to..what is Heap::isHe
haraken 2015/05/26 11:36:08 Oh, you're right. isHeapObjectAlive() is available
87 return;
88
89 unsigned char* objectStart = reinterpret_cast<unsigned char*>(context);
90 if (poisonIt)
91 ASAN_POISON_MEMORY_REGION(objectStart, sizeof(WebGLRenderingContextBase) );
92 else
93 ASAN_UNPOISON_MEMORY_REGION(objectStart, sizeof(WebGLRenderingContextBas e));
94 }
95
96 void WebGLContextGroup::poisonObject(WebGLSharedObject* object, bool poisonIt)
97 {
98 if (!Heap::willObjectBeLazilySwept(object))
haraken 2015/05/26 11:23:10 Ditto. I'd prefer using Heap::isHeapObjectAlive().
99 return;
100
101 unsigned char* objectStart = reinterpret_cast<unsigned char*>(object);
102 if (poisonIt)
103 ASAN_POISON_MEMORY_REGION(objectStart, sizeof(WebGLSharedObject));
104 else
105 ASAN_UNPOISON_MEMORY_REGION(objectStart, sizeof(WebGLSharedObject));
106 }
107 #endif
108
56 void WebGLContextGroup::addContext(WebGLRenderingContextBase* context) 109 void WebGLContextGroup::addContext(WebGLRenderingContextBase* context)
57 { 110 {
58 m_contexts.add(context); 111 m_contexts.add(context);
59 } 112 }
60 113
61 void WebGLContextGroup::removeContext(WebGLRenderingContextBase* context) 114 void WebGLContextGroup::removeContext(WebGLRenderingContextBase* context)
62 { 115 {
63 // We must call detachAndRemoveAllObjects before removing the last context. 116 // We must call detachAndRemoveAllObjects before removing the last context.
64 if (m_contexts.size() == 1 && m_contexts.contains(context)) 117 if (m_contexts.size() == 1 && m_contexts.contains(context))
65 detachAndRemoveAllObjects(); 118 detachAndRemoveAllObjects();
66 119
67 m_contexts.remove(context); 120 m_contexts.remove(context);
68 } 121 }
69 122
70 void WebGLContextGroup::removeObject(WebGLSharedObject* object) 123 void WebGLContextGroup::removeObject(WebGLSharedObject* object)
71 { 124 {
72 m_groupObjects.remove(object); 125 m_groupObjects.remove(object);
73 } 126 }
74 127
75 void WebGLContextGroup::addObject(WebGLSharedObject* object) 128 void WebGLContextGroup::addObject(WebGLSharedObject* object)
76 { 129 {
77 m_groupObjects.add(object); 130 m_groupObjects.add(object);
78 } 131 }
79 132
80 void WebGLContextGroup::detachAndRemoveAllObjects() 133 void WebGLContextGroup::detachAndRemoveAllObjects()
81 { 134 {
82 while (!m_groupObjects.isEmpty()) { 135 while (!m_groupObjects.isEmpty()) {
83 HashSet<WebGLSharedObject*>::iterator it = m_groupObjects.begin(); 136 HashSet<WebGLSharedObject*>::iterator it = m_groupObjects.begin();
137 #if ENABLE(OILPAN) && defined(ADDRESS_SANITIZER)
138 UnpoisonScope scope(this, *it);
139 #endif
84 (*it)->detachContextGroup(); 140 (*it)->detachContextGroup();
85 } 141 }
86 } 142 }
87 143
88 void WebGLContextGroup::loseContextGroup(WebGLRenderingContextBase::LostContextM ode mode, WebGLRenderingContextBase::AutoRecoveryMethod autoRecoveryMethod) 144 void WebGLContextGroup::loseContextGroup(WebGLRenderingContextBase::LostContextM ode mode, WebGLRenderingContextBase::AutoRecoveryMethod autoRecoveryMethod)
89 { 145 {
90 // Detach must happen before loseContextImpl, which destroys the GraphicsCon text3D 146 // Detach must happen before loseContextImpl, which destroys the GraphicsCon text3D
91 // and prevents groupObjects from being properly deleted. 147 // and prevents groupObjects from being properly deleted.
92 detachAndRemoveAllObjects(); 148 detachAndRemoveAllObjects();
93 149
94 for (WebGLRenderingContextBase* const context : m_contexts) 150 for (WebGLRenderingContextBase* const context : m_contexts)
95 context->loseContextImpl(mode, autoRecoveryMethod); 151 context->loseContextImpl(mode, autoRecoveryMethod);
96 } 152 }
97 153
98 } // namespace blink 154 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698