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

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

Issue 2735853002: Offset scissor and viewport when using SetDrawRectangle on surface. (Closed)
Patch Set: remove flag Created 3 years, 9 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
OLDNEW
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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 GLenum GetBoundColorDrawBufferType(GLint drawbuffer_i); 854 GLenum GetBoundColorDrawBufferType(GLint drawbuffer_i);
855 GLenum GetBoundColorDrawBufferInternalFormat(GLint drawbuffer_i); 855 GLenum GetBoundColorDrawBufferInternalFormat(GLint drawbuffer_i);
856 856
857 GLsizei GetBoundFramebufferSamples(GLenum target); 857 GLsizei GetBoundFramebufferSamples(GLenum target);
858 858
859 // Return 0 if no depth attachment. 859 // Return 0 if no depth attachment.
860 GLenum GetBoundFramebufferDepthFormat(GLenum target); 860 GLenum GetBoundFramebufferDepthFormat(GLenum target);
861 // Return 0 if no stencil attachment. 861 // Return 0 if no stencil attachment.
862 GLenum GetBoundFramebufferStencilFormat(GLenum target); 862 GLenum GetBoundFramebufferStencilFormat(GLenum target);
863 863
864 gfx::Vector2d GetBoundFramebufferDrawOffset() const {
865 if (GetBoundDrawFramebuffer() || offscreen_target_frame_buffer_.get())
866 return gfx::Vector2d();
867 return surface_->GetDrawOffset();
868 }
869
864 void MarkDrawBufferAsCleared(GLenum buffer, GLint drawbuffer_i); 870 void MarkDrawBufferAsCleared(GLenum buffer, GLint drawbuffer_i);
865 871
866 // Wrapper for CompressedTexImage{2|3}D commands. 872 // Wrapper for CompressedTexImage{2|3}D commands.
867 error::Error DoCompressedTexImage( 873 error::Error DoCompressedTexImage(
868 GLenum target, 874 GLenum target,
869 GLint level, 875 GLint level,
870 GLenum internal_format, 876 GLenum internal_format,
871 GLsizei width, 877 GLsizei width,
872 GLsizei height, 878 GLsizei height,
873 GLsizei depth, 879 GLsizei depth,
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 void DoVertexAttrib4fv(GLuint index, const volatile GLfloat* v); 1861 void DoVertexAttrib4fv(GLuint index, const volatile GLfloat* v);
1856 void DoVertexAttribI4i(GLuint index, GLint v0, GLint v1, GLint v2, GLint v3); 1862 void DoVertexAttribI4i(GLuint index, GLint v0, GLint v1, GLint v2, GLint v3);
1857 void DoVertexAttribI4iv(GLuint index, const volatile GLint* v); 1863 void DoVertexAttribI4iv(GLuint index, const volatile GLint* v);
1858 void DoVertexAttribI4ui( 1864 void DoVertexAttribI4ui(
1859 GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3); 1865 GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
1860 void DoVertexAttribI4uiv(GLuint index, const volatile GLuint* v); 1866 void DoVertexAttribI4uiv(GLuint index, const volatile GLuint* v);
1861 1867
1862 // Wrapper for glViewport 1868 // Wrapper for glViewport
1863 void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height); 1869 void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height);
1864 1870
1871 // Wrapper for glScissor
1872 void DoScissor(GLint x, GLint y, GLsizei width, GLsizei height);
1873
1865 // Wrapper for glUseProgram 1874 // Wrapper for glUseProgram
1866 void DoUseProgram(GLuint program); 1875 void DoUseProgram(GLuint program);
1867 1876
1868 // Wrapper for glValidateProgram. 1877 // Wrapper for glValidateProgram.
1869 void DoValidateProgram(GLuint program_client_id); 1878 void DoValidateProgram(GLuint program_client_id);
1870 1879
1871 void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker); 1880 void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker);
1872 void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group); 1881 void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group);
1873 void DoPopGroupMarkerEXT(void); 1882 void DoPopGroupMarkerEXT(void);
1874 1883
(...skipping 3764 matching lines...) Expand 10 before | Expand all | Expand 10 after
5639 void GLES2DecoderImpl::OnFboChanged() const { 5648 void GLES2DecoderImpl::OnFboChanged() const {
5640 state_.fbo_binding_for_scissor_workaround_dirty = true; 5649 state_.fbo_binding_for_scissor_workaround_dirty = true;
5641 } 5650 }
5642 5651
5643 // Called after the FBO is checked for completeness. 5652 // Called after the FBO is checked for completeness.
5644 void GLES2DecoderImpl::OnUseFramebuffer() const { 5653 void GLES2DecoderImpl::OnUseFramebuffer() const {
5645 if (!state_.fbo_binding_for_scissor_workaround_dirty) 5654 if (!state_.fbo_binding_for_scissor_workaround_dirty)
5646 return; 5655 return;
5647 state_.fbo_binding_for_scissor_workaround_dirty = false; 5656 state_.fbo_binding_for_scissor_workaround_dirty = false;
5648 5657
5658 if (supports_set_draw_rectangle_) {
5659 gfx::Vector2d draw_offset = GetBoundFramebufferDrawOffset();
5660 glViewport(state_.viewport_x + draw_offset.x(),
5661 state_.viewport_y + draw_offset.y(), state_.viewport_width,
5662 state_.viewport_height);
5663 }
5664
5665 if (workarounds().restore_scissor_on_fbo_change ||
5666 supports_set_draw_rectangle_) {
5667 // The driver forgets the correct scissor when modifying the FBO binding.
5668 gfx::Vector2d scissor_offset = GetBoundFramebufferDrawOffset();
5669 glScissor(state_.scissor_x + scissor_offset.x(),
5670 state_.scissor_y + scissor_offset.y(), state_.scissor_width,
5671 state_.scissor_height);
5672 }
5673
5649 if (workarounds().restore_scissor_on_fbo_change) { 5674 if (workarounds().restore_scissor_on_fbo_change) {
5650 // The driver forgets the correct scissor when modifying the FBO binding.
5651 glScissor(state_.scissor_x,
5652 state_.scissor_y,
5653 state_.scissor_width,
5654 state_.scissor_height);
5655
5656 // crbug.com/222018 - Also on QualComm, the flush here avoids flicker, 5675 // crbug.com/222018 - Also on QualComm, the flush here avoids flicker,
5657 // it's unclear how this bug works. 5676 // it's unclear how this bug works.
5658 glFlush(); 5677 glFlush();
5659 } 5678 }
5660 5679
5661 if (workarounds().force_update_scissor_state_when_binding_fbo0 && 5680 if (workarounds().force_update_scissor_state_when_binding_fbo0 &&
5662 GetBoundDrawFramebufferServiceId() == 0) { 5681 GetBoundDrawFramebufferServiceId() == 0) {
5663 // The theory is that FBO0 keeps some internal (in HW regs maybe?) scissor 5682 // The theory is that FBO0 keeps some internal (in HW regs maybe?) scissor
5664 // test state, but the driver forgets to update it with GL_SCISSOR_TEST 5683 // test state, but the driver forgets to update it with GL_SCISSOR_TEST
5665 // when FBO0 gets bound. (So it stuck with whatever state we last switched 5684 // when FBO0 gets bound. (So it stuck with whatever state we last switched
(...skipping 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after
7648 7667
7649 void GLES2DecoderImpl::RestoreClearState() { 7668 void GLES2DecoderImpl::RestoreClearState() {
7650 framebuffer_state_.clear_state_dirty = true; 7669 framebuffer_state_.clear_state_dirty = true;
7651 glClearColor( 7670 glClearColor(
7652 state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, 7671 state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue,
7653 state_.color_clear_alpha); 7672 state_.color_clear_alpha);
7654 glClearStencil(state_.stencil_clear); 7673 glClearStencil(state_.stencil_clear);
7655 glClearDepth(state_.depth_clear); 7674 glClearDepth(state_.depth_clear);
7656 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, 7675 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST,
7657 state_.enable_flags.scissor_test); 7676 state_.enable_flags.scissor_test);
7658 glScissor(state_.scissor_x, state_.scissor_y, state_.scissor_width, 7677 gfx::Vector2d scissor_offset = GetBoundFramebufferDrawOffset();
7678 glScissor(state_.scissor_x + scissor_offset.x(),
7679 state_.scissor_y + scissor_offset.y(), state_.scissor_width,
7659 state_.scissor_height); 7680 state_.scissor_height);
7660 } 7681 }
7661 7682
7662 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { 7683 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) {
7663 Framebuffer* framebuffer = 7684 Framebuffer* framebuffer =
7664 GetFramebufferInfoForTarget(target); 7685 GetFramebufferInfoForTarget(target);
7665 if (!framebuffer) { 7686 if (!framebuffer) {
7666 return GL_FRAMEBUFFER_COMPLETE; 7687 return GL_FRAMEBUFFER_COMPLETE;
7667 } 7688 }
7668 GLenum completeness = framebuffer->IsPossiblyComplete(feature_info_.get()); 7689 GLenum completeness = framebuffer->IsPossiblyComplete(feature_info_.get());
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
8711 if (!supports_set_draw_rectangle_) { 8732 if (!supports_set_draw_rectangle_) {
8712 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glSetDrawRectangleCHROMIUM", 8733 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glSetDrawRectangleCHROMIUM",
8713 "surface doesn't support SetDrawRectangle"); 8734 "surface doesn't support SetDrawRectangle");
8714 return; 8735 return;
8715 } 8736 }
8716 gfx::Rect rect(x, y, width, height); 8737 gfx::Rect rect(x, y, width, height);
8717 if (!surface_->SetDrawRectangle(rect)) { 8738 if (!surface_->SetDrawRectangle(rect)) {
8718 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glSetDrawRectangleCHROMIUM", 8739 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glSetDrawRectangleCHROMIUM",
8719 "failed on surface"); 8740 "failed on surface");
8720 } 8741 }
8742 OnFboChanged();
8721 } 8743 }
8722 8744
8723 void GLES2DecoderImpl::DoReadBuffer(GLenum src) { 8745 void GLES2DecoderImpl::DoReadBuffer(GLenum src) {
8724 Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER); 8746 Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER);
8725 if (framebuffer) { 8747 if (framebuffer) {
8726 if (src == GL_BACK) { 8748 if (src == GL_BACK) {
8727 LOCAL_SET_GL_ERROR( 8749 LOCAL_SET_GL_ERROR(
8728 GL_INVALID_ENUM, "glReadBuffer", 8750 GL_INVALID_ENUM, "glReadBuffer",
8729 "invalid src for a named framebuffer"); 8751 "invalid src for a named framebuffer");
8730 return; 8752 return;
(...skipping 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after
11165 } 11187 }
11166 return error::kNoError; 11188 return error::kNoError;
11167 } 11189 }
11168 11190
11169 void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width, 11191 void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width,
11170 GLsizei height) { 11192 GLsizei height) {
11171 state_.viewport_x = x; 11193 state_.viewport_x = x;
11172 state_.viewport_y = y; 11194 state_.viewport_y = y;
11173 state_.viewport_width = std::min(width, viewport_max_width_); 11195 state_.viewport_width = std::min(width, viewport_max_width_);
11174 state_.viewport_height = std::min(height, viewport_max_height_); 11196 state_.viewport_height = std::min(height, viewport_max_height_);
11175 glViewport(x, y, width, height); 11197 gfx::Vector2d viewport_offset = GetBoundFramebufferDrawOffset();
11198 glViewport(x + viewport_offset.x(), y + viewport_offset.y(), width, height);
11199 }
11200
11201 void GLES2DecoderImpl::DoScissor(GLint x,
11202 GLint y,
11203 GLsizei width,
11204 GLsizei height) {
11205 gfx::Vector2d draw_offset = GetBoundFramebufferDrawOffset();
11206 glScissor(x + draw_offset.x(), y + draw_offset.y(), width, height);
11176 } 11207 }
11177 11208
11178 error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( 11209 error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE(
11179 uint32_t immediate_data_size, 11210 uint32_t immediate_data_size,
11180 const volatile void* cmd_data) { 11211 const volatile void* cmd_data) {
11181 const volatile gles2::cmds::VertexAttribDivisorANGLE& c = 11212 const volatile gles2::cmds::VertexAttribDivisorANGLE& c =
11182 *static_cast<const volatile gles2::cmds::VertexAttribDivisorANGLE*>( 11213 *static_cast<const volatile gles2::cmds::VertexAttribDivisorANGLE*>(
11183 cmd_data); 11214 cmd_data);
11184 if (!features().angle_instanced_arrays) 11215 if (!features().angle_instanced_arrays)
11185 return error::kUnknownCommand; 11216 return error::kUnknownCommand;
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
12454 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != 12485 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) !=
12455 GL_FRAMEBUFFER_COMPLETE) { 12486 GL_FRAMEBUFFER_COMPLETE) {
12456 return false; 12487 return false;
12457 } 12488 }
12458 glClearStencil(0); 12489 glClearStencil(0);
12459 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); 12490 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask);
12460 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); 12491 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask);
12461 glClearDepth(1.0f); 12492 glClearDepth(1.0f);
12462 state_.SetDeviceDepthMask(GL_TRUE); 12493 state_.SetDeviceDepthMask(GL_TRUE);
12463 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); 12494 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true);
12464 glScissor(xoffset, yoffset, width, height); 12495 gfx::Vector2d scissor_offset = GetBoundFramebufferDrawOffset();
12496 glScissor(xoffset + scissor_offset.x(), yoffset + scissor_offset.y(), width,
12497 height);
12465 glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); 12498 glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0));
12466 12499
12467 RestoreClearState(); 12500 RestoreClearState();
12468 12501
12469 glDeleteFramebuffersEXT(1, &fb); 12502 glDeleteFramebuffersEXT(1, &fb);
12470 Framebuffer* framebuffer = 12503 Framebuffer* framebuffer =
12471 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); 12504 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT);
12472 GLuint fb_service_id = 12505 GLuint fb_service_id =
12473 framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); 12506 framebuffer ? framebuffer->service_id() : GetBackbufferServiceId();
12474 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); 12507 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id);
(...skipping 6860 matching lines...) Expand 10 before | Expand all | Expand 10 after
19335 } 19368 }
19336 19369
19337 // Include the auto-generated part of this file. We split this because it means 19370 // Include the auto-generated part of this file. We split this because it means
19338 // we can easily edit the non-auto generated parts right here in this file 19371 // we can easily edit the non-auto generated parts right here in this file
19339 // instead of having to edit some template or the code generator. 19372 // instead of having to edit some template or the code generator.
19340 #include "base/macros.h" 19373 #include "base/macros.h"
19341 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 19374 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
19342 19375
19343 } // namespace gles2 19376 } // namespace gles2
19344 } // namespace gpu 19377 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/build_gles2_cmd_buffer.py ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698