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