| 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 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 | 27 |
| 28 #include "core/html/canvas/WebGLVertexArrayObjectOES.h" | 28 #include "core/html/canvas/WebGLVertexArrayObjectOES.h" |
| 29 | 29 |
| 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 PassRefPtr<WebGLVertexArrayObjectOES> WebGLVertexArrayObjectOES::create(WebGLRen
deringContextBase* ctx, VaoType type) | 34 PassRefPtrWillBeRawPtr<WebGLVertexArrayObjectOES> WebGLVertexArrayObjectOES::cre
ate(WebGLRenderingContextBase* ctx, VaoType type) |
| 35 { | 35 { |
| 36 return adoptRef(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 : WebGLContextObject(ctx) |
| 41 , m_type(type) | 41 , m_type(type) |
| 42 , m_hasEverBeenBound(false) | 42 , m_hasEverBeenBound(false) |
| 43 , m_boundElementArrayBuffer(nullptr) | 43 , m_boundElementArrayBuffer(nullptr) |
| 44 { | 44 { |
| 45 ScriptWrappable::init(this); | 45 ScriptWrappable::init(this); |
| 46 m_vertexAttribState.resize(ctx->maxVertexAttribs()); | 46 m_vertexAttribState.resize(ctx->maxVertexAttribs()); |
| 47 | 47 |
| 48 switch (m_type) { | 48 switch (m_type) { |
| 49 case VaoTypeDefault: | 49 case VaoTypeDefault: |
| 50 break; | 50 break; |
| 51 default: | 51 default: |
| 52 setObject(context()->webContext()->createVertexArrayOES()); | 52 setObject(context()->webContext()->createVertexArrayOES()); |
| 53 break; | 53 break; |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 WebGLVertexArrayObjectOES::~WebGLVertexArrayObjectOES() | 57 WebGLVertexArrayObjectOES::~WebGLVertexArrayObjectOES() |
| 58 { | 58 { |
| 59 deleteObject(0); | 59 #if ENABLE(OILPAN) |
| 60 // These heap objects must not be accessed by deleteObjectImpl(), |
| 61 // clear them out before a call to it is triggered below. The |
| 62 // finalizers of these two (and their elements) will themselves |
| 63 // handle detachment. |
| 64 m_boundElementArrayBuffer.clear(); |
| 65 m_vertexAttribState.clear(); |
| 66 #endif |
| 67 // Delete the platform framebuffer resource. Explicit detachment |
| 68 // is for the benefit of Oilpan, where this vertex array object |
| 69 // isn't detached when it and the WebGLRenderingContextBase object |
| 70 // it is registered with are both finalized. Without Oilpan, the |
| 71 // object will have been detached. |
| 72 // |
| 73 // To keep the code regular, the trivial detach()ment is always |
| 74 // performed. |
| 75 detachAndDeleteObject(); |
| 60 } | 76 } |
| 61 | 77 |
| 62 void WebGLVertexArrayObjectOES::deleteObjectImpl(blink::WebGraphicsContext3D* co
ntext3d, Platform3DObject object) | 78 void WebGLVertexArrayObjectOES::deleteObjectImpl(blink::WebGraphicsContext3D* co
ntext3d, Platform3DObject object) |
| 63 { | 79 { |
| 64 switch (m_type) { | 80 switch (m_type) { |
| 65 case VaoTypeDefault: | 81 case VaoTypeDefault: |
| 66 break; | 82 break; |
| 67 default: | 83 default: |
| 68 context()->webContext()->deleteVertexArrayOES(object); | 84 context3d->deleteVertexArrayOES(object); |
| 69 break; | 85 break; |
| 70 } | 86 } |
| 71 | 87 |
| 72 if (m_boundElementArrayBuffer) | 88 if (m_boundElementArrayBuffer) |
| 73 m_boundElementArrayBuffer->onDetached(context3d); | 89 m_boundElementArrayBuffer->onDetached(context3d); |
| 74 | 90 |
| 75 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | 91 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { |
| 76 VertexAttribState& state = m_vertexAttribState[i]; | 92 VertexAttribState& state = m_vertexAttribState[i]; |
| 77 if (state.bufferBinding) | 93 if (state.bufferBinding) |
| 78 state.bufferBinding->onDetached(context3d); | 94 state.bufferBinding->onDetached(context3d); |
| 79 } | 95 } |
| 80 } | 96 } |
| 81 | 97 |
| 82 void WebGLVertexArrayObjectOES::setElementArrayBuffer(PassRefPtr<WebGLBuffer> bu
ffer) | 98 void WebGLVertexArrayObjectOES::setElementArrayBuffer(PassRefPtrWillBeRawPtr<Web
GLBuffer> buffer) |
| 83 { | 99 { |
| 84 if (buffer) | 100 if (buffer) |
| 85 buffer->onAttached(); | 101 buffer->onAttached(); |
| 86 if (m_boundElementArrayBuffer) | 102 if (m_boundElementArrayBuffer) |
| 87 m_boundElementArrayBuffer->onDetached(context()->webContext()); | 103 m_boundElementArrayBuffer->onDetached(context()->webContext()); |
| 88 m_boundElementArrayBuffer = buffer; | 104 m_boundElementArrayBuffer = buffer; |
| 89 | |
| 90 } | 105 } |
| 91 | 106 |
| 92 void WebGLVertexArrayObjectOES::setVertexAttribState( | 107 void WebGLVertexArrayObjectOES::setVertexAttribState( |
| 93 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, PassRefPtr<WebGLBuffer> buffer) | 108 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, PassRefPtrWillBeRawPtr<WebGLBuffer> b
uffer) |
| 94 { | 109 { |
| 95 GLsizei validatedStride = stride ? stride : bytesPerElement; | 110 GLsizei validatedStride = stride ? stride : bytesPerElement; |
| 96 | 111 |
| 97 VertexAttribState& state = m_vertexAttribState[index]; | 112 VertexAttribState& state = m_vertexAttribState[index]; |
| 98 | 113 |
| 99 if (buffer) | 114 if (buffer) |
| 100 buffer->onAttached(); | 115 buffer->onAttached(); |
| 101 if (state.bufferBinding) | 116 if (state.bufferBinding) |
| 102 state.bufferBinding->onDetached(context()->webContext()); | 117 state.bufferBinding->onDetached(context()->webContext()); |
| 103 | 118 |
| 104 state.bufferBinding = buffer; | 119 state.bufferBinding = buffer; |
| 105 state.bytesPerElement = bytesPerElement; | 120 state.bytesPerElement = bytesPerElement; |
| 106 state.size = size; | 121 state.size = size; |
| 107 state.type = type; | 122 state.type = type; |
| 108 state.normalized = normalized; | 123 state.normalized = normalized; |
| 109 state.stride = validatedStride; | 124 state.stride = validatedStride; |
| 110 state.originalStride = stride; | 125 state.originalStride = stride; |
| 111 state.offset = offset; | 126 state.offset = offset; |
| 112 } | 127 } |
| 113 | 128 |
| 114 void WebGLVertexArrayObjectOES::unbindBuffer(PassRefPtr<WebGLBuffer> buffer) | 129 void WebGLVertexArrayObjectOES::unbindBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer>
buffer) |
| 115 { | 130 { |
| 116 if (m_boundElementArrayBuffer == buffer) { | 131 if (m_boundElementArrayBuffer == buffer) { |
| 117 m_boundElementArrayBuffer->onDetached(context()->webContext()); | 132 m_boundElementArrayBuffer->onDetached(context()->webContext()); |
| 118 m_boundElementArrayBuffer = nullptr; | 133 m_boundElementArrayBuffer = nullptr; |
| 119 } | 134 } |
| 120 | 135 |
| 121 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | 136 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { |
| 122 VertexAttribState& state = m_vertexAttribState[i]; | 137 VertexAttribState& state = m_vertexAttribState[i]; |
| 123 if (state.bufferBinding == buffer) { | 138 if (state.bufferBinding == buffer) { |
| 124 buffer->onDetached(context()->webContext()); | 139 buffer->onDetached(context()->webContext()); |
| 125 state.bufferBinding = nullptr; | 140 state.bufferBinding = nullptr; |
| 126 } | 141 } |
| 127 } | 142 } |
| 128 } | 143 } |
| 129 | 144 |
| 130 void WebGLVertexArrayObjectOES::setVertexAttribDivisor(GLuint index, GLuint divi
sor) | 145 void WebGLVertexArrayObjectOES::setVertexAttribDivisor(GLuint index, GLuint divi
sor) |
| 131 { | 146 { |
| 132 VertexAttribState& state = m_vertexAttribState[index]; | 147 VertexAttribState& state = m_vertexAttribState[index]; |
| 133 state.divisor = divisor; | 148 state.divisor = divisor; |
| 134 } | 149 } |
| 135 | 150 |
| 151 void WebGLVertexArrayObjectOES::VertexAttribState::trace(Visitor* visitor) |
| 152 { |
| 153 visitor->trace(bufferBinding); |
| 136 } | 154 } |
| 155 |
| 156 void WebGLVertexArrayObjectOES::trace(Visitor* visitor) |
| 157 { |
| 158 visitor->trace(m_boundElementArrayBuffer); |
| 159 visitor->trace(m_vertexAttribState); |
| 160 WebGLContextObject::trace(visitor); |
| 161 } |
| 162 |
| 163 } |
| OLD | NEW |