| OLD | NEW |
| 1 /* | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * | 3 // found in the LICENSE file. |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 24 */ | |
| 25 | 4 |
| 26 #include "config.h" | 5 #include "config.h" |
| 27 | 6 |
| 28 #include "core/html/canvas/WebGLVertexArrayObjectOES.h" | 7 #include "core/html/canvas/WebGLVertexArrayObjectBase.h" |
| 29 | 8 |
| 30 #include "core/html/canvas/WebGLRenderingContextBase.h" | 9 #include "core/html/canvas/WebGLRenderingContextBase.h" |
| 31 | 10 |
| 32 namespace blink { | 11 namespace blink { |
| 33 | 12 |
| 34 PassRefPtrWillBeRawPtr<WebGLVertexArrayObjectOES> WebGLVertexArrayObjectOES::cre
ate(WebGLRenderingContextBase* ctx, VaoType type) | 13 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase(WebGLRenderingContextBase
* ctx, VaoType type) |
| 35 { | |
| 36 return adoptRefWillBeNoop(new WebGLVertexArrayObjectOES(ctx, type)); | |
| 37 } | |
| 38 | |
| 39 WebGLVertexArrayObjectOES::WebGLVertexArrayObjectOES(WebGLRenderingContextBase*
ctx, VaoType type) | |
| 40 : WebGLContextObject(ctx) | 14 : WebGLContextObject(ctx) |
| 41 , m_object(0) | 15 , m_object(0) |
| 42 , m_type(type) | 16 , m_type(type) |
| 43 , m_hasEverBeenBound(false) | 17 , m_hasEverBeenBound(false) |
| 44 #if ENABLE(OILPAN) | 18 #if ENABLE(OILPAN) |
| 45 , m_destructionInProgress(false) | 19 , m_destructionInProgress(false) |
| 46 #endif | 20 #endif |
| 47 , m_boundElementArrayBuffer(nullptr) | 21 , m_boundElementArrayBuffer(nullptr) |
| 48 { | 22 { |
| 49 m_vertexAttribState.reserveCapacity(ctx->maxVertexAttribs()); | 23 m_vertexAttribState.reserveCapacity(ctx->maxVertexAttribs()); |
| 50 | 24 |
| 51 switch (m_type) { | 25 switch (m_type) { |
| 52 case VaoTypeDefault: | 26 case VaoTypeDefault: |
| 53 break; | 27 break; |
| 54 default: | 28 default: |
| 55 m_object = context()->webContext()->createVertexArrayOES(); | 29 m_object = context()->webContext()->createVertexArrayOES(); |
| 56 break; | 30 break; |
| 57 } | 31 } |
| 58 } | 32 } |
| 59 | 33 |
| 60 WebGLVertexArrayObjectOES::~WebGLVertexArrayObjectOES() | 34 WebGLVertexArrayObjectBase::~WebGLVertexArrayObjectBase() |
| 61 { | 35 { |
| 62 #if ENABLE(OILPAN) | 36 #if ENABLE(OILPAN) |
| 63 m_destructionInProgress = true; | 37 m_destructionInProgress = true; |
| 64 #endif | 38 #endif |
| 65 | 39 |
| 66 // Delete the platform framebuffer resource. Explicit detachment | 40 // Delete the platform framebuffer resource. Explicit detachment |
| 67 // is for the benefit of Oilpan, where this vertex array object | 41 // is for the benefit of Oilpan, where this vertex array object |
| 68 // isn't detached when it and the WebGLRenderingContextBase object | 42 // isn't detached when it and the WebGLRenderingContextBase object |
| 69 // it is registered with are both finalized. Without Oilpan, the | 43 // it is registered with are both finalized. Without Oilpan, the |
| 70 // object will have been detached. | 44 // object will have been detached. |
| 71 // | 45 // |
| 72 // To keep the code regular, the trivial detach()ment is always | 46 // To keep the code regular, the trivial detach()ment is always |
| 73 // performed. | 47 // performed. |
| 74 detachAndDeleteObject(); | 48 detachAndDeleteObject(); |
| 75 } | 49 } |
| 76 | 50 |
| 77 void WebGLVertexArrayObjectOES::dispatchDetached(WebGraphicsContext3D* context3d
) | 51 void WebGLVertexArrayObjectBase::dispatchDetached(WebGraphicsContext3D* context3
d) |
| 78 { | 52 { |
| 79 if (m_boundElementArrayBuffer) | 53 if (m_boundElementArrayBuffer) |
| 80 m_boundElementArrayBuffer->onDetached(context3d); | 54 m_boundElementArrayBuffer->onDetached(context3d); |
| 81 | 55 |
| 82 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | 56 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { |
| 83 VertexAttribState* state = m_vertexAttribState[i].get(); | 57 VertexAttribState* state = m_vertexAttribState[i].get(); |
| 84 if (state->bufferBinding) | 58 if (state->bufferBinding) |
| 85 state->bufferBinding->onDetached(context3d); | 59 state->bufferBinding->onDetached(context3d); |
| 86 } | 60 } |
| 87 } | 61 } |
| 88 | 62 |
| 89 void WebGLVertexArrayObjectOES::deleteObjectImpl(WebGraphicsContext3D* context3d
) | 63 void WebGLVertexArrayObjectBase::deleteObjectImpl(WebGraphicsContext3D* context3
d) |
| 90 { | 64 { |
| 91 switch (m_type) { | 65 switch (m_type) { |
| 92 case VaoTypeDefault: | 66 case VaoTypeDefault: |
| 93 break; | 67 break; |
| 94 default: | 68 default: |
| 95 context3d->deleteVertexArrayOES(m_object); | 69 context3d->deleteVertexArrayOES(m_object); |
| 96 m_object = 0; | 70 m_object = 0; |
| 97 break; | 71 break; |
| 98 } | 72 } |
| 99 | 73 |
| 100 #if ENABLE(OILPAN) | 74 #if ENABLE(OILPAN) |
| 101 // These m_boundElementArrayBuffer and m_vertexAttribState heap | 75 // These m_boundElementArrayBuffer and m_vertexAttribState heap |
| 102 // objects must not be accessed during destruction in the oilpan | 76 // objects must not be accessed during destruction in the oilpan |
| 103 // build. They could have been already finalized. The finalizers | 77 // build. They could have been already finalized. The finalizers |
| 104 // of these objects (and their elements) will themselves handle | 78 // of these objects (and their elements) will themselves handle |
| 105 // detachment. | 79 // detachment. |
| 106 if (!m_destructionInProgress) | 80 if (!m_destructionInProgress) |
| 107 dispatchDetached(context3d); | 81 dispatchDetached(context3d); |
| 108 #else | 82 #else |
| 109 dispatchDetached(context3d); | 83 dispatchDetached(context3d); |
| 110 #endif | 84 #endif |
| 111 } | 85 } |
| 112 | 86 |
| 113 void WebGLVertexArrayObjectOES::setElementArrayBuffer(PassRefPtrWillBeRawPtr<Web
GLBuffer> buffer) | 87 void WebGLVertexArrayObjectBase::setElementArrayBuffer(PassRefPtrWillBeRawPtr<We
bGLBuffer> buffer) |
| 114 { | 88 { |
| 115 if (buffer) | 89 if (buffer) |
| 116 buffer->onAttached(); | 90 buffer->onAttached(); |
| 117 if (m_boundElementArrayBuffer) | 91 if (m_boundElementArrayBuffer) |
| 118 m_boundElementArrayBuffer->onDetached(context()->webContext()); | 92 m_boundElementArrayBuffer->onDetached(context()->webContext()); |
| 119 m_boundElementArrayBuffer = buffer; | 93 m_boundElementArrayBuffer = buffer; |
| 120 } | 94 } |
| 121 | 95 |
| 122 WebGLVertexArrayObjectOES::VertexAttribState* WebGLVertexArrayObjectOES::getVert
exAttribState(size_t index) | 96 WebGLVertexArrayObjectBase::VertexAttribState* WebGLVertexArrayObjectBase::getVe
rtexAttribState(size_t index) |
| 123 { | 97 { |
| 124 ASSERT(index < context()->maxVertexAttribs()); | 98 ASSERT(index < context()->maxVertexAttribs()); |
| 125 // Lazily create the vertex attribute states. | 99 // Lazily create the vertex attribute states. |
| 126 for (size_t i = m_vertexAttribState.size(); i <= index; i++) | 100 for (size_t i = m_vertexAttribState.size(); i <= index; i++) |
| 127 m_vertexAttribState.append(adoptPtrWillBeNoop(new VertexAttribState())); | 101 m_vertexAttribState.append(adoptPtrWillBeNoop(new VertexAttribState())); |
| 128 return m_vertexAttribState[index].get(); | 102 return m_vertexAttribState[index].get(); |
| 129 } | 103 } |
| 130 | 104 |
| 131 void WebGLVertexArrayObjectOES::setVertexAttribState( | 105 void WebGLVertexArrayObjectBase::setVertexAttribState( |
| 132 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, PassRefPtrWillBeRawPtr<WebGLBuffer> b
uffer) | 106 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, PassRefPtrWillBeRawPtr<WebGLBuffer> b
uffer) |
| 133 { | 107 { |
| 134 GLsizei validatedStride = stride ? stride : bytesPerElement; | 108 GLsizei validatedStride = stride ? stride : bytesPerElement; |
| 135 VertexAttribState* state = getVertexAttribState(index); | 109 VertexAttribState* state = getVertexAttribState(index); |
| 136 | 110 |
| 137 if (buffer) | 111 if (buffer) |
| 138 buffer->onAttached(); | 112 buffer->onAttached(); |
| 139 if (state->bufferBinding) | 113 if (state->bufferBinding) |
| 140 state->bufferBinding->onDetached(context()->webContext()); | 114 state->bufferBinding->onDetached(context()->webContext()); |
| 141 | 115 |
| 142 state->bufferBinding = buffer; | 116 state->bufferBinding = buffer; |
| 143 state->bytesPerElement = bytesPerElement; | 117 state->bytesPerElement = bytesPerElement; |
| 144 state->size = size; | 118 state->size = size; |
| 145 state->type = type; | 119 state->type = type; |
| 146 state->normalized = normalized; | 120 state->normalized = normalized; |
| 147 state->stride = validatedStride; | 121 state->stride = validatedStride; |
| 148 state->originalStride = stride; | 122 state->originalStride = stride; |
| 149 state->offset = offset; | 123 state->offset = offset; |
| 150 } | 124 } |
| 151 | 125 |
| 152 void WebGLVertexArrayObjectOES::unbindBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer>
buffer) | 126 void WebGLVertexArrayObjectBase::unbindBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer
> buffer) |
| 153 { | 127 { |
| 154 if (m_boundElementArrayBuffer == buffer) { | 128 if (m_boundElementArrayBuffer == buffer) { |
| 155 m_boundElementArrayBuffer->onDetached(context()->webContext()); | 129 m_boundElementArrayBuffer->onDetached(context()->webContext()); |
| 156 m_boundElementArrayBuffer = nullptr; | 130 m_boundElementArrayBuffer = nullptr; |
| 157 } | 131 } |
| 158 | 132 |
| 159 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | 133 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { |
| 160 VertexAttribState* state = m_vertexAttribState[i].get(); | 134 VertexAttribState* state = m_vertexAttribState[i].get(); |
| 161 if (state->bufferBinding == buffer) { | 135 if (state->bufferBinding == buffer) { |
| 162 buffer->onDetached(context()->webContext()); | 136 buffer->onDetached(context()->webContext()); |
| 163 state->bufferBinding = nullptr; | 137 state->bufferBinding = nullptr; |
| 164 } | 138 } |
| 165 } | 139 } |
| 166 } | 140 } |
| 167 | 141 |
| 168 void WebGLVertexArrayObjectOES::setVertexAttribDivisor(GLuint index, GLuint divi
sor) | 142 void WebGLVertexArrayObjectBase::setVertexAttribDivisor(GLuint index, GLuint div
isor) |
| 169 { | 143 { |
| 170 VertexAttribState* state = getVertexAttribState(index); | 144 VertexAttribState* state = getVertexAttribState(index); |
| 171 state->divisor = divisor; | 145 state->divisor = divisor; |
| 172 } | 146 } |
| 173 | 147 |
| 174 DEFINE_TRACE(WebGLVertexArrayObjectOES::VertexAttribState) | 148 DEFINE_TRACE(WebGLVertexArrayObjectBase::VertexAttribState) |
| 175 { | 149 { |
| 176 visitor->trace(bufferBinding); | 150 visitor->trace(bufferBinding); |
| 177 } | 151 } |
| 178 | 152 |
| 179 DEFINE_TRACE(WebGLVertexArrayObjectOES) | 153 DEFINE_TRACE(WebGLVertexArrayObjectBase) |
| 180 { | 154 { |
| 181 visitor->trace(m_boundElementArrayBuffer); | 155 visitor->trace(m_boundElementArrayBuffer); |
| 182 visitor->trace(m_vertexAttribState); | 156 visitor->trace(m_vertexAttribState); |
| 183 WebGLContextObject::trace(visitor); | 157 WebGLContextObject::trace(visitor); |
| 184 } | 158 } |
| 185 | 159 |
| 186 } // namespace blink | 160 } // namespace blink |
| OLD | NEW |