| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 virtual const char* GetCommandName(unsigned int command_id) const; | 458 virtual const char* GetCommandName(unsigned int command_id) const; |
| 459 | 459 |
| 460 // Overridden from GLES2Decoder. | 460 // Overridden from GLES2Decoder. |
| 461 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, | 461 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 462 const scoped_refptr<gfx::GLContext>& context, | 462 const scoped_refptr<gfx::GLContext>& context, |
| 463 const gfx::Size& size, | 463 const gfx::Size& size, |
| 464 const DisallowedExtensions& disallowed_extensions, | 464 const DisallowedExtensions& disallowed_extensions, |
| 465 const char* allowed_extensions, | 465 const char* allowed_extensions, |
| 466 const std::vector<int32>& attribs); | 466 const std::vector<int32>& attribs); |
| 467 virtual void Destroy(); | 467 virtual void Destroy(); |
| 468 virtual bool MapExternalResource(resource_type::ResourceType resource_type, | |
| 469 uint32 resource_source_id, | |
| 470 GLES2Decoder* source_decoder, | |
| 471 uint32 resource_dest_id); | |
| 472 virtual bool SetParent(GLES2Decoder* parent_decoder, | 468 virtual bool SetParent(GLES2Decoder* parent_decoder, |
| 473 uint32 parent_texture_id); | 469 uint32 parent_texture_id); |
| 474 virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size); | 470 virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size); |
| 475 virtual bool UpdateOffscreenFrameBufferSize(); | 471 virtual bool UpdateOffscreenFrameBufferSize(); |
| 476 void UpdateParentTextureInfo(); | 472 void UpdateParentTextureInfo(); |
| 477 virtual bool MakeCurrent(); | 473 virtual bool MakeCurrent(); |
| 478 virtual GLES2Util* GetGLES2Util() { return &util_; } | 474 virtual GLES2Util* GetGLES2Util() { return &util_; } |
| 479 virtual gfx::GLContext* GetGLContext() { return context_.get(); } | 475 virtual gfx::GLContext* GetGLContext() { return context_.get(); } |
| 480 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } | 476 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } |
| 481 virtual ContextGroup* GetContextGroup() { return group_.get(); } | 477 virtual ContextGroup* GetContextGroup() { return group_.get(); } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 feature_info_, client_id, service_id); | 581 feature_info_, client_id, service_id); |
| 586 } | 582 } |
| 587 | 583 |
| 588 // Gets the texture info for the given texture. Returns NULL if none exists. | 584 // Gets the texture info for the given texture. Returns NULL if none exists. |
| 589 TextureManager::TextureInfo* GetTextureInfo(GLuint client_id) { | 585 TextureManager::TextureInfo* GetTextureInfo(GLuint client_id) { |
| 590 TextureManager::TextureInfo* info = | 586 TextureManager::TextureInfo* info = |
| 591 texture_manager()->GetTextureInfo(client_id); | 587 texture_manager()->GetTextureInfo(client_id); |
| 592 return (info && !info->IsDeleted()) ? info : NULL; | 588 return (info && !info->IsDeleted()) ? info : NULL; |
| 593 } | 589 } |
| 594 | 590 |
| 595 // Adds the texture info for the given texture. | |
| 596 void AddTextureInfo(GLuint client_id, TextureManager::TextureInfo* info) { | |
| 597 texture_manager()->AddTextureInfo(feature_info_, client_id, info); | |
| 598 } | |
| 599 | |
| 600 // Deletes the texture info for the given texture. | 591 // Deletes the texture info for the given texture. |
| 601 void RemoveTextureInfo(GLuint client_id) { | 592 void RemoveTextureInfo(GLuint client_id) { |
| 602 texture_manager()->RemoveTextureInfo(feature_info_, client_id); | 593 texture_manager()->RemoveTextureInfo(feature_info_, client_id); |
| 603 } | 594 } |
| 604 | 595 |
| 605 // Get the size (in pixels) of the currently bound frame buffer (either FBO | 596 // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 606 // or regular back buffer). | 597 // or regular back buffer). |
| 607 gfx::Size GetBoundReadFrameBufferSize(); | 598 gfx::Size GetBoundReadFrameBufferSize(); |
| 608 | 599 |
| 609 // Get the format of the currently bound frame buffer (either FBO or regular | 600 // Get the format of the currently bound frame buffer (either FBO or regular |
| (...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 } | 2082 } |
| 2092 | 2083 |
| 2093 void GLES2DecoderImpl::DeleteTexturesHelper( | 2084 void GLES2DecoderImpl::DeleteTexturesHelper( |
| 2094 GLsizei n, const GLuint* client_ids) { | 2085 GLsizei n, const GLuint* client_ids) { |
| 2095 for (GLsizei ii = 0; ii < n; ++ii) { | 2086 for (GLsizei ii = 0; ii < n; ++ii) { |
| 2096 TextureManager::TextureInfo* info = GetTextureInfo(client_ids[ii]); | 2087 TextureManager::TextureInfo* info = GetTextureInfo(client_ids[ii]); |
| 2097 if (info) { | 2088 if (info) { |
| 2098 if (info->IsAttachedToFramebuffer()) { | 2089 if (info->IsAttachedToFramebuffer()) { |
| 2099 state_dirty_ = true; | 2090 state_dirty_ = true; |
| 2100 } | 2091 } |
| 2101 if (info->owner() == group_->texture_manager()) { | 2092 GLuint service_id = info->service_id(); |
| 2102 GLuint service_id = info->service_id(); | 2093 glDeleteTextures(1, &service_id); |
| 2103 glDeleteTextures(1, &service_id); | |
| 2104 } | |
| 2105 RemoveTextureInfo(client_ids[ii]); | 2094 RemoveTextureInfo(client_ids[ii]); |
| 2106 } | 2095 } |
| 2107 } | 2096 } |
| 2108 } | 2097 } |
| 2109 | 2098 |
| 2110 // } // anonymous namespace | 2099 // } // anonymous namespace |
| 2111 | 2100 |
| 2112 bool GLES2DecoderImpl::MakeCurrent() { | 2101 bool GLES2DecoderImpl::MakeCurrent() { |
| 2113 bool result = context_.get() ? context_->MakeCurrent(surface_.get()) : false; | 2102 bool result = context_.get() ? context_->MakeCurrent(surface_.get()) : false; |
| 2114 if (result && WasContextLost()) { | 2103 if (result && WasContextLost()) { |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 | 2463 |
| 2475 offscreen_target_frame_buffer_.reset(); | 2464 offscreen_target_frame_buffer_.reset(); |
| 2476 offscreen_target_color_texture_.reset(); | 2465 offscreen_target_color_texture_.reset(); |
| 2477 offscreen_target_color_render_buffer_.reset(); | 2466 offscreen_target_color_render_buffer_.reset(); |
| 2478 offscreen_target_depth_render_buffer_.reset(); | 2467 offscreen_target_depth_render_buffer_.reset(); |
| 2479 offscreen_target_stencil_render_buffer_.reset(); | 2468 offscreen_target_stencil_render_buffer_.reset(); |
| 2480 offscreen_saved_frame_buffer_.reset(); | 2469 offscreen_saved_frame_buffer_.reset(); |
| 2481 offscreen_saved_color_texture_.reset(); | 2470 offscreen_saved_color_texture_.reset(); |
| 2482 } | 2471 } |
| 2483 | 2472 |
| 2484 bool GLES2DecoderImpl::MapExternalResource( | |
| 2485 resource_type::ResourceType resource_type, | |
| 2486 uint32 resource_source_id, | |
| 2487 GLES2Decoder* source_decoder, | |
| 2488 uint32 resource_dest_id) { | |
| 2489 GLES2DecoderImpl* source_decoder_impl = static_cast<GLES2DecoderImpl*>( | |
| 2490 source_decoder); | |
| 2491 | |
| 2492 if (resource_type != resource_type::kTexture) | |
| 2493 return false; | |
| 2494 | |
| 2495 if (!source_decoder) | |
| 2496 return false; | |
| 2497 | |
| 2498 // The client should already have created the texture in the source context | |
| 2499 // group and flushed. | |
| 2500 TextureManager::TextureInfo* source_info = | |
| 2501 source_decoder_impl->GetTextureInfo(resource_source_id); | |
| 2502 if (!source_info) | |
| 2503 return false; | |
| 2504 | |
| 2505 // Delete or unmap any existing texture with this ID. | |
| 2506 DeleteTexturesHelper(1, &resource_dest_id); | |
| 2507 | |
| 2508 // Add the source texture info to this group's manager with the | |
| 2509 // requested id. | |
| 2510 AddTextureInfo(resource_dest_id, source_info); | |
| 2511 | |
| 2512 return true; | |
| 2513 } | |
| 2514 | |
| 2515 bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, | 2473 bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, |
| 2516 uint32 new_parent_texture_id) { | 2474 uint32 new_parent_texture_id) { |
| 2517 if (!offscreen_saved_color_texture_.get()) | 2475 if (!offscreen_saved_color_texture_.get()) |
| 2518 return false; | 2476 return false; |
| 2519 | 2477 |
| 2520 // Remove the saved frame buffer mapping from the parent decoder. The | 2478 // Remove the saved frame buffer mapping from the parent decoder. The |
| 2521 // parent pointer is a weak pointer so it will be null if the parent has | 2479 // parent pointer is a weak pointer so it will be null if the parent has |
| 2522 // already been destroyed. | 2480 // already been destroyed. |
| 2523 if (parent_) { | 2481 if (parent_) { |
| 2524 // First check the texture has been mapped into the parent. This might not | 2482 // First check the texture has been mapped into the parent. This might not |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2537 // it can reference it. | 2495 // it can reference it. |
| 2538 GLuint service_id = offscreen_saved_color_texture_->id(); | 2496 GLuint service_id = offscreen_saved_color_texture_->id(); |
| 2539 | 2497 |
| 2540 // Replace texture info when ID is already in use by parent. | 2498 // Replace texture info when ID is already in use by parent. |
| 2541 if (new_parent_impl->texture_manager()->GetTextureInfo( | 2499 if (new_parent_impl->texture_manager()->GetTextureInfo( |
| 2542 new_parent_texture_id)) | 2500 new_parent_texture_id)) |
| 2543 new_parent_impl->texture_manager()->RemoveTextureInfo( | 2501 new_parent_impl->texture_manager()->RemoveTextureInfo( |
| 2544 feature_info_, new_parent_texture_id); | 2502 feature_info_, new_parent_texture_id); |
| 2545 | 2503 |
| 2546 TextureManager::TextureInfo* info = | 2504 TextureManager::TextureInfo* info = |
| 2547 new TextureManager::TextureInfo(service_id); | 2505 new_parent_impl->CreateTextureInfo(new_parent_texture_id, service_id); |
| 2548 new_parent_impl->AddTextureInfo(new_parent_texture_id, info); | 2506 info->SetNotOwned(); |
| 2549 new_parent_impl->texture_manager()->SetInfoTarget(info, GL_TEXTURE_2D); | 2507 new_parent_impl->texture_manager()->SetInfoTarget(info, GL_TEXTURE_2D); |
| 2550 | 2508 |
| 2551 parent_ = new_parent_impl->AsWeakPtr(); | 2509 parent_ = new_parent_impl->AsWeakPtr(); |
| 2552 | 2510 |
| 2553 UpdateParentTextureInfo(); | 2511 UpdateParentTextureInfo(); |
| 2554 } else { | 2512 } else { |
| 2555 parent_.reset(); | 2513 parent_.reset(); |
| 2556 } | 2514 } |
| 2557 | 2515 |
| 2558 return true; | 2516 return true; |
| (...skipping 4275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6834 return false; | 6792 return false; |
| 6835 } | 6793 } |
| 6836 | 6794 |
| 6837 // Include the auto-generated part of this file. We split this because it means | 6795 // Include the auto-generated part of this file. We split this because it means |
| 6838 // we can easily edit the non-auto generated parts right here in this file | 6796 // we can easily edit the non-auto generated parts right here in this file |
| 6839 // instead of having to edit some template or the code generator. | 6797 // instead of having to edit some template or the code generator. |
| 6840 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 6798 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 6841 | 6799 |
| 6842 } // namespace gles2 | 6800 } // namespace gles2 |
| 6843 } // namespace gpu | 6801 } // namespace gpu |
| OLD | NEW |