| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webgl/WebGLVertexArrayObjectBase.h" | 5 #include "modules/webgl/WebGLVertexArrayObjectBase.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_interface.h" | 7 #include "gpu/command_buffer/client/gles2_interface.h" |
| 8 #include "modules/webgl/WebGLRenderingContextBase.h" | 8 #include "modules/webgl/WebGLRenderingContextBase.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase( | 12 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase( |
| 13 WebGLRenderingContextBase* ctx, | 13 WebGLRenderingContextBase* ctx, |
| 14 VaoType type) | 14 VaoType type) |
| 15 : WebGLContextObject(ctx), | 15 : WebGLContextObject(ctx), |
| 16 m_object(0), | 16 m_object(0), |
| 17 m_type(type), | 17 m_type(type), |
| 18 m_hasEverBeenBound(false), | 18 m_hasEverBeenBound(false), |
| 19 m_destructionInProgress(false), | |
| 20 m_boundElementArrayBuffer(this, nullptr), | 19 m_boundElementArrayBuffer(this, nullptr), |
| 21 m_isAllEnabledAttribBufferBound(true) { | 20 m_isAllEnabledAttribBufferBound(true) { |
| 22 m_arrayBufferList.resize(ctx->maxVertexAttribs()); | 21 m_arrayBufferList.resize(ctx->maxVertexAttribs()); |
| 23 m_attribEnabled.resize(ctx->maxVertexAttribs()); | 22 m_attribEnabled.resize(ctx->maxVertexAttribs()); |
| 24 for (size_t i = 0; i < m_attribEnabled.size(); ++i) { | 23 for (size_t i = 0; i < m_attribEnabled.size(); ++i) { |
| 25 m_attribEnabled[i] = false; | 24 m_attribEnabled[i] = false; |
| 26 } | 25 } |
| 27 | 26 |
| 28 switch (m_type) { | 27 switch (m_type) { |
| 29 case VaoTypeDefault: | 28 case VaoTypeDefault: |
| 30 break; | 29 break; |
| 31 default: | 30 default: |
| 32 context()->contextGL()->GenVertexArraysOES(1, &m_object); | 31 context()->contextGL()->GenVertexArraysOES(1, &m_object); |
| 33 break; | 32 break; |
| 34 } | 33 } |
| 35 } | 34 } |
| 36 | 35 |
| 37 WebGLVertexArrayObjectBase::~WebGLVertexArrayObjectBase() { | 36 WebGLVertexArrayObjectBase::~WebGLVertexArrayObjectBase() { |
| 38 m_destructionInProgress = true; | 37 runDestructor(); |
| 39 | |
| 40 // Delete the platform framebuffer resource, in case | |
| 41 // where this vertex array object isn't detached when it and | |
| 42 // the WebGLRenderingContextBase object it is registered with | |
| 43 // are both finalized. | |
| 44 detachAndDeleteObject(); | |
| 45 } | 38 } |
| 46 | 39 |
| 47 void WebGLVertexArrayObjectBase::dispatchDetached( | 40 void WebGLVertexArrayObjectBase::dispatchDetached( |
| 48 gpu::gles2::GLES2Interface* gl) { | 41 gpu::gles2::GLES2Interface* gl) { |
| 49 if (m_boundElementArrayBuffer) | 42 if (m_boundElementArrayBuffer) |
| 50 m_boundElementArrayBuffer->onDetached(gl); | 43 m_boundElementArrayBuffer->onDetached(gl); |
| 51 | 44 |
| 52 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) { | 45 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) { |
| 53 if (m_arrayBufferList[i]) | 46 if (m_arrayBufferList[i]) |
| 54 m_arrayBufferList[i]->onDetached(gl); | 47 m_arrayBufferList[i]->onDetached(gl); |
| 55 } | 48 } |
| 56 } | 49 } |
| 57 | 50 |
| 58 void WebGLVertexArrayObjectBase::deleteObjectImpl( | 51 void WebGLVertexArrayObjectBase::deleteObjectImpl( |
| 59 gpu::gles2::GLES2Interface* gl) { | 52 gpu::gles2::GLES2Interface* gl) { |
| 60 switch (m_type) { | 53 switch (m_type) { |
| 61 case VaoTypeDefault: | 54 case VaoTypeDefault: |
| 62 break; | 55 break; |
| 63 default: | 56 default: |
| 64 gl->DeleteVertexArraysOES(1, &m_object); | 57 gl->DeleteVertexArraysOES(1, &m_object); |
| 65 m_object = 0; | 58 m_object = 0; |
| 66 break; | 59 break; |
| 67 } | 60 } |
| 68 | 61 |
| 69 // Member<> objects must not be accessed during the destruction, | 62 // Member<> objects must not be accessed during the destruction, |
| 70 // since they could have been already finalized. | 63 // since they could have been already finalized. |
| 71 // The finalizers of these objects will handle their detachment | 64 // The finalizers of these objects will handle their detachment |
| 72 // by themselves. | 65 // by themselves. |
| 73 if (!m_destructionInProgress) | 66 if (!destructionInProgress()) |
| 74 dispatchDetached(gl); | 67 dispatchDetached(gl); |
| 75 } | 68 } |
| 76 | 69 |
| 77 void WebGLVertexArrayObjectBase::setElementArrayBuffer(WebGLBuffer* buffer) { | 70 void WebGLVertexArrayObjectBase::setElementArrayBuffer(WebGLBuffer* buffer) { |
| 78 if (buffer) | 71 if (buffer) |
| 79 buffer->onAttached(); | 72 buffer->onAttached(); |
| 80 if (m_boundElementArrayBuffer) | 73 if (m_boundElementArrayBuffer) |
| 81 m_boundElementArrayBuffer->onDetached(context()->contextGL()); | 74 m_boundElementArrayBuffer->onDetached(context()->contextGL()); |
| 82 m_boundElementArrayBuffer = buffer; | 75 m_boundElementArrayBuffer = buffer; |
| 83 } | 76 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 146 |
| 154 DEFINE_TRACE_WRAPPERS(WebGLVertexArrayObjectBase) { | 147 DEFINE_TRACE_WRAPPERS(WebGLVertexArrayObjectBase) { |
| 155 visitor->traceWrappers(m_boundElementArrayBuffer); | 148 visitor->traceWrappers(m_boundElementArrayBuffer); |
| 156 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) { | 149 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) { |
| 157 visitor->traceWrappers(m_arrayBufferList[i]); | 150 visitor->traceWrappers(m_arrayBufferList[i]); |
| 158 } | 151 } |
| 159 WebGLContextObject::traceWrappers(visitor); | 152 WebGLContextObject::traceWrappers(visitor); |
| 160 } | 153 } |
| 161 | 154 |
| 162 } // namespace blink | 155 } // namespace blink |
| OLD | NEW |