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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 virtual const char* GetCommandName(unsigned int command_id) const; | 475 virtual const char* GetCommandName(unsigned int command_id) const; |
476 | 476 |
477 // Overridden from GLES2Decoder. | 477 // Overridden from GLES2Decoder. |
478 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, | 478 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
479 const scoped_refptr<gfx::GLContext>& context, | 479 const scoped_refptr<gfx::GLContext>& context, |
480 bool offscreen, | 480 bool offscreen, |
481 const gfx::Size& size, | 481 const gfx::Size& size, |
482 const DisallowedFeatures& disallowed_features, | 482 const DisallowedFeatures& disallowed_features, |
483 const char* allowed_extensions, | 483 const char* allowed_extensions, |
484 const std::vector<int32>& attribs); | 484 const std::vector<int32>& attribs); |
485 virtual void Destroy(); | 485 virtual void Destroy(bool have_context); |
| 486 virtual void SetSurface( |
| 487 const scoped_refptr<gfx::GLSurface>& surface) OVERRIDE; |
486 virtual bool SetParent(GLES2Decoder* parent_decoder, | 488 virtual bool SetParent(GLES2Decoder* parent_decoder, |
487 uint32 parent_texture_id); | 489 uint32 parent_texture_id); |
488 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size); | 490 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size); |
489 void UpdateParentTextureInfo(); | 491 void UpdateParentTextureInfo(); |
490 virtual bool MakeCurrent(); | 492 virtual bool MakeCurrent(); |
491 virtual void ReleaseCurrent(); | 493 virtual void ReleaseCurrent(); |
492 virtual GLES2Util* GetGLES2Util() { return &util_; } | 494 virtual GLES2Util* GetGLES2Util() { return &util_; } |
493 virtual gfx::GLContext* GetGLContext() { return context_.get(); } | 495 virtual gfx::GLContext* GetGLContext() { return context_.get(); } |
494 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } | |
495 virtual ContextGroup* GetContextGroup() { return group_.get(); } | 496 virtual ContextGroup* GetContextGroup() { return group_.get(); } |
496 virtual QueryManager* GetQueryManager() { return query_manager_.get(); } | 497 virtual QueryManager* GetQueryManager() { return query_manager_.get(); } |
497 virtual bool ProcessPendingQueries(); | 498 virtual bool ProcessPendingQueries(); |
498 | 499 |
499 virtual void SetGLError(GLenum error, const char* msg); | 500 virtual void SetGLError(GLenum error, const char* msg); |
500 virtual void SetResizeCallback( | 501 virtual void SetResizeCallback( |
501 const base::Callback<void(gfx::Size)>& callback); | 502 const base::Callback<void(gfx::Size)>& callback); |
502 | 503 |
503 virtual void SetMsgCallback(const MsgCallback& callback); | 504 virtual void SetMsgCallback(const MsgCallback& callback); |
504 | 505 |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 } | 1978 } |
1978 | 1979 |
1979 bool GLES2DecoderImpl::Initialize( | 1980 bool GLES2DecoderImpl::Initialize( |
1980 const scoped_refptr<gfx::GLSurface>& surface, | 1981 const scoped_refptr<gfx::GLSurface>& surface, |
1981 const scoped_refptr<gfx::GLContext>& context, | 1982 const scoped_refptr<gfx::GLContext>& context, |
1982 bool offscreen, | 1983 bool offscreen, |
1983 const gfx::Size& size, | 1984 const gfx::Size& size, |
1984 const DisallowedFeatures& disallowed_features, | 1985 const DisallowedFeatures& disallowed_features, |
1985 const char* allowed_extensions, | 1986 const char* allowed_extensions, |
1986 const std::vector<int32>& attribs) { | 1987 const std::vector<int32>& attribs) { |
1987 DCHECK(context); | 1988 DCHECK(context->IsCurrent(surface.get())); |
1988 DCHECK(!context_.get()); | 1989 DCHECK(!context_.get()); |
1989 | 1990 |
1990 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1991 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1991 switches::kEnableGPUDebugging)) { | 1992 switches::kEnableGPUDebugging)) { |
1992 set_debug(true); | 1993 set_debug(true); |
1993 } | 1994 } |
1994 | 1995 |
1995 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1996 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1996 switches::kEnableGPUCommandLogging)) { | 1997 switches::kEnableGPUCommandLogging)) { |
1997 set_log_commands(true); | 1998 set_log_commands(true); |
1998 } | 1999 } |
1999 | 2000 |
2000 compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( | 2001 compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( |
2001 switches::kCompileShaderAlwaysSucceeds); | 2002 switches::kCompileShaderAlwaysSucceeds); |
2002 | 2003 |
2003 // Take ownership of the GLSurface. TODO(apatrick): once the parent / child | 2004 |
2004 // context is retired, the decoder should not take an initial surface as | 2005 // Take ownership of the context and surface. The surface can be replaced with |
2005 // an argument to this function. | 2006 // SetSurface. |
2006 // Maybe create a short lived offscreen GLSurface for the purpose of | 2007 context_ = context; |
2007 // initializing the decoder's GLContext. | |
2008 surface_ = surface; | 2008 surface_ = surface; |
2009 | 2009 |
2010 // Take ownership of the GLContext. | |
2011 context_ = context; | |
2012 | |
2013 if (!MakeCurrent()) { | |
2014 LOG(ERROR) << "GLES2DecoderImpl::Initialize failed because " | |
2015 << "MakeCurrent failed."; | |
2016 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | |
2017 Destroy(); | |
2018 return false; | |
2019 } | |
2020 | |
2021 if (!group_->Initialize(disallowed_features, allowed_extensions)) { | 2010 if (!group_->Initialize(disallowed_features, allowed_extensions)) { |
2022 LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " | 2011 LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
2023 << "failed to initialize."; | 2012 << "failed to initialize."; |
2024 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2013 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
2025 Destroy(); | 2014 Destroy(true); |
2026 return false; | 2015 return false; |
2027 } | 2016 } |
2028 CHECK_GL_ERROR(); | 2017 CHECK_GL_ERROR(); |
2029 | 2018 |
2030 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | 2019 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
2031 copy_texture_CHROMIUM_->Initialize(); | 2020 copy_texture_CHROMIUM_->Initialize(); |
2032 CHECK_GL_ERROR(); | 2021 CHECK_GL_ERROR(); |
2033 | 2022 |
2034 disallowed_features_ = disallowed_features; | 2023 disallowed_features_ = disallowed_features; |
2035 | 2024 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2202 offscreen_saved_frame_buffer_.reset(new FrameBuffer(this)); | 2191 offscreen_saved_frame_buffer_.reset(new FrameBuffer(this)); |
2203 offscreen_saved_frame_buffer_->Create(); | 2192 offscreen_saved_frame_buffer_->Create(); |
2204 // | 2193 // |
2205 offscreen_saved_color_texture_.reset(new Texture(this)); | 2194 offscreen_saved_color_texture_.reset(new Texture(this)); |
2206 offscreen_saved_color_texture_->Create(); | 2195 offscreen_saved_color_texture_->Create(); |
2207 | 2196 |
2208 // Allocate the render buffers at their initial size and check the status | 2197 // Allocate the render buffers at their initial size and check the status |
2209 // of the frame buffers is okay. | 2198 // of the frame buffers is okay. |
2210 if (!ResizeOffscreenFrameBuffer(size)) { | 2199 if (!ResizeOffscreenFrameBuffer(size)) { |
2211 LOG(ERROR) << "Could not allocate offscreen buffer storage."; | 2200 LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
2212 Destroy(); | 2201 Destroy(true); |
2213 return false; | 2202 return false; |
2214 } | 2203 } |
2215 | 2204 |
2216 // Bind to the new default frame buffer (the offscreen target frame buffer). | 2205 // Bind to the new default frame buffer (the offscreen target frame buffer). |
2217 // This should now be associated with ID zero. | 2206 // This should now be associated with ID zero. |
2218 DoBindFramebuffer(GL_FRAMEBUFFER, 0); | 2207 DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
2219 } | 2208 } |
2220 | 2209 |
2221 // Clear the backbuffer. | 2210 // Clear the backbuffer. |
2222 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 2211 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? | 2297 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
2309 ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; | 2298 ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
2310 ShaderTranslatorInterface::GlslBuiltInFunctionBehavior function_behavior = | 2299 ShaderTranslatorInterface::GlslBuiltInFunctionBehavior function_behavior = |
2311 needs_glsl_built_in_function_emulation_ ? | 2300 needs_glsl_built_in_function_emulation_ ? |
2312 ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated : | 2301 ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated : |
2313 ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal; | 2302 ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal; |
2314 if (!vertex_translator_->Init( | 2303 if (!vertex_translator_->Init( |
2315 SH_VERTEX_SHADER, shader_spec, &resources, | 2304 SH_VERTEX_SHADER, shader_spec, &resources, |
2316 implementation_type, function_behavior)) { | 2305 implementation_type, function_behavior)) { |
2317 LOG(ERROR) << "Could not initialize vertex shader translator."; | 2306 LOG(ERROR) << "Could not initialize vertex shader translator."; |
2318 Destroy(); | 2307 Destroy(true); |
2319 return false; | 2308 return false; |
2320 } | 2309 } |
2321 fragment_translator_.reset(new ShaderTranslator); | 2310 fragment_translator_.reset(new ShaderTranslator); |
2322 if (!fragment_translator_->Init( | 2311 if (!fragment_translator_->Init( |
2323 SH_FRAGMENT_SHADER, shader_spec, &resources, | 2312 SH_FRAGMENT_SHADER, shader_spec, &resources, |
2324 implementation_type, function_behavior)) { | 2313 implementation_type, function_behavior)) { |
2325 LOG(ERROR) << "Could not initialize fragment shader translator."; | 2314 LOG(ERROR) << "Could not initialize fragment shader translator."; |
2326 Destroy(); | 2315 Destroy(true); |
2327 return false; | 2316 return false; |
2328 } | 2317 } |
2329 return true; | 2318 return true; |
2330 } | 2319 } |
2331 | 2320 |
2332 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { | 2321 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
2333 for (GLsizei ii = 0; ii < n; ++ii) { | 2322 for (GLsizei ii = 0; ii < n; ++ii) { |
2334 if (GetBufferInfo(client_ids[ii])) { | 2323 if (GetBufferInfo(client_ids[ii])) { |
2335 return false; | 2324 return false; |
2336 } | 2325 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2501 } | 2490 } |
2502 #endif | 2491 #endif |
2503 RemoveTextureInfo(client_ids[ii]); | 2492 RemoveTextureInfo(client_ids[ii]); |
2504 } | 2493 } |
2505 } | 2494 } |
2506 } | 2495 } |
2507 | 2496 |
2508 // } // anonymous namespace | 2497 // } // anonymous namespace |
2509 | 2498 |
2510 bool GLES2DecoderImpl::MakeCurrent() { | 2499 bool GLES2DecoderImpl::MakeCurrent() { |
2511 bool result = context_.get() ? context_->MakeCurrent(surface_.get()) : false; | 2500 if (!context_.get() || !context_->MakeCurrent(surface_.get())) |
2512 if (result && WasContextLost()) { | 2501 return false; |
| 2502 |
| 2503 if (WasContextLost()) { |
2513 LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; | 2504 LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
2514 result = false; | 2505 return false; |
2515 } | 2506 } |
2516 | 2507 |
2517 return result; | 2508 return true; |
2518 } | 2509 } |
2519 | 2510 |
2520 void GLES2DecoderImpl::ReleaseCurrent() { | 2511 void GLES2DecoderImpl::ReleaseCurrent() { |
2521 if (context_.get()) | 2512 if (context_.get()) |
2522 context_->ReleaseCurrent(surface_.get()); | 2513 context_->ReleaseCurrent(surface_.get()); |
2523 } | 2514 } |
2524 | 2515 |
2525 void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { | 2516 void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { |
2526 RenderbufferManager::RenderbufferInfo* renderbuffer = | 2517 RenderbufferManager::RenderbufferInfo* renderbuffer = |
2527 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); | 2518 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2734 uint32* service_texture_id) { | 2725 uint32* service_texture_id) { |
2735 TextureManager::TextureInfo* texture = | 2726 TextureManager::TextureInfo* texture = |
2736 texture_manager()->GetTextureInfo(client_texture_id); | 2727 texture_manager()->GetTextureInfo(client_texture_id); |
2737 if (texture) { | 2728 if (texture) { |
2738 *service_texture_id = texture->service_id(); | 2729 *service_texture_id = texture->service_id(); |
2739 return true; | 2730 return true; |
2740 } | 2731 } |
2741 return false; | 2732 return false; |
2742 } | 2733 } |
2743 | 2734 |
2744 void GLES2DecoderImpl::Destroy() { | 2735 void GLES2DecoderImpl::Destroy(bool have_context) { |
2745 bool have_context = context_.get() && MakeCurrent(); | 2736 DCHECK(!have_context || context_->IsCurrent(NULL)); |
2746 | 2737 |
2747 ChildList children = children_; | 2738 ChildList children = children_; |
2748 for (ChildList::iterator it = children.begin(); it != children.end(); ++it) | 2739 for (ChildList::iterator it = children.begin(); it != children.end(); ++it) |
2749 (*it)->SetParent(NULL, 0); | 2740 (*it)->SetParent(NULL, 0); |
2750 DCHECK(children_.empty()); | 2741 DCHECK(children_.empty()); |
2751 SetParent(NULL, 0); | 2742 SetParent(NULL, 0); |
2752 | 2743 |
2753 // Unbind everything. | 2744 // Unbind everything. |
2754 vertex_attrib_manager_.reset(); | 2745 vertex_attrib_manager_.reset(); |
2755 texture_units_.reset(); | 2746 texture_units_.reset(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2843 | 2834 |
2844 #if defined(OS_MACOSX) | 2835 #if defined(OS_MACOSX) |
2845 for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); | 2836 for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
2846 it != texture_to_io_surface_map_.end(); ++it) { | 2837 it != texture_to_io_surface_map_.end(); ++it) { |
2847 CFRelease(it->second); | 2838 CFRelease(it->second); |
2848 } | 2839 } |
2849 texture_to_io_surface_map_.clear(); | 2840 texture_to_io_surface_map_.clear(); |
2850 #endif | 2841 #endif |
2851 } | 2842 } |
2852 | 2843 |
| 2844 void GLES2DecoderImpl::SetSurface( |
| 2845 const scoped_refptr<gfx::GLSurface>& surface) { |
| 2846 DCHECK(context_->IsCurrent(NULL)); |
| 2847 DCHECK(surface_.get()); |
| 2848 surface_ = surface; |
| 2849 RestoreCurrentFramebufferBindings(); |
| 2850 } |
| 2851 |
2853 bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, | 2852 bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, |
2854 uint32 new_parent_texture_id) { | 2853 uint32 new_parent_texture_id) { |
2855 if (!offscreen_saved_color_texture_.get()) | 2854 if (!offscreen_saved_color_texture_.get()) |
2856 return false; | 2855 return false; |
2857 | 2856 |
2858 // Remove the saved frame buffer mapping from the parent decoder. The | 2857 // Remove the saved frame buffer mapping from the parent decoder. The |
2859 // parent pointer is a weak pointer so it will be null if the parent has | 2858 // parent pointer is a weak pointer so it will be null if the parent has |
2860 // already been destroyed. | 2859 // already been destroyed. |
2861 if (parent_) { | 2860 if (parent_) { |
2862 ChildList::iterator it = std::find( | 2861 ChildList::iterator it = std::find( |
(...skipping 5865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8728 BindAndApplyTextureParameters(info); | 8727 BindAndApplyTextureParameters(info); |
8729 } | 8728 } |
8730 | 8729 |
8731 // Include the auto-generated part of this file. We split this because it means | 8730 // Include the auto-generated part of this file. We split this because it means |
8732 // we can easily edit the non-auto generated parts right here in this file | 8731 // we can easily edit the non-auto generated parts right here in this file |
8733 // instead of having to edit some template or the code generator. | 8732 // instead of having to edit some template or the code generator. |
8734 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 8733 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
8735 | 8734 |
8736 } // namespace gles2 | 8735 } // namespace gles2 |
8737 } // namespace gpu | 8736 } // namespace gpu |
OLD | NEW |