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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState( | 905 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState( |
911 this, surface_id_ != 0, true)); | 906 this, surface_id_ != 0, true)); |
912 } | 907 } |
913 } else { | 908 } else { |
914 memory_manager_client_state_.reset(); | 909 memory_manager_client_state_.reset(); |
915 } | 910 } |
916 } | 911 } |
917 | 912 |
918 void GpuCommandBufferStub::OnRegisterGpuMemoryBuffer( | 913 void GpuCommandBufferStub::OnRegisterGpuMemoryBuffer( |
919 int32 id, | 914 int32 id, |
920 gfx::GpuMemoryBufferHandle gpu_memory_buffer, | 915 gfx::GpuMemoryBufferHandle handle, |
921 uint32 width, | 916 uint32 width, |
922 uint32 height, | 917 uint32 height, |
923 uint32 internalformat) { | 918 uint32 internalformat) { |
924 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterGpuMemoryBuffer"); | 919 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterGpuMemoryBuffer"); |
925 #if defined(OS_ANDROID) | 920 #if defined(OS_ANDROID) |
926 // Verify that renderer is not trying to use a surface texture it doesn't own. | 921 // Verify that renderer is not trying to use a surface texture it doesn't own. |
927 if (gpu_memory_buffer.type == gfx::SURFACE_TEXTURE_BUFFER && | 922 if (gpu_memory_buffer.type == gfx::SURFACE_TEXTURE_BUFFER && |
928 gpu_memory_buffer.surface_texture_id.secondary_id != | 923 gpu_memory_buffer.surface_texture_id.secondary_id != |
929 channel()->client_id()) { | 924 channel()->client_id()) { |
930 LOG(ERROR) << "Illegal surface texture ID for renderer."; | 925 LOG(ERROR) << "Illegal surface texture ID for renderer."; |
931 return; | 926 return; |
932 } | 927 } |
933 #endif | 928 #endif |
934 if (gpu_control_service_) { | 929 |
935 gpu_control_service_->RegisterGpuMemoryBuffer( | 930 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
936 id, gpu_memory_buffer, width, height, internalformat); | 931 scoped_refptr<gfx::GLImage> image = |
| 932 manager->gpu_memory_buffer_factory()->CreateImageForGpuMemoryBuffer( |
| 933 handle, |
| 934 gfx::Size(width, height), |
| 935 internalformat, |
| 936 channel()->client_id()); |
| 937 if (!image) |
| 938 return; |
| 939 |
| 940 // For Android specific workaround. |
| 941 if (context_group_->feature_info()->workarounds().release_image_after_use) |
| 942 image->SetReleaseAfterUse(); |
| 943 |
| 944 if (decoder_) { |
| 945 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
| 946 if (image_manager) |
| 947 image_manager->AddImage(image, id); |
937 } | 948 } |
938 } | 949 } |
939 | 950 |
940 void GpuCommandBufferStub::OnDestroyGpuMemoryBuffer(int32 id) { | 951 void GpuCommandBufferStub::OnDestroyGpuMemoryBuffer(int32 id) { |
941 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyGpuMemoryBuffer"); | 952 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyGpuMemoryBuffer"); |
942 if (gpu_control_service_) | 953 |
943 gpu_control_service_->UnregisterGpuMemoryBuffer(id); | 954 if (decoder_) { |
| 955 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
| 956 if (image_manager) |
| 957 image_manager->RemoveImage(id); |
| 958 } |
944 } | 959 } |
945 | 960 |
946 void GpuCommandBufferStub::SendConsoleMessage( | 961 void GpuCommandBufferStub::SendConsoleMessage( |
947 int32 id, | 962 int32 id, |
948 const std::string& message) { | 963 const std::string& message) { |
949 GPUCommandBufferConsoleMessage console_message; | 964 GPUCommandBufferConsoleMessage console_message; |
950 console_message.id = id; | 965 console_message.id = id; |
951 console_message.message = message; | 966 console_message.message = message; |
952 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( | 967 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( |
953 route_id_, console_message); | 968 route_id_, console_message); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 if (decoder_) | 1050 if (decoder_) |
1036 decoder_->LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); | 1051 decoder_->LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
1037 command_buffer_->SetParseError(gpu::error::kLostContext); | 1052 command_buffer_->SetParseError(gpu::error::kLostContext); |
1038 } | 1053 } |
1039 | 1054 |
1040 uint64 GpuCommandBufferStub::GetMemoryUsage() const { | 1055 uint64 GpuCommandBufferStub::GetMemoryUsage() const { |
1041 return GetMemoryManager()->GetClientMemoryUsage(this); | 1056 return GetMemoryManager()->GetClientMemoryUsage(this); |
1042 } | 1057 } |
1043 | 1058 |
1044 } // namespace content | 1059 } // namespace content |
OLD | NEW |