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

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

Issue 5626008: Exposed support for dynamically enabling extensions in command buffer... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 GLenum bind_target; 701 GLenum bind_target;
702 702
703 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture 703 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
704 TextureManager::TextureInfo::Ref bound_texture_2d; 704 TextureManager::TextureInfo::Ref bound_texture_2d;
705 705
706 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with 706 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
707 // glBindTexture 707 // glBindTexture
708 TextureManager::TextureInfo::Ref bound_texture_cube_map; 708 TextureManager::TextureInfo::Ref bound_texture_cube_map;
709 }; 709 };
710 710
711 // Initialize or re-initialize the shader translator.
712 bool InitializeShaderTranslator();
713
711 // Helpers for the glGen and glDelete functions. 714 // Helpers for the glGen and glDelete functions.
712 bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); 715 bool GenTexturesHelper(GLsizei n, const GLuint* client_ids);
713 void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); 716 void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids);
714 bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); 717 bool GenBuffersHelper(GLsizei n, const GLuint* client_ids);
715 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); 718 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids);
716 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); 719 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids);
717 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); 720 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids);
718 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 721 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
719 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); 722 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids);
720 723
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 offscreen_saved_color_format_(0), 1763 offscreen_saved_color_format_(0),
1761 current_decoder_error_(error::kNoError), 1764 current_decoder_error_(error::kNoError),
1762 use_shader_translator_(true), 1765 use_shader_translator_(true),
1763 validators_(group_->feature_info()->validators()), 1766 validators_(group_->feature_info()->validators()),
1764 feature_info_(group_->feature_info()) { 1767 feature_info_(group_->feature_info()) {
1765 attrib_0_value_.v[0] = 0.0f; 1768 attrib_0_value_.v[0] = 0.0f;
1766 attrib_0_value_.v[1] = 0.0f; 1769 attrib_0_value_.v[1] = 0.0f;
1767 attrib_0_value_.v[2] = 0.0f; 1770 attrib_0_value_.v[2] = 0.0f;
1768 attrib_0_value_.v[3] = 1.0f; 1771 attrib_0_value_.v[3] = 1.0f;
1769 1772
1770 // The shader translator is not needed for EGL because it already uses the 1773 // The shader translator is used for WebGL even when running on EGL
1771 // GLSL ES syntax. It is translated for the unit tests because 1774 // because additional restrictions are needed (like only enabling
1772 // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the empty 1775 // GL_OES_standard_derivatives on demand). It is used for the unit
1773 // string to CompileShader and this is not a valid shader. TODO(apatrick): 1776 // tests because
1774 // fix this test. 1777 // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the
1775 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 || 1778 // empty string to CompileShader and this is not a valid shader.
1779 // TODO(apatrick): fix this test.
1780 if ((gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 &&
1781 !feature_info_->feature_flags().chromium_webglsl) ||
1776 gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) { 1782 gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) {
1777 use_shader_translator_ = false; 1783 use_shader_translator_ = false;
1778 } 1784 }
1779 } 1785 }
1780 1786
1781 bool GLES2DecoderImpl::Initialize(gfx::GLContext* context, 1787 bool GLES2DecoderImpl::Initialize(gfx::GLContext* context,
1782 const gfx::Size& size, 1788 const gfx::Size& size,
1783 const char* allowed_extensions, 1789 const char* allowed_extensions,
1784 const std::vector<int32>& attribs, 1790 const std::vector<int32>& attribs,
1785 GLES2Decoder* parent, 1791 GLES2Decoder* parent,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact 1980 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact
1975 // isn't well documented; it was discovered in the Khronos OpenGL ES 1981 // isn't well documented; it was discovered in the Khronos OpenGL ES
1976 // mailing list archives. It also implicitly enables the desktop GL 1982 // mailing list archives. It also implicitly enables the desktop GL
1977 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord 1983 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord
1978 // variable in fragment shaders. 1984 // variable in fragment shaders.
1979 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 1985 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
1980 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); 1986 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
1981 glEnable(GL_POINT_SPRITE); 1987 glEnable(GL_POINT_SPRITE);
1982 } 1988 }
1983 1989
1984 if (use_shader_translator_) { 1990 if (!InitializeShaderTranslator()) {
1985 ShBuiltInResources resources; 1991 return false;
1986 ShInitBuiltInResources(&resources);
1987 resources.MaxVertexAttribs = group_->max_vertex_attribs();
1988 resources.MaxVertexUniformVectors =
1989 group_->max_vertex_uniform_vectors();
1990 resources.MaxVaryingVectors = group_->max_varying_vectors();
1991 resources.MaxVertexTextureImageUnits =
1992 group_->max_vertex_texture_image_units();
1993 resources.MaxCombinedTextureImageUnits = group_->max_texture_units();
1994 resources.MaxTextureImageUnits = group_->max_texture_image_units();
1995 resources.MaxFragmentUniformVectors =
1996 group_->max_fragment_uniform_vectors();
1997 resources.MaxDrawBuffers = 1;
1998 resources.OES_standard_derivatives =
1999 feature_info_->feature_flags().oes_standard_derivatives ? 1 : 0;
2000 vertex_translator_.reset(new ShaderTranslator);
2001 ShShaderSpec shader_spec = feature_info_->feature_flags().chromium_webglsl ?
2002 SH_WEBGL_SPEC : SH_GLES2_SPEC;
2003 if (!vertex_translator_->Init(SH_VERTEX_SHADER, shader_spec, &resources)) {
2004 LOG(ERROR) << "Could not initialize vertex shader translator.";
2005 Destroy();
2006 return false;
2007 }
2008 fragment_translator_.reset(new ShaderTranslator);
2009 if (!fragment_translator_->Init(
2010 SH_FRAGMENT_SHADER, shader_spec, &resources)) {
2011 LOG(ERROR) << "Could not initialize fragment shader translator.";
2012 Destroy();
2013 return false;
2014 }
2015 } 1992 }
2016 1993
2017 return true; 1994 return true;
2018 } 1995 }
2019 1996
1997 bool GLES2DecoderImpl::InitializeShaderTranslator() {
1998 // Re-check the state of use_shader_translator_ each time this is called.
1999 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 &&
2000 feature_info_->feature_flags().chromium_webglsl &&
2001 !use_shader_translator_) {
2002 use_shader_translator_ = true;
2003 }
2004 if (!use_shader_translator_) {
2005 return true;
2006 }
2007 ShBuiltInResources resources;
2008 ShInitBuiltInResources(&resources);
2009 resources.MaxVertexAttribs = group_->max_vertex_attribs();
2010 resources.MaxVertexUniformVectors =
2011 group_->max_vertex_uniform_vectors();
2012 resources.MaxVaryingVectors = group_->max_varying_vectors();
2013 resources.MaxVertexTextureImageUnits =
2014 group_->max_vertex_texture_image_units();
2015 resources.MaxCombinedTextureImageUnits = group_->max_texture_units();
2016 resources.MaxTextureImageUnits = group_->max_texture_image_units();
2017 resources.MaxFragmentUniformVectors =
2018 group_->max_fragment_uniform_vectors();
2019 resources.MaxDrawBuffers = 1;
2020 resources.OES_standard_derivatives =
2021 feature_info_->feature_flags().oes_standard_derivatives ? 1 : 0;
2022 vertex_translator_.reset(new ShaderTranslator);
2023 ShShaderSpec shader_spec = feature_info_->feature_flags().chromium_webglsl ?
2024 SH_WEBGL_SPEC : SH_GLES2_SPEC;
2025 bool is_glsl_es =
2026 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2;
2027 if (!vertex_translator_->Init(
2028 SH_VERTEX_SHADER, shader_spec, &resources, is_glsl_es)) {
2029 LOG(ERROR) << "Could not initialize vertex shader translator.";
2030 Destroy();
2031 return false;
2032 }
2033 fragment_translator_.reset(new ShaderTranslator);
2034 if (!fragment_translator_->Init(
2035 SH_FRAGMENT_SHADER, shader_spec, &resources, is_glsl_es)) {
2036 LOG(ERROR) << "Could not initialize fragment shader translator.";
2037 Destroy();
2038 return false;
2039 }
2040 return true;
2041 }
2042
2020 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { 2043 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) {
2021 for (GLsizei ii = 0; ii < n; ++ii) { 2044 for (GLsizei ii = 0; ii < n; ++ii) {
2022 if (GetBufferInfo(client_ids[ii])) { 2045 if (GetBufferInfo(client_ids[ii])) {
2023 return false; 2046 return false;
2024 } 2047 }
2025 } 2048 }
2026 scoped_array<GLuint> service_ids(new GLuint[n]); 2049 scoped_array<GLuint> service_ids(new GLuint[n]);
2027 glGenBuffersARB(n, service_ids.get()); 2050 glGenBuffersARB(n, service_ids.get());
2028 for (GLsizei ii = 0; ii < n; ++ii) { 2051 for (GLsizei ii = 0; ii < n; ++ii) {
2029 CreateBufferInfo(client_ids[ii], service_ids[ii]); 2052 CreateBufferInfo(client_ids[ii], service_ids[ii]);
(...skipping 3898 matching lines...) Expand 10 before | Expand all | Expand 10 after
5928 } else if (feature_str.compare(PEPPER3D_SKIP_GLSL_TRANSLATION) == 0) { 5951 } else if (feature_str.compare(PEPPER3D_SKIP_GLSL_TRANSLATION) == 0) {
5929 use_shader_translator_ = false; 5952 use_shader_translator_ = false;
5930 } else { 5953 } else {
5931 return error::kNoError; 5954 return error::kNoError;
5932 } 5955 }
5933 5956
5934 *result = 1; // true. 5957 *result = 1; // true.
5935 return error::kNoError; 5958 return error::kNoError;
5936 } 5959 }
5937 5960
5961 error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM(
5962 uint32 immediate_data_size,
5963 const gles2::GetRequestableExtensionsCHROMIUM& c) {
5964 Bucket* bucket = CreateBucket(c.bucket_id);
5965 scoped_ptr<FeatureInfo> info(new FeatureInfo());
5966 info->Initialize(NULL);
5967 bucket->SetFromString(info->extensions().c_str());
5968 return error::kNoError;
5969 }
5970
5971 error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM(
5972 uint32 immediate_data_size, const gles2::RequestExtensionCHROMIUM& c) {
5973 Bucket* bucket = GetBucket(c.bucket_id);
5974 std::string feature_str;
5975 if (!bucket->GetAsString(&feature_str)) {
5976 return error::kInvalidArguments;
5977 }
5978
5979 bool std_derivatives_enabled =
5980 feature_info_->feature_flags().oes_standard_derivatives;
5981 bool webglsl_enabled =
5982 feature_info_->feature_flags().chromium_webglsl;
5983
5984 feature_info_->AddFeatures(feature_str.c_str());
5985
5986 // If we just enabled a feature which affects the shader translator,
5987 // we may need to re-initialize it.
5988 if (std_derivatives_enabled !=
5989 feature_info_->feature_flags().oes_standard_derivatives ||
5990 webglsl_enabled !=
5991 feature_info_->feature_flags().chromium_webglsl) {
5992 InitializeShaderTranslator();
5993 }
5994
5995 return error::kNoError;
5996 }
5997
5938 // Include the auto-generated part of this file. We split this because it means 5998 // Include the auto-generated part of this file. We split this because it means
5939 // we can easily edit the non-auto generated parts right here in this file 5999 // we can easily edit the non-auto generated parts right here in this file
5940 // instead of having to edit some template or the code generator. 6000 // instead of having to edit some template or the code generator.
5941 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 6001 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
5942 6002
5943 } // namespace gles2 6003 } // namespace gles2
5944 } // namespace gpu 6004 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/feature_info.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698