| OLD | NEW |
| 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/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> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <queue> |
| 12 #include <stack> | 13 #include <stack> |
| 13 #include <string> | 14 #include <string> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/at_exit.h" | 17 #include "base/at_exit.h" |
| 17 #include "base/bind.h" | 18 #include "base/bind.h" |
| 18 #include "base/callback_helpers.h" | 19 #include "base/callback_helpers.h" |
| 19 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 20 #include "base/float_util.h" | 21 #include "base/float_util.h" |
| 21 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 0.0f, 0.0f, 0.0f, 1.0f}; | 93 0.0f, 0.0f, 0.0f, 1.0f}; |
| 93 | 94 |
| 94 static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, | 95 static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, |
| 95 GLint rangeMax, | 96 GLint rangeMax, |
| 96 GLint precision) { | 97 GLint precision) { |
| 97 return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); | 98 return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); |
| 98 } | 99 } |
| 99 | 100 |
| 100 static void GetShaderPrecisionFormatImpl(GLenum shader_type, | 101 static void GetShaderPrecisionFormatImpl(GLenum shader_type, |
| 101 GLenum precision_type, | 102 GLenum precision_type, |
| 102 GLint *range, GLint *precision) { | 103 GLint* range, GLint* precision) { |
| 103 switch (precision_type) { | 104 switch (precision_type) { |
| 104 case GL_LOW_INT: | 105 case GL_LOW_INT: |
| 105 case GL_MEDIUM_INT: | 106 case GL_MEDIUM_INT: |
| 106 case GL_HIGH_INT: | 107 case GL_HIGH_INT: |
| 107 // These values are for a 32-bit twos-complement integer format. | 108 // These values are for a 32-bit twos-complement integer format. |
| 108 range[0] = 31; | 109 range[0] = 31; |
| 109 range[1] = 30; | 110 range[1] = 30; |
| 110 *precision = 0; | 111 *precision = 0; |
| 111 break; | 112 break; |
| 112 case GL_LOW_FLOAT: | 113 case GL_LOW_FLOAT: |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 return id_; | 497 return id_; |
| 497 } | 498 } |
| 498 | 499 |
| 499 private: | 500 private: |
| 500 GLES2DecoderImpl* decoder_; | 501 GLES2DecoderImpl* decoder_; |
| 501 GLuint id_; | 502 GLuint id_; |
| 502 DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); | 503 DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
| 503 }; | 504 }; |
| 504 | 505 |
| 505 struct FenceCallback { | 506 struct FenceCallback { |
| 506 explicit FenceCallback() | 507 FenceCallback() |
| 507 : fence(gfx::GLFence::Create()) { | 508 : fence(gfx::GLFence::Create()) { |
| 508 DCHECK(fence); | 509 DCHECK(fence); |
| 509 } | 510 } |
| 510 std::vector<base::Closure> callbacks; | 511 std::vector<base::Closure> callbacks; |
| 511 scoped_ptr<gfx::GLFence> fence; | 512 scoped_ptr<gfx::GLFence> fence; |
| 512 }; | 513 }; |
| 513 | 514 |
| 514 class AsyncUploadTokenCompletionObserver | 515 class AsyncUploadTokenCompletionObserver |
| 515 : public AsyncPixelTransferCompletionObserver { | 516 : public AsyncPixelTransferCompletionObserver { |
| 516 public: | 517 public: |
| (...skipping 3778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4295 } | 4296 } |
| 4296 } | 4297 } |
| 4297 | 4298 |
| 4298 void GLES2DecoderImpl::ClearAllAttributes() const { | 4299 void GLES2DecoderImpl::ClearAllAttributes() const { |
| 4299 // Must use native VAO 0, as RestoreAllAttributes can't fully restore | 4300 // Must use native VAO 0, as RestoreAllAttributes can't fully restore |
| 4300 // other VAOs. | 4301 // other VAOs. |
| 4301 if (feature_info_->feature_flags().native_vertex_array_object) | 4302 if (feature_info_->feature_flags().native_vertex_array_object) |
| 4302 glBindVertexArrayOES(0); | 4303 glBindVertexArrayOES(0); |
| 4303 | 4304 |
| 4304 for (uint32 i = 0; i < group_->max_vertex_attribs(); ++i) { | 4305 for (uint32 i = 0; i < group_->max_vertex_attribs(); ++i) { |
| 4305 if (i != 0) // Never disable attribute 0 | 4306 if (i != 0) // Never disable attribute 0 |
| 4306 glDisableVertexAttribArray(i); | 4307 glDisableVertexAttribArray(i); |
| 4307 if(features().angle_instanced_arrays) | 4308 if (features().angle_instanced_arrays) |
| 4308 glVertexAttribDivisorANGLE(i, 0); | 4309 glVertexAttribDivisorANGLE(i, 0); |
| 4309 } | 4310 } |
| 4310 } | 4311 } |
| 4311 | 4312 |
| 4312 void GLES2DecoderImpl::RestoreAllAttributes() const { | 4313 void GLES2DecoderImpl::RestoreAllAttributes() const { |
| 4313 state_.RestoreVertexAttribs(); | 4314 state_.RestoreVertexAttribs(); |
| 4314 } | 4315 } |
| 4315 | 4316 |
| 4316 void GLES2DecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { | 4317 void GLES2DecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
| 4317 state_.SetIgnoreCachedStateForTest(ignore); | 4318 state_.SetIgnoreCachedStateForTest(ignore); |
| (...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5668 GLenum impl_format = | 5669 GLenum impl_format = |
| 5669 renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( | 5670 renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5670 internalformat); | 5671 internalformat); |
| 5671 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER( | 5672 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER( |
| 5672 "glRenderbufferStorageMultisampleCHROMIUM"); | 5673 "glRenderbufferStorageMultisampleCHROMIUM"); |
| 5673 RenderbufferStorageMultisampleHelper( | 5674 RenderbufferStorageMultisampleHelper( |
| 5674 feature_info_.get(), target, samples, impl_format, width, height); | 5675 feature_info_.get(), target, samples, impl_format, width, height); |
| 5675 GLenum error = | 5676 GLenum error = |
| 5676 LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleCHROMIUM"); | 5677 LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleCHROMIUM"); |
| 5677 if (error == GL_NO_ERROR) { | 5678 if (error == GL_NO_ERROR) { |
| 5678 | |
| 5679 if (workarounds().validate_multisample_buffer_allocation) { | 5679 if (workarounds().validate_multisample_buffer_allocation) { |
| 5680 if (!VerifyMultisampleRenderbufferIntegrity( | 5680 if (!VerifyMultisampleRenderbufferIntegrity( |
| 5681 renderbuffer->service_id(), impl_format)) { | 5681 renderbuffer->service_id(), impl_format)) { |
| 5682 LOCAL_SET_GL_ERROR( | 5682 LOCAL_SET_GL_ERROR( |
| 5683 GL_OUT_OF_MEMORY, | 5683 GL_OUT_OF_MEMORY, |
| 5684 "glRenderbufferStorageMultisampleCHROMIUM", "out of memory"); | 5684 "glRenderbufferStorageMultisampleCHROMIUM", "out of memory"); |
| 5685 return; | 5685 return; |
| 5686 } | 5686 } |
| 5687 } | 5687 } |
| 5688 | 5688 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5736 // This function validates the allocation of a multisampled renderbuffer | 5736 // This function validates the allocation of a multisampled renderbuffer |
| 5737 // by clearing it to a key color, blitting the contents to a texture, and | 5737 // by clearing it to a key color, blitting the contents to a texture, and |
| 5738 // reading back the color to ensure it matches the key. | 5738 // reading back the color to ensure it matches the key. |
| 5739 bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity( | 5739 bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity( |
| 5740 GLuint renderbuffer, GLenum format) { | 5740 GLuint renderbuffer, GLenum format) { |
| 5741 | 5741 |
| 5742 // Only validate color buffers. | 5742 // Only validate color buffers. |
| 5743 // These formats have been selected because they are very common or are known | 5743 // These formats have been selected because they are very common or are known |
| 5744 // to be used by the WebGL backbuffer. If problems are observed with other | 5744 // to be used by the WebGL backbuffer. If problems are observed with other |
| 5745 // color formats they can be added here. | 5745 // color formats they can be added here. |
| 5746 switch(format) { | 5746 switch (format) { |
| 5747 case GL_RGB: | 5747 case GL_RGB: |
| 5748 case GL_RGB8: | 5748 case GL_RGB8: |
| 5749 case GL_RGBA: | 5749 case GL_RGBA: |
| 5750 case GL_RGBA8: | 5750 case GL_RGBA8: |
| 5751 break; | 5751 break; |
| 5752 default: | 5752 default: |
| 5753 return true; | 5753 return true; |
| 5754 } | 5754 } |
| 5755 | 5755 |
| 5756 GLint draw_framebuffer, read_framebuffer; | 5756 GLint draw_framebuffer, read_framebuffer; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5902 if (workarounds().use_current_program_after_successful_link) | 5902 if (workarounds().use_current_program_after_successful_link) |
| 5903 glUseProgram(program->service_id()); | 5903 glUseProgram(program->service_id()); |
| 5904 if (workarounds().clear_uniforms_before_first_program_use) | 5904 if (workarounds().clear_uniforms_before_first_program_use) |
| 5905 program_manager()->ClearUniforms(program); | 5905 program_manager()->ClearUniforms(program); |
| 5906 } | 5906 } |
| 5907 } | 5907 } |
| 5908 | 5908 |
| 5909 // LinkProgram can be very slow. Exit command processing to allow for | 5909 // LinkProgram can be very slow. Exit command processing to allow for |
| 5910 // context preemption and GPU watchdog checks. | 5910 // context preemption and GPU watchdog checks. |
| 5911 ExitCommandProcessingEarly(); | 5911 ExitCommandProcessingEarly(); |
| 5912 }; | 5912 } |
| 5913 | 5913 |
| 5914 void GLES2DecoderImpl::DoSamplerParameterfv( | 5914 void GLES2DecoderImpl::DoSamplerParameterfv( |
| 5915 GLuint sampler, GLenum pname, const GLfloat* params) { | 5915 GLuint sampler, GLenum pname, const GLfloat* params) { |
| 5916 DCHECK(params); | 5916 DCHECK(params); |
| 5917 glSamplerParameterf(sampler, pname, params[0]); | 5917 glSamplerParameterf(sampler, pname, params[0]); |
| 5918 } | 5918 } |
| 5919 | 5919 |
| 5920 void GLES2DecoderImpl::DoSamplerParameteriv( | 5920 void GLES2DecoderImpl::DoSamplerParameteriv( |
| 5921 GLuint sampler, GLenum pname, const GLint* params) { | 5921 GLuint sampler, GLenum pname, const GLint* params) { |
| 5922 DCHECK(params); | 5922 DCHECK(params); |
| (...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7692 | 7692 |
| 7693 state_.vertex_attrib_manager->SetDivisor( | 7693 state_.vertex_attrib_manager->SetDivisor( |
| 7694 index, | 7694 index, |
| 7695 divisor); | 7695 divisor); |
| 7696 glVertexAttribDivisorANGLE(index, divisor); | 7696 glVertexAttribDivisorANGLE(index, divisor); |
| 7697 return error::kNoError; | 7697 return error::kNoError; |
| 7698 } | 7698 } |
| 7699 | 7699 |
| 7700 template <typename pixel_data_type> | 7700 template <typename pixel_data_type> |
| 7701 static void WriteAlphaData( | 7701 static void WriteAlphaData( |
| 7702 void *pixels, uint32 row_count, uint32 channel_count, | 7702 void* pixels, uint32 row_count, uint32 channel_count, |
| 7703 uint32 alpha_channel_index, uint32 unpadded_row_size, | 7703 uint32 alpha_channel_index, uint32 unpadded_row_size, |
| 7704 uint32 padded_row_size, pixel_data_type alpha_value) { | 7704 uint32 padded_row_size, pixel_data_type alpha_value) { |
| 7705 DCHECK_GT(channel_count, 0U); | 7705 DCHECK_GT(channel_count, 0U); |
| 7706 DCHECK_EQ(unpadded_row_size % sizeof(pixel_data_type), 0U); | 7706 DCHECK_EQ(unpadded_row_size % sizeof(pixel_data_type), 0U); |
| 7707 uint32 unpadded_row_size_in_elements = | 7707 uint32 unpadded_row_size_in_elements = |
| 7708 unpadded_row_size / sizeof(pixel_data_type); | 7708 unpadded_row_size / sizeof(pixel_data_type); |
| 7709 DCHECK_EQ(padded_row_size % sizeof(pixel_data_type), 0U); | 7709 DCHECK_EQ(padded_row_size % sizeof(pixel_data_type), 0U); |
| 7710 uint32 padded_row_size_in_elements = | 7710 uint32 padded_row_size_in_elements = |
| 7711 padded_row_size / sizeof(pixel_data_type); | 7711 padded_row_size / sizeof(pixel_data_type); |
| 7712 pixel_data_type* dst = | 7712 pixel_data_type* dst = |
| (...skipping 2492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10205 LOG(ERROR) << "Context lost because SwapBuffers failed."; | 10205 LOG(ERROR) << "Context lost because SwapBuffers failed."; |
| 10206 LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); | 10206 LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 10207 } | 10207 } |
| 10208 } | 10208 } |
| 10209 | 10209 |
| 10210 // This may be a slow command. Exit command processing to allow for | 10210 // This may be a slow command. Exit command processing to allow for |
| 10211 // context preemption and GPU watchdog checks. | 10211 // context preemption and GPU watchdog checks. |
| 10212 ExitCommandProcessingEarly(); | 10212 ExitCommandProcessingEarly(); |
| 10213 } | 10213 } |
| 10214 | 10214 |
| 10215 void GLES2DecoderImpl::DoSwapInterval(int interval) | 10215 void GLES2DecoderImpl::DoSwapInterval(int interval) { |
| 10216 { | |
| 10217 context_->SetSwapInterval(interval); | 10216 context_->SetSwapInterval(interval); |
| 10218 } | 10217 } |
| 10219 | 10218 |
| 10220 error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( | 10219 error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
| 10221 uint32 immediate_data_size, | 10220 uint32 immediate_data_size, |
| 10222 const void* cmd_data) { | 10221 const void* cmd_data) { |
| 10223 const gles2::cmds::EnableFeatureCHROMIUM& c = | 10222 const gles2::cmds::EnableFeatureCHROMIUM& c = |
| 10224 *static_cast<const gles2::cmds::EnableFeatureCHROMIUM*>(cmd_data); | 10223 *static_cast<const gles2::cmds::EnableFeatureCHROMIUM*>(cmd_data); |
| 10225 Bucket* bucket = GetBucket(c.bucket_id); | 10224 Bucket* bucket = GetBucket(c.bucket_id); |
| 10226 if (!bucket || bucket->size() == 0) { | 10225 if (!bucket || bucket->size() == 0) { |
| (...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12440 } | 12439 } |
| 12441 } | 12440 } |
| 12442 | 12441 |
| 12443 // Include the auto-generated part of this file. We split this because it means | 12442 // Include the auto-generated part of this file. We split this because it means |
| 12444 // we can easily edit the non-auto generated parts right here in this file | 12443 // we can easily edit the non-auto generated parts right here in this file |
| 12445 // instead of having to edit some template or the code generator. | 12444 // instead of having to edit some template or the code generator. |
| 12446 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 12445 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 12447 | 12446 |
| 12448 } // namespace gles2 | 12447 } // namespace gles2 |
| 12449 } // namespace gpu | 12448 } // namespace gpu |
| OLD | NEW |