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

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

Powered by Google App Engine
This is Rietveld 408576698