Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 10106015: Allow textures to be moved from one GL context group to another. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/atomicops.h" 15 #include "base/atomicops.h"
16 #include "base/at_exit.h" 16 #include "base/at_exit.h"
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/debug/trace_event.h" 19 #include "base/debug/trace_event.h"
20 #if defined(OS_MACOSX) 20 #if defined(OS_MACOSX)
21 #include "base/mac/scoped_cftyperef.h" 21 #include "base/mac/scoped_cftyperef.h"
22 #endif 22 #endif
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/memory/weak_ptr.h" 24 #include "base/memory/weak_ptr.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "crypto/symmetric_key.h"
26 #define GLES2_GPU_SERVICE 1 27 #define GLES2_GPU_SERVICE 1
27 #include "gpu/command_buffer/common/gles2_cmd_format.h" 28 #include "gpu/command_buffer/common/gles2_cmd_format.h"
28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 29 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
29 #include "gpu/command_buffer/common/id_allocator.h" 30 #include "gpu/command_buffer/common/id_allocator.h"
30 #include "gpu/command_buffer/service/buffer_manager.h" 31 #include "gpu/command_buffer/service/buffer_manager.h"
31 #include "gpu/command_buffer/service/cmd_buffer_engine.h" 32 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
32 #include "gpu/command_buffer/service/context_group.h" 33 #include "gpu/command_buffer/service/context_group.h"
33 #include "gpu/command_buffer/service/feature_info.h" 34 #include "gpu/command_buffer/service/feature_info.h"
34 #include "gpu/command_buffer/service/framebuffer_manager.h" 35 #include "gpu/command_buffer/service/framebuffer_manager.h"
35 #include "gpu/command_buffer/service/gl_utils.h" 36 #include "gpu/command_buffer/service/gl_utils.h"
36 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 37 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
37 #include "gpu/command_buffer/service/gles2_cmd_validation.h" 38 #include "gpu/command_buffer/service/gles2_cmd_validation.h"
38 #include "gpu/command_buffer/service/gpu_switches.h" 39 #include "gpu/command_buffer/service/gpu_switches.h"
40 #include "gpu/command_buffer/service/mailbox_manager.h"
39 #include "gpu/command_buffer/service/program_manager.h" 41 #include "gpu/command_buffer/service/program_manager.h"
40 #include "gpu/command_buffer/service/query_manager.h" 42 #include "gpu/command_buffer/service/query_manager.h"
41 #include "gpu/command_buffer/service/renderbuffer_manager.h" 43 #include "gpu/command_buffer/service/renderbuffer_manager.h"
42 #include "gpu/command_buffer/service/shader_manager.h" 44 #include "gpu/command_buffer/service/shader_manager.h"
43 #include "gpu/command_buffer/service/shader_translator.h" 45 #include "gpu/command_buffer/service/shader_translator.h"
44 #include "gpu/command_buffer/service/stream_texture.h" 46 #include "gpu/command_buffer/service/stream_texture.h"
45 #include "gpu/command_buffer/service/stream_texture_manager.h" 47 #include "gpu/command_buffer/service/stream_texture_manager.h"
48 #include "gpu/command_buffer/service/texture_definition.h"
46 #include "gpu/command_buffer/service/texture_manager.h" 49 #include "gpu/command_buffer/service/texture_manager.h"
47 #include "gpu/command_buffer/service/vertex_attrib_manager.h" 50 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
48 #include "ui/gfx/gl/gl_context.h" 51 #include "ui/gfx/gl/gl_context.h"
49 #include "ui/gfx/gl/gl_implementation.h" 52 #include "ui/gfx/gl/gl_implementation.h"
50 #include "ui/gfx/gl/gl_surface.h" 53 #include "ui/gfx/gl/gl_surface.h"
51 #if defined(OS_MACOSX) 54 #if defined(OS_MACOSX)
52 #include "ui/gfx/surface/io_surface_support_mac.h" 55 #include "ui/gfx/surface/io_surface_support_mac.h"
53 #endif 56 #endif
54 57
55 #if !defined(GL_DEPTH24_STENCIL8) 58 #if !defined(GL_DEPTH24_STENCIL8)
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 uint32* service_texture_id); 504 uint32* service_texture_id);
502 505
503 // Restores the current state to the user's settings. 506 // Restores the current state to the user's settings.
504 void RestoreCurrentFramebufferBindings(); 507 void RestoreCurrentFramebufferBindings();
505 void RestoreCurrentRenderbufferBindings(); 508 void RestoreCurrentRenderbufferBindings();
506 void RestoreCurrentTexture2DBindings(); 509 void RestoreCurrentTexture2DBindings();
507 510
508 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. 511 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer.
509 void ApplyDirtyState(); 512 void ApplyDirtyState();
510 513
514 // Reapply the texture parameters to the given texture.
515 void BindAndApplyTextureParameters(TextureManager::TextureInfo* info);
516
511 // These check the state of the currently bound framebuffer or the 517 // These check the state of the currently bound framebuffer or the
512 // backbuffer if no framebuffer is bound. 518 // backbuffer if no framebuffer is bound.
513 bool BoundFramebufferHasColorAttachmentWithAlpha(); 519 bool BoundFramebufferHasColorAttachmentWithAlpha();
514 bool BoundFramebufferHasDepthAttachment(); 520 bool BoundFramebufferHasDepthAttachment();
515 bool BoundFramebufferHasStencilAttachment(); 521 bool BoundFramebufferHasStencilAttachment();
516 522
517 virtual error::ContextLostReason GetContextLostReason(); 523 virtual error::ContextLostReason GetContextLostReason();
518 524
519 private: 525 private:
520 friend class ScopedGLErrorSuppressor; 526 friend class ScopedGLErrorSuppressor;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 GLint level); 740 GLint level);
735 741
736 // Wrapper for TexStorage2DEXT. 742 // Wrapper for TexStorage2DEXT.
737 void DoTexStorage2DEXT( 743 void DoTexStorage2DEXT(
738 GLenum target, 744 GLenum target,
739 GLint levels, 745 GLint levels,
740 GLenum internal_format, 746 GLenum internal_format,
741 GLsizei width, 747 GLsizei width,
742 GLsizei height); 748 GLsizei height);
743 749
750 // Wrapper for SwapTexturesCHROMIUM.
Ken Russell (switch to Gerrit) 2012/04/26 01:10:53 Wrong comment.
751 void DoProduceTextureCHROMIUM(GLenum target, const char* key);
752
753 // Wrapper for TexKeyCHROMIUM.
Ken Russell (switch to Gerrit) 2012/04/26 01:10:53 Wrong comment.
754 void DoConsumeTextureCHROMIUM(GLenum target, const char* 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
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
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 uint32 bucket_id = static_cast<uint32>(c.bucket_id);
8529 Bucket* bucket = CreateBucket(bucket_id);
8530 crypto::SymmetricKey* key =
8531 crypto::SymmetricKey::GenerateRandomKey(crypto::SymmetricKey::AES,
8532 kMailboxSize * 8);
8533 std::string mailbox;
8534 if (!key->GetRawKey(&mailbox)) {
8535 SetGLError(GL_OUT_OF_MEMORY,
8536 "glHandleGenMailboxCHROMIUM: failed to generate mailbox");
8537 return error::kNoError;
8538 }
8539
8540 DCHECK(mailbox.length() == kMailboxSize);
8541
8542 bucket->SetSize(kMailboxSize);
8543 bucket->SetData(&mailbox[0], 0, kMailboxSize);
8544
8545 return error::kNoError;
8546 }
8547
8548 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target,
8549 const char* mailbox) {
8550 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
8551 if (!info) {
8552 SetGLError(GL_INVALID_OPERATION,
8553 "glProduceTextureCHROMIUM: unknown texture for target");
8554 return;
8555 }
8556
8557 TextureDefinition* definition = texture_manager()->Save(info);
8558 if (!definition) {
8559 SetGLError(GL_INVALID_OPERATION,
8560 "glProduceTextureCHROMIUM: invalid texture");
8561 return;
8562 }
8563
8564 group_->mailbox_manager()->ProduceTexture(
greggman 2012/04/26 18:09:18 I'm a little concerned that GenMailbox is optional
8565 target,
8566 *reinterpret_cast<const MailboxName*>(mailbox),
8567 definition,
8568 texture_manager());
8569
8570 BindAndApplyTextureParameters(info);
8571 }
8572
8573 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target,
8574 const char* mailbox) {
8575 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
8576 if (!info) {
8577 SetGLError(GL_INVALID_OPERATION,
8578 "glConsumeTextureCHROMIUM: unknown texture for target");
8579 return;
8580 }
8581
8582 scoped_ptr<TextureDefinition> definition(
8583 group_->mailbox_manager()->ConsumeTexture(
8584 target,
8585 *reinterpret_cast<const MailboxName*>(mailbox)));
8586 if (!definition.get()) {
8587 SetGLError(GL_INVALID_OPERATION,
8588 "glConsumeTextureCHROMIUM: empty mailbox");
8589 return;
8590 }
8591
8592 if (!texture_manager()->Restore(info, definition.release())) {
8593 SetGLError(GL_INVALID_OPERATION,
8594 "glConsumeTextureCHROMIUM: invalid texture");
8595 return;
8596 }
8597
8598 BindAndApplyTextureParameters(info);
8599 }
8600
8505 // Include the auto-generated part of this file. We split this because it means 8601 // 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 8602 // 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. 8603 // instead of having to edit some template or the code generator.
8508 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 8604 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
8509 8605
8510 } // namespace gles2 8606 } // namespace gles2
8511 } // namespace gpu 8607 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698