Chromium Code Reviews| 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 // A class to emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
| 11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
| 12 #include <GLES3/gl3.h> | 12 #include <GLES3/gl3.h> |
| 13 #include <stddef.h> | 13 #include <stddef.h> |
| 14 #include <stdint.h> | 14 #include <stdint.h> |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 #include <map> | 16 #include <map> |
| 17 #include <set> | 17 #include <set> |
| 18 #include <sstream> | 18 #include <sstream> |
| 19 #include <string> | 19 #include <string> |
| 20 #include "base/atomic_sequence_num.h" | 20 #include "base/atomic_sequence_num.h" |
| 21 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
| 22 #include "base/numerics/safe_math.h" | |
| 22 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "base/trace_event/memory_allocator_dump.h" | 27 #include "base/trace_event/memory_allocator_dump.h" |
| 27 #include "base/trace_event/memory_dump_manager.h" | 28 #include "base/trace_event/memory_dump_manager.h" |
| 28 #include "base/trace_event/process_memory_dump.h" | 29 #include "base/trace_event/process_memory_dump.h" |
| 29 #include "base/trace_event/trace_event.h" | 30 #include "base/trace_event/trace_event.h" |
| 30 #include "gpu/command_buffer/client/buffer_tracker.h" | 31 #include "gpu/command_buffer/client/buffer_tracker.h" |
| 31 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 32 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| (...skipping 3027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3059 GLint num_rows = ComputeNumRowsThatFitInBuffer( | 3060 GLint num_rows = ComputeNumRowsThatFitInBuffer( |
| 3060 buffer_padded_row_size, unpadded_row_size, buffer->size(), height); | 3061 buffer_padded_row_size, unpadded_row_size, buffer->size(), height); |
| 3061 num_rows = std::min(num_rows, height); | 3062 num_rows = std::min(num_rows, height); |
| 3062 CopyRectToBuffer( | 3063 CopyRectToBuffer( |
| 3063 source, num_rows, unpadded_row_size, pixels_padded_row_size, | 3064 source, num_rows, unpadded_row_size, pixels_padded_row_size, |
| 3064 buffer->address(), buffer_padded_row_size); | 3065 buffer->address(), buffer_padded_row_size); |
| 3065 helper_->TexSubImage2D( | 3066 helper_->TexSubImage2D( |
| 3066 target, level, xoffset, yoffset, width, num_rows, format, type, | 3067 target, level, xoffset, yoffset, width, num_rows, format, type, |
| 3067 buffer->shm_id(), buffer->offset(), internal); | 3068 buffer->shm_id(), buffer->offset(), internal); |
| 3068 buffer->Release(); | 3069 buffer->Release(); |
| 3069 yoffset += num_rows; | 3070 base::CheckedNumeric<GLint> updated_yoffset = yoffset; |
| 3071 updated_yoffset += num_rows; | |
| 3072 if (!updated_yoffset.IsValid()) { | |
| 3073 SetGLError(GL_INVALID_VALUE, "TexSubImage2DImpl", | |
| 3074 "yoffset + height overflows"); | |
|
piman
2016/09/07 17:48:18
Here and other places: we should return early and
| |
| 3075 } | |
| 3076 yoffset = updated_yoffset.ValueOrDefault(0); | |
| 3070 source += num_rows * pixels_padded_row_size; | 3077 source += num_rows * pixels_padded_row_size; |
| 3071 height -= num_rows; | 3078 height -= num_rows; |
| 3072 } | 3079 } |
| 3073 } | 3080 } |
| 3074 | 3081 |
| 3075 void GLES2Implementation::TexSubImage3DImpl(GLenum target, | 3082 void GLES2Implementation::TexSubImage3DImpl(GLenum target, |
| 3076 GLint level, | 3083 GLint level, |
| 3077 GLint xoffset, | 3084 GLint xoffset, |
| 3078 GLint yoffset, | 3085 GLint yoffset, |
| 3079 GLsizei zoffset, | 3086 GLsizei zoffset, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3150 CopyRectToBuffer( | 3157 CopyRectToBuffer( |
| 3151 source + ii * image_size_src, my_height, unpadded_row_size, | 3158 source + ii * image_size_src, my_height, unpadded_row_size, |
| 3152 pixels_padded_row_size, buffer_pointer + ii * image_size_dst, | 3159 pixels_padded_row_size, buffer_pointer + ii * image_size_dst, |
| 3153 buffer_padded_row_size); | 3160 buffer_padded_row_size); |
| 3154 } | 3161 } |
| 3155 } else { | 3162 } else { |
| 3156 CopyRectToBuffer( | 3163 CopyRectToBuffer( |
| 3157 source, my_height, unpadded_row_size, pixels_padded_row_size, | 3164 source, my_height, unpadded_row_size, pixels_padded_row_size, |
| 3158 buffer->address(), buffer_padded_row_size); | 3165 buffer->address(), buffer_padded_row_size); |
| 3159 } | 3166 } |
| 3167 base::CheckedNumeric<GLint> updated_yoffset = yoffset; | |
| 3168 updated_yoffset += row_index; | |
| 3169 if (!updated_yoffset.IsValid()) { | |
| 3170 SetGLError(GL_INVALID_VALUE, "TexSubImage3DImpl", | |
| 3171 "yoffset + row_index overflows"); | |
|
Zhenyao Mo
2016/09/07 17:39:23
row_index and depth_index below are internal imple
| |
| 3172 } | |
| 3173 base::CheckedNumeric<GLint> updated_zoffset = zoffset; | |
| 3174 updated_zoffset += depth_index; | |
| 3175 if (!updated_zoffset.IsValid()) { | |
| 3176 SetGLError(GL_INVALID_VALUE, "TexSubImage3DImpl", | |
| 3177 "zoffset + depth_index overflows"); | |
| 3178 } | |
| 3160 helper_->TexSubImage3D( | 3179 helper_->TexSubImage3D( |
| 3161 target, level, xoffset, yoffset + row_index, zoffset + depth_index, | 3180 target, level, xoffset, updated_yoffset.ValueOrDefault(0), |
| 3162 width, my_height, my_depth, | 3181 updated_zoffset.ValueOrDefault(0), width, my_height, my_depth, |
| 3163 format, type, buffer->shm_id(), buffer->offset(), internal); | 3182 format, type, buffer->shm_id(), buffer->offset(), internal); |
| 3164 buffer->Release(); | 3183 buffer->Release(); |
| 3165 | 3184 |
| 3166 total_rows -= num_rows; | 3185 total_rows -= num_rows; |
| 3167 if (total_rows > 0) { | 3186 if (total_rows > 0) { |
| 3168 GLint num_image_paddings; | 3187 GLint num_image_paddings; |
| 3169 if (num_images > 0) { | 3188 if (num_images > 0) { |
| 3170 DCHECK_EQ(row_index, 0); | 3189 DCHECK_EQ(row_index, 0); |
| 3171 depth_index += num_images; | 3190 depth_index += num_images; |
| 3172 num_image_paddings = num_images; | 3191 num_image_paddings = num_images; |
| (...skipping 3722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6895 cached_extensions_.clear(); | 6914 cached_extensions_.clear(); |
| 6896 } | 6915 } |
| 6897 | 6916 |
| 6898 // Include the auto-generated part of this file. We split this because it means | 6917 // Include the auto-generated part of this file. We split this because it means |
| 6899 // we can easily edit the non-auto generated parts right here in this file | 6918 // we can easily edit the non-auto generated parts right here in this file |
| 6900 // instead of having to edit some template or the code generator. | 6919 // instead of having to edit some template or the code generator. |
| 6901 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 6920 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
| 6902 | 6921 |
| 6903 } // namespace gles2 | 6922 } // namespace gles2 |
| 6904 } // namespace gpu | 6923 } // namespace gpu |
| OLD | NEW |