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> |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 271 |
272 static bool StringIsValidForGLES(const char* str) { | 272 static bool StringIsValidForGLES(const char* str) { |
273 for (; *str; ++str) { | 273 for (; *str; ++str) { |
274 if (!CharacterIsValidForGLES(*str)) { | 274 if (!CharacterIsValidForGLES(*str)) { |
275 return false; | 275 return false; |
276 } | 276 } |
277 } | 277 } |
278 return true; | 278 return true; |
279 } | 279 } |
280 | 280 |
281 // Wrapper for glEnable/glDisable that doesn't suck. | |
282 static void EnableDisable(GLenum pname, bool enable) { | |
283 if (enable) { | |
284 glEnable(pname); | |
285 } else { | |
286 glDisable(pname); | |
287 } | |
288 } | |
289 | |
290 // This class prevents any GL errors that occur when it is in scope from | 281 // This class prevents any GL errors that occur when it is in scope from |
291 // being reported to the client. | 282 // being reported to the client. |
292 class ScopedGLErrorSuppressor { | 283 class ScopedGLErrorSuppressor { |
293 public: | 284 public: |
294 explicit ScopedGLErrorSuppressor( | 285 explicit ScopedGLErrorSuppressor( |
295 const char* function_name, ErrorState* error_state); | 286 const char* function_name, ErrorState* error_state); |
296 ~ScopedGLErrorSuppressor(); | 287 ~ScopedGLErrorSuppressor(); |
297 private: | 288 private: |
298 const char* function_name_; | 289 const char* function_name_; |
299 ErrorState* error_state_; | 290 ErrorState* error_state_; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 virtual void SetShaderCacheCallback( | 645 virtual void SetShaderCacheCallback( |
655 const ShaderCacheCallback& callback) OVERRIDE; | 646 const ShaderCacheCallback& callback) OVERRIDE; |
656 virtual void SetWaitSyncPointCallback( | 647 virtual void SetWaitSyncPointCallback( |
657 const WaitSyncPointCallback& callback) OVERRIDE; | 648 const WaitSyncPointCallback& callback) OVERRIDE; |
658 | 649 |
659 virtual AsyncPixelTransferManager* | 650 virtual AsyncPixelTransferManager* |
660 GetAsyncPixelTransferManager() OVERRIDE; | 651 GetAsyncPixelTransferManager() OVERRIDE; |
661 virtual void ResetAsyncPixelTransferManagerForTest() OVERRIDE; | 652 virtual void ResetAsyncPixelTransferManagerForTest() OVERRIDE; |
662 virtual void SetAsyncPixelTransferManagerForTest( | 653 virtual void SetAsyncPixelTransferManagerForTest( |
663 AsyncPixelTransferManager* manager) OVERRIDE; | 654 AsyncPixelTransferManager* manager) OVERRIDE; |
| 655 virtual void SetIgnoreCachedStateForTest(bool ignore) OVERRIDE; |
664 void ProcessFinishedAsyncTransfers(); | 656 void ProcessFinishedAsyncTransfers(); |
665 | 657 |
666 virtual bool GetServiceTextureId(uint32 client_texture_id, | 658 virtual bool GetServiceTextureId(uint32 client_texture_id, |
667 uint32* service_texture_id) OVERRIDE; | 659 uint32* service_texture_id) OVERRIDE; |
668 | 660 |
669 virtual uint32 GetTextureUploadCount() OVERRIDE; | 661 virtual uint32 GetTextureUploadCount() OVERRIDE; |
670 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; | 662 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; |
671 virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; | 663 virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; |
672 virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; | 664 virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; |
673 | 665 |
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 return; | 1914 return; |
1923 } | 1915 } |
1924 } | 1916 } |
1925 targetid = decoder_->offscreen_resolved_frame_buffer_->id(); | 1917 targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
1926 } else { | 1918 } else { |
1927 targetid = decoder_->offscreen_saved_frame_buffer_->id(); | 1919 targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
1928 } | 1920 } |
1929 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); | 1921 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
1930 const int width = decoder_->offscreen_size_.width(); | 1922 const int width = decoder_->offscreen_size_.width(); |
1931 const int height = decoder_->offscreen_size_.height(); | 1923 const int height = decoder_->offscreen_size_.height(); |
1932 glDisable(GL_SCISSOR_TEST); | 1924 decoder->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
1933 decoder->BlitFramebufferHelper(0, | 1925 decoder->BlitFramebufferHelper(0, |
1934 0, | 1926 0, |
1935 width, | 1927 width, |
1936 height, | 1928 height, |
1937 0, | 1929 0, |
1938 0, | 1930 0, |
1939 width, | 1931 width, |
1940 height, | 1932 height, |
1941 GL_COLOR_BUFFER_BIT, | 1933 GL_COLOR_BUFFER_BIT, |
1942 GL_NEAREST); | 1934 GL_NEAREST); |
1943 glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); | 1935 glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
1944 } | 1936 } |
1945 | 1937 |
1946 ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { | 1938 ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
1947 if (!resolve_and_bind_) | 1939 if (!resolve_and_bind_) |
1948 return; | 1940 return; |
1949 | 1941 |
1950 ScopedGLErrorSuppressor suppressor( | 1942 ScopedGLErrorSuppressor suppressor( |
1951 "ScopedResolvedFrameBufferBinder::dtor", decoder_->GetErrorState()); | 1943 "ScopedResolvedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
1952 decoder_->RestoreCurrentFramebufferBindings(); | 1944 decoder_->RestoreCurrentFramebufferBindings(); |
1953 if (decoder_->state_.enable_flags.scissor_test) { | 1945 if (decoder_->state_.enable_flags.scissor_test) { |
1954 glEnable(GL_SCISSOR_TEST); | 1946 decoder_->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
1955 } | 1947 } |
1956 } | 1948 } |
1957 | 1949 |
1958 BackTexture::BackTexture( | 1950 BackTexture::BackTexture( |
1959 MemoryTracker* memory_tracker, | 1951 MemoryTracker* memory_tracker, |
1960 ContextState* state) | 1952 ContextState* state) |
1961 : memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), | 1953 : memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
1962 state_(state), | 1954 state_(state), |
1963 bytes_allocated_(0), | 1955 bytes_allocated_(0), |
1964 id_(0) { | 1956 id_(0) { |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3052 OnFboChanged(); | 3044 OnFboChanged(); |
3053 } | 3045 } |
3054 | 3046 |
3055 bool GLES2DecoderImpl::CheckFramebufferValid( | 3047 bool GLES2DecoderImpl::CheckFramebufferValid( |
3056 Framebuffer* framebuffer, | 3048 Framebuffer* framebuffer, |
3057 GLenum target, const char* func_name) { | 3049 GLenum target, const char* func_name) { |
3058 if (!framebuffer) { | 3050 if (!framebuffer) { |
3059 if (backbuffer_needs_clear_bits_) { | 3051 if (backbuffer_needs_clear_bits_) { |
3060 glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( | 3052 glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
3061 offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); | 3053 offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
3062 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 3054 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
3063 glClearStencil(0); | 3055 glClearStencil(0); |
3064 glStencilMask(-1); | 3056 glStencilMask(-1); |
3065 glClearDepth(1.0f); | 3057 glClearDepth(1.0f); |
3066 glDepthMask(true); | 3058 state_.SetDeviceDepthMask(GL_TRUE); |
3067 glDisable(GL_SCISSOR_TEST); | 3059 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
3068 glClear(backbuffer_needs_clear_bits_); | 3060 glClear(backbuffer_needs_clear_bits_); |
3069 backbuffer_needs_clear_bits_ = 0; | 3061 backbuffer_needs_clear_bits_ = 0; |
3070 RestoreClearState(); | 3062 RestoreClearState(); |
3071 } | 3063 } |
3072 return true; | 3064 return true; |
3073 } | 3065 } |
3074 | 3066 |
3075 if (framebuffer_manager()->IsComplete(framebuffer)) { | 3067 if (framebuffer_manager()->IsComplete(framebuffer)) { |
3076 return true; | 3068 return true; |
3077 } | 3069 } |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3560 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " | 3552 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
3561 << "because offscreen FBO was incomplete."; | 3553 << "because offscreen FBO was incomplete."; |
3562 return false; | 3554 return false; |
3563 } | 3555 } |
3564 | 3556 |
3565 // Clear the target frame buffer. | 3557 // Clear the target frame buffer. |
3566 { | 3558 { |
3567 ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); | 3559 ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
3568 glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( | 3560 glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
3569 offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); | 3561 offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
3570 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 3562 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
3571 glClearStencil(0); | 3563 glClearStencil(0); |
3572 glStencilMaskSeparate(GL_FRONT, -1); | 3564 state_.SetDeviceStencilMaskSeparate(GL_FRONT, -1); |
3573 glStencilMaskSeparate(GL_BACK, -1); | 3565 state_.SetDeviceStencilMaskSeparate(GL_BACK, -1); |
3574 glClearDepth(0); | 3566 glClearDepth(0); |
3575 glDepthMask(GL_TRUE); | 3567 state_.SetDeviceDepthMask(GL_TRUE); |
3576 glDisable(GL_SCISSOR_TEST); | 3568 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
3577 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 3569 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
3578 RestoreClearState(); | 3570 RestoreClearState(); |
3579 } | 3571 } |
3580 | 3572 |
3581 // Destroy the offscreen resolved framebuffers. | 3573 // Destroy the offscreen resolved framebuffers. |
3582 if (offscreen_resolved_frame_buffer_.get()) | 3574 if (offscreen_resolved_frame_buffer_.get()) |
3583 offscreen_resolved_frame_buffer_->Destroy(); | 3575 offscreen_resolved_frame_buffer_->Destroy(); |
3584 if (offscreen_resolved_color_texture_.get()) | 3576 if (offscreen_resolved_color_texture_.get()) |
3585 offscreen_resolved_color_texture_->Destroy(); | 3577 offscreen_resolved_color_texture_->Destroy(); |
3586 offscreen_resolved_color_texture_.reset(); | 3578 offscreen_resolved_color_texture_.reset(); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3829 } | 3821 } |
3830 if (offscreen_target_frame_buffer_.get()) { | 3822 if (offscreen_target_frame_buffer_.get()) { |
3831 return offscreen_target_stencil_format_ != 0 || | 3823 return offscreen_target_stencil_format_ != 0 || |
3832 offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; | 3824 offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
3833 } | 3825 } |
3834 return back_buffer_has_stencil_; | 3826 return back_buffer_has_stencil_; |
3835 } | 3827 } |
3836 | 3828 |
3837 void GLES2DecoderImpl::ApplyDirtyState() { | 3829 void GLES2DecoderImpl::ApplyDirtyState() { |
3838 if (framebuffer_state_.clear_state_dirty) { | 3830 if (framebuffer_state_.clear_state_dirty) { |
3839 glColorMask( | 3831 bool have_alpha = BoundFramebufferHasColorAttachmentWithAlpha(true); |
3840 state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue, | 3832 state_.SetDeviceColorMask(state_.color_mask_red, |
3841 state_.color_mask_alpha && | 3833 state_.color_mask_green, |
3842 BoundFramebufferHasColorAttachmentWithAlpha(true)); | 3834 state_.color_mask_blue, |
| 3835 state_.color_mask_alpha && have_alpha); |
| 3836 |
3843 bool have_depth = BoundFramebufferHasDepthAttachment(); | 3837 bool have_depth = BoundFramebufferHasDepthAttachment(); |
3844 glDepthMask(state_.depth_mask && have_depth); | 3838 state_.SetDeviceDepthMask(state_.depth_mask && have_depth); |
3845 EnableDisable(GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); | 3839 |
3846 bool have_stencil = BoundFramebufferHasStencilAttachment(); | 3840 bool have_stencil = BoundFramebufferHasStencilAttachment(); |
3847 glStencilMaskSeparate( | 3841 state_.SetDeviceStencilMaskSeparate( |
3848 GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); | 3842 GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); |
3849 glStencilMaskSeparate( | 3843 state_.SetDeviceStencilMaskSeparate( |
3850 GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); | 3844 GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); |
3851 EnableDisable( | 3845 |
| 3846 state_.SetDeviceCapabilityState( |
| 3847 GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); |
| 3848 state_.SetDeviceCapabilityState( |
3852 GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); | 3849 GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); |
3853 EnableDisable(GL_CULL_FACE, state_.enable_flags.cull_face); | |
3854 EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); | |
3855 EnableDisable(GL_BLEND, state_.enable_flags.blend); | |
3856 framebuffer_state_.clear_state_dirty = false; | 3850 framebuffer_state_.clear_state_dirty = false; |
3857 } | 3851 } |
3858 } | 3852 } |
3859 | 3853 |
3860 GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { | 3854 GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { |
3861 return (offscreen_target_frame_buffer_.get()) | 3855 return (offscreen_target_frame_buffer_.get()) |
3862 ? offscreen_target_frame_buffer_->id() | 3856 ? offscreen_target_frame_buffer_->id() |
3863 : (surface_.get() ? surface_->GetBackingFrameBufferObject() : 0); | 3857 : (surface_.get() ? surface_->GetBackingFrameBufferObject() : 0); |
3864 } | 3858 } |
3865 | 3859 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3918 glDisableVertexAttribArray(i); | 3912 glDisableVertexAttribArray(i); |
3919 if(features().angle_instanced_arrays) | 3913 if(features().angle_instanced_arrays) |
3920 glVertexAttribDivisorANGLE(i, 0); | 3914 glVertexAttribDivisorANGLE(i, 0); |
3921 } | 3915 } |
3922 } | 3916 } |
3923 | 3917 |
3924 void GLES2DecoderImpl::RestoreAllAttributes() const { | 3918 void GLES2DecoderImpl::RestoreAllAttributes() const { |
3925 state_.RestoreVertexAttribs(); | 3919 state_.RestoreVertexAttribs(); |
3926 } | 3920 } |
3927 | 3921 |
| 3922 void GLES2DecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
| 3923 state_.SetIgnoreCachedStateForTest(ignore); |
| 3924 } |
| 3925 |
3928 void GLES2DecoderImpl::OnFboChanged() const { | 3926 void GLES2DecoderImpl::OnFboChanged() const { |
3929 if (workarounds().restore_scissor_on_fbo_change) | 3927 if (workarounds().restore_scissor_on_fbo_change) |
3930 state_.fbo_binding_for_scissor_workaround_dirty_ = true; | 3928 state_.fbo_binding_for_scissor_workaround_dirty_ = true; |
3931 } | 3929 } |
3932 | 3930 |
3933 // Called after the FBO is checked for completeness. | 3931 // Called after the FBO is checked for completeness. |
3934 void GLES2DecoderImpl::OnUseFramebuffer() const { | 3932 void GLES2DecoderImpl::OnUseFramebuffer() const { |
3935 if (state_.fbo_binding_for_scissor_workaround_dirty_) { | 3933 if (state_.fbo_binding_for_scissor_workaround_dirty_) { |
3936 state_.fbo_binding_for_scissor_workaround_dirty_ = false; | 3934 state_.fbo_binding_for_scissor_workaround_dirty_ = false; |
3937 // The driver forgets the correct scissor when modifying the FBO binding. | 3935 // The driver forgets the correct scissor when modifying the FBO binding. |
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5011 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); | 5009 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
5012 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); | 5010 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); |
5013 } | 5011 } |
5014 GLbitfield clear_bits = 0; | 5012 GLbitfield clear_bits = 0; |
5015 if (framebuffer->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)) { | 5013 if (framebuffer->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)) { |
5016 glClearColor( | 5014 glClearColor( |
5017 0.0f, 0.0f, 0.0f, | 5015 0.0f, 0.0f, 0.0f, |
5018 (GLES2Util::GetChannelsForFormat( | 5016 (GLES2Util::GetChannelsForFormat( |
5019 framebuffer->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : | 5017 framebuffer->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : |
5020 1.0f); | 5018 1.0f); |
5021 glColorMask(true, true, true, true); | 5019 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
5022 clear_bits |= GL_COLOR_BUFFER_BIT; | 5020 clear_bits |= GL_COLOR_BUFFER_BIT; |
5023 } | 5021 } |
5024 | 5022 |
5025 if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || | 5023 if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
5026 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { | 5024 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
5027 glClearStencil(0); | 5025 glClearStencil(0); |
5028 glStencilMask(-1); | 5026 glStencilMask(-1); |
5029 clear_bits |= GL_STENCIL_BUFFER_BIT; | 5027 clear_bits |= GL_STENCIL_BUFFER_BIT; |
5030 } | 5028 } |
5031 | 5029 |
5032 if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || | 5030 if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
5033 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { | 5031 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
5034 glClearDepth(1.0f); | 5032 glClearDepth(1.0f); |
5035 glDepthMask(true); | 5033 state_.SetDeviceDepthMask(GL_TRUE); |
5036 clear_bits |= GL_DEPTH_BUFFER_BIT; | 5034 clear_bits |= GL_DEPTH_BUFFER_BIT; |
5037 } | 5035 } |
5038 | 5036 |
5039 glDisable(GL_SCISSOR_TEST); | 5037 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
5040 glClear(clear_bits); | 5038 glClear(clear_bits); |
5041 | 5039 |
5042 framebuffer_manager()->MarkAttachmentsAsCleared( | 5040 framebuffer_manager()->MarkAttachmentsAsCleared( |
5043 framebuffer, renderbuffer_manager(), texture_manager()); | 5041 framebuffer, renderbuffer_manager(), texture_manager()); |
5044 | 5042 |
5045 RestoreClearState(); | 5043 RestoreClearState(); |
5046 | 5044 |
5047 if (target == GL_READ_FRAMEBUFFER_EXT) { | 5045 if (target == GL_READ_FRAMEBUFFER_EXT) { |
5048 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); | 5046 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); |
5049 Framebuffer* draw_framebuffer = | 5047 Framebuffer* draw_framebuffer = |
5050 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); | 5048 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
5051 GLuint service_id = draw_framebuffer ? draw_framebuffer->service_id() : | 5049 GLuint service_id = draw_framebuffer ? draw_framebuffer->service_id() : |
5052 GetBackbufferServiceId(); | 5050 GetBackbufferServiceId(); |
5053 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); | 5051 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
5054 } | 5052 } |
5055 } | 5053 } |
5056 | 5054 |
5057 void GLES2DecoderImpl::RestoreClearState() { | 5055 void GLES2DecoderImpl::RestoreClearState() { |
5058 framebuffer_state_.clear_state_dirty = true; | 5056 framebuffer_state_.clear_state_dirty = true; |
5059 glClearColor( | 5057 glClearColor( |
5060 state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, | 5058 state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, |
5061 state_.color_clear_alpha); | 5059 state_.color_clear_alpha); |
5062 glClearStencil(state_.stencil_clear); | 5060 glClearStencil(state_.stencil_clear); |
5063 glClearDepth(state_.depth_clear); | 5061 glClearDepth(state_.depth_clear); |
5064 if (state_.enable_flags.scissor_test) { | 5062 if (state_.enable_flags.scissor_test) { |
5065 glEnable(GL_SCISSOR_TEST); | 5063 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
5066 } | 5064 } |
5067 } | 5065 } |
5068 | 5066 |
5069 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { | 5067 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
5070 Framebuffer* framebuffer = | 5068 Framebuffer* framebuffer = |
5071 GetFramebufferInfoForTarget(target); | 5069 GetFramebufferInfoForTarget(target); |
5072 if (!framebuffer) { | 5070 if (!framebuffer) { |
5073 return GL_FRAMEBUFFER_COMPLETE; | 5071 return GL_FRAMEBUFFER_COMPLETE; |
5074 } | 5072 } |
5075 GLenum completeness = framebuffer->IsPossiblyComplete(); | 5073 GLenum completeness = framebuffer->IsPossiblyComplete(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5232 LOCAL_SET_GL_ERROR( | 5230 LOCAL_SET_GL_ERROR( |
5233 GL_INVALID_OPERATION, | 5231 GL_INVALID_OPERATION, |
5234 "glBlitFramebufferCHROMIUM", "function not available"); | 5232 "glBlitFramebufferCHROMIUM", "function not available"); |
5235 return; | 5233 return; |
5236 } | 5234 } |
5237 | 5235 |
5238 if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { | 5236 if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { |
5239 return; | 5237 return; |
5240 } | 5238 } |
5241 | 5239 |
5242 glDisable(GL_SCISSOR_TEST); | 5240 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
5243 BlitFramebufferHelper( | 5241 BlitFramebufferHelper( |
5244 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); | 5242 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
5245 EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); | 5243 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, |
| 5244 state_.enable_flags.scissor_test); |
5246 } | 5245 } |
5247 | 5246 |
5248 void GLES2DecoderImpl::RenderbufferStorageMultisampleHelper( | 5247 void GLES2DecoderImpl::RenderbufferStorageMultisampleHelper( |
5249 const FeatureInfo* feature_info, | 5248 const FeatureInfo* feature_info, |
5250 GLenum target, | 5249 GLenum target, |
5251 GLsizei samples, | 5250 GLsizei samples, |
5252 GLenum internal_format, | 5251 GLenum internal_format, |
5253 GLsizei width, | 5252 GLsizei width, |
5254 GLsizei height) { | 5253 GLsizei height) { |
5255 // TODO(sievers): This could be resolved at the GL binding level, but the | 5254 // TODO(sievers): This could be resolved at the GL binding level, but the |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5474 } | 5473 } |
5475 | 5474 |
5476 glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); | 5475 glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
5477 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 5476 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
5478 GL_RENDERBUFFER, renderbuffer); | 5477 GL_RENDERBUFFER, renderbuffer); |
5479 | 5478 |
5480 // Cache current state and reset it to the values we require. | 5479 // Cache current state and reset it to the values we require. |
5481 GLboolean scissor_enabled = false; | 5480 GLboolean scissor_enabled = false; |
5482 glGetBooleanv(GL_SCISSOR_TEST, &scissor_enabled); | 5481 glGetBooleanv(GL_SCISSOR_TEST, &scissor_enabled); |
5483 if (scissor_enabled) | 5482 if (scissor_enabled) |
5484 glDisable(GL_SCISSOR_TEST); | 5483 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
5485 | 5484 |
5486 GLboolean color_mask[4] = {true, true, true, true}; | 5485 GLboolean color_mask[4] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}; |
5487 glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); | 5486 glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); |
5488 glColorMask(true, true, true, true); | 5487 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
5489 | 5488 |
5490 GLfloat clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | 5489 GLfloat clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
5491 glGetFloatv(GL_COLOR_CLEAR_VALUE, clear_color); | 5490 glGetFloatv(GL_COLOR_CLEAR_VALUE, clear_color); |
5492 glClearColor(1.0f, 0.0f, 1.0f, 1.0f); | 5491 glClearColor(1.0f, 0.0f, 1.0f, 1.0f); |
5493 | 5492 |
5494 // Clear the buffer to the desired key color. | 5493 // Clear the buffer to the desired key color. |
5495 glClear(GL_COLOR_BUFFER_BIT); | 5494 glClear(GL_COLOR_BUFFER_BIT); |
5496 | 5495 |
5497 // Blit from the multisample buffer to a standard texture. | 5496 // Blit from the multisample buffer to a standard texture. |
5498 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, validation_fbo_multisample_); | 5497 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, validation_fbo_multisample_); |
5499 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, validation_fbo_); | 5498 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, validation_fbo_); |
5500 | 5499 |
5501 BlitFramebufferHelper( | 5500 BlitFramebufferHelper( |
5502 0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST); | 5501 0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
5503 | 5502 |
5504 // Read a pixel from the buffer. | 5503 // Read a pixel from the buffer. |
5505 glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); | 5504 glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
5506 | 5505 |
5507 unsigned char pixel[3] = {0, 0, 0}; | 5506 unsigned char pixel[3] = {0, 0, 0}; |
5508 glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); | 5507 glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); |
5509 | 5508 |
5510 // Detach the renderbuffer. | 5509 // Detach the renderbuffer. |
5511 glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); | 5510 glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
5512 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 5511 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
5513 GL_RENDERBUFFER, 0); | 5512 GL_RENDERBUFFER, 0); |
5514 | 5513 |
5515 // Restore cached state. | 5514 // Restore cached state. |
5516 if (scissor_enabled) | 5515 if (scissor_enabled) |
5517 glEnable(GL_SCISSOR_TEST); | 5516 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
5518 | 5517 |
5519 glColorMask(color_mask[0], color_mask[1], color_mask[2], color_mask[3]); | 5518 state_.SetDeviceColorMask( |
| 5519 color_mask[0], color_mask[1], color_mask[2], color_mask[3]); |
5520 glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); | 5520 glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); |
5521 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, draw_framebuffer); | 5521 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, draw_framebuffer); |
5522 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_framebuffer); | 5522 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_framebuffer); |
5523 | 5523 |
5524 // Return true if the pixel matched the desired key color. | 5524 // Return true if the pixel matched the desired key color. |
5525 return (pixel[0] == 0xFF && | 5525 return (pixel[0] == 0xFF && |
5526 pixel[1] == 0x00 && | 5526 pixel[1] == 0x00 && |
5527 pixel[2] == 0xFF); | 5527 pixel[2] == 0xFF); |
5528 } | 5528 } |
5529 | 5529 |
(...skipping 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7825 glFramebufferTexture2DEXT( | 7825 glFramebufferTexture2DEXT( |
7826 GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); | 7826 GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); |
7827 // ANGLE promises a depth only attachment ok. | 7827 // ANGLE promises a depth only attachment ok. |
7828 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != | 7828 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
7829 GL_FRAMEBUFFER_COMPLETE) { | 7829 GL_FRAMEBUFFER_COMPLETE) { |
7830 return false; | 7830 return false; |
7831 } | 7831 } |
7832 glClearStencil(0); | 7832 glClearStencil(0); |
7833 glStencilMask(-1); | 7833 glStencilMask(-1); |
7834 glClearDepth(1.0f); | 7834 glClearDepth(1.0f); |
7835 glDepthMask(true); | 7835 state_.SetDeviceDepthMask(GL_TRUE); |
7836 glDisable(GL_SCISSOR_TEST); | 7836 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
7837 glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); | 7837 glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); |
7838 | 7838 |
7839 RestoreClearState(); | 7839 RestoreClearState(); |
7840 | 7840 |
7841 glDeleteFramebuffersEXT(1, &fb); | 7841 glDeleteFramebuffersEXT(1, &fb); |
7842 Framebuffer* framebuffer = | 7842 Framebuffer* framebuffer = |
7843 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); | 7843 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
7844 GLuint fb_service_id = | 7844 GLuint fb_service_id = |
7845 framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); | 7845 framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
7846 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); | 7846 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); |
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9152 LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); | 9152 LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
9153 return; | 9153 return; |
9154 } | 9154 } |
9155 | 9155 |
9156 // Clear the offscreen color texture. | 9156 // Clear the offscreen color texture. |
9157 // TODO(piman): Is this still necessary? | 9157 // TODO(piman): Is this still necessary? |
9158 { | 9158 { |
9159 ScopedFrameBufferBinder binder(this, | 9159 ScopedFrameBufferBinder binder(this, |
9160 offscreen_saved_frame_buffer_->id()); | 9160 offscreen_saved_frame_buffer_->id()); |
9161 glClearColor(0, 0, 0, 0); | 9161 glClearColor(0, 0, 0, 0); |
9162 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 9162 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
9163 glDisable(GL_SCISSOR_TEST); | 9163 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
9164 glClear(GL_COLOR_BUFFER_BIT); | 9164 glClear(GL_COLOR_BUFFER_BIT); |
9165 RestoreClearState(); | 9165 RestoreClearState(); |
9166 } | 9166 } |
9167 } | 9167 } |
9168 | 9168 |
9169 UpdateParentTextureInfo(); | 9169 UpdateParentTextureInfo(); |
9170 } | 9170 } |
9171 | 9171 |
9172 if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) | 9172 if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) |
9173 return; | 9173 return; |
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10787 } | 10787 } |
10788 } | 10788 } |
10789 | 10789 |
10790 // Include the auto-generated part of this file. We split this because it means | 10790 // Include the auto-generated part of this file. We split this because it means |
10791 // we can easily edit the non-auto generated parts right here in this file | 10791 // we can easily edit the non-auto generated parts right here in this file |
10792 // instead of having to edit some template or the code generator. | 10792 // instead of having to edit some template or the code generator. |
10793 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10793 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
10794 | 10794 |
10795 } // namespace gles2 | 10795 } // namespace gles2 |
10796 } // namespace gpu | 10796 } // namespace gpu |
OLD | NEW |