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

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

Issue 2518413002: Add validation to the mailbox functions in the passthrough cmd decoder. (Closed)
Patch Set: Fix explicit. Created 4 years 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/gles2_cmd_decoder_passthrough.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_passthrough.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 8
9 namespace gpu { 9 namespace gpu {
10 namespace gles2 { 10 namespace gles2 {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 size_t len) { 187 size_t len) {
188 size_t old_size = data->size(); 188 size_t old_size = data->size();
189 data->resize(old_size + len); 189 data->resize(old_size + len);
190 memcpy(data->data() + old_size, str, len); 190 memcpy(data->data() + old_size, str, len);
191 } 191 }
192 192
193 } // anonymous namespace 193 } // anonymous namespace
194 194
195 // Implementations of commands 195 // Implementations of commands
196 error::Error GLES2DecoderPassthroughImpl::DoActiveTexture(GLenum texture) { 196 error::Error GLES2DecoderPassthroughImpl::DoActiveTexture(GLenum texture) {
197 FlushErrors();
197 glActiveTexture(texture); 198 glActiveTexture(texture);
199 if (FlushErrors()) {
200 return error::kNoError;
201 }
202
198 active_texture_unit_ = static_cast<size_t>(texture) - GL_TEXTURE0; 203 active_texture_unit_ = static_cast<size_t>(texture) - GL_TEXTURE0;
199 return error::kNoError; 204 return error::kNoError;
200 } 205 }
201 206
202 error::Error GLES2DecoderPassthroughImpl::DoAttachShader(GLuint program, 207 error::Error GLES2DecoderPassthroughImpl::DoAttachShader(GLuint program,
203 GLuint shader) { 208 GLuint shader) {
204 glAttachShader(GetProgramServiceID(program, resources_), 209 glAttachShader(GetProgramServiceID(program, resources_),
205 GetShaderServiceID(shader, resources_)); 210 GetShaderServiceID(shader, resources_));
206 return error::kNoError; 211 return error::kNoError;
207 } 212 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 264 }
260 265
261 error::Error GLES2DecoderPassthroughImpl::DoBindSampler(GLuint unit, 266 error::Error GLES2DecoderPassthroughImpl::DoBindSampler(GLuint unit,
262 GLuint sampler) { 267 GLuint sampler) {
263 glBindSampler(unit, GetSamplerServiceID(sampler, resources_)); 268 glBindSampler(unit, GetSamplerServiceID(sampler, resources_));
264 return error::kNoError; 269 return error::kNoError;
265 } 270 }
266 271
267 error::Error GLES2DecoderPassthroughImpl::DoBindTexture(GLenum target, 272 error::Error GLES2DecoderPassthroughImpl::DoBindTexture(GLenum target,
268 GLuint texture) { 273 GLuint texture) {
269 glBindTexture(target, GetTextureServiceID(texture, resources_, 274 GLuint service_id =
270 bind_generates_resource_)); 275 GetTextureServiceID(texture, resources_, bind_generates_resource_);
271 if (target == GL_TEXTURE_2D && 276
272 active_texture_unit_ < bound_textures_.size()) { 277 FlushErrors();
273 bound_textures_[active_texture_unit_] = texture; 278
279 glBindTexture(target, service_id);
280
281 // Only update tracking if no error was generated in the bind call
282 if (FlushErrors()) {
283 return error::kNoError;
274 } 284 }
285
286 // Track the currently bound textures
287 DCHECK(bound_textures_.find(target) != bound_textures_.end());
288 DCHECK(bound_textures_[target].size() > active_texture_unit_);
289 bound_textures_[target][active_texture_unit_] = texture;
290
291 // Create a new texture object to track this texture
292 auto texture_object_iter = resources_->texture_object_map.find(texture);
293 if (texture_object_iter == resources_->texture_object_map.end()) {
294 resources_->texture_object_map.insert(
295 std::make_pair(texture, new TexturePassthrough(service_id, target)));
296 } else {
297 // Shouldn't be possible to get here if this texture has a different
298 // target than the one it was just bound to
299 DCHECK(texture_object_iter->second->target() == target);
300 }
301
275 return error::kNoError; 302 return error::kNoError;
276 } 303 }
277 304
278 error::Error GLES2DecoderPassthroughImpl::DoBindTransformFeedback( 305 error::Error GLES2DecoderPassthroughImpl::DoBindTransformFeedback(
279 GLenum target, 306 GLenum target,
280 GLuint transformfeedback) { 307 GLuint transformfeedback) {
281 glBindTransformFeedback( 308 glBindTransformFeedback(
282 target, GetTransformFeedbackServiceID(transformfeedback, 309 target, GetTransformFeedbackServiceID(transformfeedback,
283 &transform_feedback_id_map_)); 310 &transform_feedback_id_map_));
284 return error::kNoError; 311 return error::kNoError;
(...skipping 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 error::Error GLES2DecoderPassthroughImpl::DoVertexAttribDivisorANGLE( 2684 error::Error GLES2DecoderPassthroughImpl::DoVertexAttribDivisorANGLE(
2658 GLuint index, 2685 GLuint index,
2659 GLuint divisor) { 2686 GLuint divisor) {
2660 glVertexAttribDivisorANGLE(index, divisor); 2687 glVertexAttribDivisorANGLE(index, divisor);
2661 return error::kNoError; 2688 return error::kNoError;
2662 } 2689 }
2663 2690
2664 error::Error GLES2DecoderPassthroughImpl::DoProduceTextureCHROMIUM( 2691 error::Error GLES2DecoderPassthroughImpl::DoProduceTextureCHROMIUM(
2665 GLenum target, 2692 GLenum target,
2666 const volatile GLbyte* mailbox) { 2693 const volatile GLbyte* mailbox) {
2667 // TODO(geofflang): validation 2694 auto bound_textures_iter = bound_textures_.find(target);
2695 if (bound_textures_iter == bound_textures_.end()) {
2696 InsertError(GL_INVALID_OPERATION, "Invalid texture target.");
2697 return error::kNoError;
2698 }
2668 2699
2669 GLuint texture_client_id = bound_textures_[active_texture_unit_]; 2700 GLuint texture_client_id = bound_textures_iter->second[active_texture_unit_];
2670 scoped_refptr<TexturePassthrough> texture;
2671
2672 auto texture_object_iter = 2701 auto texture_object_iter =
2673 resources_->texture_object_map.find(texture_client_id); 2702 resources_->texture_object_map.find(texture_client_id);
2674 if (texture_object_iter != resources_->texture_object_map.end()) { 2703 if (texture_object_iter == resources_->texture_object_map.end()) {
2675 texture = texture_object_iter->second.get(); 2704 InsertError(GL_INVALID_OPERATION, "Unknown texture for target.");
2676 } else { 2705 return error::kNoError;
2677 GLuint service_id =
2678 GetTextureServiceID(texture_client_id, resources_, false);
2679 texture = new TexturePassthrough(service_id);
2680 resources_->texture_object_map.insert(
2681 std::make_pair(texture_client_id, texture));
2682 } 2706 }
2683 2707
2684 const Mailbox& mb = Mailbox::FromVolatile( 2708 const Mailbox& mb = Mailbox::FromVolatile(
2685 *reinterpret_cast<const volatile Mailbox*>(mailbox)); 2709 *reinterpret_cast<const volatile Mailbox*>(mailbox));
2686 mailbox_manager_->ProduceTexture(mb, texture.get()); 2710 mailbox_manager_->ProduceTexture(mb, texture_object_iter->second.get());
2687 return error::kNoError; 2711 return error::kNoError;
2688 } 2712 }
2689 2713
2690 error::Error GLES2DecoderPassthroughImpl::DoProduceTextureDirectCHROMIUM( 2714 error::Error GLES2DecoderPassthroughImpl::DoProduceTextureDirectCHROMIUM(
2691 GLuint texture_client_id, 2715 GLuint texture_client_id,
2692 GLenum target, 2716 GLenum target,
2693 const volatile GLbyte* mailbox) { 2717 const volatile GLbyte* mailbox) {
2694 // TODO(geofflang): validation
2695
2696 scoped_refptr<TexturePassthrough> texture;
2697 auto texture_object_iter = 2718 auto texture_object_iter =
2698 resources_->texture_object_map.find(texture_client_id); 2719 resources_->texture_object_map.find(texture_client_id);
2699 if (texture_object_iter != resources_->texture_object_map.end()) { 2720 if (texture_object_iter == resources_->texture_object_map.end()) {
2700 texture = texture_object_iter->second.get(); 2721 InsertError(GL_INVALID_OPERATION, "Unknown texture for target.");
2701 } else { 2722 return error::kNoError;
2702 GLuint service_id = 2723 }
2703 GetTextureServiceID(texture_client_id, resources_, false); 2724
2704 texture = new TexturePassthrough(service_id); 2725 scoped_refptr<TexturePassthrough> texture = texture_object_iter->second;
2705 resources_->texture_object_map.insert( 2726 if (texture->target() != target) {
2706 std::make_pair(texture_client_id, texture)); 2727 InsertError(GL_INVALID_OPERATION, "Texture target does not match.");
2728 return error::kNoError;
2707 } 2729 }
2708 2730
2709 const Mailbox& mb = Mailbox::FromVolatile( 2731 const Mailbox& mb = Mailbox::FromVolatile(
2710 *reinterpret_cast<const volatile Mailbox*>(mailbox)); 2732 *reinterpret_cast<const volatile Mailbox*>(mailbox));
2711 mailbox_manager_->ProduceTexture(mb, texture.get()); 2733 mailbox_manager_->ProduceTexture(mb, texture.get());
2712 return error::kNoError; 2734 return error::kNoError;
2713 } 2735 }
2714 2736
2715 error::Error GLES2DecoderPassthroughImpl::DoConsumeTextureCHROMIUM( 2737 error::Error GLES2DecoderPassthroughImpl::DoConsumeTextureCHROMIUM(
2716 GLenum target, 2738 GLenum target,
2717 const volatile GLbyte* mailbox) { 2739 const volatile GLbyte* mailbox) {
2718 // TODO(geofflang): validation 2740 auto bound_textures_iter = bound_textures_.find(target);
2741 if (bound_textures_iter == bound_textures_.end()) {
2742 InsertError(GL_INVALID_OPERATION, "Invalid texture target.");
2743 return error::kNoError;
2744 }
2745
2746 GLuint client_id = bound_textures_iter->second[active_texture_unit_];
2747 if (client_id == 0) {
2748 InsertError(GL_INVALID_OPERATION, "Unknown texture for target.");
2749 return error::kNoError;
2750 }
2719 2751
2720 const Mailbox& mb = Mailbox::FromVolatile( 2752 const Mailbox& mb = Mailbox::FromVolatile(
2721 *reinterpret_cast<const volatile Mailbox*>(mailbox)); 2753 *reinterpret_cast<const volatile Mailbox*>(mailbox));
2722 scoped_refptr<TexturePassthrough> texture = static_cast<TexturePassthrough*>( 2754 scoped_refptr<TexturePassthrough> texture = static_cast<TexturePassthrough*>(
2723 group_->mailbox_manager()->ConsumeTexture(mb)); 2755 group_->mailbox_manager()->ConsumeTexture(mb));
2724 if (texture == nullptr) { 2756 if (texture == nullptr) {
2725 // TODO(geofflang): error, missing mailbox 2757 InsertError(GL_INVALID_OPERATION, "Invalid mailbox name.");
2726 return error::kNoError; 2758 return error::kNoError;
2727 } 2759 }
2728 2760
2729 GLuint client_id = bound_textures_[active_texture_unit_]; 2761 if (texture->target() != target) {
2762 InsertError(GL_INVALID_OPERATION, "Texture target does not match.");
2763 return error::kNoError;
2764 }
2765
2766 // Update id mappings
2767 resources_->texture_id_map.RemoveClientID(client_id);
2730 resources_->texture_id_map.SetIDMapping(client_id, texture->service_id()); 2768 resources_->texture_id_map.SetIDMapping(client_id, texture->service_id());
2731 resources_->texture_object_map.erase(client_id); 2769 resources_->texture_object_map.erase(client_id);
2732 resources_->texture_object_map.insert(std::make_pair(client_id, texture)); 2770 resources_->texture_object_map.insert(std::make_pair(client_id, texture));
2771
2772 // Bind the service id that now represents this texture
2773 UpdateTextureBinding(target, client_id, texture->service_id());
2774
2733 return error::kNoError; 2775 return error::kNoError;
2734 } 2776 }
2735 2777
2736 error::Error GLES2DecoderPassthroughImpl::DoCreateAndConsumeTextureINTERNAL( 2778 error::Error GLES2DecoderPassthroughImpl::DoCreateAndConsumeTextureINTERNAL(
2737 GLenum target, 2779 GLenum target,
2738 GLuint texture_client_id, 2780 GLuint texture_client_id,
2739 const volatile GLbyte* mailbox) { 2781 const volatile GLbyte* mailbox) {
2740 // TODO(geofflang): validation
2741
2742 if (resources_->texture_id_map.GetServiceID(texture_client_id, nullptr)) { 2782 if (resources_->texture_id_map.GetServiceID(texture_client_id, nullptr)) {
2743 return error::kInvalidArguments; 2783 return error::kInvalidArguments;
2744 } 2784 }
2785
2745 const Mailbox& mb = Mailbox::FromVolatile( 2786 const Mailbox& mb = Mailbox::FromVolatile(
2746 *reinterpret_cast<const volatile Mailbox*>(mailbox)); 2787 *reinterpret_cast<const volatile Mailbox*>(mailbox));
2747 scoped_refptr<TexturePassthrough> texture = static_cast<TexturePassthrough*>( 2788 scoped_refptr<TexturePassthrough> texture = static_cast<TexturePassthrough*>(
2748 group_->mailbox_manager()->ConsumeTexture(mb)); 2789 group_->mailbox_manager()->ConsumeTexture(mb));
2749 if (texture == nullptr) { 2790 if (texture == nullptr) {
2750 // TODO(geofflang): error, missing mailbox 2791 InsertError(GL_INVALID_OPERATION, "Invalid mailbox name.");
2751 return error::kNoError; 2792 return error::kNoError;
2752 } 2793 }
2753 2794
2795 if (texture->target() != target) {
2796 InsertError(GL_INVALID_OPERATION, "Texture target does not match.");
2797 return error::kNoError;
2798 }
2799
2800 // Update id mappings
2801 resources_->texture_id_map.RemoveClientID(texture_client_id);
2754 resources_->texture_id_map.SetIDMapping(texture_client_id, 2802 resources_->texture_id_map.SetIDMapping(texture_client_id,
2755 texture->service_id()); 2803 texture->service_id());
2756 resources_->texture_object_map.erase(texture_client_id); 2804 resources_->texture_object_map.erase(texture_client_id);
2757 resources_->texture_object_map.insert( 2805 resources_->texture_object_map.insert(
2758 std::make_pair(texture_client_id, texture)); 2806 std::make_pair(texture_client_id, texture));
2807
2808 // Bind the service id that now represents this texture
2809 UpdateTextureBinding(target, texture_client_id, texture->service_id());
2810
2759 return error::kNoError; 2811 return error::kNoError;
2760 } 2812 }
2761 2813
2762 error::Error GLES2DecoderPassthroughImpl::DoBindUniformLocationCHROMIUM( 2814 error::Error GLES2DecoderPassthroughImpl::DoBindUniformLocationCHROMIUM(
2763 GLuint program, 2815 GLuint program,
2764 GLint location, 2816 GLint location,
2765 const char* name) { 2817 const char* name) {
2766 glBindUniformLocationCHROMIUM(GetProgramServiceID(program, resources_), 2818 glBindUniformLocationCHROMIUM(GetProgramServiceID(program, resources_),
2767 location, name); 2819 location, name);
2768 return error::kNoError; 2820 return error::kNoError;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
3183 GLES2DecoderPassthroughImpl::DoUniformMatrix4fvStreamTextureMatrixCHROMIUM( 3235 GLES2DecoderPassthroughImpl::DoUniformMatrix4fvStreamTextureMatrixCHROMIUM(
3184 GLint location, 3236 GLint location,
3185 GLboolean transpose, 3237 GLboolean transpose,
3186 const volatile GLfloat* defaultValue) { 3238 const volatile GLfloat* defaultValue) {
3187 NOTIMPLEMENTED(); 3239 NOTIMPLEMENTED();
3188 return error::kNoError; 3240 return error::kNoError;
3189 } 3241 }
3190 3242
3191 } // namespace gles2 3243 } // namespace gles2
3192 } // namespace gpu 3244 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc ('k') | gpu/command_buffer/service/texture_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698