| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 19 matching lines...) Expand all Loading... |
| 30 #include "core/html/canvas/WebGLRenderingContextBase.h" | 30 #include "core/html/canvas/WebGLRenderingContextBase.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 PassRefPtrWillBeRawPtr<WebGLVertexArrayObjectOES> WebGLVertexArrayObjectOES::cre
ate(WebGLRenderingContextBase* ctx, VaoType type) | 34 PassRefPtrWillBeRawPtr<WebGLVertexArrayObjectOES> WebGLVertexArrayObjectOES::cre
ate(WebGLRenderingContextBase* ctx, VaoType type) |
| 35 { | 35 { |
| 36 return adoptRefWillBeNoop(new WebGLVertexArrayObjectOES(ctx, type)); | 36 return adoptRefWillBeNoop(new WebGLVertexArrayObjectOES(ctx, type)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 WebGLVertexArrayObjectOES::WebGLVertexArrayObjectOES(WebGLRenderingContextBase*
ctx, VaoType type) | 39 WebGLVertexArrayObjectOES::WebGLVertexArrayObjectOES(WebGLRenderingContextBase*
ctx, VaoType type) |
| 40 : WebGLContextObject(ctx) | 40 : WebGLVertexArrayObjectBase(ctx, type) |
| 41 , m_object(0) | |
| 42 , m_type(type) | |
| 43 , m_hasEverBeenBound(false) | |
| 44 #if ENABLE(OILPAN) | |
| 45 , m_destructionInProgress(false) | |
| 46 #endif | |
| 47 , m_boundElementArrayBuffer(nullptr) | |
| 48 { | 41 { |
| 49 m_vertexAttribState.reserveCapacity(ctx->maxVertexAttribs()); | |
| 50 | |
| 51 switch (m_type) { | |
| 52 case VaoTypeDefault: | |
| 53 break; | |
| 54 default: | |
| 55 m_object = context()->webContext()->createVertexArrayOES(); | |
| 56 break; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 WebGLVertexArrayObjectOES::~WebGLVertexArrayObjectOES() | |
| 61 { | |
| 62 #if ENABLE(OILPAN) | |
| 63 m_destructionInProgress = true; | |
| 64 #endif | |
| 65 | |
| 66 // Delete the platform framebuffer resource. Explicit detachment | |
| 67 // is for the benefit of Oilpan, where this vertex array object | |
| 68 // isn't detached when it and the WebGLRenderingContextBase object | |
| 69 // it is registered with are both finalized. Without Oilpan, the | |
| 70 // object will have been detached. | |
| 71 // | |
| 72 // To keep the code regular, the trivial detach()ment is always | |
| 73 // performed. | |
| 74 detachAndDeleteObject(); | |
| 75 } | |
| 76 | |
| 77 void WebGLVertexArrayObjectOES::dispatchDetached(WebGraphicsContext3D* context3d
) | |
| 78 { | |
| 79 if (m_boundElementArrayBuffer) | |
| 80 m_boundElementArrayBuffer->onDetached(context3d); | |
| 81 | |
| 82 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | |
| 83 VertexAttribState* state = m_vertexAttribState[i].get(); | |
| 84 if (state->bufferBinding) | |
| 85 state->bufferBinding->onDetached(context3d); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 void WebGLVertexArrayObjectOES::deleteObjectImpl(WebGraphicsContext3D* context3d
) | |
| 90 { | |
| 91 switch (m_type) { | |
| 92 case VaoTypeDefault: | |
| 93 break; | |
| 94 default: | |
| 95 context3d->deleteVertexArrayOES(m_object); | |
| 96 m_object = 0; | |
| 97 break; | |
| 98 } | |
| 99 | |
| 100 #if ENABLE(OILPAN) | |
| 101 // These m_boundElementArrayBuffer and m_vertexAttribState heap | |
| 102 // objects must not be accessed during destruction in the oilpan | |
| 103 // build. They could have been already finalized. The finalizers | |
| 104 // of these objects (and their elements) will themselves handle | |
| 105 // detachment. | |
| 106 if (!m_destructionInProgress) | |
| 107 dispatchDetached(context3d); | |
| 108 #else | |
| 109 dispatchDetached(context3d); | |
| 110 #endif | |
| 111 } | |
| 112 | |
| 113 void WebGLVertexArrayObjectOES::setElementArrayBuffer(PassRefPtrWillBeRawPtr<Web
GLBuffer> buffer) | |
| 114 { | |
| 115 if (buffer) | |
| 116 buffer->onAttached(); | |
| 117 if (m_boundElementArrayBuffer) | |
| 118 m_boundElementArrayBuffer->onDetached(context()->webContext()); | |
| 119 m_boundElementArrayBuffer = buffer; | |
| 120 } | |
| 121 | |
| 122 WebGLVertexArrayObjectOES::VertexAttribState* WebGLVertexArrayObjectOES::getVert
exAttribState(size_t index) | |
| 123 { | |
| 124 ASSERT(index < context()->maxVertexAttribs()); | |
| 125 // Lazily create the vertex attribute states. | |
| 126 for (size_t i = m_vertexAttribState.size(); i <= index; i++) | |
| 127 m_vertexAttribState.append(adoptPtrWillBeNoop(new VertexAttribState())); | |
| 128 return m_vertexAttribState[index].get(); | |
| 129 } | |
| 130 | |
| 131 void WebGLVertexArrayObjectOES::setVertexAttribState( | |
| 132 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, PassRefPtrWillBeRawPtr<WebGLBuffer> b
uffer) | |
| 133 { | |
| 134 GLsizei validatedStride = stride ? stride : bytesPerElement; | |
| 135 VertexAttribState* state = getVertexAttribState(index); | |
| 136 | |
| 137 if (buffer) | |
| 138 buffer->onAttached(); | |
| 139 if (state->bufferBinding) | |
| 140 state->bufferBinding->onDetached(context()->webContext()); | |
| 141 | |
| 142 state->bufferBinding = buffer; | |
| 143 state->bytesPerElement = bytesPerElement; | |
| 144 state->size = size; | |
| 145 state->type = type; | |
| 146 state->normalized = normalized; | |
| 147 state->stride = validatedStride; | |
| 148 state->originalStride = stride; | |
| 149 state->offset = offset; | |
| 150 } | |
| 151 | |
| 152 void WebGLVertexArrayObjectOES::unbindBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer>
buffer) | |
| 153 { | |
| 154 if (m_boundElementArrayBuffer == buffer) { | |
| 155 m_boundElementArrayBuffer->onDetached(context()->webContext()); | |
| 156 m_boundElementArrayBuffer = nullptr; | |
| 157 } | |
| 158 | |
| 159 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | |
| 160 VertexAttribState* state = m_vertexAttribState[i].get(); | |
| 161 if (state->bufferBinding == buffer) { | |
| 162 buffer->onDetached(context()->webContext()); | |
| 163 state->bufferBinding = nullptr; | |
| 164 } | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 void WebGLVertexArrayObjectOES::setVertexAttribDivisor(GLuint index, GLuint divi
sor) | |
| 169 { | |
| 170 VertexAttribState* state = getVertexAttribState(index); | |
| 171 state->divisor = divisor; | |
| 172 } | |
| 173 | |
| 174 DEFINE_TRACE(WebGLVertexArrayObjectOES::VertexAttribState) | |
| 175 { | |
| 176 visitor->trace(bufferBinding); | |
| 177 } | |
| 178 | |
| 179 DEFINE_TRACE(WebGLVertexArrayObjectOES) | |
| 180 { | |
| 181 visitor->trace(m_boundElementArrayBuffer); | |
| 182 visitor->trace(m_vertexAttribState); | |
| 183 WebGLContextObject::trace(visitor); | |
| 184 } | 42 } |
| 185 | 43 |
| 186 } // namespace blink | 44 } // namespace blink |
| OLD | NEW |