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

Side by Side Diff: gpu/command_buffer/service/context_state.cc

Issue 2142353002: Validate fbo color image format and fragment shader output variable type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/context_state.h" 5 #include "gpu/command_buffer/service/context_state.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 TextureUnit::TextureUnit(const TextureUnit& other) = default; 92 TextureUnit::TextureUnit(const TextureUnit& other) = default;
93 93
94 TextureUnit::~TextureUnit() { 94 TextureUnit::~TextureUnit() {
95 } 95 }
96 96
97 bool Vec4::Equal(const Vec4& other) const { 97 bool Vec4::Equal(const Vec4& other) const {
98 if (type_ != other.type_) 98 if (type_ != other.type_)
99 return false; 99 return false;
100 switch (type_) { 100 switch (type_) {
101 case kFloat: 101 case SHADER_VARIABLE_FLOAT:
102 for (size_t ii = 0; ii < 4; ++ii) { 102 for (size_t ii = 0; ii < 4; ++ii) {
103 if (v_[ii].float_value != other.v_[ii].float_value) 103 if (v_[ii].float_value != other.v_[ii].float_value)
104 return false; 104 return false;
105 } 105 }
106 break; 106 break;
107 case kInt: 107 case SHADER_VARIABLE_INT:
108 for (size_t ii = 0; ii < 4; ++ii) { 108 for (size_t ii = 0; ii < 4; ++ii) {
109 if (v_[ii].int_value != other.v_[ii].int_value) 109 if (v_[ii].int_value != other.v_[ii].int_value)
110 return false; 110 return false;
111 } 111 }
112 break; 112 break;
113 case kUInt: 113 case SHADER_VARIABLE_UINT:
114 for (size_t ii = 0; ii < 4; ++ii) { 114 for (size_t ii = 0; ii < 4; ++ii) {
115 if (v_[ii].uint_value != other.v_[ii].uint_value) 115 if (v_[ii].uint_value != other.v_[ii].uint_value)
116 return false; 116 return false;
117 } 117 }
118 break; 118 break;
119 default:
120 NOTREACHED();
121 break;
119 } 122 }
120 return true; 123 return true;
121 } 124 }
122 125
123 template <> 126 template <>
124 void Vec4::GetValues<GLfloat>(GLfloat* values) const { 127 void Vec4::GetValues<GLfloat>(GLfloat* values) const {
125 DCHECK(values); 128 DCHECK(values);
126 switch (type_) { 129 switch (type_) {
127 case kFloat: 130 case SHADER_VARIABLE_FLOAT:
128 for (size_t ii = 0; ii < 4; ++ii) 131 for (size_t ii = 0; ii < 4; ++ii)
129 values[ii] = v_[ii].float_value; 132 values[ii] = v_[ii].float_value;
130 break; 133 break;
131 case kInt: 134 case SHADER_VARIABLE_INT:
132 for (size_t ii = 0; ii < 4; ++ii) 135 for (size_t ii = 0; ii < 4; ++ii)
133 values[ii] = static_cast<GLfloat>(v_[ii].int_value); 136 values[ii] = static_cast<GLfloat>(v_[ii].int_value);
134 break; 137 break;
135 case kUInt: 138 case SHADER_VARIABLE_UINT:
136 for (size_t ii = 0; ii < 4; ++ii) 139 for (size_t ii = 0; ii < 4; ++ii)
137 values[ii] = static_cast<GLfloat>(v_[ii].uint_value); 140 values[ii] = static_cast<GLfloat>(v_[ii].uint_value);
138 break; 141 break;
142 default:
143 NOTREACHED();
144 break;
139 } 145 }
140 } 146 }
141 147
142 template <> 148 template <>
143 void Vec4::GetValues<GLint>(GLint* values) const { 149 void Vec4::GetValues<GLint>(GLint* values) const {
144 DCHECK(values); 150 DCHECK(values);
145 switch (type_) { 151 switch (type_) {
146 case kFloat: 152 case SHADER_VARIABLE_FLOAT:
147 for (size_t ii = 0; ii < 4; ++ii) 153 for (size_t ii = 0; ii < 4; ++ii)
148 values[ii] = static_cast<GLint>(v_[ii].float_value); 154 values[ii] = static_cast<GLint>(v_[ii].float_value);
149 break; 155 break;
150 case kInt: 156 case SHADER_VARIABLE_INT:
151 for (size_t ii = 0; ii < 4; ++ii) 157 for (size_t ii = 0; ii < 4; ++ii)
152 values[ii] = v_[ii].int_value; 158 values[ii] = v_[ii].int_value;
153 break; 159 break;
154 case kUInt: 160 case SHADER_VARIABLE_UINT:
155 for (size_t ii = 0; ii < 4; ++ii) 161 for (size_t ii = 0; ii < 4; ++ii)
156 values[ii] = static_cast<GLint>(v_[ii].uint_value); 162 values[ii] = static_cast<GLint>(v_[ii].uint_value);
157 break; 163 break;
164 default:
165 NOTREACHED();
166 break;
158 } 167 }
159 } 168 }
160 169
161 template<> 170 template<>
162 void Vec4::GetValues<GLuint>(GLuint* values) const { 171 void Vec4::GetValues<GLuint>(GLuint* values) const {
163 DCHECK(values); 172 DCHECK(values);
164 switch (type_) { 173 switch (type_) {
165 case kFloat: 174 case SHADER_VARIABLE_FLOAT:
166 for (size_t ii = 0; ii < 4; ++ii) 175 for (size_t ii = 0; ii < 4; ++ii)
167 values[ii] = static_cast<GLuint>(v_[ii].float_value); 176 values[ii] = static_cast<GLuint>(v_[ii].float_value);
168 break; 177 break;
169 case kInt: 178 case SHADER_VARIABLE_INT:
170 for (size_t ii = 0; ii < 4; ++ii) 179 for (size_t ii = 0; ii < 4; ++ii)
171 values[ii] = static_cast<GLuint>(v_[ii].int_value); 180 values[ii] = static_cast<GLuint>(v_[ii].int_value);
172 break; 181 break;
173 case kUInt: 182 case SHADER_VARIABLE_UINT:
174 for (size_t ii = 0; ii < 4; ++ii) 183 for (size_t ii = 0; ii < 4; ++ii)
175 values[ii] = v_[ii].uint_value; 184 values[ii] = v_[ii].uint_value;
176 break; 185 break;
186 default:
187 NOTREACHED();
188 break;
177 } 189 }
178 } 190 }
179 191
180 template <> 192 template <>
181 void Vec4::SetValues<GLfloat>(const GLfloat* values) { 193 void Vec4::SetValues<GLfloat>(const GLfloat* values) {
182 DCHECK(values); 194 DCHECK(values);
183 for (size_t ii = 0; ii < 4; ++ii) 195 for (size_t ii = 0; ii < 4; ++ii)
184 v_[ii].float_value = values[ii]; 196 v_[ii].float_value = values[ii];
185 type_ = kFloat; 197 type_ = SHADER_VARIABLE_FLOAT;
186 } 198 }
187 199
188 template <> 200 template <>
189 void Vec4::SetValues<GLint>(const GLint* values) { 201 void Vec4::SetValues<GLint>(const GLint* values) {
190 DCHECK(values); 202 DCHECK(values);
191 for (size_t ii = 0; ii < 4; ++ii) 203 for (size_t ii = 0; ii < 4; ++ii)
192 v_[ii].int_value = values[ii]; 204 v_[ii].int_value = values[ii];
193 type_ = kInt; 205 type_ = SHADER_VARIABLE_INT;
194 } 206 }
195 207
196 template <> 208 template <>
197 void Vec4::SetValues<GLuint>(const GLuint* values) { 209 void Vec4::SetValues<GLuint>(const GLuint* values) {
198 DCHECK(values); 210 DCHECK(values);
199 for (size_t ii = 0; ii < 4; ++ii) 211 for (size_t ii = 0; ii < 4; ++ii)
200 v_[ii].uint_value = values[ii]; 212 v_[ii].uint_value = values[ii];
201 type_ = kUInt; 213 type_ = SHADER_VARIABLE_UINT;
202 } 214 }
203 215
204 ContextState::ContextState(FeatureInfo* feature_info, 216 ContextState::ContextState(FeatureInfo* feature_info,
205 ErrorStateClient* error_state_client, 217 ErrorStateClient* error_state_client,
206 Logger* logger) 218 Logger* logger)
207 : active_texture_unit(0), 219 : active_texture_unit(0),
208 bound_renderbuffer_valid(false), 220 bound_renderbuffer_valid(false),
209 pack_reverse_row_order(false), 221 pack_reverse_row_order(false),
210 ignore_cached_state(false), 222 ignore_cached_state(false),
211 fbo_binding_for_scissor_workaround_dirty(false), 223 fbo_binding_for_scissor_workaround_dirty(false),
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 DCHECK_LT(active_texture_unit, texture_units.size()); 353 DCHECK_LT(active_texture_unit, texture_units.size());
342 const TextureUnit& texture_unit = texture_units[active_texture_unit]; 354 const TextureUnit& texture_unit = texture_units[active_texture_unit];
343 if (TargetIsSupported(feature_info_, target)) 355 if (TargetIsSupported(feature_info_, target))
344 glBindTexture(target, GetServiceId(texture_unit, target)); 356 glBindTexture(target, GetServiceId(texture_unit, target));
345 } 357 }
346 358
347 void ContextState::RestoreVertexAttribValues() const { 359 void ContextState::RestoreVertexAttribValues() const {
348 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); 360 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs();
349 ++attrib) { 361 ++attrib) {
350 switch (attrib_values[attrib].type()) { 362 switch (attrib_values[attrib].type()) {
351 case Vec4::kFloat: 363 case SHADER_VARIABLE_FLOAT:
352 { 364 {
353 GLfloat v[4]; 365 GLfloat v[4];
354 attrib_values[attrib].GetValues(v); 366 attrib_values[attrib].GetValues(v);
355 glVertexAttrib4fv(attrib, v); 367 glVertexAttrib4fv(attrib, v);
356 } 368 }
357 break; 369 break;
358 case Vec4::kInt: 370 case SHADER_VARIABLE_INT:
359 { 371 {
360 GLint v[4]; 372 GLint v[4];
361 attrib_values[attrib].GetValues(v); 373 attrib_values[attrib].GetValues(v);
362 glVertexAttribI4iv(attrib, v); 374 glVertexAttribI4iv(attrib, v);
363 } 375 }
364 break; 376 break;
365 case Vec4::kUInt: 377 case SHADER_VARIABLE_UINT:
366 { 378 {
367 GLuint v[4]; 379 GLuint v[4];
368 attrib_values[attrib].GetValues(v); 380 attrib_values[attrib].GetValues(v);
369 glVertexAttribI4uiv(attrib, v); 381 glVertexAttribI4uiv(attrib, v);
370 } 382 }
371 break; 383 break;
384 default:
385 NOTREACHED();
386 break;
372 } 387 }
373 } 388 }
374 } 389 }
375 390
376 void ContextState::RestoreVertexAttribArrays( 391 void ContextState::RestoreVertexAttribArrays(
377 const scoped_refptr<VertexAttribManager> attrib_manager) const { 392 const scoped_refptr<VertexAttribManager> attrib_manager) const {
378 // This is expected to be called only for VAO with service_id 0, 393 // This is expected to be called only for VAO with service_id 0,
379 // either to restore the default VAO or a virtual VAO with service_id 0. 394 // either to restore the default VAO or a virtual VAO with service_id 0.
380 GLuint vao_service_id = attrib_manager->service_id(); 395 GLuint vao_service_id = attrib_manager->service_id();
381 DCHECK(vao_service_id == 0); 396 DCHECK(vao_service_id == 0);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 UpdateUnpackParameters(); 682 UpdateUnpackParameters();
668 } 683 }
669 684
670 // Include the auto-generated part of this file. We split this because it means 685 // Include the auto-generated part of this file. We split this because it means
671 // we can easily edit the non-auto generated parts right here in this file 686 // we can easily edit the non-auto generated parts right here in this file
672 // instead of having to edit some template or the code generator. 687 // instead of having to edit some template or the code generator.
673 #include "gpu/command_buffer/service/context_state_impl_autogen.h" 688 #include "gpu/command_buffer/service/context_state_impl_autogen.h"
674 689
675 } // namespace gles2 690 } // namespace gles2
676 } // namespace gpu 691 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698