| 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 <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2279 // the current generation when our context becomes current, then we'll rebind | 2279 // the current generation when our context becomes current, then we'll rebind |
| 2280 // all the textures to stay up to date with Texture::service_id() changes. | 2280 // all the textures to stay up to date with Texture::service_id() changes. |
| 2281 uint32_t texture_manager_service_id_generation_; | 2281 uint32_t texture_manager_service_id_generation_; |
| 2282 | 2282 |
| 2283 bool force_shader_name_hashing_for_test; | 2283 bool force_shader_name_hashing_for_test; |
| 2284 | 2284 |
| 2285 GLfloat line_width_range_[2]; | 2285 GLfloat line_width_range_[2]; |
| 2286 | 2286 |
| 2287 SamplerState default_sampler_state_; | 2287 SamplerState default_sampler_state_; |
| 2288 | 2288 |
| 2289 struct CALayerSharedState{ |
| 2290 float opacity; |
| 2291 bool is_clipped; |
| 2292 gfx::Rect clip_rect; |
| 2293 int sorting_context_id; |
| 2294 gfx::Transform transform; |
| 2295 }; |
| 2296 |
| 2297 std::unique_ptr<CALayerSharedState> ca_layer_shared_state_; |
| 2298 |
| 2289 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); | 2299 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 2290 }; | 2300 }; |
| 2291 | 2301 |
| 2292 const GLES2DecoderImpl::CommandInfo GLES2DecoderImpl::command_info[] = { | 2302 const GLES2DecoderImpl::CommandInfo GLES2DecoderImpl::command_info[] = { |
| 2293 #define GLES2_CMD_OP(name) \ | 2303 #define GLES2_CMD_OP(name) \ |
| 2294 { \ | 2304 { \ |
| 2295 &GLES2DecoderImpl::Handle##name, cmds::name::kArgFlags, \ | 2305 &GLES2DecoderImpl::Handle##name, cmds::name::kArgFlags, \ |
| 2296 cmds::name::cmd_flags, \ | 2306 cmds::name::cmd_flags, \ |
| 2297 sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ | 2307 sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
| 2298 } \ | 2308 } \ |
| (...skipping 8373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10672 bool is_tracing; | 10682 bool is_tracing; |
| 10673 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), | 10683 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 10674 &is_tracing); | 10684 &is_tracing); |
| 10675 if (is_tracing) { | 10685 if (is_tracing) { |
| 10676 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); | 10686 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 10677 ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); | 10687 ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 10678 gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( | 10688 gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 10679 is_offscreen ? offscreen_size_ : surface_->GetSize()); | 10689 is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 10680 } | 10690 } |
| 10681 | 10691 |
| 10692 // The GL_CHROMIUM_schedule_ca_layer extension requires that SwapBuffers and |
| 10693 // equivalent functions reset shared state. |
| 10694 ca_layer_shared_state_.reset(); |
| 10695 |
| 10682 if (supports_async_swap_) { | 10696 if (supports_async_swap_) { |
| 10683 TRACE_EVENT_ASYNC_BEGIN0("cc", "GLES2DecoderImpl::AsyncSwapBuffers", this); | 10697 TRACE_EVENT_ASYNC_BEGIN0("cc", "GLES2DecoderImpl::AsyncSwapBuffers", this); |
| 10684 surface_->PostSubBufferAsync( | 10698 surface_->PostSubBufferAsync( |
| 10685 c.x, c.y, c.width, c.height, | 10699 c.x, c.y, c.width, c.height, |
| 10686 base::Bind(&GLES2DecoderImpl::FinishSwapBuffers, | 10700 base::Bind(&GLES2DecoderImpl::FinishSwapBuffers, |
| 10687 base::AsWeakPtr(this))); | 10701 base::AsWeakPtr(this))); |
| 10688 } else { | 10702 } else { |
| 10689 FinishSwapBuffers(surface_->PostSubBuffer(c.x, c.y, c.width, c.height)); | 10703 FinishSwapBuffers(surface_->PostSubBuffer(c.x, c.y, c.width, c.height)); |
| 10690 } | 10704 } |
| 10691 | 10705 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10726 image, | 10740 image, |
| 10727 gfx::Rect(c.bounds_x, c.bounds_y, c.bounds_width, c.bounds_height), | 10741 gfx::Rect(c.bounds_x, c.bounds_y, c.bounds_width, c.bounds_height), |
| 10728 gfx::RectF(c.uv_x, c.uv_y, c.uv_width, c.uv_height))) { | 10742 gfx::RectF(c.uv_x, c.uv_y, c.uv_width, c.uv_height))) { |
| 10729 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | 10743 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10730 "glScheduleOverlayPlaneCHROMIUM", | 10744 "glScheduleOverlayPlaneCHROMIUM", |
| 10731 "failed to schedule overlay"); | 10745 "failed to schedule overlay"); |
| 10732 } | 10746 } |
| 10733 return error::kNoError; | 10747 return error::kNoError; |
| 10734 } | 10748 } |
| 10735 | 10749 |
| 10750 error::Error GLES2DecoderImpl::HandleScheduleCALayerSharedStateCHROMIUM( |
| 10751 uint32_t immediate_data_size, |
| 10752 const void* cmd_data) { |
| 10753 const gles2::cmds::ScheduleCALayerSharedStateCHROMIUM& c = |
| 10754 *static_cast<const gles2::cmds::ScheduleCALayerSharedStateCHROMIUM*>( |
| 10755 cmd_data); |
| 10756 |
| 10757 const GLfloat* mem = GetSharedMemoryAs<const GLfloat*>(c.shm_id, c.shm_offset, |
| 10758 20 * sizeof(GLfloat)); |
| 10759 if (!mem) { |
| 10760 return error::kOutOfBounds; |
| 10761 } |
| 10762 gfx::RectF clip_rect(mem[0], mem[1], mem[2], mem[3]); |
| 10763 gfx::Transform transform(mem[4], mem[8], mem[12], mem[16], |
| 10764 mem[5], mem[9], mem[13], mem[17], |
| 10765 mem[6], mem[10], mem[14], mem[18], |
| 10766 mem[7], mem[11], mem[15], mem[19]); |
| 10767 ca_layer_shared_state_.reset(new CALayerSharedState); |
| 10768 ca_layer_shared_state_->opacity = c.opacity; |
| 10769 ca_layer_shared_state_->is_clipped = c.is_clipped ? true : false; |
| 10770 ca_layer_shared_state_->clip_rect = gfx::ToEnclosingRect(clip_rect); |
| 10771 ca_layer_shared_state_->sorting_context_id = c.sorting_context_id; |
| 10772 ca_layer_shared_state_->transform = transform; |
| 10773 return error::kNoError; |
| 10774 } |
| 10775 |
| 10736 error::Error GLES2DecoderImpl::HandleScheduleCALayerCHROMIUM( | 10776 error::Error GLES2DecoderImpl::HandleScheduleCALayerCHROMIUM( |
| 10737 uint32_t immediate_data_size, | 10777 uint32_t immediate_data_size, |
| 10738 const void* cmd_data) { | 10778 const void* cmd_data) { |
| 10739 const gles2::cmds::ScheduleCALayerCHROMIUM& c = | 10779 const gles2::cmds::ScheduleCALayerCHROMIUM& c = |
| 10740 *static_cast<const gles2::cmds::ScheduleCALayerCHROMIUM*>(cmd_data); | 10780 *static_cast<const gles2::cmds::ScheduleCALayerCHROMIUM*>(cmd_data); |
| 10741 GLuint filter = c.filter; | 10781 GLuint filter = c.filter; |
| 10742 if (filter != GL_NEAREST && filter != GL_LINEAR) { | 10782 if (filter != GL_NEAREST && filter != GL_LINEAR) { |
| 10743 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glScheduleCALayerCHROMIUM", | 10783 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glScheduleCALayerCHROMIUM", |
| 10744 "invalid filter"); | 10784 "invalid filter"); |
| 10745 return error::kNoError; | 10785 return error::kNoError; |
| 10746 } | 10786 } |
| 10747 | 10787 |
| 10788 if (!ca_layer_shared_state_) { |
| 10789 LOCAL_SET_GL_ERROR( |
| 10790 GL_INVALID_OPERATION, "glScheduleCALayerCHROMIUM", |
| 10791 "glScheduleCALayerSharedStateCHROMIUM has not been called"); |
| 10792 return error::kNoError; |
| 10793 } |
| 10794 |
| 10748 gl::GLImage* image = nullptr; | 10795 gl::GLImage* image = nullptr; |
| 10749 GLuint contents_texture_id = c.contents_texture_id; | 10796 GLuint contents_texture_id = c.contents_texture_id; |
| 10750 if (contents_texture_id) { | 10797 if (contents_texture_id) { |
| 10751 TextureRef* ref = texture_manager()->GetTexture(contents_texture_id); | 10798 TextureRef* ref = texture_manager()->GetTexture(contents_texture_id); |
| 10752 if (!ref) { | 10799 if (!ref) { |
| 10753 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glScheduleCALayerCHROMIUM", | 10800 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glScheduleCALayerCHROMIUM", |
| 10754 "unknown texture"); | 10801 "unknown texture"); |
| 10755 return error::kNoError; | 10802 return error::kNoError; |
| 10756 } | 10803 } |
| 10757 Texture::ImageState image_state; | 10804 Texture::ImageState image_state; |
| 10758 image = ref->texture()->GetLevelImage(ref->texture()->target(), 0, | 10805 image = ref->texture()->GetLevelImage(ref->texture()->target(), 0, |
| 10759 &image_state); | 10806 &image_state); |
| 10760 if (!image) { | 10807 if (!image) { |
| 10761 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glScheduleCALayerCHROMIUM", | 10808 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glScheduleCALayerCHROMIUM", |
| 10762 "unsupported texture format"); | 10809 "unsupported texture format"); |
| 10763 return error::kNoError; | 10810 return error::kNoError; |
| 10764 } | 10811 } |
| 10765 } | 10812 } |
| 10766 | 10813 |
| 10767 const GLfloat* mem = GetSharedMemoryAs<const GLfloat*>(c.shm_id, c.shm_offset, | 10814 const GLfloat* mem = GetSharedMemoryAs<const GLfloat*>(c.shm_id, c.shm_offset, |
| 10768 28 * sizeof(GLfloat)); | 10815 8 * sizeof(GLfloat)); |
| 10769 if (!mem) { | 10816 if (!mem) { |
| 10770 return error::kOutOfBounds; | 10817 return error::kOutOfBounds; |
| 10771 } | 10818 } |
| 10772 gfx::RectF contents_rect(mem[0], mem[1], mem[2], mem[3]); | 10819 gfx::RectF contents_rect(mem[0], mem[1], mem[2], mem[3]); |
| 10773 gfx::RectF bounds_rect(mem[4], mem[5], mem[6], mem[7]); | 10820 gfx::RectF bounds_rect(mem[4], mem[5], mem[6], mem[7]); |
| 10774 gfx::RectF clip_rect(mem[8], mem[9], mem[10], mem[11]); | |
| 10775 gfx::Transform transform(mem[12], mem[16], mem[20], mem[24], | |
| 10776 mem[13], mem[17], mem[21], mem[25], | |
| 10777 mem[14], mem[18], mem[22], mem[26], | |
| 10778 mem[15], mem[19], mem[23], mem[27]); | |
| 10779 | 10821 |
| 10780 ui::CARendererLayerParams params = ui::CARendererLayerParams( | 10822 ui::CARendererLayerParams params = ui::CARendererLayerParams( |
| 10781 c.is_clipped ? true : false, gfx::ToEnclosingRect(clip_rect), | 10823 ca_layer_shared_state_->is_clipped, ca_layer_shared_state_->clip_rect, |
| 10782 c.sorting_context_id, transform, image, contents_rect, | 10824 ca_layer_shared_state_->sorting_context_id, |
| 10825 ca_layer_shared_state_->transform, image, contents_rect, |
| 10783 gfx::ToEnclosingRect(bounds_rect), c.background_color, c.edge_aa_mask, | 10826 gfx::ToEnclosingRect(bounds_rect), c.background_color, c.edge_aa_mask, |
| 10784 c.opacity, filter); | 10827 ca_layer_shared_state_->opacity, filter); |
| 10785 if (!surface_->ScheduleCALayer(params)) { | 10828 if (!surface_->ScheduleCALayer(params)) { |
| 10786 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glScheduleCALayerCHROMIUM", | 10829 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glScheduleCALayerCHROMIUM", |
| 10787 "failed to schedule CALayer"); | 10830 "failed to schedule CALayer"); |
| 10788 } | 10831 } |
| 10789 return error::kNoError; | 10832 return error::kNoError; |
| 10790 } | 10833 } |
| 10791 | 10834 |
| 10792 void GLES2DecoderImpl::DoScheduleCALayerInUseQueryCHROMIUM( | 10835 void GLES2DecoderImpl::DoScheduleCALayerInUseQueryCHROMIUM( |
| 10793 GLsizei count, | 10836 GLsizei count, |
| 10794 const GLuint* textures) { | 10837 const GLuint* textures) { |
| (...skipping 2909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13704 | 13747 |
| 13705 bool is_tracing; | 13748 bool is_tracing; |
| 13706 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), | 13749 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 13707 &is_tracing); | 13750 &is_tracing); |
| 13708 if (is_tracing) { | 13751 if (is_tracing) { |
| 13709 ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); | 13752 ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 13710 gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( | 13753 gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 13711 is_offscreen ? offscreen_size_ : surface_->GetSize()); | 13754 is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 13712 } | 13755 } |
| 13713 | 13756 |
| 13757 // The GL_CHROMIUM_schedule_ca_layer extension requires that SwapBuffers and |
| 13758 // equivalent functions reset shared state. |
| 13759 ca_layer_shared_state_.reset(); |
| 13760 |
| 13714 // If offscreen then don't actually SwapBuffers to the display. Just copy | 13761 // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 13715 // the rendered frame to another frame buffer. | 13762 // the rendered frame to another frame buffer. |
| 13716 if (is_offscreen) { | 13763 if (is_offscreen) { |
| 13717 TRACE_EVENT2("gpu", "Offscreen", | 13764 TRACE_EVENT2("gpu", "Offscreen", |
| 13718 "width", offscreen_size_.width(), "height", offscreen_size_.height()); | 13765 "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
| 13719 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { | 13766 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 13720 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, | 13767 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 13721 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will | 13768 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 13722 // fix this. | 13769 // fix this. |
| 13723 if (workarounds().needs_offscreen_buffer_workaround) { | 13770 if (workarounds().needs_offscreen_buffer_workaround) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13822 } | 13869 } |
| 13823 } | 13870 } |
| 13824 | 13871 |
| 13825 void GLES2DecoderImpl::DoCommitOverlayPlanes() { | 13872 void GLES2DecoderImpl::DoCommitOverlayPlanes() { |
| 13826 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCommitOverlayPlanes"); | 13873 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCommitOverlayPlanes"); |
| 13827 if (!supports_commit_overlay_planes_) { | 13874 if (!supports_commit_overlay_planes_) { |
| 13828 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCommitOverlayPlanes", | 13875 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCommitOverlayPlanes", |
| 13829 "command not supported by surface"); | 13876 "command not supported by surface"); |
| 13830 return; | 13877 return; |
| 13831 } | 13878 } |
| 13879 // The GL_CHROMIUM_schedule_ca_layer extension requires that SwapBuffers and |
| 13880 // equivalent functions reset shared state. |
| 13881 ca_layer_shared_state_.reset(); |
| 13832 if (supports_async_swap_) { | 13882 if (supports_async_swap_) { |
| 13833 surface_->CommitOverlayPlanesAsync(base::Bind( | 13883 surface_->CommitOverlayPlanesAsync(base::Bind( |
| 13834 &GLES2DecoderImpl::FinishSwapBuffers, base::AsWeakPtr(this))); | 13884 &GLES2DecoderImpl::FinishSwapBuffers, base::AsWeakPtr(this))); |
| 13835 } else { | 13885 } else { |
| 13836 FinishSwapBuffers(surface_->CommitOverlayPlanes()); | 13886 FinishSwapBuffers(surface_->CommitOverlayPlanes()); |
| 13837 } | 13887 } |
| 13838 } | 13888 } |
| 13839 | 13889 |
| 13840 void GLES2DecoderImpl::DoSwapInterval(int interval) { | 13890 void GLES2DecoderImpl::DoSwapInterval(int interval) { |
| 13841 context_->SetSwapInterval(interval); | 13891 context_->SetSwapInterval(interval); |
| (...skipping 3566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17408 } | 17458 } |
| 17409 | 17459 |
| 17410 // Include the auto-generated part of this file. We split this because it means | 17460 // Include the auto-generated part of this file. We split this because it means |
| 17411 // we can easily edit the non-auto generated parts right here in this file | 17461 // we can easily edit the non-auto generated parts right here in this file |
| 17412 // instead of having to edit some template or the code generator. | 17462 // instead of having to edit some template or the code generator. |
| 17413 #include "base/macros.h" | 17463 #include "base/macros.h" |
| 17414 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 17464 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 17415 | 17465 |
| 17416 } // namespace gles2 | 17466 } // namespace gles2 |
| 17417 } // namespace gpu | 17467 } // namespace gpu |
| OLD | NEW |