| 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 <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 bool GenSamplersHelper(GLsizei n, const GLuint* client_ids); | 700 bool GenSamplersHelper(GLsizei n, const GLuint* client_ids); |
| 701 void DeleteSamplersHelper(GLsizei n, const volatile GLuint* client_ids); | 701 void DeleteSamplersHelper(GLsizei n, const volatile GLuint* client_ids); |
| 702 bool GenTransformFeedbacksHelper(GLsizei n, const GLuint* client_ids); | 702 bool GenTransformFeedbacksHelper(GLsizei n, const GLuint* client_ids); |
| 703 void DeleteTransformFeedbacksHelper(GLsizei n, | 703 void DeleteTransformFeedbacksHelper(GLsizei n, |
| 704 const volatile GLuint* client_ids); | 704 const volatile GLuint* client_ids); |
| 705 void DeleteSyncHelper(GLuint sync); | 705 void DeleteSyncHelper(GLuint sync); |
| 706 | 706 |
| 707 // Workarounds | 707 // Workarounds |
| 708 void OnFboChanged() const; | 708 void OnFboChanged() const; |
| 709 void OnUseFramebuffer() const; | 709 void OnUseFramebuffer() const; |
| 710 void UpdateFramebufferSRGB(Framebuffer* framebuffer); | |
| 711 | 710 |
| 712 error::ContextLostReason GetContextLostReasonFromResetStatus( | 711 error::ContextLostReason GetContextLostReasonFromResetStatus( |
| 713 GLenum reset_status) const; | 712 GLenum reset_status) const; |
| 714 | 713 |
| 715 // TODO(gman): Cache these pointers? | 714 // TODO(gman): Cache these pointers? |
| 716 BufferManager* buffer_manager() { | 715 BufferManager* buffer_manager() { |
| 717 return group_->buffer_manager(); | 716 return group_->buffer_manager(); |
| 718 } | 717 } |
| 719 | 718 |
| 720 RenderbufferManager* renderbuffer_manager() { | 719 RenderbufferManager* renderbuffer_manager() { |
| (...skipping 2731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3452 return false; | 3451 return false; |
| 3453 } | 3452 } |
| 3454 } | 3453 } |
| 3455 | 3454 |
| 3456 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); | 3455 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
| 3457 | 3456 |
| 3458 DoBindBuffer(GL_ARRAY_BUFFER, 0); | 3457 DoBindBuffer(GL_ARRAY_BUFFER, 0); |
| 3459 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 3458 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 3460 DoBindFramebuffer(GL_FRAMEBUFFER, 0); | 3459 DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 3461 DoBindRenderbuffer(GL_RENDERBUFFER, 0); | 3460 DoBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 3462 UpdateFramebufferSRGB(nullptr); | |
| 3463 | 3461 |
| 3464 bool call_gl_clear = !surfaceless_ && !offscreen; | 3462 bool call_gl_clear = !surfaceless_ && !offscreen; |
| 3465 #if defined(OS_ANDROID) | 3463 #if defined(OS_ANDROID) |
| 3466 // Temporary workaround for Android WebView because this clear ignores the | 3464 // Temporary workaround for Android WebView because this clear ignores the |
| 3467 // clip and corrupts that external UI of the App. Not calling glClear is ok | 3465 // clip and corrupts that external UI of the App. Not calling glClear is ok |
| 3468 // because the system already clears the buffer before each draw. Proper | 3466 // because the system already clears the buffer before each draw. Proper |
| 3469 // fix might be setting the scissor clip properly before initialize. See | 3467 // fix might be setting the scissor clip properly before initialize. See |
| 3470 // crbug.com/259023 for details. | 3468 // crbug.com/259023 for details. |
| 3471 call_gl_clear = surface_->GetHandle(); | 3469 call_gl_clear = surface_->GetHandle(); |
| 3472 #endif | 3470 #endif |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4288 } | 4286 } |
| 4289 return true; | 4287 return true; |
| 4290 } | 4288 } |
| 4291 | 4289 |
| 4292 bool GLES2DecoderImpl::CheckBoundDrawFramebufferValid(const char* func_name) { | 4290 bool GLES2DecoderImpl::CheckBoundDrawFramebufferValid(const char* func_name) { |
| 4293 GLenum target = features().chromium_framebuffer_multisample ? | 4291 GLenum target = features().chromium_framebuffer_multisample ? |
| 4294 GL_DRAW_FRAMEBUFFER : GL_FRAMEBUFFER; | 4292 GL_DRAW_FRAMEBUFFER : GL_FRAMEBUFFER; |
| 4295 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); | 4293 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 4296 bool valid = CheckFramebufferValid( | 4294 bool valid = CheckFramebufferValid( |
| 4297 framebuffer, target, GL_INVALID_FRAMEBUFFER_OPERATION, func_name); | 4295 framebuffer, target, GL_INVALID_FRAMEBUFFER_OPERATION, func_name); |
| 4298 if (!valid) | 4296 if (valid && !features().chromium_framebuffer_multisample) |
| 4299 return false; | |
| 4300 | |
| 4301 if (!features().chromium_framebuffer_multisample) | |
| 4302 OnUseFramebuffer(); | 4297 OnUseFramebuffer(); |
| 4303 | 4298 if (valid && feature_info_->feature_flags().desktop_srgb_support) { |
| 4304 UpdateFramebufferSRGB(framebuffer); | 4299 // If framebuffer contains sRGB images, then enable FRAMEBUFFER_SRGB. |
| 4305 return true; | 4300 // Otherwise, disable FRAMEBUFFER_SRGB. Assume default fbo does not have |
| 4306 } | 4301 // sRGB image. |
| 4307 | 4302 // In theory, we can just leave FRAMEBUFFER_SRGB on. However, many drivers |
| 4308 void GLES2DecoderImpl::UpdateFramebufferSRGB(Framebuffer* framebuffer) { | 4303 // behave incorrectly when all images are linear encoding, they still apply |
| 4309 // Manually set the value of FRAMEBUFFER_SRGB based on the state that was set | 4304 // the sRGB conversion, but when at least one image is sRGB, then they |
| 4310 // by the client. | 4305 // behave correctly. |
| 4311 bool needs_enable_disable_framebuffer_srgb = false; | 4306 bool enable_framebuffer_srgb = |
| 4312 bool enable_framebuffer_srgb = true; | 4307 framebuffer && framebuffer->HasSRGBAttachments(); |
| 4313 if (feature_info_->feature_flags().ext_srgb_write_control) { | 4308 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb); |
| 4314 needs_enable_disable_framebuffer_srgb = true; | |
| 4315 enable_framebuffer_srgb &= state_.GetEnabled(GL_FRAMEBUFFER_SRGB); | |
| 4316 } | 4309 } |
| 4317 // On desktop, enable FRAMEBUFFER_SRGB only if the framebuffer contains sRGB | 4310 return valid; |
| 4318 // attachments. In theory, we can just leave FRAMEBUFFER_SRGB enabled, | |
| 4319 // however, | |
| 4320 // many drivers behave incorrectly when no attachments are sRGB. When at | |
| 4321 // least one attachment is sRGB, then they behave correctly. | |
| 4322 if (feature_info_->feature_flags().desktop_srgb_support) { | |
| 4323 needs_enable_disable_framebuffer_srgb = true; | |
| 4324 // Assume that the default fbo does not have an sRGB image. | |
| 4325 enable_framebuffer_srgb &= framebuffer && framebuffer->HasSRGBAttachments(); | |
| 4326 } | |
| 4327 if (needs_enable_disable_framebuffer_srgb) | |
| 4328 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb); | |
| 4329 } | 4311 } |
| 4330 | 4312 |
| 4331 bool GLES2DecoderImpl::CheckBoundReadFramebufferValid( | 4313 bool GLES2DecoderImpl::CheckBoundReadFramebufferValid( |
| 4332 const char* func_name, GLenum gl_error) { | 4314 const char* func_name, GLenum gl_error) { |
| 4333 GLenum target = features().chromium_framebuffer_multisample ? | 4315 GLenum target = features().chromium_framebuffer_multisample ? |
| 4334 GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER; | 4316 GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER; |
| 4335 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); | 4317 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 4336 bool valid = CheckFramebufferValid( | 4318 bool valid = CheckFramebufferValid( |
| 4337 framebuffer, target, gl_error, func_name); | 4319 framebuffer, target, gl_error, func_name); |
| 4338 return valid; | 4320 return valid; |
| (...skipping 3089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7428 } | 7410 } |
| 7429 | 7411 |
| 7430 void GLES2DecoderImpl::DoDisable(GLenum cap) { | 7412 void GLES2DecoderImpl::DoDisable(GLenum cap) { |
| 7431 if (SetCapabilityState(cap, false)) { | 7413 if (SetCapabilityState(cap, false)) { |
| 7432 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX && | 7414 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX && |
| 7433 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) { | 7415 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) { |
| 7434 // Enable and Disable PRIMITIVE_RESTART only before and after | 7416 // Enable and Disable PRIMITIVE_RESTART only before and after |
| 7435 // DrawElements* for old desktop GL. | 7417 // DrawElements* for old desktop GL. |
| 7436 return; | 7418 return; |
| 7437 } | 7419 } |
| 7438 if (cap == GL_FRAMEBUFFER_SRGB) { | |
| 7439 // Enable and Disable GL_FRAMEBUFFER_SRGB is done manually in | |
| 7440 // CheckBoundDrawFramebufferValid. | |
| 7441 return; | |
| 7442 } | |
| 7443 glDisable(cap); | 7420 glDisable(cap); |
| 7444 } | 7421 } |
| 7445 } | 7422 } |
| 7446 | 7423 |
| 7447 void GLES2DecoderImpl::DoEnable(GLenum cap) { | 7424 void GLES2DecoderImpl::DoEnable(GLenum cap) { |
| 7448 if (SetCapabilityState(cap, true)) { | 7425 if (SetCapabilityState(cap, true)) { |
| 7449 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX && | 7426 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX && |
| 7450 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) { | 7427 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) { |
| 7451 // Enable and Disable PRIMITIVE_RESTART only before and after | 7428 // Enable and Disable PRIMITIVE_RESTART only before and after |
| 7452 // DrawElements* for old desktop GL. | 7429 // DrawElements* for old desktop GL. |
| 7453 return; | 7430 return; |
| 7454 } | 7431 } |
| 7455 if (cap == GL_FRAMEBUFFER_SRGB) { | |
| 7456 // Enable and Disable GL_FRAMEBUFFER_SRGB is done manually in | |
| 7457 // CheckBoundDrawFramebufferValid. | |
| 7458 return; | |
| 7459 } | |
| 7460 glEnable(cap); | 7432 glEnable(cap); |
| 7461 } | 7433 } |
| 7462 } | 7434 } |
| 7463 | 7435 |
| 7464 void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { | 7436 void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { |
| 7465 state_.z_near = std::min(1.0f, std::max(0.0f, znear)); | 7437 state_.z_near = std::min(1.0f, std::max(0.0f, znear)); |
| 7466 state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); | 7438 state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); |
| 7467 glDepthRange(znear, zfar); | 7439 glDepthRange(znear, zfar); |
| 7468 } | 7440 } |
| 7469 | 7441 |
| (...skipping 11423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18893 } | 18865 } |
| 18894 | 18866 |
| 18895 // Include the auto-generated part of this file. We split this because it means | 18867 // Include the auto-generated part of this file. We split this because it means |
| 18896 // we can easily edit the non-auto generated parts right here in this file | 18868 // we can easily edit the non-auto generated parts right here in this file |
| 18897 // instead of having to edit some template or the code generator. | 18869 // instead of having to edit some template or the code generator. |
| 18898 #include "base/macros.h" | 18870 #include "base/macros.h" |
| 18899 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 18871 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 18900 | 18872 |
| 18901 } // namespace gles2 | 18873 } // namespace gles2 |
| 18902 } // namespace gpu | 18874 } // namespace gpu |
| OLD | NEW |