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

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

Issue 7782038: Prepare WebGL contexts for resource sharing with the compositor context. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add an additional feature to GLES2DecoderImpl that is used to force the context to obey WebGL fea... Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 29 matching lines...) Expand all
40 #include "ui/gfx/gl/gl_implementation.h" 40 #include "ui/gfx/gl/gl_implementation.h"
41 #include "ui/gfx/gl/gl_surface.h" 41 #include "ui/gfx/gl/gl_surface.h"
42 42
43 #if !defined(GL_DEPTH24_STENCIL8) 43 #if !defined(GL_DEPTH24_STENCIL8)
44 #define GL_DEPTH24_STENCIL8 0x88F0 44 #define GL_DEPTH24_STENCIL8 0x88F0
45 #endif 45 #endif
46 46
47 namespace gpu { 47 namespace gpu {
48 namespace gles2 { 48 namespace gles2 {
49 49
50 namespace {
51 static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives";
52 }
53
50 class GLES2DecoderImpl; 54 class GLES2DecoderImpl;
51 55
52 // Check that certain assumptions the code makes are true. There are places in 56 // Check that certain assumptions the code makes are true. There are places in
53 // the code where shared memory is passed direclty to GL. Example, glUniformiv, 57 // the code where shared memory is passed direclty to GL. Example, glUniformiv,
54 // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe 58 // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe
55 // a few others) are 32bits. If they are not 32bits the code will have to change 59 // a few others) are 32bits. If they are not 32bits the code will have to change
56 // to call those GL functions with service side memory and then copy the results 60 // to call those GL functions with service side memory and then copy the results
57 // to shared memory, converting the sizes. 61 // to shared memory, converting the sizes.
58 COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT 62 COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT
59 GLint_not_same_size_as_uint32); 63 GLint_not_same_size_as_uint32);
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 bool tex_image_2d_failed_; 1321 bool tex_image_2d_failed_;
1318 1322
1319 int frame_number_; 1323 int frame_number_;
1320 1324
1321 bool has_arb_robustness_; 1325 bool has_arb_robustness_;
1322 GLenum reset_status_; 1326 GLenum reset_status_;
1323 1327
1324 bool needs_mac_nvidia_driver_workaround_; 1328 bool needs_mac_nvidia_driver_workaround_;
1325 bool needs_glsl_built_in_function_emulation_; 1329 bool needs_glsl_built_in_function_emulation_;
1326 1330
1331 // These flags are used to override the state of the shared feature_info_
1332 // member. Because the same FeatureInfo instance may be shared among many
1333 // contexts, the assumptions on the availablity of extensions in WebGL
1334 // contexts may be broken. These flags override the shared state to preserve
1335 // WebGL semantics.
1336 bool force_webgl_glsl_validation_;
1337 bool derivatives_explicitly_enabled_;
1338
1327 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); 1339 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl);
1328 }; 1340 };
1329 1341
1330 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder) 1342 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder)
1331 : decoder_(decoder) { 1343 : decoder_(decoder) {
1332 decoder_->CopyRealGLErrorsToWrapper(); 1344 decoder_->CopyRealGLErrorsToWrapper();
1333 } 1345 }
1334 1346
1335 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { 1347 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() {
1336 decoder_->ClearRealGLErrors(); 1348 decoder_->ClearRealGLErrors();
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 bufferdata_faster_than_buffersubdata_(true), 1689 bufferdata_faster_than_buffersubdata_(true),
1678 current_decoder_error_(error::kNoError), 1690 current_decoder_error_(error::kNoError),
1679 use_shader_translator_(true), 1691 use_shader_translator_(true),
1680 validators_(group_->feature_info()->validators()), 1692 validators_(group_->feature_info()->validators()),
1681 feature_info_(group_->feature_info()), 1693 feature_info_(group_->feature_info()),
1682 tex_image_2d_failed_(false), 1694 tex_image_2d_failed_(false),
1683 frame_number_(0), 1695 frame_number_(0),
1684 has_arb_robustness_(false), 1696 has_arb_robustness_(false),
1685 reset_status_(GL_NO_ERROR), 1697 reset_status_(GL_NO_ERROR),
1686 needs_mac_nvidia_driver_workaround_(false), 1698 needs_mac_nvidia_driver_workaround_(false),
1687 needs_glsl_built_in_function_emulation_(false) { 1699 needs_glsl_built_in_function_emulation_(false),
1700 force_webgl_glsl_validation_(false),
1701 derivatives_explicitly_enabled_(false) {
1688 DCHECK(group); 1702 DCHECK(group);
1689 1703
1690 attrib_0_value_.v[0] = 0.0f; 1704 attrib_0_value_.v[0] = 0.0f;
1691 attrib_0_value_.v[1] = 0.0f; 1705 attrib_0_value_.v[1] = 0.0f;
1692 attrib_0_value_.v[2] = 0.0f; 1706 attrib_0_value_.v[2] = 0.0f;
1693 attrib_0_value_.v[3] = 1.0f; 1707 attrib_0_value_.v[3] = 1.0f;
1694 1708
1695 // The shader translator is used for WebGL even when running on EGL 1709 // The shader translator is used for WebGL even when running on EGL
1696 // because additional restrictions are needed (like only enabling 1710 // because additional restrictions are needed (like only enabling
1697 // GL_OES_standard_derivatives on demand). It is used for the unit 1711 // GL_OES_standard_derivatives on demand). It is used for the unit
1698 // tests because 1712 // tests because
1699 // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the 1713 // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the
1700 // empty string to CompileShader and this is not a valid shader. 1714 // empty string to CompileShader and this is not a valid shader.
1701 // TODO(apatrick): fix this test. 1715 // TODO(apatrick): fix this test.
1702 if ((gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && 1716 if ((gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 &&
1703 !feature_info_->feature_flags().chromium_webglsl) || 1717 !feature_info_->feature_flags().chromium_webglsl &&
1718 !force_webgl_glsl_validation_) ||
1704 gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) { 1719 gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) {
1705 use_shader_translator_ = false; 1720 use_shader_translator_ = false;
1706 } 1721 }
1707 1722
1708 // TODO(gman): Consider setting these based on GPU and/or driver. 1723 // TODO(gman): Consider setting these based on GPU and/or driver.
1709 if (IsAngle()) { 1724 if (IsAngle()) {
1710 teximage2d_faster_than_texsubimage2d_ = false; 1725 teximage2d_faster_than_texsubimage2d_ = false;
1711 bufferdata_faster_than_buffersubdata_ = false; 1726 bufferdata_faster_than_buffersubdata_ = false;
1712 } 1727 }
1713 } 1728 }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 void GLES2DecoderImpl::UpdateCapabilities() { 1977 void GLES2DecoderImpl::UpdateCapabilities() {
1963 util_.set_num_compressed_texture_formats( 1978 util_.set_num_compressed_texture_formats(
1964 validators_->compressed_texture_format.GetValues().size()); 1979 validators_->compressed_texture_format.GetValues().size());
1965 util_.set_num_shader_binary_formats( 1980 util_.set_num_shader_binary_formats(
1966 validators_->shader_binary_format.GetValues().size()); 1981 validators_->shader_binary_format.GetValues().size());
1967 } 1982 }
1968 1983
1969 bool GLES2DecoderImpl::InitializeShaderTranslator() { 1984 bool GLES2DecoderImpl::InitializeShaderTranslator() {
1970 // Re-check the state of use_shader_translator_ each time this is called. 1985 // Re-check the state of use_shader_translator_ each time this is called.
1971 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && 1986 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 &&
1972 feature_info_->feature_flags().chromium_webglsl && 1987 (feature_info_->feature_flags().chromium_webglsl ||
1988 force_webgl_glsl_validation_) &&
1973 !use_shader_translator_) { 1989 !use_shader_translator_) {
1974 use_shader_translator_ = true; 1990 use_shader_translator_ = true;
1975 } 1991 }
1976 if (!use_shader_translator_) { 1992 if (!use_shader_translator_) {
1977 return true; 1993 return true;
1978 } 1994 }
1979 ShBuiltInResources resources; 1995 ShBuiltInResources resources;
1980 ShInitBuiltInResources(&resources); 1996 ShInitBuiltInResources(&resources);
1981 resources.MaxVertexAttribs = group_->max_vertex_attribs(); 1997 resources.MaxVertexAttribs = group_->max_vertex_attribs();
1982 resources.MaxVertexUniformVectors = 1998 resources.MaxVertexUniformVectors =
1983 group_->max_vertex_uniform_vectors(); 1999 group_->max_vertex_uniform_vectors();
1984 resources.MaxVaryingVectors = group_->max_varying_vectors(); 2000 resources.MaxVaryingVectors = group_->max_varying_vectors();
1985 resources.MaxVertexTextureImageUnits = 2001 resources.MaxVertexTextureImageUnits =
1986 group_->max_vertex_texture_image_units(); 2002 group_->max_vertex_texture_image_units();
1987 resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); 2003 resources.MaxCombinedTextureImageUnits = group_->max_texture_units();
1988 resources.MaxTextureImageUnits = group_->max_texture_image_units(); 2004 resources.MaxTextureImageUnits = group_->max_texture_image_units();
1989 resources.MaxFragmentUniformVectors = 2005 resources.MaxFragmentUniformVectors =
1990 group_->max_fragment_uniform_vectors(); 2006 group_->max_fragment_uniform_vectors();
1991 resources.MaxDrawBuffers = 1; 2007 resources.MaxDrawBuffers = 1;
1992 resources.OES_standard_derivatives = 2008
1993 feature_info_->feature_flags().oes_standard_derivatives ? 1 : 0; 2009 if (force_webgl_glsl_validation_) {
2010 resources.OES_standard_derivatives = derivatives_explicitly_enabled_;
2011 } else {
2012 resources.OES_standard_derivatives =
2013 feature_info_->feature_flags().oes_standard_derivatives ? 1 : 0;
2014 }
2015
1994 vertex_translator_.reset(new ShaderTranslator); 2016 vertex_translator_.reset(new ShaderTranslator);
1995 ShShaderSpec shader_spec = feature_info_->feature_flags().chromium_webglsl ? 2017 ShShaderSpec shader_spec = force_webgl_glsl_validation_ ||
1996 SH_WEBGL_SPEC : SH_GLES2_SPEC; 2018 feature_info_->feature_flags().chromium_webglsl ?
2019 SH_WEBGL_SPEC : SH_GLES2_SPEC;
1997 ShaderTranslatorInterface::GlslImplementationType implementation_type = 2020 ShaderTranslatorInterface::GlslImplementationType implementation_type =
1998 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? 2021 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ?
1999 ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; 2022 ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl;
2000 ShaderTranslatorInterface::GlslBuiltInFunctionBehavior function_behavior = 2023 ShaderTranslatorInterface::GlslBuiltInFunctionBehavior function_behavior =
2001 needs_glsl_built_in_function_emulation_ ? 2024 needs_glsl_built_in_function_emulation_ ?
2002 ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated : 2025 ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated :
2003 ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal; 2026 ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal;
2004 if (!vertex_translator_->Init( 2027 if (!vertex_translator_->Init(
2005 SH_VERTEX_SHADER, shader_spec, &resources, 2028 SH_VERTEX_SHADER, shader_spec, &resources,
2006 implementation_type, function_behavior)) { 2029 implementation_type, function_behavior)) {
(...skipping 3455 matching lines...) Expand 10 before | Expand all | Expand 10 after
5462 5485
5463 error::Error GLES2DecoderImpl::HandleGetString( 5486 error::Error GLES2DecoderImpl::HandleGetString(
5464 uint32 immediate_data_size, const gles2::GetString& c) { 5487 uint32 immediate_data_size, const gles2::GetString& c) {
5465 GLenum name = static_cast<GLenum>(c.name); 5488 GLenum name = static_cast<GLenum>(c.name);
5466 if (!validators_->string_type.IsValid(name)) { 5489 if (!validators_->string_type.IsValid(name)) {
5467 SetGLError(GL_INVALID_ENUM, "glGetString: name GL_INVALID_ENUM"); 5490 SetGLError(GL_INVALID_ENUM, "glGetString: name GL_INVALID_ENUM");
5468 return error::kNoError; 5491 return error::kNoError;
5469 } 5492 }
5470 const char* gl_str = reinterpret_cast<const char*>(glGetString(name)); 5493 const char* gl_str = reinterpret_cast<const char*>(glGetString(name));
5471 const char* str = NULL; 5494 const char* str = NULL;
5495 std::string extensions;
5472 switch (name) { 5496 switch (name) {
5473 case GL_VERSION: 5497 case GL_VERSION:
5474 str = "OpenGL ES 2.0 Chromium"; 5498 str = "OpenGL ES 2.0 Chromium";
5475 break; 5499 break;
5476 case GL_SHADING_LANGUAGE_VERSION: 5500 case GL_SHADING_LANGUAGE_VERSION:
5477 str = "OpenGL ES GLSL ES 1.0 Chromium"; 5501 str = "OpenGL ES GLSL ES 1.0 Chromium";
5478 break; 5502 break;
5479 case GL_EXTENSIONS: 5503 case GL_EXTENSIONS:
5480 str = feature_info_->extensions().c_str(); 5504 {
5505 // For WebGL contexts, strip out the OES derivatives extension if it has
5506 // not been enabled.
greggman 2011/09/29 22:15:07 Is this necessary? It seems like the model we wa
5507 if (force_webgl_glsl_validation_ &&
5508 !derivatives_explicitly_enabled_) {
5509 extensions = feature_info_->extensions();
5510 size_t offset = extensions.find(kOESDerivativeExtension);
5511 if (std::string::npos != offset) {
5512 extensions.replace(offset,
5513 offset + arraysize(kOESDerivativeExtension),
5514 std::string());
5515 }
5516 str = extensions.c_str();
5517 } else {
5518 str = feature_info_->extensions().c_str();
5519 }
5520
5521 }
5481 break; 5522 break;
5482 default: 5523 default:
5483 str = gl_str; 5524 str = gl_str;
5484 break; 5525 break;
5485 } 5526 }
5486 Bucket* bucket = CreateBucket(c.bucket_id); 5527 Bucket* bucket = CreateBucket(c.bucket_id);
5487 bucket->SetFromString(str); 5528 bucket->SetFromString(str);
5488 return error::kNoError; 5529 return error::kNoError;
5489 } 5530 }
5490 5531
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
6706 // TODO(gman): decide how to remove the need for this const_cast. 6747 // TODO(gman): decide how to remove the need for this const_cast.
6707 // I could make validators_ non const but that seems bad as this is the only 6748 // I could make validators_ non const but that seems bad as this is the only
6708 // place it is needed. I could make some special friend class of validators 6749 // place it is needed. I could make some special friend class of validators
6709 // just to allow this to set them. That seems silly. I could refactor this 6750 // just to allow this to set them. That seems silly. I could refactor this
6710 // code to use the extension mechanism or the initialization attributes to 6751 // code to use the extension mechanism or the initialization attributes to
6711 // turn this feature on. Given that the only real point of this is to make 6752 // turn this feature on. Given that the only real point of this is to make
6712 // the conformance tests pass and given that there is lots of real work that 6753 // the conformance tests pass and given that there is lots of real work that
6713 // needs to be done it seems like refactoring for one to one of those 6754 // needs to be done it seems like refactoring for one to one of those
6714 // methods is a very low priority. 6755 // methods is a very low priority.
6715 const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); 6756 const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED);
6757 } else if (feature_str.compare("webgl_enable_glsl_webgl_validation") == 0) {
6758 force_webgl_glsl_validation_ = true;
6759 InitializeShaderTranslator();
6716 } else { 6760 } else {
6717 return error::kNoError; 6761 return error::kNoError;
6718 } 6762 }
6719 6763
6720 *result = 1; // true. 6764 *result = 1; // true.
6721 return error::kNoError; 6765 return error::kNoError;
6722 } 6766 }
6723 6767
6724 error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( 6768 error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM(
6725 uint32 immediate_data_size, 6769 uint32 immediate_data_size,
(...skipping 13 matching lines...) Expand all
6739 return error::kInvalidArguments; 6783 return error::kInvalidArguments;
6740 } 6784 }
6741 6785
6742 bool std_derivatives_enabled = 6786 bool std_derivatives_enabled =
6743 feature_info_->feature_flags().oes_standard_derivatives; 6787 feature_info_->feature_flags().oes_standard_derivatives;
6744 bool webglsl_enabled = 6788 bool webglsl_enabled =
6745 feature_info_->feature_flags().chromium_webglsl; 6789 feature_info_->feature_flags().chromium_webglsl;
6746 6790
6747 feature_info_->AddFeatures(feature_str.c_str()); 6791 feature_info_->AddFeatures(feature_str.c_str());
6748 6792
6793 bool initialization_required = false;
6794 if (force_webgl_glsl_validation_ && !derivatives_explicitly_enabled_) {
6795 size_t derivatives_offset = feature_str.find(kOESDerivativeExtension);
6796 if (std::string::npos != derivatives_offset) {
6797 derivatives_explicitly_enabled_ = true;
6798 initialization_required = true;
6799 }
6800 }
6801
6749 // If we just enabled a feature which affects the shader translator, 6802 // If we just enabled a feature which affects the shader translator,
6750 // we may need to re-initialize it. 6803 // we may need to re-initialize it.
6751 if (std_derivatives_enabled != 6804 if (std_derivatives_enabled !=
6752 feature_info_->feature_flags().oes_standard_derivatives || 6805 feature_info_->feature_flags().oes_standard_derivatives ||
6753 webglsl_enabled != 6806 webglsl_enabled !=
6754 feature_info_->feature_flags().chromium_webglsl) { 6807 feature_info_->feature_flags().chromium_webglsl ||
6808 initialization_required) {
6755 InitializeShaderTranslator(); 6809 InitializeShaderTranslator();
6756 } 6810 }
6757 6811
6758 UpdateCapabilities(); 6812 UpdateCapabilities();
6759 6813
6760 return error::kNoError; 6814 return error::kNoError;
6761 } 6815 }
6762 6816
6763 error::Error GLES2DecoderImpl::HandleGetMultipleIntegervCHROMIUM( 6817 error::Error GLES2DecoderImpl::HandleGetMultipleIntegervCHROMIUM(
6764 uint32 immediate_data_size, const gles2::GetMultipleIntegervCHROMIUM& c) { 6818 uint32 immediate_data_size, const gles2::GetMultipleIntegervCHROMIUM& c) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
6885 return false; 6939 return false;
6886 } 6940 }
6887 6941
6888 // Include the auto-generated part of this file. We split this because it means 6942 // Include the auto-generated part of this file. We split this because it means
6889 // we can easily edit the non-auto generated parts right here in this file 6943 // we can easily edit the non-auto generated parts right here in this file
6890 // instead of having to edit some template or the code generator. 6944 // instead of having to edit some template or the code generator.
6891 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 6945 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
6892 6946
6893 } // namespace gles2 6947 } // namespace gles2
6894 } // namespace gpu 6948 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698