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 "content/common/gpu/gpu_command_buffer_stub.h" | 5 #include "content/common/gpu/gpu_command_buffer_stub.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/hash.h" | 12 #include "base/hash.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/sys_info.h" | |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "content/common/gpu/gpu_channel.h" | 20 #include "content/common/gpu/gpu_channel.h" |
20 #include "content/common/gpu/gpu_channel_manager.h" | 21 #include "content/common/gpu/gpu_channel_manager.h" |
21 #include "content/common/gpu/gpu_memory_manager.h" | 22 #include "content/common/gpu/gpu_memory_manager.h" |
22 #include "content/common/gpu/gpu_memory_tracking.h" | 23 #include "content/common/gpu/gpu_memory_tracking.h" |
23 #include "content/common/gpu/gpu_messages.h" | 24 #include "content/common/gpu/gpu_messages.h" |
24 #include "content/common/gpu/gpu_watchdog.h" | 25 #include "content/common/gpu/gpu_watchdog.h" |
25 #include "content/common/gpu/image_transport_surface.h" | 26 #include "content/common/gpu/image_transport_surface.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 res->SetInteger("renderer_pid", channel->GetClientPID()); | 155 res->SetInteger("renderer_pid", channel->GetClientPID()); |
155 res->SetDouble("used_bytes", channel->GetMemoryUsage()); | 156 res->SetDouble("used_bytes", channel->GetMemoryUsage()); |
156 return new DevToolsChannelData(res.release()); | 157 return new DevToolsChannelData(res.release()); |
157 } | 158 } |
158 | 159 |
159 uint64_t GetCommandBufferID(int channel_id, int32_t route_id) { | 160 uint64_t GetCommandBufferID(int channel_id, int32_t route_id) { |
160 return (static_cast<uint64_t>(channel_id) << 32) | route_id; | 161 return (static_cast<uint64_t>(channel_id) << 32) | route_id; |
161 } | 162 } |
162 | 163 |
163 gfx::GLSurface::Format GetSurfaceFormatFromAttribute( | 164 gfx::GLSurface::Format GetSurfaceFormatFromAttribute( |
164 const gpu::gles2::ContextCreationAttribHelper& attrib, | 165 const gpu::gles2::ContextCreationAttribHelper& attrib) { |
165 bool use_virtualized_gl_context) { | |
166 gfx::GLSurface::Format format = gfx::GLSurface::SURFACE_DEFAULT; // ARGB8888 | 166 gfx::GLSurface::Format format = gfx::GLSurface::SURFACE_DEFAULT; // ARGB8888 |
167 if (!use_virtualized_gl_context && | 167 if (attrib.red_size <= 5 && |
168 attrib.red_size <= 5 && | |
169 attrib.green_size <= 6 && | 168 attrib.green_size <= 6 && |
170 attrib.blue_size <= 5 && | 169 attrib.blue_size <= 5 && |
171 attrib.alpha_size == 0) { | 170 attrib.alpha_size == 0) { |
172 format = gfx::GLSurface::SURFACE_RGB565; | 171 format = gfx::GLSurface::SURFACE_RGB565; |
173 } | 172 } |
174 return format; | 173 return format; |
175 } | 174 } |
176 } // namespace | 175 } // namespace |
177 | 176 |
178 GpuCommandBufferStub::GpuCommandBufferStub( | 177 GpuCommandBufferStub::GpuCommandBufferStub( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 use_virtualized_gl_context_ = true; | 242 use_virtualized_gl_context_ = true; |
244 #endif | 243 #endif |
245 | 244 |
246 use_virtualized_gl_context_ |= | 245 use_virtualized_gl_context_ |= |
247 context_group_->feature_info()->workarounds().use_virtualized_gl_contexts; | 246 context_group_->feature_info()->workarounds().use_virtualized_gl_contexts; |
248 | 247 |
249 // MailboxManagerSync synchronization correctness currently depends on having | 248 // MailboxManagerSync synchronization correctness currently depends on having |
250 // only a single context. See crbug.com/510243 for details. | 249 // only a single context. See crbug.com/510243 for details. |
251 use_virtualized_gl_context_ |= mailbox_manager->UsesSync(); | 250 use_virtualized_gl_context_ |= mailbox_manager->UsesSync(); |
252 | 251 |
253 surface_format_ = GetSurfaceFormatFromAttribute(attrib_parser, | 252 surface_format_ = GetSurfaceFormatFromAttribute(attrib_parser); |
254 use_virtualized_gl_context_); | |
255 | 253 |
256 if (offscreen && initial_size_.IsEmpty()) { | 254 if (offscreen && initial_size_.IsEmpty()) { |
257 // If we're an offscreen surface with zero width and/or height, set to a | 255 // If we're an offscreen surface with zero width and/or height, set to a |
258 // non-zero size so that we have a complete framebuffer for operations like | 256 // non-zero size so that we have a complete framebuffer for operations like |
259 // glClear. | 257 // glClear. |
260 initial_size_ = gfx::Size(1, 1); | 258 initial_size_ = gfx::Size(1, 1); |
261 } | 259 } |
262 } | 260 } |
263 | 261 |
264 GpuCommandBufferStub::~GpuCommandBufferStub() { | 262 GpuCommandBufferStub::~GpuCommandBufferStub() { |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 surface_ = manager->GetDefaultOffscreenSurface(); | 552 surface_ = manager->GetDefaultOffscreenSurface(); |
555 } | 553 } |
556 | 554 |
557 if (!surface_.get()) { | 555 if (!surface_.get()) { |
558 DLOG(ERROR) << "Failed to create surface."; | 556 DLOG(ERROR) << "Failed to create surface."; |
559 OnInitializeFailed(reply_message); | 557 OnInitializeFailed(reply_message); |
560 return; | 558 return; |
561 } | 559 } |
562 | 560 |
563 scoped_refptr<gfx::GLContext> context; | 561 scoped_refptr<gfx::GLContext> context; |
564 if (use_virtualized_gl_context_ && channel_->share_group()) { | 562 gfx::GLShareGroup* share_group = channel_->share_group(); |
565 context = channel_->share_group()->GetSharedContext(); | 563 if (use_virtualized_gl_context_ && share_group) { |
564 context = share_group->GetSharedContext(); | |
566 if (!context.get()) { | 565 if (!context.get()) { |
567 context = gfx::GLContext::CreateGLContext( | 566 context = gfx::GLContext::CreateGLContext( |
568 channel_->share_group(), | 567 channel_->share_group(), |
569 channel_->gpu_channel_manager()->GetDefaultOffscreenSurface(), | 568 channel_->gpu_channel_manager()->GetDefaultOffscreenSurface(), |
570 gpu_preference_); | 569 gpu_preference_); |
571 if (!context.get()) { | 570 if (!context.get()) { |
572 DLOG(ERROR) << "Failed to create shared context for virtualization."; | 571 DLOG(ERROR) << "Failed to create shared context for virtualization."; |
573 OnInitializeFailed(reply_message); | 572 OnInitializeFailed(reply_message); |
574 return; | 573 return; |
575 } | 574 } |
576 channel_->share_group()->SetSharedContext(context.get()); | 575 channel_->share_group()->SetSharedContext(context.get()); |
577 } | 576 } |
578 // This should be a non-virtual GL context. | 577 // This should be a non-virtual GL context. |
579 DCHECK(context->GetHandle()); | 578 DCHECK(context->GetHandle()); |
580 context = new gpu::GLContextVirtual( | 579 context = new gpu::GLContextVirtual( |
581 channel_->share_group(), context.get(), decoder_->AsWeakPtr()); | 580 share_group, context.get(), decoder_->AsWeakPtr()); |
582 if (!context->Initialize(surface_.get(), gpu_preference_)) { | 581 if (!context->Initialize(surface_.get(), gpu_preference_)) { |
no sievers
2016/02/18 20:19:45
Unfortunately Initialize() is not reliable to dete
Jinsuk Kim
2016/02/19 01:04:40
Got it. I guarded it with #if for it to take effec
| |
583 // TODO(sievers): The real context created above for the default | 582 // The real context created above for the default offscreen surface |
584 // offscreen surface might not be compatible with this surface. | 583 // is not compatible with this surface. Do not use a virtualized context. |
585 // Need to adjust at least GLX to be able to create the initial context | 584 // in this case. |
586 // with a config that is compatible with onscreen and offscreen surfaces. | |
587 context = NULL; | 585 context = NULL; |
588 | |
589 DLOG(ERROR) << "Failed to initialize virtual GL context."; | |
590 OnInitializeFailed(reply_message); | |
591 return; | |
592 } | 586 } |
593 } | 587 } |
594 if (!context.get()) { | 588 if (!context.get()) { |
595 context = gfx::GLContext::CreateGLContext( | 589 context = gfx::GLContext::CreateGLContext( |
596 channel_->share_group(), surface_.get(), gpu_preference_); | 590 share_group, surface_.get(), gpu_preference_); |
597 } | 591 } |
598 if (!context.get()) { | 592 if (!context.get()) { |
599 DLOG(ERROR) << "Failed to create context."; | 593 DLOG(ERROR) << "Failed to create context."; |
600 OnInitializeFailed(reply_message); | 594 OnInitializeFailed(reply_message); |
601 return; | 595 return; |
602 } | 596 } |
603 | 597 |
604 if (!context->MakeCurrent(surface_.get())) { | 598 if (!context->MakeCurrent(surface_.get())) { |
605 LOG(ERROR) << "Failed to make context current."; | 599 LOG(ERROR) << "Failed to make context current."; |
606 OnInitializeFailed(reply_message); | 600 OnInitializeFailed(reply_message); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1178 result)); | 1172 result)); |
1179 } | 1173 } |
1180 | 1174 |
1181 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1175 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
1182 base::TimeDelta interval) { | 1176 base::TimeDelta interval) { |
1183 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1177 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
1184 interval)); | 1178 interval)); |
1185 } | 1179 } |
1186 | 1180 |
1187 } // namespace content | 1181 } // namespace content |
OLD | NEW |