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

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

Issue 2019513004: Validate bound buffer for draw calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLVertexArrayObjectBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "modules/webgl/WebGLVertexArrayObjectBase.h" 5 #include "modules/webgl/WebGLVertexArrayObjectBase.h"
6 6
7 #include "gpu/command_buffer/client/gles2_interface.h" 7 #include "gpu/command_buffer/client/gles2_interface.h"
8 #include "modules/webgl/WebGLRenderingContextBase.h" 8 #include "modules/webgl/WebGLRenderingContextBase.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase(WebGLRenderingContextBase * ctx, VaoType type) 12 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase(WebGLRenderingContextBase * ctx, VaoType type)
13 : WebGLContextObject(ctx) 13 : WebGLContextObject(ctx)
14 , m_object(0) 14 , m_object(0)
15 , m_type(type) 15 , m_type(type)
16 , m_hasEverBeenBound(false) 16 , m_hasEverBeenBound(false)
17 , m_destructionInProgress(false) 17 , m_destructionInProgress(false)
18 , m_boundElementArrayBuffer(nullptr) 18 , m_boundElementArrayBuffer(nullptr)
19 { 19 {
20 m_arrayBufferList.resize(ctx->maxVertexAttribs()); 20 m_arrayBufferList.resize(ctx->maxVertexAttribs());
21 m_attribEnabled.resize(ctx->maxVertexAttribs());
22 for (size_t i = 0; i < m_attribEnabled.size(); ++i) {
23 m_attribEnabled[i] = false;
24 }
21 25
22 switch (m_type) { 26 switch (m_type) {
23 case VaoTypeDefault: 27 case VaoTypeDefault:
24 break; 28 break;
25 default: 29 default:
26 context()->contextGL()->GenVertexArraysOES(1, &m_object); 30 context()->contextGL()->GenVertexArraysOES(1, &m_object);
27 break; 31 break;
28 } 32 }
29 } 33 }
30 34
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 { 77 {
74 if (buffer) 78 if (buffer)
75 buffer->onAttached(); 79 buffer->onAttached();
76 if (m_boundElementArrayBuffer) 80 if (m_boundElementArrayBuffer)
77 m_boundElementArrayBuffer->onDetached(context()->contextGL()); 81 m_boundElementArrayBuffer->onDetached(context()->contextGL());
78 m_boundElementArrayBuffer = buffer; 82 m_boundElementArrayBuffer = buffer;
79 } 83 }
80 84
81 WebGLBuffer* WebGLVertexArrayObjectBase::getArrayBufferForAttrib(size_t index) 85 WebGLBuffer* WebGLVertexArrayObjectBase::getArrayBufferForAttrib(size_t index)
82 { 86 {
83 ASSERT(index < context()->maxVertexAttribs()); 87 DCHECK(index < context()->maxVertexAttribs());
84 return m_arrayBufferList[index].get(); 88 return m_arrayBufferList[index].get();
85 } 89 }
86 90
87 void WebGLVertexArrayObjectBase::setArrayBufferForAttrib(GLuint index, WebGLBuff er* buffer) 91 void WebGLVertexArrayObjectBase::setArrayBufferForAttrib(GLuint index, WebGLBuff er* buffer)
88 { 92 {
89 if (buffer) 93 if (buffer)
90 buffer->onAttached(); 94 buffer->onAttached();
91 if (m_arrayBufferList[index]) 95 if (m_arrayBufferList[index])
92 m_arrayBufferList[index]->onDetached(context()->contextGL()); 96 m_arrayBufferList[index]->onDetached(context()->contextGL());
93 97
94 m_arrayBufferList[index] = buffer; 98 m_arrayBufferList[index] = buffer;
95 } 99 }
96 100
101 void WebGLVertexArrayObjectBase::setAttribEnabled(GLuint index, bool enabled)
102 {
103 DCHECK(index < context()->maxVertexAttribs());
104 m_attribEnabled[index] = enabled;
105 }
106
107 bool WebGLVertexArrayObjectBase::getAttribEnabled(GLuint index)
108 {
109 DCHECK(index < context()->maxVertexAttribs());
110 return m_attribEnabled[index];
111 }
112
113 bool WebGLVertexArrayObjectBase::isAllEnabledAttribBufferBound()
Ken Russell (switch to Gerrit) 2016/06/01 20:55:24 This function is potentially very hot -- it will b
qiankun 2016/06/06 11:28:36 Thanks for your suggestion. I updated this CL to s
114 {
115 for (size_t i = 0; i < m_attribEnabled.size(); ++i) {
116 if (m_attribEnabled[i] && !m_arrayBufferList[i])
117 return false;
118 }
119 return true;
120 }
121
97 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer) 122 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer)
98 { 123 {
99 if (m_boundElementArrayBuffer == buffer) { 124 if (m_boundElementArrayBuffer == buffer) {
100 m_boundElementArrayBuffer->onDetached(context()->contextGL()); 125 m_boundElementArrayBuffer->onDetached(context()->contextGL());
101 m_boundElementArrayBuffer = nullptr; 126 m_boundElementArrayBuffer = nullptr;
102 } 127 }
103 128
104 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) { 129 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) {
105 if (m_arrayBufferList[i] == buffer) { 130 if (m_arrayBufferList[i] == buffer) {
106 m_arrayBufferList[i]->onDetached(context()->contextGL()); 131 m_arrayBufferList[i]->onDetached(context()->contextGL());
107 m_arrayBufferList[i] = nullptr; 132 m_arrayBufferList[i] = nullptr;
108 } 133 }
109 } 134 }
110 } 135 }
111 136
112 ScopedPersistent<v8::Array>* WebGLVertexArrayObjectBase::getPersistentCache() 137 ScopedPersistent<v8::Array>* WebGLVertexArrayObjectBase::getPersistentCache()
113 { 138 {
114 return &m_arrayBufferWrappers; 139 return &m_arrayBufferWrappers;
115 } 140 }
116 141
117 DEFINE_TRACE(WebGLVertexArrayObjectBase) 142 DEFINE_TRACE(WebGLVertexArrayObjectBase)
118 { 143 {
119 visitor->trace(m_boundElementArrayBuffer); 144 visitor->trace(m_boundElementArrayBuffer);
120 visitor->trace(m_arrayBufferList); 145 visitor->trace(m_arrayBufferList);
121 WebGLContextObject::trace(visitor); 146 WebGLContextObject::trace(visitor);
122 } 147 }
123 148
124 } // namespace blink 149 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLVertexArrayObjectBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698