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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 52 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
53 #include "gpu/command_buffer/service/shader_manager.h" | 53 #include "gpu/command_buffer/service/shader_manager.h" |
54 #include "gpu/command_buffer/service/shader_translator.h" | 54 #include "gpu/command_buffer/service/shader_translator.h" |
55 #include "gpu/command_buffer/service/shader_translator_cache.h" | 55 #include "gpu/command_buffer/service/shader_translator_cache.h" |
56 #include "gpu/command_buffer/service/stream_texture.h" | 56 #include "gpu/command_buffer/service/stream_texture.h" |
57 #include "gpu/command_buffer/service/stream_texture_manager.h" | 57 #include "gpu/command_buffer/service/stream_texture_manager.h" |
58 #include "gpu/command_buffer/service/texture_manager.h" | 58 #include "gpu/command_buffer/service/texture_manager.h" |
59 #include "gpu/command_buffer/service/vertex_array_manager.h" | 59 #include "gpu/command_buffer/service/vertex_array_manager.h" |
60 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 60 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
61 #include "ui/gl/gl_bindings.h" | 61 #include "ui/gl/gl_bindings.h" |
| 62 #include "ui/gl/gl_fence.h" |
62 #include "ui/gl/gl_image.h" | 63 #include "ui/gl/gl_image.h" |
63 #include "ui/gl/gl_implementation.h" | 64 #include "ui/gl/gl_implementation.h" |
64 #include "ui/gl/gl_surface.h" | 65 #include "ui/gl/gl_surface.h" |
65 | 66 |
66 #if defined(OS_MACOSX) | 67 #if defined(OS_MACOSX) |
67 #include "ui/gl/io_surface_support_mac.h" | 68 #include "ui/gl/io_surface_support_mac.h" |
68 #endif | 69 #endif |
69 | 70 |
70 // TODO(zmo): we can't include "City.h" due to type def conflicts. | 71 // TODO(zmo): we can't include "City.h" due to type def conflicts. |
71 extern uint64 CityHash64(const char*, size_t); | 72 extern uint64 CityHash64(const char*, size_t); |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 GLuint id() const { | 471 GLuint id() const { |
471 return id_; | 472 return id_; |
472 } | 473 } |
473 | 474 |
474 private: | 475 private: |
475 GLES2DecoderImpl* decoder_; | 476 GLES2DecoderImpl* decoder_; |
476 GLuint id_; | 477 GLuint id_; |
477 DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); | 478 DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
478 }; | 479 }; |
479 | 480 |
| 481 struct FenceCallback { |
| 482 explicit FenceCallback() |
| 483 : fence(gfx::GLFence::Create()) { |
| 484 DCHECK(fence); |
| 485 } |
| 486 void AddCallback(base::Closure cb) { |
| 487 callbacks.push_back(cb); |
| 488 } |
| 489 std::vector<base::Closure> callbacks; |
| 490 scoped_ptr<gfx::GLFence> fence; |
| 491 }; |
| 492 |
| 493 |
480 // } // anonymous namespace. | 494 // } // anonymous namespace. |
481 | 495 |
482 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, | 496 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
483 uint32* service_texture_id) { | 497 uint32* service_texture_id) { |
484 return false; | 498 return false; |
485 } | 499 } |
486 | 500 |
487 GLES2Decoder::GLES2Decoder() | 501 GLES2Decoder::GLES2Decoder() |
488 : initialized_(false), | 502 : initialized_(false), |
489 debug_(false), | 503 debug_(false), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 virtual QueryManager* GetQueryManager() OVERRIDE { | 594 virtual QueryManager* GetQueryManager() OVERRIDE { |
581 return query_manager_.get(); | 595 return query_manager_.get(); |
582 } | 596 } |
583 virtual VertexArrayManager* GetVertexArrayManager() OVERRIDE { | 597 virtual VertexArrayManager* GetVertexArrayManager() OVERRIDE { |
584 return vertex_array_manager_.get(); | 598 return vertex_array_manager_.get(); |
585 } | 599 } |
586 virtual bool ProcessPendingQueries() OVERRIDE; | 600 virtual bool ProcessPendingQueries() OVERRIDE; |
587 virtual bool HasMoreIdleWork() OVERRIDE; | 601 virtual bool HasMoreIdleWork() OVERRIDE; |
588 virtual void PerformIdleWork() OVERRIDE; | 602 virtual void PerformIdleWork() OVERRIDE; |
589 | 603 |
| 604 virtual void WaitForReadPixels(base::Closure callback) OVERRIDE; |
| 605 |
590 virtual void SetResizeCallback( | 606 virtual void SetResizeCallback( |
591 const base::Callback<void(gfx::Size, float)>& callback) OVERRIDE; | 607 const base::Callback<void(gfx::Size, float)>& callback) OVERRIDE; |
592 | 608 |
593 virtual Logger* GetLogger() OVERRIDE; | 609 virtual Logger* GetLogger() OVERRIDE; |
594 virtual ErrorState* GetErrorState() OVERRIDE; | 610 virtual ErrorState* GetErrorState() OVERRIDE; |
595 | 611 |
596 virtual void SetShaderCacheCallback( | 612 virtual void SetShaderCacheCallback( |
597 const ShaderCacheCallback& callback) OVERRIDE; | 613 const ShaderCacheCallback& callback) OVERRIDE; |
598 virtual void SetWaitSyncPointCallback( | 614 virtual void SetWaitSyncPointCallback( |
599 const WaitSyncPointCallback& callback) OVERRIDE; | 615 const WaitSyncPointCallback& callback) OVERRIDE; |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 state_.bound_draw_framebuffer.get() == NULL && | 1566 state_.bound_draw_framebuffer.get() == NULL && |
1551 surface_->DeferDraws(); | 1567 surface_->DeferDraws(); |
1552 } | 1568 } |
1553 | 1569 |
1554 bool ShouldDeferReads() { | 1570 bool ShouldDeferReads() { |
1555 return !offscreen_target_frame_buffer_.get() && | 1571 return !offscreen_target_frame_buffer_.get() && |
1556 state_.bound_read_framebuffer.get() == NULL && | 1572 state_.bound_read_framebuffer.get() == NULL && |
1557 surface_->DeferDraws(); | 1573 surface_->DeferDraws(); |
1558 } | 1574 } |
1559 | 1575 |
| 1576 void ProcessPendingReadPixels(); |
| 1577 void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer); |
| 1578 |
1560 void ForceCompileShaderIfPending(Shader* shader); | 1579 void ForceCompileShaderIfPending(Shader* shader); |
1561 | 1580 |
1562 // Generate a member function prototype for each command in an automated and | 1581 // Generate a member function prototype for each command in an automated and |
1563 // typesafe way. | 1582 // typesafe way. |
1564 #define GLES2_CMD_OP(name) \ | 1583 #define GLES2_CMD_OP(name) \ |
1565 Error Handle ## name( \ | 1584 Error Handle ## name( \ |
1566 uint32 immediate_data_size, \ | 1585 uint32 immediate_data_size, \ |
1567 const cmds::name& args); \ | 1586 const cmds::name& args); \ |
1568 | 1587 |
1569 GLES2_COMMAND_LIST(GLES2_CMD_OP) | 1588 GLES2_COMMAND_LIST(GLES2_CMD_OP) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 GLsizei viewport_max_width_; | 1737 GLsizei viewport_max_width_; |
1719 GLsizei viewport_max_height_; | 1738 GLsizei viewport_max_height_; |
1720 | 1739 |
1721 // Command buffer stats. | 1740 // Command buffer stats. |
1722 int texture_upload_count_; | 1741 int texture_upload_count_; |
1723 base::TimeDelta total_texture_upload_time_; | 1742 base::TimeDelta total_texture_upload_time_; |
1724 base::TimeDelta total_processing_commands_time_; | 1743 base::TimeDelta total_processing_commands_time_; |
1725 | 1744 |
1726 scoped_ptr<GPUTracer> gpu_tracer_; | 1745 scoped_ptr<GPUTracer> gpu_tracer_; |
1727 | 1746 |
| 1747 std::queue<linked_ptr<FenceCallback> > pending_readpixel_fences_; |
| 1748 |
1728 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); | 1749 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
1729 }; | 1750 }; |
1730 | 1751 |
1731 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor( | 1752 ScopedGLErrorSuppressor::ScopedGLErrorSuppressor( |
1732 const char* function_name, GLES2DecoderImpl* decoder) | 1753 const char* function_name, GLES2DecoderImpl* decoder) |
1733 : function_name_(function_name), | 1754 : function_name_(function_name), |
1734 decoder_(decoder) { | 1755 decoder_(decoder) { |
1735 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(decoder_->GetErrorState(), | 1756 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(decoder_->GetErrorState(), |
1736 function_name_); | 1757 function_name_); |
1737 } | 1758 } |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2801 // Rebind the FBO if it was unbound by the context. | 2822 // Rebind the FBO if it was unbound by the context. |
2802 if (workarounds().unbind_fbo_on_context_switch) | 2823 if (workarounds().unbind_fbo_on_context_switch) |
2803 RestoreFramebufferBindings(); | 2824 RestoreFramebufferBindings(); |
2804 | 2825 |
2805 clear_state_dirty_ = true; | 2826 clear_state_dirty_ = true; |
2806 | 2827 |
2807 return true; | 2828 return true; |
2808 } | 2829 } |
2809 | 2830 |
2810 void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { | 2831 void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { |
| 2832 ProcessPendingReadPixels(); |
2811 if (engine() && query_manager_.get()) | 2833 if (engine() && query_manager_.get()) |
2812 query_manager_->ProcessPendingTransferQueries(); | 2834 query_manager_->ProcessPendingTransferQueries(); |
2813 | 2835 |
2814 // TODO(epenner): Is there a better place to do this? | 2836 // TODO(epenner): Is there a better place to do this? |
2815 // This needs to occur before we execute any batch of commands | 2837 // This needs to occur before we execute any batch of commands |
2816 // from the client, as the client may have recieved an async | 2838 // from the client, as the client may have recieved an async |
2817 // completion while issuing those commands. | 2839 // completion while issuing those commands. |
2818 // "DidFlushStart" would be ideal if we had such a callback. | 2840 // "DidFlushStart" would be ideal if we had such a callback. |
2819 async_pixel_transfer_manager_->BindCompletedAsyncTransfers(); | 2841 async_pixel_transfer_manager_->BindCompletedAsyncTransfers(); |
2820 } | 2842 } |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3533 } | 3555 } |
3534 GLuint service_id = glCreateShader(type); | 3556 GLuint service_id = glCreateShader(type); |
3535 if (service_id != 0) { | 3557 if (service_id != 0) { |
3536 CreateShader(client_id, service_id, type); | 3558 CreateShader(client_id, service_id, type); |
3537 } | 3559 } |
3538 return true; | 3560 return true; |
3539 } | 3561 } |
3540 | 3562 |
3541 void GLES2DecoderImpl::DoFinish() { | 3563 void GLES2DecoderImpl::DoFinish() { |
3542 glFinish(); | 3564 glFinish(); |
| 3565 ProcessPendingReadPixels(); |
3543 ProcessPendingQueries(); | 3566 ProcessPendingQueries(); |
3544 } | 3567 } |
3545 | 3568 |
3546 void GLES2DecoderImpl::DoFlush() { | 3569 void GLES2DecoderImpl::DoFlush() { |
3547 glFlush(); | 3570 glFlush(); |
3548 ProcessPendingQueries(); | 3571 ProcessPendingQueries(); |
3549 } | 3572 } |
3550 | 3573 |
3551 void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { | 3574 void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
3552 GLuint texture_index = texture_unit - GL_TEXTURE0; | 3575 GLuint texture_index = texture_unit - GL_TEXTURE0; |
(...skipping 3148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6701 return error::kNoError; | 6724 return error::kNoError; |
6702 } | 6725 } |
6703 | 6726 |
6704 state_.vertex_attrib_manager->SetDivisor( | 6727 state_.vertex_attrib_manager->SetDivisor( |
6705 index, | 6728 index, |
6706 divisor); | 6729 divisor); |
6707 glVertexAttribDivisorANGLE(index, divisor); | 6730 glVertexAttribDivisorANGLE(index, divisor); |
6708 return error::kNoError; | 6731 return error::kNoError; |
6709 } | 6732 } |
6710 | 6733 |
| 6734 void GLES2DecoderImpl::FinishReadPixels( |
| 6735 const cmds::ReadPixels& c, |
| 6736 GLuint buffer) { |
| 6737 TRACE_EVENT0("gpu", "GLES2DecoderImpl::FinishReadPixels"); |
| 6738 GLsizei width = c.width; |
| 6739 GLsizei height = c.height; |
| 6740 GLenum format = c.format; |
| 6741 GLenum type = c.type; |
| 6742 typedef cmds::ReadPixels::Result Result; |
| 6743 uint32 pixels_size; |
| 6744 Result* result = NULL; |
| 6745 if (c.result_shm_id != 0) { |
| 6746 result = GetSharedMemoryAs<Result*>( |
| 6747 c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 6748 if (!result) { |
| 6749 if (buffer != 0) { |
| 6750 glDeleteBuffersARB(1, &buffer); |
| 6751 } |
| 6752 return; |
| 6753 } |
| 6754 } |
| 6755 GLES2Util::ComputeImageDataSizes( |
| 6756 width, height, format, type, state_.pack_alignment, &pixels_size, |
| 6757 NULL, NULL); |
| 6758 void* pixels = GetSharedMemoryAs<void*>( |
| 6759 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 6760 if (!pixels) { |
| 6761 if (buffer != 0) { |
| 6762 glDeleteBuffersARB(1, &buffer); |
| 6763 } |
| 6764 return; |
| 6765 } |
| 6766 |
| 6767 if (buffer != 0) { |
| 6768 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
| 6769 void* data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
| 6770 memcpy(pixels, data, pixels_size); |
| 6771 // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
| 6772 // have to restore the state. |
| 6773 glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
| 6774 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 6775 glDeleteBuffersARB(1, &buffer); |
| 6776 } |
| 6777 |
| 6778 if (result != NULL) { |
| 6779 *result = true; |
| 6780 } |
| 6781 |
| 6782 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 6783 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 6784 if ((channels_exist & 0x0008) == 0 && |
| 6785 workarounds().clear_alpha_in_readpixels) { |
| 6786 // Set the alpha to 255 because some drivers are buggy in this regard. |
| 6787 uint32 temp_size; |
| 6788 |
| 6789 uint32 unpadded_row_size; |
| 6790 uint32 padded_row_size; |
| 6791 if (!GLES2Util::ComputeImageDataSizes( |
| 6792 width, 2, format, type, state_.pack_alignment, &temp_size, |
| 6793 &unpadded_row_size, &padded_row_size)) { |
| 6794 return; |
| 6795 } |
| 6796 // NOTE: Assumes the type is GL_UNSIGNED_BYTE which was true at the time |
| 6797 // of this implementation. |
| 6798 if (type != GL_UNSIGNED_BYTE) { |
| 6799 return; |
| 6800 } |
| 6801 switch (format) { |
| 6802 case GL_RGBA: |
| 6803 case GL_BGRA_EXT: |
| 6804 case GL_ALPHA: { |
| 6805 int offset = (format == GL_ALPHA) ? 0 : 3; |
| 6806 int step = (format == GL_ALPHA) ? 1 : 4; |
| 6807 uint8* dst = static_cast<uint8*>(pixels) + offset; |
| 6808 for (GLint yy = 0; yy < height; ++yy) { |
| 6809 uint8* end = dst + unpadded_row_size; |
| 6810 for (uint8* d = dst; d < end; d += step) { |
| 6811 *d = 255; |
| 6812 } |
| 6813 dst += padded_row_size; |
| 6814 } |
| 6815 break; |
| 6816 } |
| 6817 default: |
| 6818 break; |
| 6819 } |
| 6820 } |
| 6821 } |
| 6822 |
| 6823 |
6711 error::Error GLES2DecoderImpl::HandleReadPixels( | 6824 error::Error GLES2DecoderImpl::HandleReadPixels( |
6712 uint32 immediate_data_size, const cmds::ReadPixels& c) { | 6825 uint32 immediate_data_size, const cmds::ReadPixels& c) { |
6713 if (ShouldDeferReads()) | 6826 if (ShouldDeferReads()) |
6714 return error::kDeferCommandUntilLater; | 6827 return error::kDeferCommandUntilLater; |
6715 GLint x = c.x; | 6828 GLint x = c.x; |
6716 GLint y = c.y; | 6829 GLint y = c.y; |
6717 GLsizei width = c.width; | 6830 GLsizei width = c.width; |
6718 GLsizei height = c.height; | 6831 GLsizei height = c.height; |
6719 GLenum format = c.format; | 6832 GLenum format = c.format; |
6720 GLenum type = c.type; | 6833 GLenum type = c.type; |
| 6834 GLboolean async = c.async; |
6721 if (width < 0 || height < 0) { | 6835 if (width < 0 || height < 0) { |
6722 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); | 6836 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
6723 return error::kNoError; | 6837 return error::kNoError; |
6724 } | 6838 } |
6725 typedef cmds::ReadPixels::Result Result; | 6839 typedef cmds::ReadPixels::Result Result; |
6726 uint32 pixels_size; | 6840 uint32 pixels_size; |
6727 if (!GLES2Util::ComputeImageDataSizes( | 6841 if (!GLES2Util::ComputeImageDataSizes( |
6728 width, height, format, type, state_.pack_alignment, &pixels_size, | 6842 width, height, format, type, state_.pack_alignment, &pixels_size, |
6729 NULL, NULL)) { | 6843 NULL, NULL)) { |
6730 return error::kOutOfBounds; | 6844 return error::kOutOfBounds; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6810 memset(dst, 0, unpadded_row_size); | 6924 memset(dst, 0, unpadded_row_size); |
6811 | 6925 |
6812 // If the row is in range, copy it. | 6926 // If the row is in range, copy it. |
6813 if (ry >= 0 && ry < max_size.height() && read_width > 0) { | 6927 if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
6814 glReadPixels( | 6928 glReadPixels( |
6815 read_x, ry, read_width, 1, format, type, dst + dest_row_offset); | 6929 read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
6816 } | 6930 } |
6817 dst += padded_row_size; | 6931 dst += padded_row_size; |
6818 } | 6932 } |
6819 } else { | 6933 } else { |
| 6934 if (async && features().use_async_readpixels) { |
| 6935 GLuint buffer; |
| 6936 glGenBuffersARB(1, &buffer); |
| 6937 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
| 6938 glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, GL_STREAM_READ); |
| 6939 GLenum error = glGetError(); |
| 6940 if (error == GL_NO_ERROR) { |
| 6941 glReadPixels(x, y, width, height, format, type, 0); |
| 6942 pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
| 6943 new FenceCallback())); |
| 6944 WaitForReadPixels(base::Bind( |
| 6945 &GLES2DecoderImpl::FinishReadPixels, |
| 6946 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 6947 <GLES2DecoderImpl>(this), |
| 6948 c, buffer)); |
| 6949 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 6950 return error::kNoError; |
| 6951 } |
| 6952 } |
6820 glReadPixels(x, y, width, height, format, type, pixels); | 6953 glReadPixels(x, y, width, height, format, type, pixels); |
6821 } | 6954 } |
6822 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); | 6955 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
6823 if (error == GL_NO_ERROR) { | 6956 if (error == GL_NO_ERROR) { |
6824 if (result != NULL) { | 6957 if (result != NULL) { |
6825 *result = true; | 6958 *result = true; |
6826 } | 6959 } |
6827 | 6960 FinishReadPixels(c, 0); |
6828 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); | |
6829 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); | |
6830 if ((channels_exist & 0x0008) == 0 && | |
6831 workarounds().clear_alpha_in_readpixels) { | |
6832 // Set the alpha to 255 because some drivers are buggy in this regard. | |
6833 uint32 temp_size; | |
6834 | |
6835 uint32 unpadded_row_size; | |
6836 uint32 padded_row_size; | |
6837 if (!GLES2Util::ComputeImageDataSizes( | |
6838 width, 2, format, type, state_.pack_alignment, &temp_size, | |
6839 &unpadded_row_size, &padded_row_size)) { | |
6840 LOCAL_SET_GL_ERROR( | |
6841 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); | |
6842 return error::kNoError; | |
6843 } | |
6844 // NOTE: Assumes the type is GL_UNSIGNED_BYTE which was true at the time | |
6845 // of this implementation. | |
6846 if (type != GL_UNSIGNED_BYTE) { | |
6847 LOCAL_SET_GL_ERROR( | |
6848 GL_INVALID_OPERATION, "glReadPixels", | |
6849 "unsupported readPixel format"); | |
6850 return error::kNoError; | |
6851 } | |
6852 switch (format) { | |
6853 case GL_RGBA: | |
6854 case GL_BGRA_EXT: | |
6855 case GL_ALPHA: { | |
6856 int offset = (format == GL_ALPHA) ? 0 : 3; | |
6857 int step = (format == GL_ALPHA) ? 1 : 4; | |
6858 uint8* dst = static_cast<uint8*>(pixels) + offset; | |
6859 for (GLint yy = 0; yy < height; ++yy) { | |
6860 uint8* end = dst + unpadded_row_size; | |
6861 for (uint8* d = dst; d < end; d += step) { | |
6862 *d = 255; | |
6863 } | |
6864 dst += padded_row_size; | |
6865 } | |
6866 break; | |
6867 } | |
6868 default: | |
6869 break; | |
6870 } | |
6871 } | |
6872 } | 6961 } |
6873 | 6962 |
6874 return error::kNoError; | 6963 return error::kNoError; |
6875 } | 6964 } |
6876 | 6965 |
6877 error::Error GLES2DecoderImpl::HandlePixelStorei( | 6966 error::Error GLES2DecoderImpl::HandlePixelStorei( |
6878 uint32 immediate_data_size, const cmds::PixelStorei& c) { | 6967 uint32 immediate_data_size, const cmds::PixelStorei& c) { |
6879 GLenum pname = c.pname; | 6968 GLenum pname = c.pname; |
6880 GLenum param = c.param; | 6969 GLenum param = c.param; |
6881 if (!validators_->pixel_store.IsValid(pname)) { | 6970 if (!validators_->pixel_store.IsValid(pname)) { |
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9091 bool GLES2DecoderImpl::ProcessPendingQueries() { | 9180 bool GLES2DecoderImpl::ProcessPendingQueries() { |
9092 if (query_manager_.get() == NULL) { | 9181 if (query_manager_.get() == NULL) { |
9093 return false; | 9182 return false; |
9094 } | 9183 } |
9095 if (!query_manager_->ProcessPendingQueries()) { | 9184 if (!query_manager_->ProcessPendingQueries()) { |
9096 current_decoder_error_ = error::kOutOfBounds; | 9185 current_decoder_error_ = error::kOutOfBounds; |
9097 } | 9186 } |
9098 return query_manager_->HavePendingQueries(); | 9187 return query_manager_->HavePendingQueries(); |
9099 } | 9188 } |
9100 | 9189 |
| 9190 // Note that if there are no pending readpixels right now, |
| 9191 // this function will call the callback immediately. |
| 9192 void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { |
| 9193 if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { |
| 9194 pending_readpixel_fences_.back()->callbacks.push_back(callback); |
| 9195 } else { |
| 9196 callback.Run(); |
| 9197 } |
| 9198 } |
| 9199 |
| 9200 void GLES2DecoderImpl::ProcessPendingReadPixels() { |
| 9201 while (!pending_readpixel_fences_.empty() && |
| 9202 pending_readpixel_fences_.front()->fence->HasCompleted()) { |
| 9203 std::vector<base::Closure> callbacks = |
| 9204 pending_readpixel_fences_.front()->callbacks; |
| 9205 pending_readpixel_fences_.pop(); |
| 9206 for (size_t i = 0; i < callbacks.size(); i++) { |
| 9207 callbacks[i].Run(); |
| 9208 } |
| 9209 } |
| 9210 } |
| 9211 |
9101 bool GLES2DecoderImpl::HasMoreIdleWork() { | 9212 bool GLES2DecoderImpl::HasMoreIdleWork() { |
9102 return async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers(); | 9213 return !pending_readpixel_fences_.empty() || |
| 9214 async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers(); |
9103 } | 9215 } |
9104 | 9216 |
9105 void GLES2DecoderImpl::PerformIdleWork() { | 9217 void GLES2DecoderImpl::PerformIdleWork() { |
| 9218 ProcessPendingReadPixels(); |
9106 if (!async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers()) | 9219 if (!async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers()) |
9107 return; | 9220 return; |
9108 async_pixel_transfer_manager_->ProcessMorePendingTransfers(); | 9221 async_pixel_transfer_manager_->ProcessMorePendingTransfers(); |
9109 ProcessFinishedAsyncTransfers(); | 9222 ProcessFinishedAsyncTransfers(); |
9110 } | 9223 } |
9111 | 9224 |
9112 error::Error GLES2DecoderImpl::HandleBeginQueryEXT( | 9225 error::Error GLES2DecoderImpl::HandleBeginQueryEXT( |
9113 uint32 immediate_data_size, const cmds::BeginQueryEXT& c) { | 9226 uint32 immediate_data_size, const cmds::BeginQueryEXT& c) { |
9114 GLenum target = static_cast<GLenum>(c.target); | 9227 GLenum target = static_cast<GLenum>(c.target); |
9115 GLuint client_id = static_cast<GLuint>(c.id); | 9228 GLuint client_id = static_cast<GLuint>(c.id); |
9116 int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); | 9229 int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); |
9117 uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); | 9230 uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
9118 | 9231 |
9119 switch (target) { | 9232 switch (target) { |
9120 case GL_COMMANDS_ISSUED_CHROMIUM: | 9233 case GL_COMMANDS_ISSUED_CHROMIUM: |
9121 case GL_LATENCY_QUERY_CHROMIUM: | 9234 case GL_LATENCY_QUERY_CHROMIUM: |
9122 case GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM: | 9235 case GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM: |
| 9236 case GL_ASYNC_READ_PIXELS_COMPLETED_CHROMIUM: |
9123 case GL_GET_ERROR_QUERY_CHROMIUM: | 9237 case GL_GET_ERROR_QUERY_CHROMIUM: |
9124 break; | 9238 break; |
9125 default: | 9239 default: |
9126 if (!features().occlusion_query_boolean) { | 9240 if (!features().occlusion_query_boolean) { |
9127 LOCAL_SET_GL_ERROR( | 9241 LOCAL_SET_GL_ERROR( |
9128 GL_INVALID_OPERATION, "glBeginQueryEXT", | 9242 GL_INVALID_OPERATION, "glBeginQueryEXT", |
9129 "not enabled for occlusion queries"); | 9243 "not enabled for occlusion queries"); |
9130 return error::kNoError; | 9244 return error::kNoError; |
9131 } | 9245 } |
9132 break; | 9246 break; |
9133 } | 9247 } |
9134 | 9248 |
| 9249 // TODO(hubbe): Make it possible to have one query per type running at the |
| 9250 // same time. |
9135 if (state_.current_query.get()) { | 9251 if (state_.current_query.get()) { |
9136 LOCAL_SET_GL_ERROR( | 9252 LOCAL_SET_GL_ERROR( |
9137 GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); | 9253 GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
9138 return error::kNoError; | 9254 return error::kNoError; |
9139 } | 9255 } |
9140 | 9256 |
9141 if (client_id == 0) { | 9257 if (client_id == 0) { |
9142 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); | 9258 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
9143 return error::kNoError; | 9259 return error::kNoError; |
9144 } | 9260 } |
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10346 return error::kNoError; | 10462 return error::kNoError; |
10347 } | 10463 } |
10348 | 10464 |
10349 // Include the auto-generated part of this file. We split this because it means | 10465 // Include the auto-generated part of this file. We split this because it means |
10350 // we can easily edit the non-auto generated parts right here in this file | 10466 // we can easily edit the non-auto generated parts right here in this file |
10351 // instead of having to edit some template or the code generator. | 10467 // instead of having to edit some template or the code generator. |
10352 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10468 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
10353 | 10469 |
10354 } // namespace gles2 | 10470 } // namespace gles2 |
10355 } // namespace gpu | 10471 } // namespace gpu |
OLD | NEW |