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