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 23 matching lines...) Expand all Loading... |
34 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 34 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
35 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" | 35 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
36 #include "gpu/command_buffer/service/buffer_manager.h" | 36 #include "gpu/command_buffer/service/buffer_manager.h" |
37 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 37 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
38 #include "gpu/command_buffer/service/context_group.h" | 38 #include "gpu/command_buffer/service/context_group.h" |
39 #include "gpu/command_buffer/service/context_state.h" | 39 #include "gpu/command_buffer/service/context_state.h" |
40 #include "gpu/command_buffer/service/error_state.h" | 40 #include "gpu/command_buffer/service/error_state.h" |
41 #include "gpu/command_buffer/service/feature_info.h" | 41 #include "gpu/command_buffer/service/feature_info.h" |
42 #include "gpu/command_buffer/service/framebuffer_manager.h" | 42 #include "gpu/command_buffer/service/framebuffer_manager.h" |
43 #include "gpu/command_buffer/service/gl_utils.h" | 43 #include "gpu/command_buffer/service/gl_utils.h" |
| 44 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" |
44 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 45 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
45 #include "gpu/command_buffer/service/gles2_cmd_validation.h" | 46 #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
46 #include "gpu/command_buffer/service/gpu_state_tracer.h" | 47 #include "gpu/command_buffer/service/gpu_state_tracer.h" |
47 #include "gpu/command_buffer/service/gpu_switches.h" | 48 #include "gpu/command_buffer/service/gpu_switches.h" |
48 #include "gpu/command_buffer/service/gpu_tracer.h" | 49 #include "gpu/command_buffer/service/gpu_tracer.h" |
49 #include "gpu/command_buffer/service/image_manager.h" | 50 #include "gpu/command_buffer/service/image_manager.h" |
50 #include "gpu/command_buffer/service/mailbox_manager.h" | 51 #include "gpu/command_buffer/service/mailbox_manager.h" |
51 #include "gpu/command_buffer/service/memory_tracking.h" | 52 #include "gpu/command_buffer/service/memory_tracking.h" |
52 #include "gpu/command_buffer/service/program_manager.h" | 53 #include "gpu/command_buffer/service/program_manager.h" |
53 #include "gpu/command_buffer/service/query_manager.h" | 54 #include "gpu/command_buffer/service/query_manager.h" |
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 | 1834 |
1834 // Log extra info. | 1835 // Log extra info. |
1835 bool service_logging_; | 1836 bool service_logging_; |
1836 | 1837 |
1837 #if defined(OS_MACOSX) | 1838 #if defined(OS_MACOSX) |
1838 typedef std::map<GLuint, IOSurfaceRef> TextureToIOSurfaceMap; | 1839 typedef std::map<GLuint, IOSurfaceRef> TextureToIOSurfaceMap; |
1839 TextureToIOSurfaceMap texture_to_io_surface_map_; | 1840 TextureToIOSurfaceMap texture_to_io_surface_map_; |
1840 #endif | 1841 #endif |
1841 | 1842 |
1842 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; | 1843 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
| 1844 scoped_ptr<ClearFramebufferResourceManager> clear_framebuffer_blit_; |
1843 | 1845 |
1844 // Cached values of the currently assigned viewport dimensions. | 1846 // Cached values of the currently assigned viewport dimensions. |
1845 GLsizei viewport_max_width_; | 1847 GLsizei viewport_max_width_; |
1846 GLsizei viewport_max_height_; | 1848 GLsizei viewport_max_height_; |
1847 | 1849 |
1848 // Command buffer stats. | 1850 // Command buffer stats. |
1849 base::TimeDelta total_processing_commands_time_; | 1851 base::TimeDelta total_processing_commands_time_; |
1850 | 1852 |
1851 // States related to each manager. | 1853 // States related to each manager. |
1852 DecoderTextureState texture_state_; | 1854 DecoderTextureState texture_state_; |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2757 // that can be safely migrated between the iGPU and the dGPU. Mark | 2759 // that can be safely migrated between the iGPU and the dGPU. Mark |
2758 // those contexts as safe to forcibly transition between the GPUs. | 2760 // those contexts as safe to forcibly transition between the GPUs. |
2759 // http://crbug.com/180876, http://crbug.com/227228 | 2761 // http://crbug.com/180876, http://crbug.com/227228 |
2760 if (!offscreen) | 2762 if (!offscreen) |
2761 context_->SetSafeToForceGpuSwitch(); | 2763 context_->SetSafeToForceGpuSwitch(); |
2762 | 2764 |
2763 async_pixel_transfer_manager_.reset( | 2765 async_pixel_transfer_manager_.reset( |
2764 AsyncPixelTransferManager::Create(context.get())); | 2766 AsyncPixelTransferManager::Create(context.get())); |
2765 async_pixel_transfer_manager_->Initialize(texture_manager()); | 2767 async_pixel_transfer_manager_->Initialize(texture_manager()); |
2766 | 2768 |
| 2769 if (workarounds().gl_clear_broken) { |
| 2770 DCHECK(!clear_framebuffer_blit_.get()); |
| 2771 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glClearWorkaroundInit"); |
| 2772 clear_framebuffer_blit_.reset(new ClearFramebufferResourceManager(this)); |
| 2773 if (LOCAL_PEEK_GL_ERROR("glClearWorkaroundInit") != GL_NO_ERROR) |
| 2774 return false; |
| 2775 } |
| 2776 |
2767 framebuffer_manager()->AddObserver(this); | 2777 framebuffer_manager()->AddObserver(this); |
2768 | 2778 |
2769 return true; | 2779 return true; |
2770 } | 2780 } |
2771 | 2781 |
2772 Capabilities GLES2DecoderImpl::GetCapabilities() { | 2782 Capabilities GLES2DecoderImpl::GetCapabilities() { |
2773 DCHECK(initialized()); | 2783 DCHECK(initialized()); |
2774 | 2784 |
2775 Capabilities caps; | 2785 Capabilities caps; |
2776 caps.VisitPrecisions([](GLenum shader, GLenum type, | 2786 caps.VisitPrecisions([](GLenum shader, GLenum type, |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3542 offscreen_saved_color_texture_->id()); | 3552 offscreen_saved_color_texture_->id()); |
3543 offscreen_saved_color_texture_->Invalidate(); | 3553 offscreen_saved_color_texture_->Invalidate(); |
3544 offscreen_saved_color_texture_info_ = NULL; | 3554 offscreen_saved_color_texture_info_ = NULL; |
3545 } | 3555 } |
3546 if (have_context) { | 3556 if (have_context) { |
3547 if (copy_texture_CHROMIUM_.get()) { | 3557 if (copy_texture_CHROMIUM_.get()) { |
3548 copy_texture_CHROMIUM_->Destroy(); | 3558 copy_texture_CHROMIUM_->Destroy(); |
3549 copy_texture_CHROMIUM_.reset(); | 3559 copy_texture_CHROMIUM_.reset(); |
3550 } | 3560 } |
3551 | 3561 |
| 3562 clear_framebuffer_blit_.reset(); |
| 3563 |
3552 if (state_.current_program.get()) { | 3564 if (state_.current_program.get()) { |
3553 program_manager()->UnuseProgram(shader_manager(), | 3565 program_manager()->UnuseProgram(shader_manager(), |
3554 state_.current_program.get()); | 3566 state_.current_program.get()); |
3555 } | 3567 } |
3556 | 3568 |
3557 if (attrib_0_buffer_id_) { | 3569 if (attrib_0_buffer_id_) { |
3558 glDeleteBuffersARB(1, &attrib_0_buffer_id_); | 3570 glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
3559 } | 3571 } |
3560 if (fixed_attrib_buffer_id_) { | 3572 if (fixed_attrib_buffer_id_) { |
3561 glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); | 3573 glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3607 } | 3619 } |
3608 | 3620 |
3609 // Current program must be cleared after calling ProgramManager::UnuseProgram. | 3621 // Current program must be cleared after calling ProgramManager::UnuseProgram. |
3610 // Otherwise, we can leak objects. http://crbug.com/258772. | 3622 // Otherwise, we can leak objects. http://crbug.com/258772. |
3611 // state_.current_program must be reset before group_ is reset because | 3623 // state_.current_program must be reset before group_ is reset because |
3612 // the later deletes the ProgramManager object that referred by | 3624 // the later deletes the ProgramManager object that referred by |
3613 // state_.current_program object. | 3625 // state_.current_program object. |
3614 state_.current_program = NULL; | 3626 state_.current_program = NULL; |
3615 | 3627 |
3616 copy_texture_CHROMIUM_.reset(); | 3628 copy_texture_CHROMIUM_.reset(); |
| 3629 clear_framebuffer_blit_.reset(); |
3617 | 3630 |
3618 if (query_manager_.get()) { | 3631 if (query_manager_.get()) { |
3619 query_manager_->Destroy(have_context); | 3632 query_manager_->Destroy(have_context); |
3620 query_manager_.reset(); | 3633 query_manager_.reset(); |
3621 } | 3634 } |
3622 | 3635 |
3623 if (vertex_array_manager_ .get()) { | 3636 if (vertex_array_manager_ .get()) { |
3624 vertex_array_manager_->Destroy(have_context); | 3637 vertex_array_manager_->Destroy(have_context); |
3625 vertex_array_manager_.reset(); | 3638 vertex_array_manager_.reset(); |
3626 } | 3639 } |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5099 } | 5112 } |
5100 } | 5113 } |
5101 return error::kNoError; | 5114 return error::kNoError; |
5102 } | 5115 } |
5103 | 5116 |
5104 error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { | 5117 error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
5105 DCHECK(!ShouldDeferDraws()); | 5118 DCHECK(!ShouldDeferDraws()); |
5106 if (CheckBoundFramebuffersValid("glClear")) { | 5119 if (CheckBoundFramebuffersValid("glClear")) { |
5107 ApplyDirtyState(); | 5120 ApplyDirtyState(); |
5108 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); | 5121 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
| 5122 if (workarounds().gl_clear_broken) { |
| 5123 ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::ClearWorkaround", |
| 5124 GetErrorState()); |
| 5125 if (!BoundFramebufferHasDepthAttachment()) |
| 5126 mask &= ~GL_DEPTH_BUFFER_BIT; |
| 5127 if (!BoundFramebufferHasStencilAttachment()) |
| 5128 mask &= ~GL_STENCIL_BUFFER_BIT; |
| 5129 clear_framebuffer_blit_->ClearFramebuffer( |
| 5130 this, GetBoundReadFrameBufferSize(), mask, state_.color_clear_red, |
| 5131 state_.color_clear_green, state_.color_clear_blue, |
| 5132 state_.color_clear_alpha, state_.depth_clear, state_.stencil_clear); |
| 5133 return error::kNoError; |
| 5134 } |
5109 glClear(mask); | 5135 glClear(mask); |
5110 } | 5136 } |
5111 return error::kNoError; | 5137 return error::kNoError; |
5112 } | 5138 } |
5113 | 5139 |
5114 void GLES2DecoderImpl::DoFramebufferRenderbuffer( | 5140 void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
5115 GLenum target, GLenum attachment, GLenum renderbuffertarget, | 5141 GLenum target, GLenum attachment, GLenum renderbuffertarget, |
5116 GLuint client_renderbuffer_id) { | 5142 GLuint client_renderbuffer_id) { |
5117 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); | 5143 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
5118 if (!framebuffer) { | 5144 if (!framebuffer) { |
(...skipping 2452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7571 | 7597 |
7572 if (buffer != 0) { | 7598 if (buffer != 0) { |
7573 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); | 7599 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
7574 void* data; | 7600 void* data; |
7575 if (features().map_buffer_range) { | 7601 if (features().map_buffer_range) { |
7576 data = glMapBufferRange( | 7602 data = glMapBufferRange( |
7577 GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); | 7603 GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); |
7578 } else { | 7604 } else { |
7579 data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); | 7605 data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
7580 } | 7606 } |
| 7607 if (!data) { |
| 7608 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glMapBuffer", |
| 7609 "Unable to map memory for readback."); |
| 7610 return; |
| 7611 } |
7581 memcpy(pixels, data, pixels_size); | 7612 memcpy(pixels, data, pixels_size); |
7582 // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't | 7613 // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
7583 // have to restore the state. | 7614 // have to restore the state. |
7584 glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); | 7615 glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
7585 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 7616 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
7586 glDeleteBuffersARB(1, &buffer); | 7617 glDeleteBuffersARB(1, &buffer); |
7587 } | 7618 } |
7588 | 7619 |
7589 if (result != NULL) { | 7620 if (result != NULL) { |
7590 *result = true; | 7621 *result = true; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7772 glReadPixels( | 7803 glReadPixels( |
7773 read_x, ry, read_width, 1, format, type, dst + dest_row_offset); | 7804 read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
7774 } | 7805 } |
7775 dst += padded_row_size; | 7806 dst += padded_row_size; |
7776 } | 7807 } |
7777 } else { | 7808 } else { |
7778 if (async && features().use_async_readpixels) { | 7809 if (async && features().use_async_readpixels) { |
7779 GLuint buffer = 0; | 7810 GLuint buffer = 0; |
7780 glGenBuffersARB(1, &buffer); | 7811 glGenBuffersARB(1, &buffer); |
7781 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); | 7812 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
7782 glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, GL_STREAM_READ); | 7813 // For ANGLE client version 2, GL_STREAM_READ is not available. |
| 7814 const GLenum usage_hint = |
| 7815 features().is_angle ? GL_STATIC_DRAW : GL_STREAM_READ; |
| 7816 glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, usage_hint); |
7783 GLenum error = glGetError(); | 7817 GLenum error = glGetError(); |
7784 if (error == GL_NO_ERROR) { | 7818 if (error == GL_NO_ERROR) { |
7785 glReadPixels(x, y, width, height, format, type, 0); | 7819 glReadPixels(x, y, width, height, format, type, 0); |
7786 pending_readpixel_fences_.push(linked_ptr<FenceCallback>( | 7820 pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
7787 new FenceCallback())); | 7821 new FenceCallback())); |
7788 WaitForReadPixels(base::Bind( | 7822 WaitForReadPixels(base::Bind( |
7789 &GLES2DecoderImpl::FinishReadPixels, | 7823 &GLES2DecoderImpl::FinishReadPixels, |
7790 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr | 7824 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
7791 <GLES2DecoderImpl>(this), | 7825 <GLES2DecoderImpl>(this), |
7792 c, buffer)); | 7826 c, buffer)); |
(...skipping 3615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11408 } | 11442 } |
11409 } | 11443 } |
11410 | 11444 |
11411 // Include the auto-generated part of this file. We split this because it means | 11445 // Include the auto-generated part of this file. We split this because it means |
11412 // we can easily edit the non-auto generated parts right here in this file | 11446 // we can easily edit the non-auto generated parts right here in this file |
11413 // instead of having to edit some template or the code generator. | 11447 // instead of having to edit some template or the code generator. |
11414 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 11448 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
11415 | 11449 |
11416 } // namespace gles2 | 11450 } // namespace gles2 |
11417 } // namespace gpu | 11451 } // namespace gpu |
OLD | NEW |