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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 1474513003: Upgrade PixelStorei to ES3/WebGL2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: client side Created 5 years 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 // 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>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 TransferBufferInterface* transfer_buffer, 78 TransferBufferInterface* transfer_buffer,
79 bool bind_generates_resource, 79 bool bind_generates_resource,
80 bool lose_context_when_out_of_memory, 80 bool lose_context_when_out_of_memory,
81 bool support_client_side_arrays, 81 bool support_client_side_arrays,
82 GpuControl* gpu_control) 82 GpuControl* gpu_control)
83 : helper_(helper), 83 : helper_(helper),
84 transfer_buffer_(transfer_buffer), 84 transfer_buffer_(transfer_buffer),
85 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), 85 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus),
86 chromium_framebuffer_multisample_(kUnknownExtensionStatus), 86 chromium_framebuffer_multisample_(kUnknownExtensionStatus),
87 pack_alignment_(4), 87 pack_alignment_(4),
88 pack_row_length_(0),
89 pack_skip_pixels_(0),
90 pack_skip_rows_(0),
88 unpack_alignment_(4), 91 unpack_alignment_(4),
89 unpack_row_length_(0), 92 unpack_row_length_(0),
90 unpack_image_height_(0), 93 unpack_image_height_(0),
91 unpack_skip_rows_(0), 94 unpack_skip_rows_(0),
92 unpack_skip_pixels_(0), 95 unpack_skip_pixels_(0),
93 unpack_skip_images_(0), 96 unpack_skip_images_(0),
94 pack_reverse_row_order_(false), 97 pack_reverse_row_order_(false),
95 active_texture_unit_(0), 98 active_texture_unit_(0),
96 bound_framebuffer_(0), 99 bound_framebuffer_(0),
97 bound_read_framebuffer_(0), 100 bound_read_framebuffer_(0),
(...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 CheckGLError(); 1713 CheckGLError();
1711 } 1714 }
1712 1715
1713 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) { 1716 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) {
1714 GPU_CLIENT_SINGLE_THREAD_CHECK(); 1717 GPU_CLIENT_SINGLE_THREAD_CHECK();
1715 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPixelStorei(" 1718 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPixelStorei("
1716 << GLES2Util::GetStringPixelStore(pname) << ", " 1719 << GLES2Util::GetStringPixelStore(pname) << ", "
1717 << param << ")"); 1720 << param << ")");
1718 switch (pname) { 1721 switch (pname) {
1719 case GL_PACK_ALIGNMENT: 1722 case GL_PACK_ALIGNMENT:
1720 pack_alignment_ = param; 1723 pack_alignment_ = param;
1721 break; 1724 break;
1725 case GL_PACK_ROW_LENGTH:
1726 pack_row_length_ = param;
1727 break;
1728 case GL_PACK_SKIP_PIXELS:
1729 pack_skip_pixels_ = param;
1730 break;
1731 case GL_PACK_SKIP_ROWS:
1732 pack_skip_rows_ = param;
1733 break;
1722 case GL_UNPACK_ALIGNMENT: 1734 case GL_UNPACK_ALIGNMENT:
1723 unpack_alignment_ = param; 1735 unpack_alignment_ = param;
1724 break; 1736 break;
1725 case GL_UNPACK_ROW_LENGTH_EXT: 1737 case GL_UNPACK_ROW_LENGTH_EXT:
1726 unpack_row_length_ = param; 1738 unpack_row_length_ = param;
1727 return; 1739 return;
1728 case GL_UNPACK_IMAGE_HEIGHT: 1740 case GL_UNPACK_IMAGE_HEIGHT:
1729 unpack_image_height_ = param; 1741 unpack_image_height_ = param;
1730 return; 1742 return;
1731 case GL_UNPACK_SKIP_ROWS_EXT: 1743 case GL_UNPACK_SKIP_ROWS_EXT:
1732 unpack_skip_rows_ = param; 1744 unpack_skip_rows_ = param;
1733 return; 1745 return;
1734 case GL_UNPACK_SKIP_PIXELS_EXT: 1746 case GL_UNPACK_SKIP_PIXELS_EXT:
1735 unpack_skip_pixels_ = param; 1747 unpack_skip_pixels_ = param;
1736 return; 1748 return;
1737 case GL_UNPACK_SKIP_IMAGES: 1749 case GL_UNPACK_SKIP_IMAGES:
1738 unpack_skip_images_ = param; 1750 unpack_skip_images_ = param;
1739 return; 1751 return;
1740 case GL_PACK_REVERSE_ROW_ORDER_ANGLE: 1752 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
1741 pack_reverse_row_order_ = 1753 pack_reverse_row_order_ =
1742 IsAnglePackReverseRowOrderAvailable() ? (param != 0) : false; 1754 IsAnglePackReverseRowOrderAvailable() ? (param != 0) : false;
1743 break; 1755 break;
1744 default: 1756 default:
1745 break; 1757 break;
1746 } 1758 }
1747 helper_->PixelStorei(pname, param); 1759 helper_->PixelStorei(pname, param);
1748 CheckGLError(); 1760 CheckGLError();
1749 } 1761 }
1750 1762
1751 void GLES2Implementation::VertexAttribIPointer( 1763 void GLES2Implementation::VertexAttribIPointer(
1752 GLuint index, GLint size, GLenum type, GLsizei stride, const void* ptr) { 1764 GLuint index, GLint size, GLenum type, GLsizei stride, const void* ptr) {
1753 GPU_CLIENT_SINGLE_THREAD_CHECK(); 1765 GPU_CLIENT_SINGLE_THREAD_CHECK();
1754 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glVertexAttribIPointer(" 1766 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glVertexAttribIPointer("
1755 << index << ", " 1767 << index << ", "
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after
3465 uint32 temp_size; 3477 uint32 temp_size;
3466 uint32 unpadded_row_size; 3478 uint32 unpadded_row_size;
3467 uint32 padded_row_size; 3479 uint32 padded_row_size;
3468 if (!GLES2Util::ComputeImageDataSizes( 3480 if (!GLES2Util::ComputeImageDataSizes(
3469 width, 2, 1, format, type, pack_alignment_, &temp_size, 3481 width, 2, 1, format, type, pack_alignment_, &temp_size,
3470 &unpadded_row_size, &padded_row_size)) { 3482 &unpadded_row_size, &padded_row_size)) {
3471 SetGLError(GL_INVALID_VALUE, "glReadPixels", "size too large."); 3483 SetGLError(GL_INVALID_VALUE, "glReadPixels", "size too large.");
3472 return; 3484 return;
3473 } 3485 }
3474 3486
3487 if (bound_pixel_pack_buffer_) {
3488 // TODO(zmo): Need to handle the case of reading into a PIXEL_PACK_BUFFER
3489 // in ES3. For now, generate a GL error.
3490 SetGLError(GL_INVALID_OPERATION, "glReadPixels",
3491 "ReadPixels to a pixel pack buffer isn't implemented");
3492 return;
3493 }
3494
3475 if (bound_pixel_pack_transfer_buffer_id_) { 3495 if (bound_pixel_pack_transfer_buffer_id_) {
3476 GLuint offset = ToGLuint(pixels); 3496 GLuint offset = ToGLuint(pixels);
3477 BufferTracker::Buffer* buffer = GetBoundPixelUnpackTransferBufferIfValid( 3497 BufferTracker::Buffer* buffer = GetBoundPixelUnpackTransferBufferIfValid(
3478 bound_pixel_pack_transfer_buffer_id_, 3498 bound_pixel_pack_transfer_buffer_id_,
3479 "glReadPixels", offset, padded_row_size * height); 3499 "glReadPixels", offset, padded_row_size * height);
3480 if (buffer && buffer->shm_id() != -1) { 3500 if (buffer && buffer->shm_id() != -1) {
3481 helper_->ReadPixels(xoffset, yoffset, width, height, format, type, 3501 helper_->ReadPixels(xoffset, yoffset, width, height, format, type,
3482 buffer->shm_id(), buffer->shm_offset(), 3502 buffer->shm_id(), buffer->shm_offset(),
3483 0, 0, true); 3503 0, 0, true);
3484 CheckGLError(); 3504 CheckGLError();
3485 } 3505 }
3486 return; 3506 return;
3487 } 3507 }
3488 3508
3489 if (!pixels) { 3509 if (!pixels) {
3490 SetGLError(GL_INVALID_OPERATION, "glReadPixels", "pixels = NULL"); 3510 SetGLError(GL_INVALID_OPERATION, "glReadPixels", "pixels = NULL");
3491 return; 3511 return;
3492 } 3512 }
3493 3513
3514 // compute the advance bytes per row for the dst pixels
3515 uint32 dst_padded_row_size;
3516 if (pack_row_length_ > 0) {
3517 if (!GLES2Util::ComputeImagePaddedRowSize(
3518 pack_row_length_, format, type, pack_alignment_,
3519 &dst_padded_row_size)) {
3520 SetGLError(
3521 GL_INVALID_VALUE, "glReadPixels", "pack row length too large");
3522 return;
3523 }
3524 } else {
3525 dst_padded_row_size = padded_row_size;
3526 }
3527
3528 // Advance pixels pointer past the skip rows and skip pixels
3529 dest += pack_skip_rows_ * dst_padded_row_size;
3530 if (pack_skip_pixels_) {
3531 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type);
3532 dest += pack_skip_pixels_ * group_size;
3533 }
3534
3494 // Transfer by rows. 3535 // Transfer by rows.
3495 // The max rows we can transfer. 3536 // The max rows we can transfer.
3496 while (height) { 3537 while (height) {
3497 GLsizei desired_size = padded_row_size * (height - 1) + unpadded_row_size; 3538 GLsizei desired_size = padded_row_size * (height - 1) + unpadded_row_size;
3498 ScopedTransferBufferPtr buffer(desired_size, helper_, transfer_buffer_); 3539 ScopedTransferBufferPtr buffer(desired_size, helper_, transfer_buffer_);
3499 if (!buffer.valid()) { 3540 if (!buffer.valid()) {
3500 return; 3541 return;
3501 } 3542 }
3502 GLint num_rows = ComputeNumRowsThatFitInBuffer( 3543 GLint num_rows = ComputeNumRowsThatFitInBuffer(
3503 padded_row_size, unpadded_row_size, buffer.size(), height); 3544 padded_row_size, unpadded_row_size, buffer.size(), height);
(...skipping 10 matching lines...) Expand all
3514 buffer.shm_id(), buffer.offset(), 3555 buffer.shm_id(), buffer.offset(),
3515 GetResultShmId(), GetResultShmOffset(), 3556 GetResultShmId(), GetResultShmOffset(),
3516 false); 3557 false);
3517 WaitForCmd(); 3558 WaitForCmd();
3518 if (*result != 0) { 3559 if (*result != 0) {
3519 // when doing a y-flip we have to iterate through top-to-bottom chunks 3560 // when doing a y-flip we have to iterate through top-to-bottom chunks
3520 // of the dst. The service side handles reversing the rows within a 3561 // of the dst. The service side handles reversing the rows within a
3521 // chunk. 3562 // chunk.
3522 int8* rows_dst; 3563 int8* rows_dst;
3523 if (pack_reverse_row_order_) { 3564 if (pack_reverse_row_order_) {
3524 rows_dst = dest + (height - num_rows) * padded_row_size; 3565 rows_dst = dest + (height - num_rows) * dst_padded_row_size;
3525 } else { 3566 } else {
3526 rows_dst = dest; 3567 rows_dst = dest;
3527 } 3568 }
3528 // We have to copy 1 row at a time to avoid writing pad bytes. 3569 // We have to copy 1 row at a time to avoid writing pad bytes.
3529 const int8* src = static_cast<const int8*>(buffer.address()); 3570 const int8* src = static_cast<const int8*>(buffer.address());
3530 for (GLint yy = 0; yy < num_rows; ++yy) { 3571 for (GLint yy = 0; yy < num_rows; ++yy) {
3531 memcpy(rows_dst, src, unpadded_row_size); 3572 memcpy(rows_dst, src, unpadded_row_size);
3532 rows_dst += padded_row_size; 3573 rows_dst += dst_padded_row_size;
3533 src += padded_row_size; 3574 src += padded_row_size;
3534 } 3575 }
3535 if (!pack_reverse_row_order_) { 3576 if (!pack_reverse_row_order_) {
3536 dest = rows_dst; 3577 dest = rows_dst;
3537 } 3578 }
3538 } 3579 }
3539 // If it was not marked as successful exit. 3580 // If it was not marked as successful exit.
3540 if (*result == 0) { 3581 if (*result == 0) {
3541 return; 3582 return;
3542 } 3583 }
(...skipping 2847 matching lines...) Expand 10 before | Expand all | Expand 10 after
6390 CheckGLError(); 6431 CheckGLError();
6391 } 6432 }
6392 6433
6393 // Include the auto-generated part of this file. We split this because it means 6434 // Include the auto-generated part of this file. We split this because it means
6394 // we can easily edit the non-auto generated parts right here in this file 6435 // we can easily edit the non-auto generated parts right here in this file
6395 // instead of having to edit some template or the code generator. 6436 // instead of having to edit some template or the code generator.
6396 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 6437 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
6397 6438
6398 } // namespace gles2 6439 } // namespace gles2
6399 } // namespace gpu 6440 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.h ('k') | gpu/command_buffer/service/context_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698