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