| 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 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 7520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7531 } | 7531 } |
| 7532 GLES2Util::ComputeImageDataSizes( | 7532 GLES2Util::ComputeImageDataSizes( |
| 7533 width, height, format, type, state_.pack_alignment, &pixels_size, | 7533 width, height, format, type, state_.pack_alignment, &pixels_size, |
| 7534 NULL, NULL); | 7534 NULL, NULL); |
| 7535 void* pixels = GetSharedMemoryAs<void*>( | 7535 void* pixels = GetSharedMemoryAs<void*>( |
| 7536 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); | 7536 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 7537 if (!pixels) { | 7537 if (!pixels) { |
| 7538 if (buffer != 0) { | 7538 if (buffer != 0) { |
| 7539 glDeleteBuffersARB(1, &buffer); | 7539 glDeleteBuffersARB(1, &buffer); |
| 7540 } | 7540 } |
| 7541 if (result) |
| 7542 *result = GL_INVALID_VALUE; |
| 7541 return; | 7543 return; |
| 7542 } | 7544 } |
| 7543 | 7545 |
| 7544 if (buffer != 0) { | 7546 if (buffer != 0) { // Asynchronous readback path. |
| 7545 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); | 7547 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
| 7546 void* data; | 7548 void* data; |
| 7547 if (features().map_buffer_range) { | 7549 if (features().map_buffer_range) { |
| 7548 data = glMapBufferRange( | 7550 data = glMapBufferRange( |
| 7549 GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); | 7551 GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); |
| 7550 } else { | 7552 } else { |
| 7551 data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); | 7553 data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
| 7552 } | 7554 } |
| 7553 memcpy(pixels, data, pixels_size); | 7555 if (result) |
| 7556 *result = glGetError(); |
| 7557 if (data) |
| 7558 memcpy(pixels, data, pixels_size); |
| 7554 // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't | 7559 // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
| 7555 // have to restore the state. | 7560 // have to restore the state. |
| 7556 glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); | 7561 glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
| 7557 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 7562 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7558 glDeleteBuffersARB(1, &buffer); | 7563 glDeleteBuffersARB(1, &buffer); |
| 7559 } | 7564 if (!data) |
| 7560 | 7565 return; |
| 7561 if (result != NULL) { | |
| 7562 *result = true; | |
| 7563 } | 7566 } |
| 7564 | 7567 |
| 7565 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); | 7568 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 7566 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); | 7569 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 7567 if ((channels_exist & 0x0008) == 0 && | 7570 if ((channels_exist & 0x0008) == 0 && |
| 7568 workarounds().clear_alpha_in_readpixels) { | 7571 workarounds().clear_alpha_in_readpixels) { |
| 7569 // Set the alpha to 255 because some drivers are buggy in this regard. | 7572 // Set the alpha to 255 because some drivers are buggy in this regard. |
| 7570 uint32 temp_size; | 7573 uint32 temp_size; |
| 7571 | 7574 |
| 7572 uint32 unpadded_row_size; | 7575 uint32 unpadded_row_size; |
| 7573 uint32 padded_row_size; | 7576 uint32 padded_row_size; |
| 7574 if (!GLES2Util::ComputeImageDataSizes( | 7577 if (!GLES2Util::ComputeImageDataSizes( |
| 7575 width, 2, format, type, state_.pack_alignment, &temp_size, | 7578 width, 2, format, type, state_.pack_alignment, &temp_size, |
| 7576 &unpadded_row_size, &padded_row_size)) { | 7579 &unpadded_row_size, &padded_row_size)) { |
| 7580 if (result) |
| 7581 *result = GL_INVALID_VALUE; |
| 7577 return; | 7582 return; |
| 7578 } | 7583 } |
| 7579 | 7584 |
| 7580 uint32 channel_count = 0; | 7585 uint32 channel_count = 0; |
| 7581 uint32 alpha_channel = 0; | 7586 uint32 alpha_channel = 0; |
| 7582 switch (format) { | 7587 switch (format) { |
| 7583 case GL_RGBA: | 7588 case GL_RGBA: |
| 7584 case GL_BGRA_EXT: | 7589 case GL_BGRA_EXT: |
| 7585 channel_count = 4; | 7590 channel_count = 4; |
| 7586 alpha_channel = 3; | 7591 alpha_channel = 3; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7744 glReadPixels( | 7749 glReadPixels( |
| 7745 read_x, ry, read_width, 1, format, type, dst + dest_row_offset); | 7750 read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 7746 } | 7751 } |
| 7747 dst += padded_row_size; | 7752 dst += padded_row_size; |
| 7748 } | 7753 } |
| 7749 } else { | 7754 } else { |
| 7750 if (async && features().use_async_readpixels) { | 7755 if (async && features().use_async_readpixels) { |
| 7751 GLuint buffer = 0; | 7756 GLuint buffer = 0; |
| 7752 glGenBuffersARB(1, &buffer); | 7757 glGenBuffersARB(1, &buffer); |
| 7753 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); | 7758 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
| 7754 glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, GL_STREAM_READ); | 7759 // For ANGLE client version 2, GL_STREAM_READ is not available. |
| 7760 const GLenum usage_hint = |
| 7761 features().is_angle ? GL_STATIC_DRAW : GL_STREAM_READ; |
| 7762 glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, usage_hint); |
| 7755 GLenum error = glGetError(); | 7763 GLenum error = glGetError(); |
| 7756 if (error == GL_NO_ERROR) { | 7764 if (error == GL_NO_ERROR) { |
| 7757 glReadPixels(x, y, width, height, format, type, 0); | 7765 glReadPixels(x, y, width, height, format, type, 0); |
| 7758 pending_readpixel_fences_.push(linked_ptr<FenceCallback>( | 7766 error = glGetError(); |
| 7759 new FenceCallback())); | 7767 if (result) |
| 7760 WaitForReadPixels(base::Bind( | 7768 *result = error; |
| 7761 &GLES2DecoderImpl::FinishReadPixels, | 7769 if (error == GL_NO_ERROR) { |
| 7762 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr | 7770 pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
| 7763 <GLES2DecoderImpl>(this), | 7771 new FenceCallback())); |
| 7764 c, buffer)); | 7772 WaitForReadPixels(base::Bind( |
| 7773 &GLES2DecoderImpl::FinishReadPixels, |
| 7774 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 7775 <GLES2DecoderImpl>(this), |
| 7776 c, buffer)); |
| 7777 } |
| 7765 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 7778 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7766 return error::kNoError; | 7779 return error::kNoError; |
| 7767 } else { | 7780 } else { |
| 7768 // On error, unbind pack buffer and fall through to sync readpixels | 7781 // On error, unbind pack buffer and fall through to sync readpixels |
| 7769 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 7782 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7770 glDeleteBuffersARB(1, &buffer); | 7783 glDeleteBuffersARB(1, &buffer); |
| 7771 } | 7784 } |
| 7772 } | 7785 } |
| 7773 glReadPixels(x, y, width, height, format, type, pixels); | 7786 glReadPixels(x, y, width, height, format, type, pixels); |
| 7774 } | 7787 } |
| 7775 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); | 7788 const GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
| 7776 if (error == GL_NO_ERROR) { | 7789 if (result) |
| 7777 if (result != NULL) { | 7790 *result = error; |
| 7778 *result = true; | 7791 if (error == GL_NO_ERROR) |
| 7779 } | |
| 7780 FinishReadPixels(c, 0); | 7792 FinishReadPixels(c, 0); |
| 7781 } | |
| 7782 | 7793 |
| 7783 return error::kNoError; | 7794 return error::kNoError; |
| 7784 } | 7795 } |
| 7785 | 7796 |
| 7786 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, | 7797 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, |
| 7787 const void* cmd_data) { | 7798 const void* cmd_data) { |
| 7788 const gles2::cmds::PixelStorei& c = | 7799 const gles2::cmds::PixelStorei& c = |
| 7789 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); | 7800 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); |
| 7790 GLenum pname = c.pname; | 7801 GLenum pname = c.pname; |
| 7791 GLenum param = c.param; | 7802 GLenum param = c.param; |
| (...skipping 3670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11462 } | 11473 } |
| 11463 } | 11474 } |
| 11464 | 11475 |
| 11465 // Include the auto-generated part of this file. We split this because it means | 11476 // Include the auto-generated part of this file. We split this because it means |
| 11466 // we can easily edit the non-auto generated parts right here in this file | 11477 // we can easily edit the non-auto generated parts right here in this file |
| 11467 // instead of having to edit some template or the code generator. | 11478 // instead of having to edit some template or the code generator. |
| 11468 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 11479 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 11469 | 11480 |
| 11470 } // namespace gles2 | 11481 } // namespace gles2 |
| 11471 } // namespace gpu | 11482 } // namespace gpu |
| OLD | NEW |