 Chromium Code Reviews
 Chromium Code Reviews Issue 10106015:
  Allow textures to be moved from one GL context group to another.  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/src/
    
  
    Issue 10106015:
  Allow textures to be moved from one GL context group to another.  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/src/| 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 18 matching lines...) Expand all Loading... | |
| 29 #include "gpu/command_buffer/common/id_allocator.h" | 29 #include "gpu/command_buffer/common/id_allocator.h" | 
| 30 #include "gpu/command_buffer/service/buffer_manager.h" | 30 #include "gpu/command_buffer/service/buffer_manager.h" | 
| 31 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 31 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 
| 32 #include "gpu/command_buffer/service/context_group.h" | 32 #include "gpu/command_buffer/service/context_group.h" | 
| 33 #include "gpu/command_buffer/service/feature_info.h" | 33 #include "gpu/command_buffer/service/feature_info.h" | 
| 34 #include "gpu/command_buffer/service/framebuffer_manager.h" | 34 #include "gpu/command_buffer/service/framebuffer_manager.h" | 
| 35 #include "gpu/command_buffer/service/gl_utils.h" | 35 #include "gpu/command_buffer/service/gl_utils.h" | 
| 36 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 36 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 
| 37 #include "gpu/command_buffer/service/gles2_cmd_validation.h" | 37 #include "gpu/command_buffer/service/gles2_cmd_validation.h" | 
| 38 #include "gpu/command_buffer/service/gpu_switches.h" | 38 #include "gpu/command_buffer/service/gpu_switches.h" | 
| 39 #include "gpu/command_buffer/service/mailbox_manager.h" | |
| 39 #include "gpu/command_buffer/service/program_manager.h" | 40 #include "gpu/command_buffer/service/program_manager.h" | 
| 40 #include "gpu/command_buffer/service/query_manager.h" | 41 #include "gpu/command_buffer/service/query_manager.h" | 
| 41 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 42 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 
| 42 #include "gpu/command_buffer/service/shader_manager.h" | 43 #include "gpu/command_buffer/service/shader_manager.h" | 
| 43 #include "gpu/command_buffer/service/shader_translator.h" | 44 #include "gpu/command_buffer/service/shader_translator.h" | 
| 44 #include "gpu/command_buffer/service/stream_texture.h" | 45 #include "gpu/command_buffer/service/stream_texture.h" | 
| 45 #include "gpu/command_buffer/service/stream_texture_manager.h" | 46 #include "gpu/command_buffer/service/stream_texture_manager.h" | 
| 47 #include "gpu/command_buffer/service/texture_definition.h" | |
| 46 #include "gpu/command_buffer/service/texture_manager.h" | 48 #include "gpu/command_buffer/service/texture_manager.h" | 
| 47 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 49 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 
| 48 #include "ui/gfx/gl/gl_context.h" | 50 #include "ui/gfx/gl/gl_context.h" | 
| 49 #include "ui/gfx/gl/gl_implementation.h" | 51 #include "ui/gfx/gl/gl_implementation.h" | 
| 50 #include "ui/gfx/gl/gl_surface.h" | 52 #include "ui/gfx/gl/gl_surface.h" | 
| 51 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) | 
| 52 #include "ui/gfx/surface/io_surface_support_mac.h" | 54 #include "ui/gfx/surface/io_surface_support_mac.h" | 
| 53 #endif | 55 #endif | 
| 54 | 56 | 
| 55 #if !defined(GL_DEPTH24_STENCIL8) | 57 #if !defined(GL_DEPTH24_STENCIL8) | 
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 uint32* service_texture_id); | 503 uint32* service_texture_id); | 
| 502 | 504 | 
| 503 // Restores the current state to the user's settings. | 505 // Restores the current state to the user's settings. | 
| 504 void RestoreCurrentFramebufferBindings(); | 506 void RestoreCurrentFramebufferBindings(); | 
| 505 void RestoreCurrentRenderbufferBindings(); | 507 void RestoreCurrentRenderbufferBindings(); | 
| 506 void RestoreCurrentTexture2DBindings(); | 508 void RestoreCurrentTexture2DBindings(); | 
| 507 | 509 | 
| 508 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. | 510 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. | 
| 509 void ApplyDirtyState(); | 511 void ApplyDirtyState(); | 
| 510 | 512 | 
| 513 // Reapply the texture parameters to the given texture. | |
| 514 void BindAndApplyTextureParameters(TextureManager::TextureInfo* info); | |
| 515 | |
| 511 // These check the state of the currently bound framebuffer or the | 516 // These check the state of the currently bound framebuffer or the | 
| 512 // backbuffer if no framebuffer is bound. | 517 // backbuffer if no framebuffer is bound. | 
| 513 bool BoundFramebufferHasColorAttachmentWithAlpha(); | 518 bool BoundFramebufferHasColorAttachmentWithAlpha(); | 
| 514 bool BoundFramebufferHasDepthAttachment(); | 519 bool BoundFramebufferHasDepthAttachment(); | 
| 515 bool BoundFramebufferHasStencilAttachment(); | 520 bool BoundFramebufferHasStencilAttachment(); | 
| 516 | 521 | 
| 517 virtual error::ContextLostReason GetContextLostReason(); | 522 virtual error::ContextLostReason GetContextLostReason(); | 
| 518 | 523 | 
| 519 private: | 524 private: | 
| 520 friend class ScopedGLErrorSuppressor; | 525 friend class ScopedGLErrorSuppressor; | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 } | 616 } | 
| 612 | 617 | 
| 613 ShaderManager* shader_manager() { | 618 ShaderManager* shader_manager() { | 
| 614 return group_->shader_manager(); | 619 return group_->shader_manager(); | 
| 615 } | 620 } | 
| 616 | 621 | 
| 617 TextureManager* texture_manager() { | 622 TextureManager* texture_manager() { | 
| 618 return group_->texture_manager(); | 623 return group_->texture_manager(); | 
| 619 } | 624 } | 
| 620 | 625 | 
| 626 MailboxManager* mailbox_manager() { | |
| 627 return group_->mailbox_manager(); | |
| 628 } | |
| 629 | |
| 621 bool IsOffscreenBufferMultisampled() const { | 630 bool IsOffscreenBufferMultisampled() const { | 
| 622 return offscreen_target_samples_ > 1; | 631 return offscreen_target_samples_ > 1; | 
| 623 } | 632 } | 
| 624 | 633 | 
| 625 // Creates a TextureInfo for the given texture. | 634 // Creates a TextureInfo for the given texture. | 
| 626 TextureManager::TextureInfo* CreateTextureInfo( | 635 TextureManager::TextureInfo* CreateTextureInfo( | 
| 627 GLuint client_id, GLuint service_id) { | 636 GLuint client_id, GLuint service_id) { | 
| 628 return texture_manager()->CreateTextureInfo(client_id, service_id); | 637 return texture_manager()->CreateTextureInfo(client_id, service_id); | 
| 629 } | 638 } | 
| 630 | 639 | 
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 GLint level); | 743 GLint level); | 
| 735 | 744 | 
| 736 // Wrapper for TexStorage2DEXT. | 745 // Wrapper for TexStorage2DEXT. | 
| 737 void DoTexStorage2DEXT( | 746 void DoTexStorage2DEXT( | 
| 738 GLenum target, | 747 GLenum target, | 
| 739 GLint levels, | 748 GLint levels, | 
| 740 GLenum internal_format, | 749 GLenum internal_format, | 
| 741 GLsizei width, | 750 GLsizei width, | 
| 742 GLsizei height); | 751 GLsizei height); | 
| 743 | 752 | 
| 753 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | |
| 754 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); | |
| 755 | |
| 744 // Creates a ProgramInfo for the given program. | 756 // Creates a ProgramInfo for the given program. | 
| 745 ProgramManager::ProgramInfo* CreateProgramInfo( | 757 ProgramManager::ProgramInfo* CreateProgramInfo( | 
| 746 GLuint client_id, GLuint service_id) { | 758 GLuint client_id, GLuint service_id) { | 
| 747 return program_manager()->CreateProgramInfo(client_id, service_id); | 759 return program_manager()->CreateProgramInfo(client_id, service_id); | 
| 748 } | 760 } | 
| 749 | 761 | 
| 750 // Gets the program info for the given program. Returns NULL if none exists. | 762 // Gets the program info for the given program. Returns NULL if none exists. | 
| 751 ProgramManager::ProgramInfo* GetProgramInfo(GLuint client_id) { | 763 ProgramManager::ProgramInfo* GetProgramInfo(GLuint client_id) { | 
| 752 return program_manager()->GetProgramInfo(client_id); | 764 return program_manager()->GetProgramInfo(client_id); | 
| 753 } | 765 } | 
| (...skipping 2502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3256 bool have_stencil = BoundFramebufferHasStencilAttachment(); | 3268 bool have_stencil = BoundFramebufferHasStencilAttachment(); | 
| 3257 glStencilMaskSeparate(GL_FRONT, have_stencil ? mask_stencil_front_ : 0); | 3269 glStencilMaskSeparate(GL_FRONT, have_stencil ? mask_stencil_front_ : 0); | 
| 3258 glStencilMaskSeparate(GL_BACK, have_stencil ? mask_stencil_back_ : 0); | 3270 glStencilMaskSeparate(GL_BACK, have_stencil ? mask_stencil_back_ : 0); | 
| 3259 EnableDisable(GL_STENCIL_TEST, enable_stencil_test_ && have_stencil); | 3271 EnableDisable(GL_STENCIL_TEST, enable_stencil_test_ && have_stencil); | 
| 3260 EnableDisable(GL_CULL_FACE, enable_cull_face_); | 3272 EnableDisable(GL_CULL_FACE, enable_cull_face_); | 
| 3261 EnableDisable(GL_SCISSOR_TEST, enable_scissor_test_); | 3273 EnableDisable(GL_SCISSOR_TEST, enable_scissor_test_); | 
| 3262 state_dirty_ = false; | 3274 state_dirty_ = false; | 
| 3263 } | 3275 } | 
| 3264 } | 3276 } | 
| 3265 | 3277 | 
| 3278 void GLES2DecoderImpl::BindAndApplyTextureParameters( | |
| 3279 TextureManager::TextureInfo* info) { | |
| 3280 glBindTexture(info->target(), info->service_id()); | |
| 3281 glTexParameteri(info->target(), GL_TEXTURE_MIN_FILTER, info->min_filter()); | |
| 3282 glTexParameteri(info->target(), GL_TEXTURE_MAG_FILTER, info->mag_filter()); | |
| 3283 glTexParameteri(info->target(), GL_TEXTURE_WRAP_S, info->wrap_s()); | |
| 3284 glTexParameteri(info->target(), GL_TEXTURE_WRAP_T, info->wrap_t()); | |
| 3285 } | |
| 3286 | |
| 3266 GLuint GLES2DecoderImpl::GetBackbufferServiceId() { | 3287 GLuint GLES2DecoderImpl::GetBackbufferServiceId() { | 
| 3267 return (offscreen_target_frame_buffer_.get()) ? | 3288 return (offscreen_target_frame_buffer_.get()) ? | 
| 3268 offscreen_target_frame_buffer_->id() : | 3289 offscreen_target_frame_buffer_->id() : | 
| 3269 surface_->GetBackingFrameBufferObject(); | 3290 surface_->GetBackingFrameBufferObject(); | 
| 3270 } | 3291 } | 
| 3271 | 3292 | 
| 3272 void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { | 3293 void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { | 
| 3273 FramebufferManager::FramebufferInfo* info = NULL; | 3294 FramebufferManager::FramebufferInfo* info = NULL; | 
| 3274 GLuint service_id = 0; | 3295 GLuint service_id = 0; | 
| 3275 if (client_id != 0) { | 3296 if (client_id != 0) { | 
| (...skipping 5219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8495 texture_manager()->SetLevelInfo( | 8516 texture_manager()->SetLevelInfo( | 
| 8496 info, target, 0, format, level_width, level_height, 1, 0, format, | 8517 info, target, 0, format, level_width, level_height, 1, 0, format, | 
| 8497 type, false); | 8518 type, false); | 
| 8498 level_width = std::max(1, level_width >> 1); | 8519 level_width = std::max(1, level_width >> 1); | 
| 8499 level_height = std::max(1, level_height >> 1); | 8520 level_height = std::max(1, level_height >> 1); | 
| 8500 } | 8521 } | 
| 8501 info->SetImmutable(true); | 8522 info->SetImmutable(true); | 
| 8502 } | 8523 } | 
| 8503 } | 8524 } | 
| 8504 | 8525 | 
| 8526 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( | |
| 8527 uint32 immediate_data_size, const gles2::GenMailboxCHROMIUM& c) { | |
| 8528 MailboxName name; | |
| 8529 mailbox_manager()->GenerateMailboxName(&name); | |
| 8530 uint32 bucket_id = static_cast<uint32>(c.bucket_id); | |
| 8531 Bucket* bucket = CreateBucket(bucket_id); | |
| 8532 | |
| 8533 bucket->SetSize(GL_MAILBOX_SIZE_CHROMIUM); | |
| 8534 bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM); | |
| 8535 | |
| 8536 return error::kNoError; | |
| 8537 } | |
| 8538 | |
| 8539 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, | |
| 8540 const GLbyte* mailbox) { | |
| 8541 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); | |
| 8542 if (!info) { | |
| 8543 SetGLError(GL_INVALID_OPERATION, | |
| 8544 "glProduceTextureCHROMIUM: unknown texture for target"); | |
| 8545 return; | |
| 8546 } | |
| 8547 | |
| 8548 TextureDefinition* definition = texture_manager()->Save(info); | |
| 8549 if (!definition) { | |
| 8550 SetGLError(GL_INVALID_OPERATION, | |
| 8551 "glProduceTextureCHROMIUM: invalid texture"); | |
| 8552 return; | |
| 8553 } | |
| 8554 | |
| 8555 if (!group_->mailbox_manager()->ProduceTexture( | |
| 8556 target, | |
| 8557 *reinterpret_cast<const MailboxName*>(mailbox), | |
| 8558 definition, | |
| 8559 texture_manager())) { | |
| 8560 SetGLError(GL_INVALID_OPERATION, | |
| 8561 "glProduceTextureCHROMIUM: invalid mailbox name"); | |
| 8562 return; | |
| 
Ken Russell (switch to Gerrit)
2012/04/26 22:34:14
What happens to the texture in this case? Looks li
 
apatrick_chromium
2012/04/27 22:31:58
Fixed and added a test.
 | |
| 8563 } | |
| 8564 | |
| 8565 BindAndApplyTextureParameters(info); | |
| 8566 } | |
| 8567 | |
| 8568 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, | |
| 8569 const GLbyte* mailbox) { | |
| 8570 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); | |
| 8571 if (!info) { | |
| 8572 SetGLError(GL_INVALID_OPERATION, | |
| 8573 "glConsumeTextureCHROMIUM: unknown texture for target"); | |
| 8574 return; | |
| 8575 } | |
| 8576 | |
| 8577 scoped_ptr<TextureDefinition> definition( | |
| 8578 group_->mailbox_manager()->ConsumeTexture( | |
| 8579 target, | |
| 8580 *reinterpret_cast<const MailboxName*>(mailbox))); | |
| 8581 if (!definition.get()) { | |
| 8582 SetGLError(GL_INVALID_OPERATION, | |
| 8583 "glConsumeTextureCHROMIUM: invalid mailbox name"); | |
| 8584 return; | |
| 8585 } | |
| 8586 | |
| 8587 if (!texture_manager()->Restore(info, definition.release())) { | |
| 8588 SetGLError(GL_INVALID_OPERATION, | |
| 8589 "glConsumeTextureCHROMIUM: invalid texture"); | |
| 8590 return; | |
| 8591 } | |
| 8592 | |
| 8593 BindAndApplyTextureParameters(info); | |
| 8594 } | |
| 8595 | |
| 8505 // Include the auto-generated part of this file. We split this because it means | 8596 // Include the auto-generated part of this file. We split this because it means | 
| 8506 // we can easily edit the non-auto generated parts right here in this file | 8597 // we can easily edit the non-auto generated parts right here in this file | 
| 8507 // instead of having to edit some template or the code generator. | 8598 // instead of having to edit some template or the code generator. | 
| 8508 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 8599 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 
| 8509 | 8600 | 
| 8510 } // namespace gles2 | 8601 } // namespace gles2 | 
| 8511 } // namespace gpu | 8602 } // namespace gpu | 
| OLD | NEW |