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

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 refactoring 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 gfx::Size read_size = GetBoundReadFramebufferSize();
7994 gfx::Rect rect(0, 0, read_size.width(), read_size.height());
7995 GLuint src_x = srcX1 > srcX0 ? srcX0 : srcX1;
Zhenyao Mo 2016/10/13 00:35:56 From your code, it seems you include the lower bou
yunchao 2016/10/13 01:50:47 (Just a quick reply about this, I think the spec i
Zhenyao Mo 2016/10/13 22:51:23 Yes, your interpretation sounds reasonable. The sp
7996 GLuint src_y = srcY1 > srcY0 ? srcY0 : srcY1;
7997 GLuint src_width = srcX1 > srcX0 ? srcX1 - srcX0 : srcX0 - srcX1;
Zhenyao Mo 2016/10/13 00:35:56 These math needs to be safe (using base::CheckedNu
yunchao 2016/10/14 13:49:05 Done.
7998 GLuint src_height = srcY1 > srcY0 ? srcY1 - srcY0 : srcY0 - srcY1;
7999 gfx::Rect src_region(src_x, src_y, src_width, src_height);
8000 if (!rect.Contains(src_region) && (src_width != 0) && (src_height != 0)) {
8001 // If pixels lying outside the read framebuffer, adjust src region
8002 // and dst region to appropriate in-bounds regions respectively.
8003 rect.Intersect(gfx::Rect(src_x, src_y, src_width, src_height));
8004 GLuint src_real_width = rect.width();
8005 GLuint src_real_height = rect.height();
8006 GLuint xoffset = rect.x() - src_x;
Zhenyao Mo 2016/10/13 00:35:56 This could also cause overflow since src_x can be
yunchao 2016/10/14 13:49:05 Done.
8007 GLuint yoffset = rect.y() - src_y;
8008 // if X/Y is reversed, use the top/right out-of-bounds region for mapping to
8009 // dst region, instead of left/bottom out-of-bounds region for mapping.
8010 if (((srcX1 > srcX0) && (dstX1 < dstX0)) ||
8011 ((srcX1 < srcX0) && (dstX1 > dstX0))) {
8012 xoffset = src_x + src_width - rect.x() - rect.width();
8013 }
8014 if (((srcY1 > srcY0) && (dstY1 < dstY0)) ||
8015 ((srcY1 < srcY0) && (dstY1 > dstY0))) {
8016 yoffset = src_y + src_height - rect.y() - rect.height();
8017 }
8018
8019 GLuint dst_x = dstX1 > dstX0 ? dstX0 : dstX1;
8020 GLuint dst_y = dstY1 > dstY0 ? dstY0 : dstY1;
8021 GLuint dst_width = dstX1 > dstX0 ? dstX1 - dstX0 : dstX0 - dstX1;
8022 GLuint dst_height = dstY1 > dstY0 ? dstY1 - dstY0 : dstY0 - dstY1;
8023 GLfloat dst_mapping_width =
8024 static_cast<GLfloat>(src_real_width) * dst_width / src_width;
8025 GLfloat dst_mapping_height =
8026 static_cast<GLfloat>(src_real_height) * dst_height / src_height;
8027 GLfloat dst_mapping_xoffset =
8028 static_cast<GLfloat>(xoffset) * dst_width / src_width;
8029 GLfloat dst_mapping_yoffset =
8030 static_cast<GLfloat>(yoffset) * dst_height / src_height;
8031
8032 GLuint dst_mapping_x0 = (filter == GL_LINEAR) ?
yunchao 2016/10/12 15:26:14 Please see the discuss at https://github.com/Khron
Zhenyao Mo 2016/10/13 00:35:56 I think no matter what the filter is, we should on
yunchao 2016/10/13 01:50:47 According to the GLES3 spec, for NEAREST filter, "
Corentin Wallez 2016/10/13 14:35:53 I understand the spec differently, see my comment
Zhenyao Mo 2016/10/13 22:51:23 cwallez: I fail to understand you here. I think wh
Zhenyao Mo 2016/10/13 22:51:23 yunchao: I think the spec you quoted is for both L
Zhenyao Mo 2016/10/13 23:16:15 Thinking more about this: for the scaled valid low
yunchao 2016/10/14 02:52:50 I agree with you, Zhenyao. I am just waiting for t
yunchao 2016/10/14 02:52:50 Yes, the most part of this patch should be OK, I h
yunchao 2016/10/14 02:52:50 That's true.
8033 std::floor(dst_x + dst_mapping_xoffset) :
8034 std::round(dst_x + dst_mapping_xoffset);
8035 GLuint dst_mapping_y0 = (filter == GL_LINEAR) ?
8036 std::floor(dst_y + dst_mapping_yoffset) :
8037 std::round(dst_y + dst_mapping_yoffset);
8038
8039 GLuint dst_mapping_x1 = (filter == GL_LINEAR) ?
8040 std::ceil(dst_x + dst_mapping_xoffset + dst_mapping_width) :
8041 std::round(dst_x + dst_mapping_xoffset + dst_mapping_width);
8042 GLuint dst_mapping_y1 = (filter == GL_LINEAR) ?
8043 std::ceil(dst_y + dst_mapping_yoffset + dst_mapping_height) :
8044 std::round(dst_y + dst_mapping_yoffset + dst_mapping_height);
8045
8046 srcX0 = srcX0 < srcX1 ? rect.x() : rect.x() + rect.width();
8047 srcY0 = srcY0 < srcY1 ? rect.y() : rect.y() + rect.height();
8048 srcX1 = srcX0 < srcX1 ? rect.x() + rect.width() : rect.x();
8049 srcY1 = srcY0 < srcY1 ? rect.y() + rect.height() : rect.y();
8050
8051 dstX0 = dstX0 < dstX1 ? dst_mapping_x0 : dst_mapping_x1;
8052 dstY0 = dstY0 < dstY1 ? dst_mapping_y0 : dst_mapping_y1;
8053 dstX1 = dstX0 < dstX1 ? dst_mapping_x1 : dst_mapping_x0;
8054 dstY1 = dstY0 < dstY1 ? dst_mapping_y1 : dst_mapping_y0;
8055 }
8056
7993 bool enable_srgb = 8057 bool enable_srgb =
7994 (read_buffer_has_srgb || draw_buffers_has_srgb) && 8058 (read_buffer_has_srgb || draw_buffers_has_srgb) &&
7995 ((mask & GL_COLOR_BUFFER_BIT) != 0); 8059 ((mask & GL_COLOR_BUFFER_BIT) != 0);
7996 bool encode_srgb_only = 8060 bool encode_srgb_only =
7997 (draw_buffers_has_srgb && !read_buffer_has_srgb) && 8061 (draw_buffers_has_srgb && !read_buffer_has_srgb) &&
7998 ((mask & GL_COLOR_BUFFER_BIT) != 0); 8062 ((mask & GL_COLOR_BUFFER_BIT) != 0);
7999 if (!enable_srgb || 8063 if (!enable_srgb ||
8000 read_buffer_samples > 0 || 8064 read_buffer_samples > 0 ||
8001 !feature_info_->feature_flags().desktop_srgb_support || 8065 !feature_info_->feature_flags().desktop_srgb_support ||
8002 gl_version_info().IsAtLeastGL(4, 4) || 8066 gl_version_info().IsAtLeastGL(4, 4) ||
(...skipping 10541 matching lines...) Expand 10 before | Expand all | Expand 10 after
18544 } 18608 }
18545 18609
18546 // 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
18547 // 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
18548 // instead of having to edit some template or the code generator. 18612 // instead of having to edit some template or the code generator.
18549 #include "base/macros.h" 18613 #include "base/macros.h"
18550 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 18614 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18551 18615
18552 } // namespace gles2 18616 } // namespace gles2
18553 } // namespace gpu 18617 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698