Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: Source/modules/webgl/WebGLVertexArrayObjectBase.cpp

Issue 1234883002: [Oilpan] Migrate classes under module/webgl onto oilpan heap (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase & work for some comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
38 #endif
39 35
40 // Delete the platform framebuffer resource. Explicit detachment 36 // Delete the platform framebuffer resource, in case
41 // is for the benefit of Oilpan, where this vertex array object 37 // where this vertex array object isn't detached when it and
42 // isn't detached when it and the WebGLRenderingContextBase object 38 // the WebGLRenderingContextBase object it is registered with
43 // it is registered with are both finalized. Without Oilpan, the 39 // are both finalized.
44 // object will have been detached.
45 //
46 // To keep the code regular, the trivial detach()ment is always
47 // performed.
48 detachAndDeleteObject(); 40 detachAndDeleteObject();
49 } 41 }
50 42
51 void WebGLVertexArrayObjectBase::dispatchDetached(WebGraphicsContext3D* context3 d) 43 void WebGLVertexArrayObjectBase::dispatchDetached(WebGraphicsContext3D* context3 d)
52 { 44 {
53 if (m_boundElementArrayBuffer) 45 if (m_boundElementArrayBuffer)
54 m_boundElementArrayBuffer->onDetached(context3d); 46 m_boundElementArrayBuffer->onDetached(context3d);
55 47
56 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { 48 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) {
57 VertexAttribState* state = m_vertexAttribState[i].get(); 49 VertexAttribState* state = m_vertexAttribState[i].get();
58 if (state->bufferBinding) 50 if (state->bufferBinding)
59 state->bufferBinding->onDetached(context3d); 51 state->bufferBinding->onDetached(context3d);
60 } 52 }
61 } 53 }
62 54
63 void WebGLVertexArrayObjectBase::deleteObjectImpl(WebGraphicsContext3D* context3 d) 55 void WebGLVertexArrayObjectBase::deleteObjectImpl(WebGraphicsContext3D* context3 d)
64 { 56 {
65 switch (m_type) { 57 switch (m_type) {
66 case VaoTypeDefault: 58 case VaoTypeDefault:
67 break; 59 break;
68 default: 60 default:
69 context3d->deleteVertexArrayOES(m_object); 61 context3d->deleteVertexArrayOES(m_object);
70 m_object = 0; 62 m_object = 0;
71 break; 63 break;
72 } 64 }
73 65
74 #if ENABLE(OILPAN)
75 // These m_boundElementArrayBuffer and m_vertexAttribState heap 66 // These m_boundElementArrayBuffer and m_vertexAttribState heap
76 // objects must not be accessed during destruction in the oilpan 67 // objects must not be accessed during destruction.
77 // build. They could have been already finalized. The finalizers 68 // They could have been already finalized. The finalizers
78 // of these objects (and their elements) will themselves handle 69 // of these objects (and their elements) will themselves handle
79 // detachment. 70 // detachment.
80 if (!m_destructionInProgress)
81 dispatchDetached(context3d);
82 #else
83 dispatchDetached(context3d); 71 dispatchDetached(context3d);
haraken 2015/08/05 04:12:19 You need the if(m_destructionInProgress) check.
peria 2015/08/06 05:47:00 Done.
84 #endif
85 } 72 }
86 73
87 void WebGLVertexArrayObjectBase::setElementArrayBuffer(PassRefPtrWillBeRawPtr<We bGLBuffer> buffer) 74 void WebGLVertexArrayObjectBase::setElementArrayBuffer(WebGLBuffer* buffer)
88 { 75 {
89 if (buffer) 76 if (buffer)
90 buffer->onAttached(); 77 buffer->onAttached();
91 if (m_boundElementArrayBuffer) 78 if (m_boundElementArrayBuffer)
92 m_boundElementArrayBuffer->onDetached(context()->webContext()); 79 m_boundElementArrayBuffer->onDetached(context()->webContext());
93 m_boundElementArrayBuffer = buffer; 80 m_boundElementArrayBuffer = buffer;
94 } 81 }
95 82
96 WebGLVertexArrayObjectBase::VertexAttribState* WebGLVertexArrayObjectBase::getVe rtexAttribState(size_t index) 83 WebGLVertexArrayObjectBase::VertexAttribState* WebGLVertexArrayObjectBase::getVe rtexAttribState(size_t index)
97 { 84 {
98 ASSERT(index < context()->maxVertexAttribs()); 85 ASSERT(index < context()->maxVertexAttribs());
99 // Lazily create the vertex attribute states. 86 // Lazily create the vertex attribute states.
100 for (size_t i = m_vertexAttribState.size(); i <= index; i++) 87 for (size_t i = m_vertexAttribState.size(); i <= index; i++)
101 m_vertexAttribState.append(adoptPtrWillBeNoop(new VertexAttribState())); 88 m_vertexAttribState.append(new VertexAttribState);
102 return m_vertexAttribState[index].get(); 89 return m_vertexAttribState[index].get();
103 } 90 }
104 91
105 void WebGLVertexArrayObjectBase::setVertexAttribState( 92 void WebGLVertexArrayObjectBase::setVertexAttribState(
106 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no rmalized, GLsizei stride, GLintptr offset, PassRefPtrWillBeRawPtr<WebGLBuffer> b uffer) 93 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no rmalized, GLsizei stride, GLintptr offset, WebGLBuffer* buffer)
107 { 94 {
108 GLsizei validatedStride = stride ? stride : bytesPerElement; 95 GLsizei validatedStride = stride ? stride : bytesPerElement;
109 VertexAttribState* state = getVertexAttribState(index); 96 VertexAttribState* state = getVertexAttribState(index);
110 97
111 if (buffer) 98 if (buffer)
112 buffer->onAttached(); 99 buffer->onAttached();
113 if (state->bufferBinding) 100 if (state->bufferBinding)
114 state->bufferBinding->onDetached(context()->webContext()); 101 state->bufferBinding->onDetached(context()->webContext());
115 102
116 state->bufferBinding = buffer; 103 state->bufferBinding = buffer;
117 state->bytesPerElement = bytesPerElement; 104 state->bytesPerElement = bytesPerElement;
118 state->size = size; 105 state->size = size;
119 state->type = type; 106 state->type = type;
120 state->normalized = normalized; 107 state->normalized = normalized;
121 state->stride = validatedStride; 108 state->stride = validatedStride;
122 state->originalStride = stride; 109 state->originalStride = stride;
123 state->offset = offset; 110 state->offset = offset;
124 } 111 }
125 112
126 void WebGLVertexArrayObjectBase::unbindBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer > buffer) 113 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer)
127 { 114 {
128 if (m_boundElementArrayBuffer == buffer) { 115 if (m_boundElementArrayBuffer == buffer) {
129 m_boundElementArrayBuffer->onDetached(context()->webContext()); 116 m_boundElementArrayBuffer->onDetached(context()->webContext());
130 m_boundElementArrayBuffer = nullptr; 117 m_boundElementArrayBuffer = nullptr;
131 } 118 }
132 119
133 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { 120 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) {
134 VertexAttribState* state = m_vertexAttribState[i].get(); 121 VertexAttribState* state = m_vertexAttribState[i];
135 if (state->bufferBinding == buffer) { 122 if (state->bufferBinding == buffer) {
136 buffer->onDetached(context()->webContext()); 123 buffer->onDetached(context()->webContext());
137 state->bufferBinding = nullptr; 124 state->bufferBinding = nullptr;
138 } 125 }
139 } 126 }
140 } 127 }
141 128
142 void WebGLVertexArrayObjectBase::setVertexAttribDivisor(GLuint index, GLuint div isor) 129 void WebGLVertexArrayObjectBase::setVertexAttribDivisor(GLuint index, GLuint div isor)
143 { 130 {
144 VertexAttribState* state = getVertexAttribState(index); 131 VertexAttribState* state = getVertexAttribState(index);
145 state->divisor = divisor; 132 state->divisor = divisor;
146 } 133 }
147 134
148 DEFINE_TRACE(WebGLVertexArrayObjectBase::VertexAttribState) 135 DEFINE_TRACE(WebGLVertexArrayObjectBase::VertexAttribState)
149 { 136 {
150 visitor->trace(bufferBinding); 137 visitor->trace(bufferBinding);
151 } 138 }
152 139
153 DEFINE_TRACE(WebGLVertexArrayObjectBase) 140 DEFINE_TRACE(WebGLVertexArrayObjectBase)
154 { 141 {
155 visitor->trace(m_boundElementArrayBuffer); 142 visitor->trace(m_boundElementArrayBuffer);
156 visitor->trace(m_vertexAttribState); 143 visitor->trace(m_vertexAttribState);
157 WebGLContextObject::trace(visitor); 144 WebGLContextObject::trace(visitor);
158 } 145 }
159 146
160 } // namespace blink 147 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698