| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 | 705 |
| 706 // Overridden from AsyncAPIInterface. | 706 // Overridden from AsyncAPIInterface. |
| 707 virtual const char* GetCommandName(unsigned int command_id) const; | 707 virtual const char* GetCommandName(unsigned int command_id) const; |
| 708 | 708 |
| 709 // Overridden from GLES2Decoder. | 709 // Overridden from GLES2Decoder. |
| 710 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, | 710 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 711 const scoped_refptr<gfx::GLContext>& context, | 711 const scoped_refptr<gfx::GLContext>& context, |
| 712 const gfx::Size& size, | 712 const gfx::Size& size, |
| 713 const DisallowedExtensions& disallowed_extensions, | 713 const DisallowedExtensions& disallowed_extensions, |
| 714 const char* allowed_extensions, | 714 const char* allowed_extensions, |
| 715 const std::vector<int32>& attribs, | 715 const std::vector<int32>& attribs); |
| 716 GLES2Decoder* parent, | |
| 717 uint32 parent_client_texture_id); | |
| 718 virtual void Destroy(); | 716 virtual void Destroy(); |
| 717 virtual bool SetParent(GLES2Decoder* parent_decoder, |
| 718 uint32 parent_texture_id); |
| 719 virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size); | 719 virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size); |
| 720 virtual bool UpdateOffscreenFrameBufferSize(); | 720 virtual bool UpdateOffscreenFrameBufferSize(); |
| 721 virtual bool MakeCurrent(); | 721 virtual bool MakeCurrent(); |
| 722 virtual GLES2Util* GetGLES2Util() { return &util_; } | 722 virtual GLES2Util* GetGLES2Util() { return &util_; } |
| 723 virtual gfx::GLContext* GetGLContext() { return context_.get(); } | 723 virtual gfx::GLContext* GetGLContext() { return context_.get(); } |
| 724 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } | 724 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } |
| 725 virtual ContextGroup* GetContextGroup() { return group_.get(); } | 725 virtual ContextGroup* GetContextGroup() { return group_.get(); } |
| 726 | 726 |
| 727 virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback); | 727 virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback); |
| 728 virtual void SetSwapBuffersCallback(Callback0::Type* callback); | 728 virtual void SetSwapBuffersCallback(Callback0::Type* callback); |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 bufferdata_faster_than_buffersubdata_ = false; | 1883 bufferdata_faster_than_buffersubdata_ = false; |
| 1884 } | 1884 } |
| 1885 } | 1885 } |
| 1886 | 1886 |
| 1887 bool GLES2DecoderImpl::Initialize( | 1887 bool GLES2DecoderImpl::Initialize( |
| 1888 const scoped_refptr<gfx::GLSurface>& surface, | 1888 const scoped_refptr<gfx::GLSurface>& surface, |
| 1889 const scoped_refptr<gfx::GLContext>& context, | 1889 const scoped_refptr<gfx::GLContext>& context, |
| 1890 const gfx::Size& size, | 1890 const gfx::Size& size, |
| 1891 const DisallowedExtensions& disallowed_extensions, | 1891 const DisallowedExtensions& disallowed_extensions, |
| 1892 const char* allowed_extensions, | 1892 const char* allowed_extensions, |
| 1893 const std::vector<int32>& attribs, | 1893 const std::vector<int32>& attribs) { |
| 1894 GLES2Decoder* parent, | |
| 1895 uint32 parent_client_texture_id) { | |
| 1896 DCHECK(context); | 1894 DCHECK(context); |
| 1897 DCHECK(!context_.get()); | 1895 DCHECK(!context_.get()); |
| 1898 | 1896 |
| 1899 // Take ownership of the GLSurface. TODO(apatrick): once the parent / child | 1897 // Take ownership of the GLSurface. TODO(apatrick): once the parent / child |
| 1900 // context is retired, the decoder should not take an initial surface as | 1898 // context is retired, the decoder should not take an initial surface as |
| 1901 // an argument to this function. | 1899 // an argument to this function. |
| 1902 // Maybe create a short lived offscreen GLSurface for the purpose of | 1900 // Maybe create a short lived offscreen GLSurface for the purpose of |
| 1903 // initializing the decoder's GLContext. | 1901 // initializing the decoder's GLContext. |
| 1904 surface_ = surface; | 1902 surface_ = surface; |
| 1905 | 1903 |
| 1906 // Take ownership of the GLContext. | 1904 // Take ownership of the GLContext. |
| 1907 context_ = context; | 1905 context_ = context; |
| 1908 | 1906 |
| 1909 // Keep only a weak pointer to the parent so we don't unmap its client | |
| 1910 // frame buffer after it has been destroyed. | |
| 1911 if (parent) | |
| 1912 parent_ = static_cast<GLES2DecoderImpl*>(parent)->AsWeakPtr(); | |
| 1913 | |
| 1914 if (!MakeCurrent()) { | 1907 if (!MakeCurrent()) { |
| 1915 LOG(ERROR) << "GLES2DecoderImpl::Initialize failed because " | 1908 LOG(ERROR) << "GLES2DecoderImpl::Initialize failed because " |
| 1916 << "MakeCurrent failed."; | 1909 << "MakeCurrent failed."; |
| 1917 Destroy(); | 1910 Destroy(); |
| 1918 return false; | 1911 return false; |
| 1919 } | 1912 } |
| 1920 | 1913 |
| 1921 if (!group_->Initialize(disallowed_extensions, allowed_extensions)) { | 1914 if (!group_->Initialize(disallowed_extensions, allowed_extensions)) { |
| 1922 LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " | 1915 LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
| 1923 << "failed to initialize."; | 1916 << "failed to initialize."; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 offscreen_target_stencil_render_buffer_->Create(); | 2054 offscreen_target_stencil_render_buffer_->Create(); |
| 2062 | 2055 |
| 2063 // Create the saved offscreen texture. The target frame buffer is copied | 2056 // Create the saved offscreen texture. The target frame buffer is copied |
| 2064 // here when SwapBuffers is called. | 2057 // here when SwapBuffers is called. |
| 2065 offscreen_saved_frame_buffer_.reset(new FrameBuffer(this)); | 2058 offscreen_saved_frame_buffer_.reset(new FrameBuffer(this)); |
| 2066 offscreen_saved_frame_buffer_->Create(); | 2059 offscreen_saved_frame_buffer_->Create(); |
| 2067 // | 2060 // |
| 2068 offscreen_saved_color_texture_.reset(new Texture(this)); | 2061 offscreen_saved_color_texture_.reset(new Texture(this)); |
| 2069 offscreen_saved_color_texture_->Create(); | 2062 offscreen_saved_color_texture_->Create(); |
| 2070 | 2063 |
| 2071 // Map the ID of the saved offscreen texture into the parent so that | |
| 2072 // it can reference it. | |
| 2073 if (parent_) { | |
| 2074 GLuint service_id = offscreen_saved_color_texture_->id(); | |
| 2075 TextureManager::TextureInfo* info = | |
| 2076 parent_->CreateTextureInfo(parent_client_texture_id, service_id); | |
| 2077 info->SetNotOwned(); | |
| 2078 parent_->texture_manager()->SetInfoTarget(info, GL_TEXTURE_2D); | |
| 2079 } | |
| 2080 | |
| 2081 // Allocate the render buffers at their initial size and check the status | 2064 // Allocate the render buffers at their initial size and check the status |
| 2082 // of the frame buffers is okay. | 2065 // of the frame buffers is okay. |
| 2083 pending_offscreen_size_ = size; | 2066 pending_offscreen_size_ = size; |
| 2084 if (!UpdateOffscreenFrameBufferSize()) { | 2067 if (!UpdateOffscreenFrameBufferSize()) { |
| 2085 LOG(ERROR) << "Could not allocate offscreen buffer storage."; | 2068 LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
| 2086 Destroy(); | 2069 Destroy(); |
| 2087 return false; | 2070 return false; |
| 2088 } | 2071 } |
| 2089 | 2072 |
| 2090 // Bind to the new default frame buffer (the offscreen target frame buffer). | 2073 // Bind to the new default frame buffer (the offscreen target frame buffer). |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2551 } | 2534 } |
| 2552 return false; | 2535 return false; |
| 2553 } | 2536 } |
| 2554 | 2537 |
| 2555 void GLES2DecoderImpl::Destroy() { | 2538 void GLES2DecoderImpl::Destroy() { |
| 2556 bool have_context = context_.get() && MakeCurrent(); | 2539 bool have_context = context_.get() && MakeCurrent(); |
| 2557 | 2540 |
| 2558 if (group_.get()) | 2541 if (group_.get()) |
| 2559 group_->set_have_context(have_context); | 2542 group_->set_have_context(have_context); |
| 2560 | 2543 |
| 2544 SetParent(NULL, 0); |
| 2545 |
| 2561 if (have_context) { | 2546 if (have_context) { |
| 2562 if (current_program_) { | 2547 if (current_program_) { |
| 2563 program_manager()->UnuseProgram(shader_manager(), current_program_); | 2548 program_manager()->UnuseProgram(shader_manager(), current_program_); |
| 2564 current_program_ = NULL; | 2549 current_program_ = NULL; |
| 2565 } | 2550 } |
| 2566 | 2551 |
| 2567 if (attrib_0_buffer_id_) { | 2552 if (attrib_0_buffer_id_) { |
| 2568 glDeleteBuffersARB(1, &attrib_0_buffer_id_); | 2553 glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 2569 } | 2554 } |
| 2570 if (fixed_attrib_buffer_id_) { | 2555 if (fixed_attrib_buffer_id_) { |
| 2571 glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); | 2556 glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 2572 } | 2557 } |
| 2573 | 2558 |
| 2574 // Remove the saved frame buffer mapping from the parent decoder. The | 2559 if (copy_texture_to_parent_texture_fb_) |
| 2575 // parent pointer is a weak pointer so it will be null if the parent has | |
| 2576 // already been destroyed. | |
| 2577 if (parent_) { | |
| 2578 // First check the texture has been mapped into the parent. This might not | |
| 2579 // be the case if initialization failed midway through. | |
| 2580 GLuint service_id = offscreen_saved_color_texture_->id(); | |
| 2581 GLuint client_id = 0; | |
| 2582 if (parent_->texture_manager()->GetClientId(service_id, &client_id)) { | |
| 2583 parent_->texture_manager()->RemoveTextureInfo(feature_info_, client_id); | |
| 2584 } | |
| 2585 | |
| 2586 glDeleteFramebuffersEXT(1, ©_texture_to_parent_texture_fb_); | 2560 glDeleteFramebuffersEXT(1, ©_texture_to_parent_texture_fb_); |
| 2587 } | |
| 2588 | 2561 |
| 2589 if (offscreen_target_frame_buffer_.get()) | 2562 if (offscreen_target_frame_buffer_.get()) |
| 2590 offscreen_target_frame_buffer_->Destroy(); | 2563 offscreen_target_frame_buffer_->Destroy(); |
| 2591 if (offscreen_target_color_texture_.get()) | 2564 if (offscreen_target_color_texture_.get()) |
| 2592 offscreen_target_color_texture_->Destroy(); | 2565 offscreen_target_color_texture_->Destroy(); |
| 2593 if (offscreen_target_color_render_buffer_.get()) | 2566 if (offscreen_target_color_render_buffer_.get()) |
| 2594 offscreen_target_color_render_buffer_->Destroy(); | 2567 offscreen_target_color_render_buffer_->Destroy(); |
| 2595 if (offscreen_target_depth_render_buffer_.get()) | 2568 if (offscreen_target_depth_render_buffer_.get()) |
| 2596 offscreen_target_depth_render_buffer_->Destroy(); | 2569 offscreen_target_depth_render_buffer_->Destroy(); |
| 2597 if (offscreen_target_stencil_render_buffer_.get()) | 2570 if (offscreen_target_stencil_render_buffer_.get()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2629 | 2602 |
| 2630 offscreen_target_frame_buffer_.reset(); | 2603 offscreen_target_frame_buffer_.reset(); |
| 2631 offscreen_target_color_texture_.reset(); | 2604 offscreen_target_color_texture_.reset(); |
| 2632 offscreen_target_color_render_buffer_.reset(); | 2605 offscreen_target_color_render_buffer_.reset(); |
| 2633 offscreen_target_depth_render_buffer_.reset(); | 2606 offscreen_target_depth_render_buffer_.reset(); |
| 2634 offscreen_target_stencil_render_buffer_.reset(); | 2607 offscreen_target_stencil_render_buffer_.reset(); |
| 2635 offscreen_saved_frame_buffer_.reset(); | 2608 offscreen_saved_frame_buffer_.reset(); |
| 2636 offscreen_saved_color_texture_.reset(); | 2609 offscreen_saved_color_texture_.reset(); |
| 2637 } | 2610 } |
| 2638 | 2611 |
| 2612 bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, |
| 2613 uint32 new_parent_texture_id) { |
| 2614 // Remove the saved frame buffer mapping from the parent decoder. The |
| 2615 // parent pointer is a weak pointer so it will be null if the parent has |
| 2616 // already been destroyed. |
| 2617 if (parent_) { |
| 2618 // First check the texture has been mapped into the parent. This might not |
| 2619 // be the case if initialization failed midway through. |
| 2620 GLuint service_id = offscreen_saved_color_texture_->id(); |
| 2621 GLuint client_id = 0; |
| 2622 if (parent_->texture_manager()->GetClientId(service_id, &client_id)) { |
| 2623 parent_->texture_manager()->RemoveTextureInfo(feature_info_, client_id); |
| 2624 } |
| 2625 } |
| 2626 |
| 2627 GLES2DecoderImpl* new_parent_impl = static_cast<GLES2DecoderImpl*>( |
| 2628 new_parent); |
| 2629 if (new_parent_impl) { |
| 2630 // Map the ID of the saved offscreen texture into the parent so that |
| 2631 // it can reference it. |
| 2632 GLuint service_id = offscreen_saved_color_texture_->id(); |
| 2633 TextureManager::TextureInfo* info = |
| 2634 new_parent_impl->CreateTextureInfo(new_parent_texture_id, service_id); |
| 2635 info->SetNotOwned(); |
| 2636 new_parent_impl->texture_manager()->SetInfoTarget(info, GL_TEXTURE_2D); |
| 2637 |
| 2638 parent_ = new_parent_impl->AsWeakPtr(); |
| 2639 } else { |
| 2640 parent_.reset(); |
| 2641 } |
| 2642 |
| 2643 return true; |
| 2644 } |
| 2645 |
| 2639 void GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { | 2646 void GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 2640 // We can't resize the render buffers immediately because there might be a | 2647 // We can't resize the render buffers immediately because there might be a |
| 2641 // partial frame rendered into them and we don't want the tail end of that | 2648 // partial frame rendered into them and we don't want the tail end of that |
| 2642 // rendered into the reallocated storage. Defer until the next SwapBuffers. | 2649 // rendered into the reallocated storage. Defer until the next SwapBuffers. |
| 2643 pending_offscreen_size_ = size; | 2650 pending_offscreen_size_ = size; |
| 2644 } | 2651 } |
| 2645 | 2652 |
| 2646 void GLES2DecoderImpl::DoCopyTextureToParentTextureCHROMIUM( | 2653 void GLES2DecoderImpl::DoCopyTextureToParentTextureCHROMIUM( |
| 2647 GLuint client_texture_id, | 2654 GLuint client_texture_id, |
| 2648 GLuint parent_client_texture_id) { | 2655 GLuint parent_client_texture_id) { |
| (...skipping 3987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6636 return error::kNoError; | 6643 return error::kNoError; |
| 6637 } | 6644 } |
| 6638 | 6645 |
| 6639 // Include the auto-generated part of this file. We split this because it means | 6646 // Include the auto-generated part of this file. We split this because it means |
| 6640 // we can easily edit the non-auto generated parts right here in this file | 6647 // we can easily edit the non-auto generated parts right here in this file |
| 6641 // instead of having to edit some template or the code generator. | 6648 // instead of having to edit some template or the code generator. |
| 6642 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 6649 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 6643 | 6650 |
| 6644 } // namespace gles2 | 6651 } // namespace gles2 |
| 6645 } // namespace gpu | 6652 } // namespace gpu |
| OLD | NEW |