| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "modules/webgl/WebGLVertexArrayObjectBase.h" | 7 #include "modules/webgl/WebGLVertexArrayObjectBase.h" |
| 8 | 8 |
| 9 #include "modules/webgl/WebGLRenderingContextBase.h" | 9 #include "modules/webgl/WebGLRenderingContextBase.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase(WebGLRenderingContextBase
* ctx, VaoType type) | 13 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase(WebGLRenderingContextBase
* ctx, VaoType type) |
| 14 : WebGLContextObject(ctx) | 14 : WebGLContextObject(ctx) |
| 15 , m_object(0) | 15 , m_object(0) |
| 16 , m_type(type) | 16 , m_type(type) |
| 17 , m_hasEverBeenBound(false) | 17 , m_hasEverBeenBound(false) |
| 18 #if ENABLE(OILPAN) |
| 18 , m_destructionInProgress(false) | 19 , m_destructionInProgress(false) |
| 20 #endif |
| 19 , m_boundElementArrayBuffer(nullptr) | 21 , m_boundElementArrayBuffer(nullptr) |
| 20 { | 22 { |
| 21 m_vertexAttribState.reserveCapacity(ctx->maxVertexAttribs()); | 23 m_vertexAttribState.reserveCapacity(ctx->maxVertexAttribs()); |
| 22 | 24 |
| 23 switch (m_type) { | 25 switch (m_type) { |
| 24 case VaoTypeDefault: | 26 case VaoTypeDefault: |
| 25 break; | 27 break; |
| 26 default: | 28 default: |
| 27 m_object = context()->webContext()->createVertexArrayOES(); | 29 m_object = context()->webContext()->createVertexArrayOES(); |
| 28 break; | 30 break; |
| 29 } | 31 } |
| 30 } | 32 } |
| 31 | 33 |
| 32 WebGLVertexArrayObjectBase::~WebGLVertexArrayObjectBase() | 34 WebGLVertexArrayObjectBase::~WebGLVertexArrayObjectBase() |
| 33 { | 35 { |
| 36 #if ENABLE(OILPAN) |
| 34 m_destructionInProgress = true; | 37 m_destructionInProgress = true; |
| 38 #endif |
| 35 | 39 |
| 36 // Delete the platform framebuffer resource, in case | 40 // Delete the platform framebuffer resource. Explicit detachment |
| 37 // where this vertex array object isn't detached when it and | 41 // is for the benefit of Oilpan, where this vertex array object |
| 38 // the WebGLRenderingContextBase object it is registered with | 42 // isn't detached when it and the WebGLRenderingContextBase object |
| 39 // are both finalized. | 43 // it is registered with are both finalized. Without Oilpan, the |
| 44 // object will have been detached. |
| 45 // |
| 46 // To keep the code regular, the trivial detach()ment is always |
| 47 // performed. |
| 40 detachAndDeleteObject(); | 48 detachAndDeleteObject(); |
| 41 } | 49 } |
| 42 | 50 |
| 43 void WebGLVertexArrayObjectBase::dispatchDetached(WebGraphicsContext3D* context3
d) | 51 void WebGLVertexArrayObjectBase::dispatchDetached(WebGraphicsContext3D* context3
d) |
| 44 { | 52 { |
| 45 if (m_boundElementArrayBuffer) | 53 if (m_boundElementArrayBuffer) |
| 46 m_boundElementArrayBuffer->onDetached(context3d); | 54 m_boundElementArrayBuffer->onDetached(context3d); |
| 47 | 55 |
| 48 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | 56 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { |
| 49 VertexAttribState* state = m_vertexAttribState[i].get(); | 57 VertexAttribState* state = m_vertexAttribState[i].get(); |
| 50 if (state->bufferBinding) | 58 if (state->bufferBinding) |
| 51 state->bufferBinding->onDetached(context3d); | 59 state->bufferBinding->onDetached(context3d); |
| 52 } | 60 } |
| 53 } | 61 } |
| 54 | 62 |
| 55 void WebGLVertexArrayObjectBase::deleteObjectImpl(WebGraphicsContext3D* context3
d) | 63 void WebGLVertexArrayObjectBase::deleteObjectImpl(WebGraphicsContext3D* context3
d) |
| 56 { | 64 { |
| 57 switch (m_type) { | 65 switch (m_type) { |
| 58 case VaoTypeDefault: | 66 case VaoTypeDefault: |
| 59 break; | 67 break; |
| 60 default: | 68 default: |
| 61 context3d->deleteVertexArrayOES(m_object); | 69 context3d->deleteVertexArrayOES(m_object); |
| 62 m_object = 0; | 70 m_object = 0; |
| 63 break; | 71 break; |
| 64 } | 72 } |
| 65 | 73 |
| 66 // Member<> objects must not be accessed during the destruction, | 74 #if ENABLE(OILPAN) |
| 67 // since they could have been already finalized. | 75 // These m_boundElementArrayBuffer and m_vertexAttribState heap |
| 68 // The finalizers of these objects will handle their detachment | 76 // objects must not be accessed during destruction in the oilpan |
| 69 // by themselves. | 77 // build. They could have been already finalized. The finalizers |
| 78 // of these objects (and their elements) will themselves handle |
| 79 // detachment. |
| 70 if (!m_destructionInProgress) | 80 if (!m_destructionInProgress) |
| 71 dispatchDetached(context3d); | 81 dispatchDetached(context3d); |
| 82 #else |
| 83 dispatchDetached(context3d); |
| 84 #endif |
| 72 } | 85 } |
| 73 | 86 |
| 74 void WebGLVertexArrayObjectBase::setElementArrayBuffer(WebGLBuffer* buffer) | 87 void WebGLVertexArrayObjectBase::setElementArrayBuffer(PassRefPtrWillBeRawPtr<We
bGLBuffer> buffer) |
| 75 { | 88 { |
| 76 if (buffer) | 89 if (buffer) |
| 77 buffer->onAttached(); | 90 buffer->onAttached(); |
| 78 if (m_boundElementArrayBuffer) | 91 if (m_boundElementArrayBuffer) |
| 79 m_boundElementArrayBuffer->onDetached(context()->webContext()); | 92 m_boundElementArrayBuffer->onDetached(context()->webContext()); |
| 80 m_boundElementArrayBuffer = buffer; | 93 m_boundElementArrayBuffer = buffer; |
| 81 } | 94 } |
| 82 | 95 |
| 83 WebGLVertexArrayObjectBase::VertexAttribState* WebGLVertexArrayObjectBase::getVe
rtexAttribState(size_t index) | 96 WebGLVertexArrayObjectBase::VertexAttribState* WebGLVertexArrayObjectBase::getVe
rtexAttribState(size_t index) |
| 84 { | 97 { |
| 85 ASSERT(index < context()->maxVertexAttribs()); | 98 ASSERT(index < context()->maxVertexAttribs()); |
| 86 // Lazily create the vertex attribute states. | 99 // Lazily create the vertex attribute states. |
| 87 for (size_t i = m_vertexAttribState.size(); i <= index; i++) | 100 for (size_t i = m_vertexAttribState.size(); i <= index; i++) |
| 88 m_vertexAttribState.append(new VertexAttribState); | 101 m_vertexAttribState.append(adoptPtrWillBeNoop(new VertexAttribState())); |
| 89 return m_vertexAttribState[index].get(); | 102 return m_vertexAttribState[index].get(); |
| 90 } | 103 } |
| 91 | 104 |
| 92 void WebGLVertexArrayObjectBase::setVertexAttribState( | 105 void WebGLVertexArrayObjectBase::setVertexAttribState( |
| 93 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, WebGLBuffer* buffer) | 106 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, PassRefPtrWillBeRawPtr<WebGLBuffer> b
uffer) |
| 94 { | 107 { |
| 95 GLsizei validatedStride = stride ? stride : bytesPerElement; | 108 GLsizei validatedStride = stride ? stride : bytesPerElement; |
| 96 VertexAttribState* state = getVertexAttribState(index); | 109 VertexAttribState* state = getVertexAttribState(index); |
| 97 | 110 |
| 98 if (buffer) | 111 if (buffer) |
| 99 buffer->onAttached(); | 112 buffer->onAttached(); |
| 100 if (state->bufferBinding) | 113 if (state->bufferBinding) |
| 101 state->bufferBinding->onDetached(context()->webContext()); | 114 state->bufferBinding->onDetached(context()->webContext()); |
| 102 | 115 |
| 103 state->bufferBinding = buffer; | 116 state->bufferBinding = buffer; |
| 104 state->bytesPerElement = bytesPerElement; | 117 state->bytesPerElement = bytesPerElement; |
| 105 state->size = size; | 118 state->size = size; |
| 106 state->type = type; | 119 state->type = type; |
| 107 state->normalized = normalized; | 120 state->normalized = normalized; |
| 108 state->stride = validatedStride; | 121 state->stride = validatedStride; |
| 109 state->originalStride = stride; | 122 state->originalStride = stride; |
| 110 state->offset = offset; | 123 state->offset = offset; |
| 111 } | 124 } |
| 112 | 125 |
| 113 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer) | 126 void WebGLVertexArrayObjectBase::unbindBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer
> buffer) |
| 114 { | 127 { |
| 115 if (m_boundElementArrayBuffer == buffer) { | 128 if (m_boundElementArrayBuffer == buffer) { |
| 116 m_boundElementArrayBuffer->onDetached(context()->webContext()); | 129 m_boundElementArrayBuffer->onDetached(context()->webContext()); |
| 117 m_boundElementArrayBuffer = nullptr; | 130 m_boundElementArrayBuffer = nullptr; |
| 118 } | 131 } |
| 119 | 132 |
| 120 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | 133 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { |
| 121 VertexAttribState* state = m_vertexAttribState[i]; | 134 VertexAttribState* state = m_vertexAttribState[i].get(); |
| 122 if (state->bufferBinding == buffer) { | 135 if (state->bufferBinding == buffer) { |
| 123 buffer->onDetached(context()->webContext()); | 136 buffer->onDetached(context()->webContext()); |
| 124 state->bufferBinding = nullptr; | 137 state->bufferBinding = nullptr; |
| 125 } | 138 } |
| 126 } | 139 } |
| 127 } | 140 } |
| 128 | 141 |
| 129 void WebGLVertexArrayObjectBase::setVertexAttribDivisor(GLuint index, GLuint div
isor) | 142 void WebGLVertexArrayObjectBase::setVertexAttribDivisor(GLuint index, GLuint div
isor) |
| 130 { | 143 { |
| 131 VertexAttribState* state = getVertexAttribState(index); | 144 VertexAttribState* state = getVertexAttribState(index); |
| 132 state->divisor = divisor; | 145 state->divisor = divisor; |
| 133 } | 146 } |
| 134 | 147 |
| 135 DEFINE_TRACE(WebGLVertexArrayObjectBase::VertexAttribState) | 148 DEFINE_TRACE(WebGLVertexArrayObjectBase::VertexAttribState) |
| 136 { | 149 { |
| 137 visitor->trace(bufferBinding); | 150 visitor->trace(bufferBinding); |
| 138 } | 151 } |
| 139 | 152 |
| 140 DEFINE_TRACE(WebGLVertexArrayObjectBase) | 153 DEFINE_TRACE(WebGLVertexArrayObjectBase) |
| 141 { | 154 { |
| 142 visitor->trace(m_boundElementArrayBuffer); | 155 visitor->trace(m_boundElementArrayBuffer); |
| 143 visitor->trace(m_vertexAttribState); | 156 visitor->trace(m_vertexAttribState); |
| 144 WebGLContextObject::trace(visitor); | 157 WebGLContextObject::trace(visitor); |
| 145 } | 158 } |
| 146 | 159 |
| 147 } // namespace blink | 160 } // namespace blink |
| OLD | NEW |