OLD | NEW |
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 |
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/WebGLObject.h" | 26 #include "modules/webgl/WebGLObject.h" |
27 | 27 |
| 28 #include "modules/webgl/WebGLRenderingContextBase.h" |
28 #include "public/platform/WebGraphicsContext3D.h" | 29 #include "public/platform/WebGraphicsContext3D.h" |
29 | 30 |
30 namespace blink { | 31 namespace blink { |
31 | 32 |
32 WebGLObject::WebGLObject(WebGLRenderingContextBase*) | 33 WebGLObject::WebGLObject(WebGLRenderingContextBase*) |
33 : m_attachmentCount(0) | 34 : m_attachmentCount(0) |
34 , m_deleted(false) | 35 , m_deleted(false) |
35 { | 36 { |
36 } | 37 } |
37 | 38 |
38 WebGLObject::~WebGLObject() | 39 WebGLObject::~WebGLObject() |
39 { | 40 { |
40 // Verify that platform objects have been explicitly deleted. | 41 // Verify that platform objects have been explicitly deleted. |
41 ASSERT(m_deleted); | 42 ASSERT(m_deleted); |
42 } | 43 } |
43 | 44 |
44 void WebGLObject::deleteObject(WebGraphicsContext3D* context3d, gpu::gles2::GLES
2Interface* gl) | 45 void WebGLObject::deleteObject(gpu::gles2::GLES2Interface* gl) |
45 { | 46 { |
46 m_deleted = true; | 47 m_deleted = true; |
47 if (!hasObject()) | 48 if (!hasObject()) |
48 return; | 49 return; |
49 | 50 |
50 if (!hasGroupOrContext()) | 51 if (!hasGroupOrContext()) |
51 return; | 52 return; |
52 | 53 |
53 if (!m_attachmentCount) { | 54 if (!m_attachmentCount) { |
54 if (!context3d) { | 55 if (!gl) |
55 context3d = getAWebGraphicsContext3D(); | 56 gl = getAGLInterface(); |
56 gl = context3d ? context3d->getGLES2Interface() : nullptr; | 57 if (gl) { |
57 } | 58 deleteObjectImpl(gl); |
58 | |
59 if (context3d) { | |
60 deleteObjectImpl(context3d, gl); | |
61 // Ensure the inherited class no longer claims to have a valid objec
t | 59 // Ensure the inherited class no longer claims to have a valid objec
t |
62 ASSERT(!hasObject()); | 60 ASSERT(!hasObject()); |
63 } | 61 } |
64 } | 62 } |
65 } | 63 } |
66 | 64 |
67 void WebGLObject::detach() | 65 void WebGLObject::detach() |
68 { | 66 { |
69 m_attachmentCount = 0; // Make sure OpenGL resource is deleted. | 67 m_attachmentCount = 0; // Make sure OpenGL resource is deleted. |
70 } | 68 } |
71 | 69 |
72 void WebGLObject::detachAndDeleteObject() | 70 void WebGLObject::detachAndDeleteObject() |
73 { | 71 { |
74 // To ensure that all platform objects are deleted after being detached, | 72 // To ensure that all platform objects are deleted after being detached, |
75 // this method does them together. | 73 // this method does them together. |
76 // | 74 // |
77 // The individual WebGL destructors need to call detachAndDeleteObject() | 75 // The individual WebGL destructors need to call detachAndDeleteObject() |
78 // rather than do it based on Oilpan GC. | 76 // rather than do it based on Oilpan GC. |
79 detach(); | 77 detach(); |
80 deleteObject(nullptr, nullptr); | 78 deleteObject(nullptr); |
81 } | 79 } |
82 | 80 |
83 void WebGLObject::onDetached(WebGraphicsContext3D* context3d, gpu::gles2::GLES2I
nterface* gl) | 81 void WebGLObject::onDetached(gpu::gles2::GLES2Interface* gl) |
84 { | 82 { |
85 if (m_attachmentCount) | 83 if (m_attachmentCount) |
86 --m_attachmentCount; | 84 --m_attachmentCount; |
87 if (m_deleted) | 85 if (m_deleted) |
88 deleteObject(context3d, gl); | 86 deleteObject(gl); |
89 } | 87 } |
90 | 88 |
91 } // namespace blink | 89 } // namespace blink |
OLD | NEW |