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 "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <queue> | 11 #include <queue> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 #include <string.h> | 15 #include <string.h> |
| 16 #include <GLES2/gl2ext.h> | 16 #include <GLES2/gl2ext.h> |
| 17 #include "../client/buffer_tracker.h" | |
| 17 #include "../client/mapped_memory.h" | 18 #include "../client/mapped_memory.h" |
| 18 #include "../client/program_info_manager.h" | 19 #include "../client/program_info_manager.h" |
| 19 #include "../client/query_tracker.h" | 20 #include "../client/query_tracker.h" |
| 20 #include "../client/transfer_buffer.h" | 21 #include "../client/transfer_buffer.h" |
| 21 #include "../common/gles2_cmd_utils.h" | 22 #include "../common/gles2_cmd_utils.h" |
| 22 #include "../common/trace_event.h" | 23 #include "../common/trace_event.h" |
| 23 | 24 |
| 24 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 25 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
| 25 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS | 26 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS |
| 26 #endif | 27 #endif |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 unpack_row_length_(0), | 434 unpack_row_length_(0), |
| 434 unpack_skip_rows_(0), | 435 unpack_skip_rows_(0), |
| 435 unpack_skip_pixels_(0), | 436 unpack_skip_pixels_(0), |
| 436 pack_reverse_row_order_(false), | 437 pack_reverse_row_order_(false), |
| 437 active_texture_unit_(0), | 438 active_texture_unit_(0), |
| 438 bound_framebuffer_(0), | 439 bound_framebuffer_(0), |
| 439 bound_renderbuffer_(0), | 440 bound_renderbuffer_(0), |
| 440 current_program_(0), | 441 current_program_(0), |
| 441 bound_array_buffer_id_(0), | 442 bound_array_buffer_id_(0), |
| 442 bound_element_array_buffer_id_(0), | 443 bound_element_array_buffer_id_(0), |
| 444 bound_pixel_unpack_transfer_buffer_id_(0), | |
| 443 client_side_array_id_(0), | 445 client_side_array_id_(0), |
| 444 client_side_element_array_id_(0), | 446 client_side_element_array_id_(0), |
| 445 bound_vertex_array_id_(0), | 447 bound_vertex_array_id_(0), |
| 446 error_bits_(0), | 448 error_bits_(0), |
| 447 debug_(false), | 449 debug_(false), |
| 448 use_count_(0), | 450 use_count_(0), |
| 449 current_query_(NULL), | 451 current_query_(NULL), |
| 450 error_message_callback_(NULL) { | 452 error_message_callback_(NULL) { |
| 451 GPU_DCHECK(helper); | 453 GPU_DCHECK(helper); |
| 452 GPU_DCHECK(transfer_buffer); | 454 GPU_DCHECK(transfer_buffer); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 util_.set_num_compressed_texture_formats( | 512 util_.set_num_compressed_texture_formats( |
| 511 static_state_.int_state.num_compressed_texture_formats); | 513 static_state_.int_state.num_compressed_texture_formats); |
| 512 util_.set_num_shader_binary_formats( | 514 util_.set_num_shader_binary_formats( |
| 513 static_state_.int_state.num_shader_binary_formats); | 515 static_state_.int_state.num_shader_binary_formats); |
| 514 | 516 |
| 515 texture_units_.reset( | 517 texture_units_.reset( |
| 516 new TextureUnit[ | 518 new TextureUnit[ |
| 517 static_state_.int_state.max_combined_texture_image_units]); | 519 static_state_.int_state.max_combined_texture_image_units]); |
| 518 | 520 |
| 519 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); | 521 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); |
| 522 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); | |
| 520 | 523 |
| 521 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 524 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
| 522 GetIdHandler(id_namespaces::kBuffers)->MakeIds( | 525 GetIdHandler(id_namespaces::kBuffers)->MakeIds( |
| 523 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); | 526 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); |
| 524 | 527 |
| 525 client_side_buffer_helper_.reset(new ClientSideBufferHelper( | 528 client_side_buffer_helper_.reset(new ClientSideBufferHelper( |
| 526 static_state_.int_state.max_vertex_attribs, | 529 static_state_.int_state.max_vertex_attribs, |
| 527 reserved_ids_[0], | 530 reserved_ids_[0], |
| 528 reserved_ids_[1])); | 531 reserved_ids_[1])); |
| 529 #endif | 532 #endif |
| 530 | 533 |
| 531 return true; | 534 return true; |
| 532 } | 535 } |
| 533 | 536 |
| 534 GLES2Implementation::~GLES2Implementation() { | 537 GLES2Implementation::~GLES2Implementation() { |
| 535 // Make sure the queries are finished otherwise we'll delete the | 538 // Make sure the queries are finished otherwise we'll delete the |
| 536 // shared memory (mapped_memory_) which will free the memory used | 539 // shared memory (mapped_memory_) which will free the memory used |
| 537 // by the queries. The GPU process when validating that memory is still | 540 // by the queries. The GPU process when validating that memory is still |
| 538 // shared will fail and abort (ie, it will stop running). | 541 // shared will fail and abort (ie, it will stop running). |
| 539 Finish(); | 542 Finish(); |
| 540 query_tracker_.reset(); | 543 query_tracker_.reset(); |
| 541 | 544 |
| 542 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 545 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
| 543 DeleteBuffers(arraysize(reserved_ids_), &reserved_ids_[0]); | 546 DeleteBuffers(arraysize(reserved_ids_), &reserved_ids_[0]); |
| 544 #endif | 547 #endif |
| 548 buffer_tracker_.reset(); | |
| 549 | |
| 545 // The share group needs to be able to use a command buffer to talk | 550 // The share group needs to be able to use a command buffer to talk |
| 546 // to service if it's destroyed so set one for it then release the reference. | 551 // to service if it's destroyed so set one for it then release the reference. |
| 547 // If it's destroyed it will use this GLES2Implemenation. | 552 // If it's destroyed it will use this GLES2Implemenation. |
| 548 share_group_->SetGLES2ImplementationForDestruction(this); | 553 share_group_->SetGLES2ImplementationForDestruction(this); |
| 549 share_group_ = NULL; | 554 share_group_ = NULL; |
| 550 // Make sure the commands make it the service. | 555 // Make sure the commands make it the service. |
| 551 Finish(); | 556 Finish(); |
| 552 } | 557 } |
| 553 | 558 |
| 554 GLES2CmdHelper* GLES2Implementation::helper() const { | 559 GLES2CmdHelper* GLES2Implementation::helper() const { |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 *params = bound_array_buffer_id_; | 901 *params = bound_array_buffer_id_; |
| 897 return true; | 902 return true; |
| 898 } | 903 } |
| 899 return false; | 904 return false; |
| 900 case GL_ELEMENT_ARRAY_BUFFER_BINDING: | 905 case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 901 if (share_group_->bind_generates_resource()) { | 906 if (share_group_->bind_generates_resource()) { |
| 902 *params = bound_element_array_buffer_id_; | 907 *params = bound_element_array_buffer_id_; |
| 903 return true; | 908 return true; |
| 904 } | 909 } |
| 905 return false; | 910 return false; |
| 911 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_BINDING_CHROMIUM: | |
| 912 if (share_group_->bind_generates_resource()) { | |
|
greggman
2012/11/19 04:50:14
don't need this if. As this is a client side imple
reveman
2012/11/20 16:49:30
Done.
| |
| 913 *params = bound_pixel_unpack_transfer_buffer_id_; | |
| 914 return true; | |
| 915 } | |
| 916 return false; | |
| 906 case GL_ACTIVE_TEXTURE: | 917 case GL_ACTIVE_TEXTURE: |
| 907 *params = active_texture_unit_ + GL_TEXTURE0; | 918 *params = active_texture_unit_ + GL_TEXTURE0; |
| 908 return true; | 919 return true; |
| 909 case GL_TEXTURE_BINDING_2D: | 920 case GL_TEXTURE_BINDING_2D: |
| 910 if (share_group_->bind_generates_resource()) { | 921 if (share_group_->bind_generates_resource()) { |
| 911 *params = texture_units_[active_texture_unit_].bound_texture_2d; | 922 *params = texture_units_[active_texture_unit_].bound_texture_2d; |
| 912 return true; | 923 return true; |
| 913 } | 924 } |
| 914 return false; | 925 return false; |
| 915 case GL_TEXTURE_BINDING_CUBE_MAP: | 926 case GL_TEXTURE_BINDING_CUBE_MAP: |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1201 void GLES2Implementation::BindAttribLocation( | 1212 void GLES2Implementation::BindAttribLocation( |
| 1202 GLuint program, GLuint index, const char* name) { | 1213 GLuint program, GLuint index, const char* name) { |
| 1203 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1214 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 1204 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glBindAttribLocation(" | 1215 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glBindAttribLocation(" |
| 1205 << program << ", " << index << ", " << name << ")"); | 1216 << program << ", " << index << ", " << name << ")"); |
| 1206 SetBucketAsString(kResultBucketId, name); | 1217 SetBucketAsString(kResultBucketId, name); |
| 1207 helper_->BindAttribLocationBucket(program, index, kResultBucketId); | 1218 helper_->BindAttribLocationBucket(program, index, kResultBucketId); |
| 1208 helper_->SetBucketSize(kResultBucketId, 0); | 1219 helper_->SetBucketSize(kResultBucketId, 0); |
| 1209 } | 1220 } |
| 1210 | 1221 |
| 1222 void GLES2Implementation::BindBuffer(GLenum target, GLuint buffer) { | |
| 1223 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
| 1224 GPU_CLIENT_LOG("[" << this << "] glBindBuffer(" << | |
| 1225 GLES2Util::GetStringBufferTarget(target) << ", " << buffer << ")"); | |
| 1226 if (IsBufferReservedId(buffer)) { | |
| 1227 SetGLError(GL_INVALID_OPERATION, "BindBuffer", "buffer reserved id"); | |
| 1228 return; | |
| 1229 } | |
| 1230 BindBufferHelper(target, buffer); | |
| 1231 if (target != GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) | |
|
greggman
2012/11/19 04:50:14
this is redundant. You already set this in BindBuf
reveman
2012/11/20 16:49:30
Done.
| |
| 1232 helper_->BindBuffer(target, buffer); | |
| 1233 } | |
| 1234 | |
| 1211 void GLES2Implementation::BindUniformLocationCHROMIUM( | 1235 void GLES2Implementation::BindUniformLocationCHROMIUM( |
| 1212 GLuint program, GLint location, const char* name) { | 1236 GLuint program, GLint location, const char* name) { |
| 1213 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1237 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 1214 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glBindUniformLocationCHROMIUM(" | 1238 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glBindUniformLocationCHROMIUM(" |
| 1215 << program << ", " << location << ", " << name << ")"); | 1239 << program << ", " << location << ", " << name << ")"); |
| 1216 SetBucketAsString(kResultBucketId, name); | 1240 SetBucketAsString(kResultBucketId, name); |
| 1217 helper_->BindUniformLocationCHROMIUMBucket( | 1241 helper_->BindUniformLocationCHROMIUMBucket( |
| 1218 program, location, kResultBucketId); | 1242 program, location, kResultBucketId); |
| 1219 helper_->SetBucketSize(kResultBucketId, 0); | 1243 helper_->SetBucketSize(kResultBucketId, 0); |
| 1220 } | 1244 } |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1560 GLenum target, GLsizeiptr size, const void* data, GLenum usage) { | 1584 GLenum target, GLsizeiptr size, const void* data, GLenum usage) { |
| 1561 if (size == 0) { | 1585 if (size == 0) { |
| 1562 return; | 1586 return; |
| 1563 } | 1587 } |
| 1564 | 1588 |
| 1565 if (size < 0) { | 1589 if (size < 0) { |
| 1566 SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); | 1590 SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); |
| 1567 return; | 1591 return; |
| 1568 } | 1592 } |
| 1569 | 1593 |
| 1594 if (target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) { | |
| 1595 GLuint buffer_id = bound_pixel_unpack_transfer_buffer_id_; | |
| 1596 if (!buffer_id) { | |
| 1597 SetGLError(GL_INVALID_VALUE, "glBufferData", "unknown buffer"); | |
| 1598 return; | |
| 1599 } | |
| 1600 | |
| 1601 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); | |
| 1602 if (buffer) { | |
| 1603 // Free buffer memory, pending the passage of a token. | |
| 1604 buffer_tracker_->FreePendingToken(buffer, helper_->InsertToken()); | |
| 1605 | |
| 1606 // Remove old buffer. | |
| 1607 buffer_tracker_->RemoveBuffer(buffer_id); | |
| 1608 } | |
| 1609 | |
| 1610 // Create new buffer. | |
| 1611 buffer = buffer_tracker_->CreateBuffer(buffer_id, size); | |
| 1612 GPU_DCHECK(buffer); | |
| 1613 if (data) | |
| 1614 memcpy(buffer->address(), data, size); | |
| 1615 return; | |
| 1616 } | |
| 1617 | |
| 1570 // If there is no data just send BufferData | 1618 // If there is no data just send BufferData |
| 1571 if (!data) { | 1619 if (!data) { |
| 1572 helper_->BufferData(target, size, 0, 0, usage); | 1620 helper_->BufferData(target, size, 0, 0, usage); |
| 1573 return; | 1621 return; |
| 1574 } | 1622 } |
| 1575 | 1623 |
| 1576 // See if we can send all at once. | 1624 // See if we can send all at once. |
| 1577 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); | 1625 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); |
| 1578 if (!buffer.valid()) { | 1626 if (!buffer.valid()) { |
| 1579 return; | 1627 return; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1608 | 1656 |
| 1609 void GLES2Implementation::BufferSubDataHelper( | 1657 void GLES2Implementation::BufferSubDataHelper( |
| 1610 GLenum target, GLintptr offset, GLsizeiptr size, const void* data) { | 1658 GLenum target, GLintptr offset, GLsizeiptr size, const void* data) { |
| 1611 if (size == 0) { | 1659 if (size == 0) { |
| 1612 return; | 1660 return; |
| 1613 } | 1661 } |
| 1614 | 1662 |
| 1615 if (size < 0) { | 1663 if (size < 0) { |
| 1616 SetGLError(GL_INVALID_VALUE, "glBufferSubData", "size < 0"); | 1664 SetGLError(GL_INVALID_VALUE, "glBufferSubData", "size < 0"); |
| 1617 return; | 1665 return; |
| 1618 } | 1666 } |
|
greggman
2012/11/19 04:50:14
should BufferSubData also work?
reveman
2012/11/20 16:49:30
Done. We don't need it but I feel like it should b
| |
| 1619 | 1667 |
| 1620 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); | 1668 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); |
| 1621 BufferSubDataHelperImpl(target, offset, size, data, &buffer); | 1669 BufferSubDataHelperImpl(target, offset, size, data, &buffer); |
| 1622 } | 1670 } |
| 1623 | 1671 |
| 1624 void GLES2Implementation::BufferSubDataHelperImpl( | 1672 void GLES2Implementation::BufferSubDataHelperImpl( |
| 1625 GLenum target, GLintptr offset, GLsizeiptr size, const void* data, | 1673 GLenum target, GLintptr offset, GLsizeiptr size, const void* data, |
| 1626 ScopedTransferBufferPtr* buffer) { | 1674 ScopedTransferBufferPtr* buffer) { |
| 1627 GPU_DCHECK(buffer); | 1675 GPU_DCHECK(buffer); |
| 1628 GPU_DCHECK_GT(size, 0); | 1676 GPU_DCHECK_GT(size, 0); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1666 << width << ", " << height << ", " << border << ", " | 1714 << width << ", " << height << ", " << border << ", " |
| 1667 << image_size << ", " | 1715 << image_size << ", " |
| 1668 << static_cast<const void*>(data) << ")"); | 1716 << static_cast<const void*>(data) << ")"); |
| 1669 if (width < 0 || height < 0 || level < 0) { | 1717 if (width < 0 || height < 0 || level < 0) { |
| 1670 SetGLError(GL_INVALID_VALUE, "glCompressedTexImage2D", "dimension < 0"); | 1718 SetGLError(GL_INVALID_VALUE, "glCompressedTexImage2D", "dimension < 0"); |
| 1671 return; | 1719 return; |
| 1672 } | 1720 } |
| 1673 if (height == 0 || width == 0) { | 1721 if (height == 0 || width == 0) { |
| 1674 return; | 1722 return; |
| 1675 } | 1723 } |
| 1724 // If there's a pixel unpack buffer bound use it when issuing | |
| 1725 // CompressedTexImage2D. | |
| 1726 if (bound_pixel_unpack_transfer_buffer_id_) { | |
| 1727 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer( | |
| 1728 bound_pixel_unpack_transfer_buffer_id_); | |
| 1729 if (!buffer) { | |
| 1730 SetGLError(GL_INVALID_VALUE, "glCompressedTexImage2D", "invalid buffer"); | |
| 1731 return; | |
| 1732 } | |
| 1733 GLuint offset = ToGLuint(data); | |
| 1734 if ((buffer->size() - offset) < static_cast<GLuint>(image_size)) { | |
| 1735 SetGLError(GL_INVALID_VALUE, "glCompressedTexImage2D", | |
| 1736 "unpack size to large"); | |
| 1737 return; | |
| 1738 } | |
| 1739 helper_->CompressedTexImage2D( | |
| 1740 target, level, internalformat, width, height, border, image_size, | |
| 1741 buffer->shm_id(), buffer->shm_offset() + offset); | |
| 1742 return; | |
| 1743 } | |
| 1676 SetBucketContents(kResultBucketId, data, image_size); | 1744 SetBucketContents(kResultBucketId, data, image_size); |
| 1677 helper_->CompressedTexImage2DBucket( | 1745 helper_->CompressedTexImage2DBucket( |
| 1678 target, level, internalformat, width, height, border, kResultBucketId); | 1746 target, level, internalformat, width, height, border, kResultBucketId); |
| 1679 // Free the bucket. This is not required but it does free up the memory. | 1747 // Free the bucket. This is not required but it does free up the memory. |
| 1680 // and we don't have to wait for the result so from the client's perspective | 1748 // and we don't have to wait for the result so from the client's perspective |
| 1681 // it's cheap. | 1749 // it's cheap. |
| 1682 helper_->SetBucketSize(kResultBucketId, 0); | 1750 helper_->SetBucketSize(kResultBucketId, 0); |
| 1683 } | 1751 } |
| 1684 | 1752 |
| 1685 void GLES2Implementation::CompressedTexSubImage2D( | 1753 void GLES2Implementation::CompressedTexSubImage2D( |
| 1686 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, | 1754 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
| 1687 GLsizei height, GLenum format, GLsizei image_size, const void* data) { | 1755 GLsizei height, GLenum format, GLsizei image_size, const void* data) { |
| 1688 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1756 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 1689 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCompressedTexSubImage2D(" | 1757 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCompressedTexSubImage2D(" |
| 1690 << GLES2Util::GetStringTextureTarget(target) << ", " | 1758 << GLES2Util::GetStringTextureTarget(target) << ", " |
| 1691 << level << ", " | 1759 << level << ", " |
| 1692 << xoffset << ", " << yoffset << ", " | 1760 << xoffset << ", " << yoffset << ", " |
| 1693 << width << ", " << height << ", " | 1761 << width << ", " << height << ", " |
| 1694 << GLES2Util::GetStringCompressedTextureFormat(format) << ", " | 1762 << GLES2Util::GetStringCompressedTextureFormat(format) << ", " |
| 1695 << image_size << ", " | 1763 << image_size << ", " |
| 1696 << static_cast<const void*>(data) << ")"); | 1764 << static_cast<const void*>(data) << ")"); |
| 1697 if (width < 0 || height < 0 || level < 0) { | 1765 if (width < 0 || height < 0 || level < 0) { |
| 1698 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "dimension < 0"); | 1766 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "dimension < 0"); |
| 1699 return; | 1767 return; |
| 1700 } | 1768 } |
| 1769 // If there's a pixel unpack buffer bound use it when issuing | |
| 1770 // CompressedTexSubImage2D. | |
| 1771 if (bound_pixel_unpack_transfer_buffer_id_) { | |
| 1772 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer( | |
|
greggman
2012/11/19 04:50:14
It seems like this code and the code above and twi
reveman
2012/11/20 16:49:30
Done. Made it GetBoundPixelUnpackTransferBufferIfV
| |
| 1773 bound_pixel_unpack_transfer_buffer_id_); | |
| 1774 if (!buffer) { | |
| 1775 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", | |
| 1776 "invalid buffer"); | |
| 1777 return; | |
| 1778 } | |
| 1779 GLuint offset = ToGLuint(data); | |
| 1780 if ((buffer->size() - offset) < static_cast<GLuint>(image_size)) { | |
| 1781 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", | |
| 1782 "unpack size to large"); | |
| 1783 return; | |
| 1784 } | |
| 1785 helper_->CompressedTexSubImage2D( | |
| 1786 target, level, xoffset, yoffset, width, height, format, image_size, | |
| 1787 buffer->shm_id(), buffer->shm_offset() + offset); | |
| 1788 return; | |
| 1789 } | |
| 1701 SetBucketContents(kResultBucketId, data, image_size); | 1790 SetBucketContents(kResultBucketId, data, image_size); |
| 1702 helper_->CompressedTexSubImage2DBucket( | 1791 helper_->CompressedTexSubImage2DBucket( |
| 1703 target, level, xoffset, yoffset, width, height, format, kResultBucketId); | 1792 target, level, xoffset, yoffset, width, height, format, kResultBucketId); |
| 1704 // Free the bucket. This is not required but it does free up the memory. | 1793 // Free the bucket. This is not required but it does free up the memory. |
| 1705 // and we don't have to wait for the result so from the client's perspective | 1794 // and we don't have to wait for the result so from the client's perspective |
| 1706 // it's cheap. | 1795 // it's cheap. |
| 1707 helper_->SetBucketSize(kResultBucketId, 0); | 1796 helper_->SetBucketSize(kResultBucketId, 0); |
| 1708 } | 1797 } |
| 1709 | 1798 |
| 1710 namespace { | 1799 namespace { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1762 uint32 size; | 1851 uint32 size; |
| 1763 uint32 unpadded_row_size; | 1852 uint32 unpadded_row_size; |
| 1764 uint32 padded_row_size; | 1853 uint32 padded_row_size; |
| 1765 if (!GLES2Util::ComputeImageDataSizes( | 1854 if (!GLES2Util::ComputeImageDataSizes( |
| 1766 width, height, format, type, unpack_alignment_, &size, | 1855 width, height, format, type, unpack_alignment_, &size, |
| 1767 &unpadded_row_size, &padded_row_size)) { | 1856 &unpadded_row_size, &padded_row_size)) { |
| 1768 SetGLError(GL_INVALID_VALUE, "glTexImage2D", "image size too large"); | 1857 SetGLError(GL_INVALID_VALUE, "glTexImage2D", "image size too large"); |
| 1769 return; | 1858 return; |
| 1770 } | 1859 } |
| 1771 | 1860 |
| 1861 // If there's a pixel unpack buffer bound use it when issuing TexImage2D. | |
| 1862 if (bound_pixel_unpack_transfer_buffer_id_) { | |
| 1863 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer( | |
| 1864 bound_pixel_unpack_transfer_buffer_id_); | |
| 1865 if (!buffer) { | |
| 1866 SetGLError(GL_INVALID_VALUE, "glTexImage2D", "invalid buffer"); | |
| 1867 return; | |
| 1868 } | |
| 1869 GLuint offset = ToGLuint(pixels); | |
| 1870 if ((buffer->size() - offset) < size) { | |
| 1871 SetGLError(GL_INVALID_VALUE, "glTexImage2D", "unpack size to large"); | |
| 1872 return; | |
| 1873 } | |
| 1874 helper_->TexImage2D( | |
| 1875 target, level, internalformat, width, height, border, format, type, | |
| 1876 buffer->shm_id(), buffer->shm_offset() + offset); | |
| 1877 return; | |
| 1878 } | |
| 1879 | |
| 1772 // If there's no data just issue TexImage2D | 1880 // If there's no data just issue TexImage2D |
| 1773 if (!pixels) { | 1881 if (!pixels) { |
| 1774 helper_->TexImage2D( | 1882 helper_->TexImage2D( |
| 1775 target, level, internalformat, width, height, border, format, type, | 1883 target, level, internalformat, width, height, border, format, type, |
| 1776 0, 0); | 1884 0, 0); |
| 1777 return; | 1885 return; |
| 1778 } | 1886 } |
| 1779 | 1887 |
| 1780 // compute the advance bytes per row for the src pixels | 1888 // compute the advance bytes per row for the src pixels |
| 1781 uint32 src_padded_row_size; | 1889 uint32 src_padded_row_size; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1849 uint32 temp_size; | 1957 uint32 temp_size; |
| 1850 uint32 unpadded_row_size; | 1958 uint32 unpadded_row_size; |
| 1851 uint32 padded_row_size; | 1959 uint32 padded_row_size; |
| 1852 if (!GLES2Util::ComputeImageDataSizes( | 1960 if (!GLES2Util::ComputeImageDataSizes( |
| 1853 width, height, format, type, unpack_alignment_, &temp_size, | 1961 width, height, format, type, unpack_alignment_, &temp_size, |
| 1854 &unpadded_row_size, &padded_row_size)) { | 1962 &unpadded_row_size, &padded_row_size)) { |
| 1855 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "size to large"); | 1963 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "size to large"); |
| 1856 return; | 1964 return; |
| 1857 } | 1965 } |
| 1858 | 1966 |
| 1967 // If there's a pixel unpack buffer bound use it when issuing TexSubImage2D. | |
| 1968 if (bound_pixel_unpack_transfer_buffer_id_) { | |
| 1969 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer( | |
| 1970 bound_pixel_unpack_transfer_buffer_id_); | |
| 1971 if (!buffer) { | |
| 1972 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "invalid buffer"); | |
| 1973 return; | |
| 1974 } | |
| 1975 GLuint offset = ToGLuint(pixels); | |
| 1976 if ((buffer->size() - offset) < temp_size) { | |
| 1977 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "unpack size to large"); | |
| 1978 return; | |
| 1979 } | |
| 1980 helper_->TexSubImage2D( | |
| 1981 target, level, xoffset, yoffset, width, height, format, type, | |
| 1982 buffer->shm_id(), buffer->shm_offset() + offset, false); | |
| 1983 return; | |
| 1984 } | |
| 1985 | |
| 1859 // compute the advance bytes per row for the src pixels | 1986 // compute the advance bytes per row for the src pixels |
| 1860 uint32 src_padded_row_size; | 1987 uint32 src_padded_row_size; |
| 1861 if (unpack_row_length_ > 0) { | 1988 if (unpack_row_length_ > 0) { |
| 1862 if (!GLES2Util::ComputeImagePaddedRowSize( | 1989 if (!GLES2Util::ComputeImagePaddedRowSize( |
| 1863 unpack_row_length_, format, type, unpack_alignment_, | 1990 unpack_row_length_, format, type, unpack_alignment_, |
| 1864 &src_padded_row_size)) { | 1991 &src_padded_row_size)) { |
| 1865 SetGLError( | 1992 SetGLError( |
| 1866 GL_INVALID_VALUE, "glTexImage2D", "unpack row length too large"); | 1993 GL_INVALID_VALUE, "glTexImage2D", "unpack row length too large"); |
| 1867 return; | 1994 return; |
| 1868 } | 1995 } |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2372 bound_array_buffer_id_ = buffer; | 2499 bound_array_buffer_id_ = buffer; |
| 2373 changed = true; | 2500 changed = true; |
| 2374 } | 2501 } |
| 2375 break; | 2502 break; |
| 2376 case GL_ELEMENT_ARRAY_BUFFER: | 2503 case GL_ELEMENT_ARRAY_BUFFER: |
| 2377 if (bound_element_array_buffer_id_ != buffer) { | 2504 if (bound_element_array_buffer_id_ != buffer) { |
| 2378 bound_element_array_buffer_id_ = buffer; | 2505 bound_element_array_buffer_id_ = buffer; |
| 2379 changed = true; | 2506 changed = true; |
| 2380 } | 2507 } |
| 2381 break; | 2508 break; |
| 2509 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: | |
| 2510 bound_pixel_unpack_transfer_buffer_id_ = buffer; | |
| 2511 break; | |
| 2382 default: | 2512 default: |
| 2383 changed = true; | 2513 changed = true; |
| 2384 break; | 2514 break; |
| 2385 } | 2515 } |
| 2386 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | 2516 // TODO(gman): There's a bug here. If the target is invalid the ID will not be |
| 2387 // used even though it's marked it as used here. | 2517 // used even though it's marked it as used here. |
| 2388 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind(buffer); | 2518 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind(buffer); |
| 2389 return changed; | 2519 return changed; |
| 2390 } | 2520 } |
| 2391 | 2521 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2493 "glDeleteBuffers", "id not created by this context."); | 2623 "glDeleteBuffers", "id not created by this context."); |
| 2494 return; | 2624 return; |
| 2495 } | 2625 } |
| 2496 for (GLsizei ii = 0; ii < n; ++ii) { | 2626 for (GLsizei ii = 0; ii < n; ++ii) { |
| 2497 if (buffers[ii] == bound_array_buffer_id_) { | 2627 if (buffers[ii] == bound_array_buffer_id_) { |
| 2498 bound_array_buffer_id_ = 0; | 2628 bound_array_buffer_id_ = 0; |
| 2499 } | 2629 } |
| 2500 if (buffers[ii] == bound_element_array_buffer_id_) { | 2630 if (buffers[ii] == bound_element_array_buffer_id_) { |
| 2501 bound_element_array_buffer_id_ = 0; | 2631 bound_element_array_buffer_id_ = 0; |
| 2502 } | 2632 } |
| 2633 if (buffers[ii] == bound_pixel_unpack_transfer_buffer_id_) { | |
| 2634 bound_pixel_unpack_transfer_buffer_id_ = 0; | |
| 2635 } | |
| 2636 | |
| 2637 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffers[ii]); | |
| 2638 if (buffer) { | |
| 2639 // Free buffer memory, pending the passage of a token. | |
| 2640 buffer_tracker_->FreePendingToken(buffer, helper_->InsertToken()); | |
| 2641 // Remove buffer. | |
| 2642 buffer_tracker_->RemoveBuffer(buffers[ii]); | |
| 2643 } | |
| 2503 } | 2644 } |
| 2504 } | 2645 } |
| 2505 | 2646 |
| 2506 void GLES2Implementation::DeleteBuffersStub( | 2647 void GLES2Implementation::DeleteBuffersStub( |
| 2507 GLsizei n, const GLuint* buffers) { | 2648 GLsizei n, const GLuint* buffers) { |
| 2508 helper_->DeleteBuffersImmediate(n, buffers); | 2649 helper_->DeleteBuffersImmediate(n, buffers); |
| 2509 } | 2650 } |
| 2510 | 2651 |
| 2511 | 2652 |
| 2512 void GLES2Implementation::DeleteFramebuffersHelper( | 2653 void GLES2Implementation::DeleteFramebuffersHelper( |
| (...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3462 void GLES2Implementation::TraceBeginCHROMIUM(const char* name) { | 3603 void GLES2Implementation::TraceBeginCHROMIUM(const char* name) { |
| 3463 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3604 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 3464 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTraceBeginCHROMIUM(" | 3605 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTraceBeginCHROMIUM(" |
| 3465 << name << ")"); | 3606 << name << ")"); |
| 3466 | 3607 |
| 3467 SetBucketAsCString(kResultBucketId, name); | 3608 SetBucketAsCString(kResultBucketId, name); |
| 3468 helper_->TraceBeginCHROMIUM(kResultBucketId); | 3609 helper_->TraceBeginCHROMIUM(kResultBucketId); |
| 3469 helper_->SetBucketSize(kResultBucketId, 0); | 3610 helper_->SetBucketSize(kResultBucketId, 0); |
| 3470 } | 3611 } |
| 3471 | 3612 |
| 3613 void* GLES2Implementation::MapBufferCHROMIUM(GLuint target, GLenum access) { | |
| 3614 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
| 3615 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapBufferCHROMIUM(" | |
| 3616 << target << ", " << GLES2Util::GetStringEnum(access) << ")"); | |
| 3617 if (target != GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) { | |
|
greggman
2012/11/19 04:50:14
Looking at glMapBuffer you're not aloud to map a b
reveman
2012/11/20 16:49:30
Done.
| |
| 3618 SetGLError( | |
| 3619 GL_INVALID_ENUM, "glMapBufferCHROMIUM", "invalid target"); | |
| 3620 return NULL; | |
| 3621 } | |
| 3622 if (access != GL_WRITE_ONLY) { | |
| 3623 SetGLError( | |
| 3624 GL_INVALID_ENUM, "glMapBufferCHROMIUM", "bad access mode"); | |
| 3625 return NULL; | |
| 3626 } | |
| 3627 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer( | |
| 3628 bound_pixel_unpack_transfer_buffer_id_); | |
| 3629 if (!buffer) { | |
| 3630 SetGLError( | |
| 3631 GL_INVALID_VALUE, "glMapBufferCHROMIUM", "invalid buffer"); | |
| 3632 return NULL; | |
| 3633 } | |
| 3634 | |
| 3635 GPU_DCHECK(buffer->address()); | |
| 3636 GPU_CLIENT_LOG(" returned " << buffer->address()); | |
| 3637 return buffer->address(); | |
| 3638 } | |
| 3639 | |
| 3640 GLboolean GLES2Implementation::UnmapBufferCHROMIUM(GLuint target) { | |
| 3641 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
| 3642 GPU_CLIENT_LOG( | |
| 3643 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")"); | |
| 3644 if (target != GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) { | |
| 3645 SetGLError( | |
| 3646 GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); | |
| 3647 return false; | |
| 3648 } | |
| 3649 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer( | |
| 3650 bound_pixel_unpack_transfer_buffer_id_); | |
| 3651 if (!buffer) { | |
| 3652 SetGLError( | |
| 3653 GL_INVALID_VALUE, "glMapBufferCHROMIUM", "invalid buffer"); | |
| 3654 return false; | |
| 3655 } | |
| 3656 | |
| 3657 return true; | |
| 3658 } | |
| 3659 | |
| 3472 // Include the auto-generated part of this file. We split this because it means | 3660 // Include the auto-generated part of this file. We split this because it means |
| 3473 // we can easily edit the non-auto generated parts right here in this file | 3661 // we can easily edit the non-auto generated parts right here in this file |
| 3474 // instead of having to edit some template or the code generator. | 3662 // instead of having to edit some template or the code generator. |
| 3475 #include "../client/gles2_implementation_impl_autogen.h" | 3663 #include "../client/gles2_implementation_impl_autogen.h" |
| 3476 | 3664 |
| 3477 } // namespace gles2 | 3665 } // namespace gles2 |
| 3478 } // namespace gpu | 3666 } // namespace gpu |
| OLD | NEW |