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

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

Issue 2409523002: [Command buffer] Fix the bug when blitting pixels outside read framebuffer (Closed)
Patch Set: Addressed feedbacks from Corentin and Zhenyao Created 4 years, 2 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 7972 matching lines...) Expand 10 before | Expand all | Expand 10 after
7983 if ((GetBoundFramebufferDepthFormat(GL_READ_FRAMEBUFFER) != 7983 if ((GetBoundFramebufferDepthFormat(GL_READ_FRAMEBUFFER) !=
7984 GetBoundFramebufferDepthFormat(GL_DRAW_FRAMEBUFFER)) || 7984 GetBoundFramebufferDepthFormat(GL_DRAW_FRAMEBUFFER)) ||
7985 (GetBoundFramebufferStencilFormat(GL_READ_FRAMEBUFFER) != 7985 (GetBoundFramebufferStencilFormat(GL_READ_FRAMEBUFFER) !=
7986 GetBoundFramebufferStencilFormat(GL_DRAW_FRAMEBUFFER))) { 7986 GetBoundFramebufferStencilFormat(GL_DRAW_FRAMEBUFFER))) {
7987 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, 7987 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
7988 "src and dst formats differ for depth/stencil"); 7988 "src and dst formats differ for depth/stencil");
7989 return; 7989 return;
7990 } 7990 }
7991 } 7991 }
7992 7992
7993 if (workarounds().adjust_src_dst_region_for_blitframebuffer) {
7994 gfx::Size read_size = GetBoundReadFramebufferSize();
7995 gfx::Rect src_bounds(0, 0, read_size.width(), read_size.height());
7996 GLuint src_x = srcX1 > srcX0 ? srcX0 : srcX1;
7997 GLuint src_y = srcY1 > srcY0 ? srcY0 : srcY1;
Zhenyao Mo 2016/10/17 20:16:21 These two needs to be GLint.
yunchao 2016/10/17 23:51:29 Done.
7998 base::CheckedNumeric<GLint> src_width_temp = srcX1;
7999 src_width_temp -= srcX0;
8000 base::CheckedNumeric<GLint> src_height_temp = srcY1;
8001 src_height_temp -= srcY0;
8002 GLuint src_width = 0, src_height = 0;
8003 if (!src_width_temp.IsValid() || !src_height_temp.IsValid()) {
8004 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
8005 "the width or height of src region overflow");
8006 return;
8007 } else {
8008 src_width = std::abs(src_width_temp.ValueOrDefault(0));
8009 src_height = std::abs(src_height_temp.ValueOrDefault(0));
8010 }
8011
8012 gfx::Rect src_region(src_x, src_y, src_width, src_height);
8013 if (!src_bounds.Contains(src_region) &&
8014 (src_width != 0) && (src_height != 0)) {
8015 // If pixels lying outside the read framebuffer, adjust src region
8016 // and dst region to appropriate in-bounds regions respectively.
8017 src_bounds.Intersect(gfx::Rect(src_x, src_y, src_width, src_height));
8018 GLuint src_real_width = src_bounds.width();
8019 GLuint src_real_height = src_bounds.height();
8020 GLuint xoffset = src_bounds.x() - src_x;
yunchao 2016/10/15 14:34:58 Thought about the calculation here. Now that the w
8021 GLuint yoffset = src_bounds.y() - src_y;
8022 // if X/Y is reversed, use the top/right out-of-bounds region for mapping
8023 // to dst region, instead of left/bottom out-of-bounds region for mapping.
8024 if (((srcX1 > srcX0) && (dstX1 < dstX0)) ||
8025 ((srcX1 < srcX0) && (dstX1 > dstX0))) {
8026 xoffset = src_x + src_width - src_bounds.x() - src_bounds.width();
yunchao 2016/10/15 14:34:58 Not overflow for every step during "+" and "-", co
8027 }
8028 if (((srcY1 > srcY0) && (dstY1 < dstY0)) ||
8029 ((srcY1 < srcY0) && (dstY1 > dstY0))) {
8030 yoffset = src_y + src_height - src_bounds.y() - src_bounds.height();
8031 }
8032
8033 GLuint dst_x = dstX1 > dstX0 ? dstX0 : dstX1;
8034 GLuint dst_y = dstY1 > dstY0 ? dstY0 : dstY1;
Zhenyao Mo 2016/10/17 20:16:21 Same here: these two needs to be GLint.
yunchao 2016/10/17 23:51:29 Done.
8035 base::CheckedNumeric<GLint> dst_width_temp = dstX1;
8036 dst_width_temp -= dstX0;
8037 base::CheckedNumeric<GLint> dst_height_temp = dstY1;
8038 dst_height_temp -= dstY0;
8039 GLuint dst_width = 0, dst_height = 0;
8040 if (!dst_width_temp.IsValid() || !dst_height_temp.IsValid()) {
8041 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
8042 "the width or height of dst region overflow");
8043 return;
8044 } else {
8045 dst_width = std::abs(dst_width_temp.ValueOrDefault(0));
8046 dst_height = std::abs(dst_height_temp.ValueOrDefault(0));
8047 }
8048 GLfloat dst_mapping_width =
8049 static_cast<GLfloat>(src_real_width) * dst_width / src_width;
8050 GLfloat dst_mapping_height =
8051 static_cast<GLfloat>(src_real_height) * dst_height / src_height;
8052 GLfloat dst_mapping_xoffset =
8053 static_cast<GLfloat>(xoffset) * dst_width / src_width;
8054 GLfloat dst_mapping_yoffset =
8055 static_cast<GLfloat>(yoffset) * dst_height / src_height;
8056
8057 GLuint dst_mapping_x0 =
8058 std::round(dst_x + dst_mapping_xoffset);
8059 GLuint dst_mapping_y0 =
8060 std::round(dst_y + dst_mapping_yoffset);
8061
8062 GLuint dst_mapping_x1 =
8063 std::round(dst_x + dst_mapping_xoffset + dst_mapping_width);
8064 GLuint dst_mapping_y1 =
8065 std::round(dst_y + dst_mapping_yoffset + dst_mapping_height);
8066
8067 // adjust the src region and dst region to fit the read framebuffer
8068 srcX0 = srcX0 < srcX1 ?
8069 src_bounds.x() : src_bounds.x() + src_bounds.width();
8070 srcY0 = srcY0 < srcY1 ?
8071 src_bounds.y() : src_bounds.y() + src_bounds.height();
8072 srcX1 = srcX0 < srcX1 ?
8073 src_bounds.x() + src_bounds.width() : src_bounds.x();
8074 srcY1 = srcY0 < srcY1 ?
8075 src_bounds.y() + src_bounds.height() : src_bounds.y();
8076
8077 dstX0 = dstX0 < dstX1 ? dst_mapping_x0 : dst_mapping_x1;
8078 dstY0 = dstY0 < dstY1 ? dst_mapping_y0 : dst_mapping_y1;
8079 dstX1 = dstX0 < dstX1 ? dst_mapping_x1 : dst_mapping_x0;
8080 dstY1 = dstY0 < dstY1 ? dst_mapping_y1 : dst_mapping_y0;
8081 }
8082 }
8083
7993 bool enable_srgb = 8084 bool enable_srgb =
7994 (read_buffer_has_srgb || draw_buffers_has_srgb) && 8085 (read_buffer_has_srgb || draw_buffers_has_srgb) &&
7995 ((mask & GL_COLOR_BUFFER_BIT) != 0); 8086 ((mask & GL_COLOR_BUFFER_BIT) != 0);
7996 bool encode_srgb_only = 8087 bool encode_srgb_only =
7997 (draw_buffers_has_srgb && !read_buffer_has_srgb) && 8088 (draw_buffers_has_srgb && !read_buffer_has_srgb) &&
7998 ((mask & GL_COLOR_BUFFER_BIT) != 0); 8089 ((mask & GL_COLOR_BUFFER_BIT) != 0);
7999 if (!enable_srgb || 8090 if (!enable_srgb ||
8000 read_buffer_samples > 0 || 8091 read_buffer_samples > 0 ||
8001 !feature_info_->feature_flags().desktop_srgb_support || 8092 !feature_info_->feature_flags().desktop_srgb_support ||
8002 gl_version_info().IsAtLeastGL(4, 4) || 8093 gl_version_info().IsAtLeastGL(4, 4) ||
(...skipping 10516 matching lines...) Expand 10 before | Expand all | Expand 10 after
18519 } 18610 }
18520 18611
18521 // Include the auto-generated part of this file. We split this because it means 18612 // Include the auto-generated part of this file. We split this because it means
18522 // we can easily edit the non-auto generated parts right here in this file 18613 // we can easily edit the non-auto generated parts right here in this file
18523 // instead of having to edit some template or the code generator. 18614 // instead of having to edit some template or the code generator.
18524 #include "base/macros.h" 18615 #include "base/macros.h"
18525 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 18616 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18526 18617
18527 } // namespace gles2 18618 } // namespace gles2
18528 } // namespace gpu 18619 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698