| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 : helper_(helper), | 536 : helper_(helper), |
| 537 transfer_buffer_( | 537 transfer_buffer_( |
| 538 kStartingOffset, | 538 kStartingOffset, |
| 539 transfer_buffer_size - kStartingOffset, | 539 transfer_buffer_size - kStartingOffset, |
| 540 helper, | 540 helper, |
| 541 static_cast<char*>(transfer_buffer) + kStartingOffset), | 541 static_cast<char*>(transfer_buffer) + kStartingOffset), |
| 542 transfer_buffer_id_(transfer_buffer_id), | 542 transfer_buffer_id_(transfer_buffer_id), |
| 543 pack_alignment_(4), | 543 pack_alignment_(4), |
| 544 unpack_alignment_(4), | 544 unpack_alignment_(4), |
| 545 unpack_flip_y_(false), | 545 unpack_flip_y_(false), |
| 546 pack_flip_y_(false), |
| 546 active_texture_unit_(0), | 547 active_texture_unit_(0), |
| 547 bound_framebuffer_(0), | 548 bound_framebuffer_(0), |
| 548 bound_renderbuffer_(0), | 549 bound_renderbuffer_(0), |
| 549 bound_array_buffer_id_(0), | 550 bound_array_buffer_id_(0), |
| 550 bound_element_array_buffer_id_(0), | 551 bound_element_array_buffer_id_(0), |
| 551 client_side_array_id_(0), | 552 client_side_array_id_(0), |
| 552 client_side_element_array_id_(0), | 553 client_side_element_array_id_(0), |
| 553 error_bits_(0), | 554 error_bits_(0), |
| 554 debug_(false), | 555 debug_(false), |
| 555 sharing_resources_(share_resources), | 556 sharing_resources_(share_resources), |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 switch (pname) { | 1215 switch (pname) { |
| 1215 case GL_PACK_ALIGNMENT: | 1216 case GL_PACK_ALIGNMENT: |
| 1216 pack_alignment_ = param; | 1217 pack_alignment_ = param; |
| 1217 break; | 1218 break; |
| 1218 case GL_UNPACK_ALIGNMENT: | 1219 case GL_UNPACK_ALIGNMENT: |
| 1219 unpack_alignment_ = param; | 1220 unpack_alignment_ = param; |
| 1220 break; | 1221 break; |
| 1221 case GL_UNPACK_FLIP_Y_CHROMIUM: | 1222 case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 1222 unpack_flip_y_ = (param != 0); | 1223 unpack_flip_y_ = (param != 0); |
| 1223 return; | 1224 return; |
| 1225 case GL_PACK_FLIP_Y_ANGLE: |
| 1226 pack_flip_y_ = (param != 0); |
| 1227 break; |
| 1224 default: | 1228 default: |
| 1225 break; | 1229 break; |
| 1226 } | 1230 } |
| 1227 helper_->PixelStorei(pname, param); | 1231 helper_->PixelStorei(pname, param); |
| 1228 } | 1232 } |
| 1229 | 1233 |
| 1230 | 1234 |
| 1231 void GLES2Implementation::VertexAttribPointer( | 1235 void GLES2Implementation::VertexAttribPointer( |
| 1232 GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, | 1236 GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, |
| 1233 const void* ptr) { | 1237 const void* ptr) { |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 GLsizeiptr part_size = | 1972 GLsizeiptr part_size = |
| 1969 unpadded_row_size + padded_row_size * (num_rows - 1); | 1973 unpadded_row_size + padded_row_size * (num_rows - 1); |
| 1970 void* buffer = transfer_buffer_.Alloc(part_size); | 1974 void* buffer = transfer_buffer_.Alloc(part_size); |
| 1971 *result = 0; // mark as failed. | 1975 *result = 0; // mark as failed. |
| 1972 helper_->ReadPixels( | 1976 helper_->ReadPixels( |
| 1973 xoffset, yoffset, width, num_rows, format, type, | 1977 xoffset, yoffset, width, num_rows, format, type, |
| 1974 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), | 1978 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), |
| 1975 result_shm_id(), result_shm_offset()); | 1979 result_shm_id(), result_shm_offset()); |
| 1976 WaitForCmd(); | 1980 WaitForCmd(); |
| 1977 if (*result != 0) { | 1981 if (*result != 0) { |
| 1982 // when doing a y-flip we have to iterate through top-to-bottom chunks |
| 1983 // of the dst. The service side handles reversing the rows within a |
| 1984 // chunk. |
| 1985 int8* rows_dst; |
| 1986 if (pack_flip_y_) { |
| 1987 rows_dst = dest + (height - num_rows) * padded_row_size; |
| 1988 } else { |
| 1989 rows_dst = dest; |
| 1990 } |
| 1978 // We have to copy 1 row at a time to avoid writing pad bytes. | 1991 // We have to copy 1 row at a time to avoid writing pad bytes. |
| 1979 const int8* src = static_cast<const int8*>(buffer); | 1992 const int8* src = static_cast<const int8*>(buffer); |
| 1980 for (GLint yy = 0; yy < num_rows; ++yy) { | 1993 for (GLint yy = 0; yy < num_rows; ++yy) { |
| 1981 memcpy(dest, src, unpadded_row_size); | 1994 memcpy(rows_dst, src, unpadded_row_size); |
| 1982 dest += padded_row_size; | 1995 rows_dst += padded_row_size; |
| 1983 src += padded_row_size; | 1996 src += padded_row_size; |
| 1984 } | 1997 } |
| 1998 if (!pack_flip_y_) { |
| 1999 dest = rows_dst; |
| 2000 } |
| 1985 } | 2001 } |
| 1986 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | 2002 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
| 1987 // If it was not marked as successful exit. | 2003 // If it was not marked as successful exit. |
| 1988 if (*result == 0) { | 2004 if (*result == 0) { |
| 1989 return; | 2005 return; |
| 1990 } | 2006 } |
| 1991 yoffset += num_rows; | 2007 yoffset += num_rows; |
| 1992 height -= num_rows; | 2008 height -= num_rows; |
| 1993 } | 2009 } |
| 1994 } else { | 2010 } else { |
| 1995 // Transfer by sub rows. Because GL has no maximum texture dimensions. | 2011 // Transfer by sub rows. Because GL has no maximum texture dimensions. |
| 1996 GLES2Util::ComputeImageDataSize( | 2012 GLES2Util::ComputeImageDataSize( |
| 1997 1, 1, format, type, pack_alignment_, &temp_size); | 2013 1, 1, format, type, pack_alignment_, &temp_size); |
| 1998 GLsizeiptr element_size = temp_size; | 2014 GLsizeiptr element_size = temp_size; |
| 1999 max_size -= max_size % element_size; | 2015 max_size -= max_size % element_size; |
| 2000 GLint max_sub_row_pixels = max_size / element_size; | 2016 GLint max_sub_row_pixels = max_size / element_size; |
| 2017 if (pack_flip_y_) { |
| 2018 // start at the last row when flipping y. |
| 2019 dest = dest + (height - 1) * padded_row_size; |
| 2020 } |
| 2001 for (; height; --height) { | 2021 for (; height; --height) { |
| 2002 GLint temp_width = width; | 2022 GLint temp_width = width; |
| 2003 GLint temp_xoffset = xoffset; | 2023 GLint temp_xoffset = xoffset; |
| 2004 int8* row_dest = dest; | 2024 int8* row_dest = dest; |
| 2005 while (temp_width) { | 2025 while (temp_width) { |
| 2006 GLint num_pixels = std::min(width, max_sub_row_pixels); | 2026 GLint num_pixels = std::min(width, max_sub_row_pixels); |
| 2007 GLsizeiptr part_size = num_pixels * element_size; | 2027 GLsizeiptr part_size = num_pixels * element_size; |
| 2008 void* buffer = transfer_buffer_.Alloc(part_size); | 2028 void* buffer = transfer_buffer_.Alloc(part_size); |
| 2009 *result = 0; // mark as failed. | 2029 *result = 0; // mark as failed. |
| 2010 helper_->ReadPixels( | 2030 helper_->ReadPixels( |
| 2011 temp_xoffset, yoffset, temp_width, 1, format, type, | 2031 temp_xoffset, yoffset, temp_width, 1, format, type, |
| 2012 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), | 2032 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), |
| 2013 result_shm_id(), result_shm_offset()); | 2033 result_shm_id(), result_shm_offset()); |
| 2014 WaitForCmd(); | 2034 WaitForCmd(); |
| 2015 if (*result != 0) { | 2035 if (*result != 0) { |
| 2016 memcpy(row_dest, buffer, part_size); | 2036 memcpy(row_dest, buffer, part_size); |
| 2017 } | 2037 } |
| 2018 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | 2038 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
| 2019 // If it was not marked as successful exit. | 2039 // If it was not marked as successful exit. |
| 2020 if (*result == 0) { | 2040 if (*result == 0) { |
| 2021 return; | 2041 return; |
| 2022 } | 2042 } |
| 2023 row_dest += part_size; | 2043 row_dest += part_size; |
| 2024 temp_xoffset += num_pixels; | 2044 temp_xoffset += num_pixels; |
| 2025 temp_width -= num_pixels; | 2045 temp_width -= num_pixels; |
| 2026 } | 2046 } |
| 2027 ++yoffset; | 2047 ++yoffset; |
| 2028 dest += padded_row_size; | 2048 dest += pack_flip_y_ ? -padded_row_size : padded_row_size; |
| 2029 } | 2049 } |
| 2030 } | 2050 } |
| 2031 } | 2051 } |
| 2032 | 2052 |
| 2033 void GLES2Implementation::ActiveTexture(GLenum texture) { | 2053 void GLES2Implementation::ActiveTexture(GLenum texture) { |
| 2034 GPU_CLIENT_LOG("[" << this << "] glActiveTexture(" | 2054 GPU_CLIENT_LOG("[" << this << "] glActiveTexture(" |
| 2035 << GLES2Util::GetStringEnum(texture) << ")"); | 2055 << GLES2Util::GetStringEnum(texture) << ")"); |
| 2036 GLuint texture_index = texture - GL_TEXTURE0; | 2056 GLuint texture_index = texture - GL_TEXTURE0; |
| 2037 if (texture_index >= | 2057 if (texture_index >= |
| 2038 static_cast<GLuint>(gl_state_.max_combined_texture_image_units)) { | 2058 static_cast<GLuint>(gl_state_.max_combined_texture_image_units)) { |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 helper_->PostSubBufferCHROMIUM(x, y, width, height); | 2680 helper_->PostSubBufferCHROMIUM(x, y, width, height); |
| 2661 helper_->CommandBufferHelper::Flush(); | 2681 helper_->CommandBufferHelper::Flush(); |
| 2662 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) { | 2682 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) { |
| 2663 helper_->WaitForToken(swap_buffers_tokens_.front()); | 2683 helper_->WaitForToken(swap_buffers_tokens_.front()); |
| 2664 swap_buffers_tokens_.pop(); | 2684 swap_buffers_tokens_.pop(); |
| 2665 } | 2685 } |
| 2666 } | 2686 } |
| 2667 | 2687 |
| 2668 } // namespace gles2 | 2688 } // namespace gles2 |
| 2669 } // namespace gpu | 2689 } // namespace gpu |
| OLD | NEW |