| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/hash.h" | 9 #include "base/hash.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "content/common/gpu/devtools_gpu_instrumentation.h" | 13 #include "content/common/gpu/devtools_gpu_instrumentation.h" |
| 14 #include "content/common/gpu/gpu_channel.h" | 14 #include "content/common/gpu/gpu_channel.h" |
| 15 #include "content/common/gpu/gpu_channel_manager.h" | 15 #include "content/common/gpu/gpu_channel_manager.h" |
| 16 #include "content/common/gpu/gpu_command_buffer_stub.h" | 16 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 17 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 17 #include "content/common/gpu/gpu_memory_manager.h" | 18 #include "content/common/gpu/gpu_memory_manager.h" |
| 18 #include "content/common/gpu/gpu_memory_tracking.h" | 19 #include "content/common/gpu/gpu_memory_tracking.h" |
| 19 #include "content/common/gpu/gpu_messages.h" | 20 #include "content/common/gpu/gpu_messages.h" |
| 20 #include "content/common/gpu/gpu_watchdog.h" | 21 #include "content/common/gpu/gpu_watchdog.h" |
| 21 #include "content/common/gpu/image_transport_surface.h" | 22 #include "content/common/gpu/image_transport_surface.h" |
| 22 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | 23 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
| 23 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" | 24 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" |
| 24 #include "content/common/gpu/sync_point_manager.h" | 25 #include "content/common/gpu/sync_point_manager.h" |
| 25 #include "content/public/common/content_client.h" | 26 #include "content/public/common/content_client.h" |
| 26 #include "gpu/command_buffer/common/constants.h" | 27 #include "gpu/command_buffer/common/constants.h" |
| 27 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 28 #include "gpu/command_buffer/common/mailbox.h" | 29 #include "gpu/command_buffer/common/mailbox.h" |
| 29 #include "gpu/command_buffer/service/gl_context_virtual.h" | 30 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 30 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" | 31 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" |
| 31 #include "gpu/command_buffer/service/gpu_control_service.h" | |
| 32 #include "gpu/command_buffer/service/image_manager.h" | 32 #include "gpu/command_buffer/service/image_manager.h" |
| 33 #include "gpu/command_buffer/service/logger.h" | 33 #include "gpu/command_buffer/service/logger.h" |
| 34 #include "gpu/command_buffer/service/mailbox_manager.h" | 34 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 35 #include "gpu/command_buffer/service/memory_tracking.h" | 35 #include "gpu/command_buffer/service/memory_tracking.h" |
| 36 #include "gpu/command_buffer/service/query_manager.h" | 36 #include "gpu/command_buffer/service/query_manager.h" |
| 37 #include "ui/gl/gl_bindings.h" | 37 #include "ui/gl/gl_bindings.h" |
| 38 #include "ui/gl/gl_switches.h" | 38 #include "ui/gl/gl_switches.h" |
| 39 | 39 |
| 40 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 41 #include "content/public/common/sandbox_init.h" | 41 #include "content/public/common/sandbox_init.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Prevents idle work from being starved. | 111 // Prevents idle work from being starved. |
| 112 const int64 kMaxTimeSinceIdleMs = 10; | 112 const int64 kMaxTimeSinceIdleMs = 10; |
| 113 | 113 |
| 114 } // namespace | 114 } // namespace |
| 115 | 115 |
| 116 GpuCommandBufferStub::GpuCommandBufferStub( | 116 GpuCommandBufferStub::GpuCommandBufferStub( |
| 117 GpuChannel* channel, | 117 GpuChannel* channel, |
| 118 GpuCommandBufferStub* share_group, | 118 GpuCommandBufferStub* share_group, |
| 119 const gfx::GLSurfaceHandle& handle, | 119 const gfx::GLSurfaceHandle& handle, |
| 120 gpu::gles2::MailboxManager* mailbox_manager, | 120 gpu::gles2::MailboxManager* mailbox_manager, |
| 121 gpu::gles2::ImageManager* image_manager, | |
| 122 const gfx::Size& size, | 121 const gfx::Size& size, |
| 123 const gpu::gles2::DisallowedFeatures& disallowed_features, | 122 const gpu::gles2::DisallowedFeatures& disallowed_features, |
| 124 const std::vector<int32>& attribs, | 123 const std::vector<int32>& attribs, |
| 125 gfx::GpuPreference gpu_preference, | 124 gfx::GpuPreference gpu_preference, |
| 126 bool use_virtualized_gl_context, | 125 bool use_virtualized_gl_context, |
| 127 int32 route_id, | 126 int32 route_id, |
| 128 int32 surface_id, | 127 int32 surface_id, |
| 129 GpuWatchdog* watchdog, | 128 GpuWatchdog* watchdog, |
| 130 bool software, | 129 bool software, |
| 131 const GURL& active_url) | 130 const GURL& active_url) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 153 gpu::gles2::ContextCreationAttribHelper attrib_parser; | 152 gpu::gles2::ContextCreationAttribHelper attrib_parser; |
| 154 attrib_parser.Parse(requested_attribs_); | 153 attrib_parser.Parse(requested_attribs_); |
| 155 | 154 |
| 156 if (share_group) { | 155 if (share_group) { |
| 157 context_group_ = share_group->context_group_; | 156 context_group_ = share_group->context_group_; |
| 158 DCHECK(context_group_->bind_generates_resource() == | 157 DCHECK(context_group_->bind_generates_resource() == |
| 159 attrib_parser.bind_generates_resource_); | 158 attrib_parser.bind_generates_resource_); |
| 160 } else { | 159 } else { |
| 161 context_group_ = new gpu::gles2::ContextGroup( | 160 context_group_ = new gpu::gles2::ContextGroup( |
| 162 mailbox_manager, | 161 mailbox_manager, |
| 163 image_manager, | |
| 164 new GpuCommandBufferMemoryTracker(channel), | 162 new GpuCommandBufferMemoryTracker(channel), |
| 165 channel_->gpu_channel_manager()->shader_translator_cache(), | 163 channel_->gpu_channel_manager()->shader_translator_cache(), |
| 166 NULL, | 164 NULL, |
| 167 attrib_parser.bind_generates_resource_); | 165 attrib_parser.bind_generates_resource_); |
| 168 } | 166 } |
| 169 | 167 |
| 170 use_virtualized_gl_context_ |= | 168 use_virtualized_gl_context_ |= |
| 171 context_group_->feature_info()->workarounds().use_virtualized_gl_contexts; | 169 context_group_->feature_info()->workarounds().use_virtualized_gl_contexts; |
| 172 } | 170 } |
| 173 | 171 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 context, | 531 context, |
| 534 !surface_id(), | 532 !surface_id(), |
| 535 initial_size_, | 533 initial_size_, |
| 536 disallowed_features_, | 534 disallowed_features_, |
| 537 requested_attribs_)) { | 535 requested_attribs_)) { |
| 538 DLOG(ERROR) << "Failed to initialize decoder."; | 536 DLOG(ERROR) << "Failed to initialize decoder."; |
| 539 OnInitializeFailed(reply_message); | 537 OnInitializeFailed(reply_message); |
| 540 return; | 538 return; |
| 541 } | 539 } |
| 542 | 540 |
| 543 gpu_control_service_.reset( | |
| 544 new gpu::GpuControlService(context_group_->image_manager(), NULL)); | |
| 545 | |
| 546 if (CommandLine::ForCurrentProcess()->HasSwitch( | 541 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 547 switches::kEnableGPUServiceLogging)) { | 542 switches::kEnableGPUServiceLogging)) { |
| 548 decoder_->set_log_commands(true); | 543 decoder_->set_log_commands(true); |
| 549 } | 544 } |
| 550 | 545 |
| 551 decoder_->GetLogger()->SetMsgCallback( | 546 decoder_->GetLogger()->SetMsgCallback( |
| 552 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, | 547 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, |
| 553 base::Unretained(this))); | 548 base::Unretained(this))); |
| 554 decoder_->SetShaderCacheCallback( | 549 decoder_->SetShaderCacheCallback( |
| 555 base::Bind(&GpuCommandBufferStub::SendCachedShader, | 550 base::Bind(&GpuCommandBufferStub::SendCachedShader, |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState( | 908 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState( |
| 914 this, surface_id_ != 0, true)); | 909 this, surface_id_ != 0, true)); |
| 915 } | 910 } |
| 916 } else { | 911 } else { |
| 917 memory_manager_client_state_.reset(); | 912 memory_manager_client_state_.reset(); |
| 918 } | 913 } |
| 919 } | 914 } |
| 920 | 915 |
| 921 void GpuCommandBufferStub::OnRegisterGpuMemoryBuffer( | 916 void GpuCommandBufferStub::OnRegisterGpuMemoryBuffer( |
| 922 int32 id, | 917 int32 id, |
| 923 gfx::GpuMemoryBufferHandle gpu_memory_buffer, | 918 gfx::GpuMemoryBufferHandle handle, |
| 924 uint32 width, | 919 uint32 width, |
| 925 uint32 height, | 920 uint32 height, |
| 926 uint32 internalformat) { | 921 uint32 internalformat) { |
| 927 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterGpuMemoryBuffer"); | 922 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterGpuMemoryBuffer"); |
| 928 #if defined(OS_ANDROID) | 923 #if defined(OS_ANDROID) |
| 929 // Verify that renderer is not trying to use a surface texture it doesn't own. | 924 // Verify that renderer is not trying to use a surface texture it doesn't own. |
| 930 if (gpu_memory_buffer.type == gfx::SURFACE_TEXTURE_BUFFER && | 925 if (handle.type == gfx::SURFACE_TEXTURE_BUFFER && |
| 931 gpu_memory_buffer.surface_texture_id.secondary_id != | 926 handle.surface_texture_id.secondary_id != channel()->client_id()) { |
| 932 channel()->client_id()) { | |
| 933 LOG(ERROR) << "Illegal surface texture ID for renderer."; | 927 LOG(ERROR) << "Illegal surface texture ID for renderer."; |
| 934 return; | 928 return; |
| 935 } | 929 } |
| 936 #endif | 930 #endif |
| 937 if (gpu_control_service_) { | 931 |
| 938 gpu_control_service_->RegisterGpuMemoryBuffer( | 932 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 939 id, gpu_memory_buffer, width, height, internalformat); | 933 scoped_refptr<gfx::GLImage> image = |
| 934 manager->gpu_memory_buffer_factory()->CreateImageForGpuMemoryBuffer( |
| 935 handle, |
| 936 gfx::Size(width, height), |
| 937 internalformat, |
| 938 channel()->client_id()); |
| 939 if (!image) |
| 940 return; |
| 941 |
| 942 // For Android specific workaround. |
| 943 if (context_group_->feature_info()->workarounds().release_image_after_use) |
| 944 image->SetReleaseAfterUse(); |
| 945 |
| 946 if (decoder_) { |
| 947 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
| 948 DCHECK(image_manager); |
| 949 image_manager->AddImage(image.get(), id); |
| 940 } | 950 } |
| 941 } | 951 } |
| 942 | 952 |
| 943 void GpuCommandBufferStub::OnDestroyGpuMemoryBuffer(int32 id) { | 953 void GpuCommandBufferStub::OnDestroyGpuMemoryBuffer(int32 id) { |
| 944 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyGpuMemoryBuffer"); | 954 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyGpuMemoryBuffer"); |
| 945 if (gpu_control_service_) | 955 |
| 946 gpu_control_service_->UnregisterGpuMemoryBuffer(id); | 956 if (decoder_) { |
| 957 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
| 958 DCHECK(image_manager); |
| 959 image_manager->RemoveImage(id); |
| 960 } |
| 947 } | 961 } |
| 948 | 962 |
| 949 void GpuCommandBufferStub::SendConsoleMessage( | 963 void GpuCommandBufferStub::SendConsoleMessage( |
| 950 int32 id, | 964 int32 id, |
| 951 const std::string& message) { | 965 const std::string& message) { |
| 952 GPUCommandBufferConsoleMessage console_message; | 966 GPUCommandBufferConsoleMessage console_message; |
| 953 console_message.id = id; | 967 console_message.id = id; |
| 954 console_message.message = message; | 968 console_message.message = message; |
| 955 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( | 969 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( |
| 956 route_id_, console_message); | 970 route_id_, console_message); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 if (decoder_) | 1052 if (decoder_) |
| 1039 decoder_->LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); | 1053 decoder_->LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 1040 command_buffer_->SetParseError(gpu::error::kLostContext); | 1054 command_buffer_->SetParseError(gpu::error::kLostContext); |
| 1041 } | 1055 } |
| 1042 | 1056 |
| 1043 uint64 GpuCommandBufferStub::GetMemoryUsage() const { | 1057 uint64 GpuCommandBufferStub::GetMemoryUsage() const { |
| 1044 return GetMemoryManager()->GetClientMemoryUsage(this); | 1058 return GetMemoryManager()->GetClientMemoryUsage(this); |
| 1045 } | 1059 } |
| 1046 | 1060 |
| 1047 } // namespace content | 1061 } // namespace content |
| OLD | NEW |