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

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: Fix 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 DCHECK_LT(active_texture_unit, texture_units.size()); 373 DCHECK_LT(active_texture_unit, texture_units.size());
362 const TextureUnit& texture_unit = texture_units[active_texture_unit]; 374 const TextureUnit& texture_unit = texture_units[active_texture_unit];
363 if (TargetIsSupported(feature_info_, target)) 375 if (TargetIsSupported(feature_info_, target))
364 glBindTexture(target, GetServiceId(texture_unit, target)); 376 glBindTexture(target, GetServiceId(texture_unit, target));
365 } 377 }
366 378
367 void ContextState::RestoreVertexAttribValues() const { 379 void ContextState::RestoreVertexAttribValues() const {
368 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); 380 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs();
369 ++attrib) { 381 ++attrib) {
370 switch (attrib_values[attrib].type()) { 382 switch (attrib_values[attrib].type()) {
371 case Vec4::kFloat: 383 case SHADER_VARIABLE_FLOAT:
372 { 384 {
373 GLfloat v[4]; 385 GLfloat v[4];
374 attrib_values[attrib].GetValues(v); 386 attrib_values[attrib].GetValues(v);
375 glVertexAttrib4fv(attrib, v); 387 glVertexAttrib4fv(attrib, v);
376 } 388 }
377 break; 389 break;
378 case Vec4::kInt: 390 case SHADER_VARIABLE_INT:
379 { 391 {
380 GLint v[4]; 392 GLint v[4];
381 attrib_values[attrib].GetValues(v); 393 attrib_values[attrib].GetValues(v);
382 glVertexAttribI4iv(attrib, v); 394 glVertexAttribI4iv(attrib, v);
383 } 395 }
384 break; 396 break;
385 case Vec4::kUInt: 397 case SHADER_VARIABLE_UINT:
386 { 398 {
387 GLuint v[4]; 399 GLuint v[4];
388 attrib_values[attrib].GetValues(v); 400 attrib_values[attrib].GetValues(v);
389 glVertexAttribI4uiv(attrib, v); 401 glVertexAttribI4uiv(attrib, v);
390 } 402 }
391 break; 403 break;
404 default:
405 NOTREACHED();
406 break;
392 } 407 }
393 } 408 }
394 } 409 }
395 410
396 void ContextState::RestoreVertexAttribArrays( 411 void ContextState::RestoreVertexAttribArrays(
397 const scoped_refptr<VertexAttribManager> attrib_manager) const { 412 const scoped_refptr<VertexAttribManager> attrib_manager) const {
398 // This is expected to be called only for VAO with service_id 0, 413 // This is expected to be called only for VAO with service_id 0,
399 // either to restore the default VAO or a virtual VAO with service_id 0. 414 // either to restore the default VAO or a virtual VAO with service_id 0.
400 GLuint vao_service_id = attrib_manager->service_id(); 415 GLuint vao_service_id = attrib_manager->service_id();
401 DCHECK(vao_service_id == 0); 416 DCHECK(vao_service_id == 0);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 UpdateUnpackParameters(); 702 UpdateUnpackParameters();
688 } 703 }
689 704
690 // Include the auto-generated part of this file. We split this because it means 705 // Include the auto-generated part of this file. We split this because it means
691 // we can easily edit the non-auto generated parts right here in this file 706 // we can easily edit the non-auto generated parts right here in this file
692 // instead of having to edit some template or the code generator. 707 // instead of having to edit some template or the code generator.
693 #include "gpu/command_buffer/service/context_state_impl_autogen.h" 708 #include "gpu/command_buffer/service/context_state_impl_autogen.h"
694 709
695 } // namespace gles2 710 } // namespace gles2
696 } // namespace gpu 711 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/context_state.h ('k') | gpu/command_buffer/service/context_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698