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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLObject.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) 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 11 matching lines...) Expand all
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/WebGLObject.h" 26 #include "modules/webgl/WebGLObject.h"
27 27
28 #include "modules/webgl/WebGLRenderingContextBase.h" 28 #include "modules/webgl/WebGLRenderingContextBase.h"
29 29
30 namespace blink { 30 namespace blink {
31 31
32 WebGLObject::WebGLObject(WebGLRenderingContextBase*) 32 WebGLObject::WebGLObject(WebGLRenderingContextBase* context)
33 : m_attachmentCount(0), m_deleted(false) {} 33 : m_cachedNumberOfContextLosses(context->numberOfContextLosses()),
34 m_attachmentCount(0),
35 m_deleted(false),
36 m_destructionInProgress(false) {}
34 37
35 WebGLObject::~WebGLObject() { 38 WebGLObject::~WebGLObject() {}
36 // Verify that platform objects have been explicitly deleted. 39
37 ASSERT(m_deleted); 40 uint32_t WebGLObject::cachedNumberOfContextLosses() const {
41 return m_cachedNumberOfContextLosses;
38 } 42 }
39 43
40 void WebGLObject::deleteObject(gpu::gles2::GLES2Interface* gl) { 44 void WebGLObject::deleteObject(gpu::gles2::GLES2Interface* gl) {
41 m_deleted = true; 45 m_deleted = true;
42 if (!hasObject()) 46 if (!hasObject())
43 return; 47 return;
44 48
45 if (!hasGroupOrContext()) 49 if (!hasGroupOrContext())
46 return; 50 return;
47 51
52 if (currentNumberOfContextLosses() != m_cachedNumberOfContextLosses) {
53 // This object has been invalidated.
54 return;
55 }
56
48 if (!m_attachmentCount) { 57 if (!m_attachmentCount) {
49 if (!gl) 58 if (!gl)
50 gl = getAGLInterface(); 59 gl = getAGLInterface();
51 if (gl) { 60 if (gl) {
52 deleteObjectImpl(gl); 61 deleteObjectImpl(gl);
53 // Ensure the inherited class no longer claims to have a valid object 62 // Ensure the inherited class no longer claims to have a valid object
54 ASSERT(!hasObject()); 63 ASSERT(!hasObject());
55 } 64 }
56 } 65 }
57 } 66 }
58 67
59 void WebGLObject::detach() { 68 void WebGLObject::detach() {
60 m_attachmentCount = 0; // Make sure OpenGL resource is deleted. 69 m_attachmentCount = 0; // Make sure OpenGL resource is deleted.
61 } 70 }
62 71
63 void WebGLObject::detachAndDeleteObject() { 72 void WebGLObject::detachAndDeleteObject() {
64 // To ensure that all platform objects are deleted after being detached, 73 // To ensure that all platform objects are deleted after being detached,
65 // this method does them together. 74 // this method does them together.
66 //
67 // The individual WebGL destructors need to call detachAndDeleteObject()
68 // rather than do it based on Oilpan GC.
69 detach(); 75 detach();
70 deleteObject(nullptr); 76 deleteObject(nullptr);
71 } 77 }
72 78
79 void WebGLObject::runDestructor() {
80 DCHECK(!m_destructionInProgress);
81 // This boilerplate destructor is sufficient for all subclasses, as long
82 // as they implement deleteObjectImpl properly, and don't try to touch
83 // other objects on the Oilpan heap if the destructor's been entered.
84 m_destructionInProgress = true;
85 detachAndDeleteObject();
86 }
87
88 bool WebGLObject::destructionInProgress() const {
89 return m_destructionInProgress;
90 }
91
73 void WebGLObject::onDetached(gpu::gles2::GLES2Interface* gl) { 92 void WebGLObject::onDetached(gpu::gles2::GLES2Interface* gl) {
74 if (m_attachmentCount) 93 if (m_attachmentCount)
75 --m_attachmentCount; 94 --m_attachmentCount;
76 if (m_deleted) 95 if (m_deleted)
77 deleteObject(gl); 96 deleteObject(gl);
78 } 97 }
79 98
99 DEFINE_TRACE_WRAPPERS(WebGLObject) {}
100
80 } // namespace blink 101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698