| 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 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 width, 2, format, type, unpack_alignment_, &temp_size)) { | 1562 width, 2, format, type, unpack_alignment_, &temp_size)) { |
| 1563 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large"); | 1563 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large"); |
| 1564 return; | 1564 return; |
| 1565 } | 1565 } |
| 1566 GLsizeiptr padded_row_size = temp_size - unpadded_row_size; | 1566 GLsizeiptr padded_row_size = temp_size - unpadded_row_size; |
| 1567 if (padded_row_size < 0 || unpadded_row_size < 0) { | 1567 if (padded_row_size < 0 || unpadded_row_size < 0) { |
| 1568 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large"); | 1568 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large"); |
| 1569 return; | 1569 return; |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 GLsizei original_height = height; | 1572 GLint original_yoffset = yoffset; |
| 1573 if (padded_row_size <= max_size) { | 1573 if (padded_row_size <= max_size) { |
| 1574 // Transfer by rows. | 1574 // Transfer by rows. |
| 1575 GLint max_rows = max_size / std::max(padded_row_size, | 1575 GLint max_rows = max_size / std::max(padded_row_size, |
| 1576 static_cast<GLsizeiptr>(1)); | 1576 static_cast<GLsizeiptr>(1)); |
| 1577 while (height) { | 1577 while (height) { |
| 1578 GLint num_rows = std::min(height, max_rows); | 1578 GLint num_rows = std::min(height, max_rows); |
| 1579 GLsizeiptr part_size = | 1579 GLsizeiptr part_size = |
| 1580 (num_rows - 1) * padded_row_size + unpadded_row_size; | 1580 (num_rows - 1) * padded_row_size + unpadded_row_size; |
| 1581 void* buffer = transfer_buffer_.Alloc(part_size); | 1581 void* buffer = transfer_buffer_.Alloc(part_size); |
| 1582 GLint y; | 1582 GLint y; |
| 1583 if (unpack_flip_y_) { | 1583 if (unpack_flip_y_) { |
| 1584 CopyRectToBufferFlipped( | 1584 CopyRectToBufferFlipped( |
| 1585 source, width, num_rows, format, type, buffer); | 1585 source, width, num_rows, format, type, buffer); |
| 1586 // GPU_DCHECK(copy_success); // can't check this because bot fails! | 1586 // GPU_DCHECK(copy_success); // can't check this because bot fails! |
| 1587 y = original_height - yoffset - num_rows; | 1587 y = original_yoffset + height - num_rows; |
| 1588 } else { | 1588 } else { |
| 1589 memcpy(buffer, source, part_size); | 1589 memcpy(buffer, source, part_size); |
| 1590 y = yoffset; | 1590 y = yoffset; |
| 1591 } | 1591 } |
| 1592 helper_->TexSubImage2D( | 1592 helper_->TexSubImage2D( |
| 1593 target, level, xoffset, y, width, num_rows, format, type, | 1593 target, level, xoffset, y, width, num_rows, format, type, |
| 1594 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), internal); | 1594 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), internal); |
| 1595 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | 1595 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
| 1596 yoffset += num_rows; | 1596 yoffset += num_rows; |
| 1597 source += num_rows * padded_row_size; | 1597 source += num_rows * padded_row_size; |
| 1598 height -= num_rows; | 1598 height -= num_rows; |
| 1599 } | 1599 } |
| 1600 } else { | 1600 } else { |
| 1601 // Transfer by sub rows. Because GL has no maximum texture dimensions. | 1601 // Transfer by sub rows. Because GL has no maximum texture dimensions. |
| 1602 uint32 temp; | 1602 uint32 temp; |
| 1603 GLES2Util::ComputeImageDataSize( | 1603 GLES2Util::ComputeImageDataSize( |
| 1604 1, 1, format, type, unpack_alignment_, &temp); | 1604 1, 1, format, type, unpack_alignment_, &temp); |
| 1605 GLsizeiptr element_size = temp; | 1605 GLsizeiptr element_size = temp; |
| 1606 max_size -= max_size % element_size; | 1606 max_size -= max_size % element_size; |
| 1607 GLint max_sub_row_pixels = max_size / element_size; | 1607 GLint max_sub_row_pixels = max_size / element_size; |
| 1608 for (; height; --height) { | 1608 for (; height; --height) { |
| 1609 GLint temp_width = width; | 1609 GLint temp_width = width; |
| 1610 GLint temp_xoffset = xoffset; | 1610 GLint temp_xoffset = xoffset; |
| 1611 const int8* row_source = source; | 1611 const int8* row_source = source; |
| 1612 while (temp_width) { | 1612 while (temp_width) { |
| 1613 GLint num_pixels = std::min(width, max_sub_row_pixels); | 1613 GLint num_pixels = std::min(width, max_sub_row_pixels); |
| 1614 GLsizeiptr part_size = num_pixels * element_size; | 1614 GLsizeiptr part_size = num_pixels * element_size; |
| 1615 void* buffer = transfer_buffer_.Alloc(part_size); | 1615 void* buffer = transfer_buffer_.Alloc(part_size); |
| 1616 memcpy(buffer, row_source, part_size); | 1616 memcpy(buffer, row_source, part_size); |
| 1617 GLint y = unpack_flip_y_ ? (original_height - yoffset - 1) : yoffset; | 1617 GLint y = unpack_flip_y_ ? (original_yoffset + height - 1) : yoffset; |
| 1618 helper_->TexSubImage2D( | 1618 helper_->TexSubImage2D( |
| 1619 target, level, temp_xoffset, y, num_pixels, 1, format, type, | 1619 target, level, temp_xoffset, y, num_pixels, 1, format, type, |
| 1620 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), internal); | 1620 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), internal); |
| 1621 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | 1621 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
| 1622 row_source += part_size; | 1622 row_source += part_size; |
| 1623 temp_xoffset += num_pixels; | 1623 temp_xoffset += num_pixels; |
| 1624 temp_width -= num_pixels; | 1624 temp_width -= num_pixels; |
| 1625 } | 1625 } |
| 1626 ++yoffset; | 1626 ++yoffset; |
| 1627 source += padded_row_size; | 1627 source += padded_row_size; |
| (...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 helper_->PostSubBufferCHROMIUM(x, y, width, height); | 2660 helper_->PostSubBufferCHROMIUM(x, y, width, height); |
| 2661 helper_->CommandBufferHelper::Flush(); | 2661 helper_->CommandBufferHelper::Flush(); |
| 2662 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) { | 2662 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) { |
| 2663 helper_->WaitForToken(swap_buffers_tokens_.front()); | 2663 helper_->WaitForToken(swap_buffers_tokens_.front()); |
| 2664 swap_buffers_tokens_.pop(); | 2664 swap_buffers_tokens_.pop(); |
| 2665 } | 2665 } |
| 2666 } | 2666 } |
| 2667 | 2667 |
| 2668 } // namespace gles2 | 2668 } // namespace gles2 |
| 2669 } // namespace gpu | 2669 } // namespace gpu |
| OLD | NEW |