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/image_transport_surface.h" | 5 #include "content/common/gpu/image_transport_surface.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "content/common/gpu/gpu_channel.h" | 11 #include "content/common/gpu/gpu_channel.h" |
12 #include "content/common/gpu/gpu_channel_manager.h" | 12 #include "content/common/gpu/gpu_channel_manager.h" |
13 #include "content/common/gpu/gpu_command_buffer_stub.h" | 13 #include "content/common/gpu/gpu_command_buffer_stub.h" |
14 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
15 #include "content/common/gpu/null_transport_surface.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "gpu/command_buffer/service/sync_point_manager.h" | 16 #include "gpu/command_buffer/service/sync_point_manager.h" |
17 #include "ui/gfx/vsync_provider.h" | 17 #include "ui/gfx/vsync_provider.h" |
18 #include "ui/gl/gl_context.h" | 18 #include "ui/gl/gl_context.h" |
19 #include "ui/gl/gl_implementation.h" | 19 #include "ui/gl/gl_implementation.h" |
20 #include "ui/gl/gl_switches.h" | 20 #include "ui/gl/gl_switches.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 ImageTransportSurface::ImageTransportSurface() {} | 24 ImageTransportSurface::ImageTransportSurface() {} |
25 | 25 |
26 ImageTransportSurface::~ImageTransportSurface() {} | 26 ImageTransportSurface::~ImageTransportSurface() {} |
27 | 27 |
28 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 28 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
29 GpuChannelManager* manager, | 29 GpuChannelManager* manager, |
30 GpuCommandBufferStub* stub, | 30 GpuCommandBufferStub* stub, |
31 const gfx::GLSurfaceHandle& handle) { | 31 const gfx::GLSurfaceHandle& handle) { |
32 scoped_refptr<gfx::GLSurface> surface; | 32 scoped_refptr<gfx::GLSurface> surface; |
33 if (handle.transport_type == gfx::NULL_TRANSPORT) { | 33 if (handle.transport_type == gfx::NULL_TRANSPORT) { |
34 #if defined(OS_ANDROID) | 34 GpuChannel* parent_channel = manager->LookupChannel( |
35 surface = CreateTransportSurface(manager, stub, handle); | 35 handle.parent_client_id); |
36 #else | 36 if (parent_channel) { |
37 surface = new NullTransportSurface(manager, stub, handle); | 37 const base::CommandLine* command_line = |
38 #endif | 38 base::CommandLine::ForCurrentProcess(); |
| 39 if (command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess)) |
| 40 stub->channel()->SetPreemptByFlag(parent_channel->GetPreemptionFlag()); |
| 41 } |
| 42 |
| 43 surface = manager->GetDefaultOffscreenSurface(); |
39 } else { | 44 } else { |
40 surface = CreateNativeSurface(manager, stub, handle); | 45 surface = CreateNativeSurface(manager, stub, handle); |
| 46 if (!surface.get() || !surface->Initialize()) |
| 47 return NULL; |
41 } | 48 } |
42 | 49 |
43 if (!surface.get() || !surface->Initialize()) | |
44 return NULL; | |
45 return surface; | 50 return surface; |
46 } | 51 } |
47 | 52 |
48 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, | 53 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, |
49 GpuChannelManager* manager, | 54 GpuChannelManager* manager, |
50 GpuCommandBufferStub* stub, | 55 GpuCommandBufferStub* stub, |
51 gfx::PluginWindowHandle handle) | 56 gfx::PluginWindowHandle handle) |
52 : surface_(surface), | 57 : surface_(surface), |
53 manager_(manager), | 58 manager_(manager), |
54 stub_(stub->AsWeakPtr()), | 59 stub_(stub->AsWeakPtr()), |
(...skipping 16 matching lines...) Expand all Loading... |
71 if (!decoder) | 76 if (!decoder) |
72 return false; | 77 return false; |
73 | 78 |
74 decoder->SetResizeCallback( | 79 decoder->SetResizeCallback( |
75 base::Bind(&ImageTransportHelper::Resize, base::Unretained(this))); | 80 base::Bind(&ImageTransportHelper::Resize, base::Unretained(this))); |
76 | 81 |
77 stub_->SetLatencyInfoCallback( | 82 stub_->SetLatencyInfoCallback( |
78 base::Bind(&ImageTransportHelper::SetLatencyInfo, | 83 base::Bind(&ImageTransportHelper::SetLatencyInfo, |
79 base::Unretained(this))); | 84 base::Unretained(this))); |
80 | 85 |
81 manager_->Send(new GpuHostMsg_AcceleratedSurfaceInitialized( | |
82 stub_->surface_id(), route_id_)); | |
83 | |
84 return true; | 86 return true; |
85 } | 87 } |
86 | 88 |
87 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { | 89 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
| 90 #if defined(OS_MACOSX) |
88 bool handled = true; | 91 bool handled = true; |
89 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) | 92 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
90 #if defined(OS_MACOSX) | |
91 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, | 93 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, |
92 OnBufferPresented) | 94 OnBufferPresented) |
93 #endif | |
94 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_WakeUpGpu, OnWakeUpGpu); | |
95 IPC_MESSAGE_UNHANDLED(handled = false) | 95 IPC_MESSAGE_UNHANDLED(handled = false) |
96 IPC_END_MESSAGE_MAP() | 96 IPC_END_MESSAGE_MAP() |
97 return handled; | 97 return handled; |
| 98 #else |
| 99 NOTREACHED(); |
| 100 return false; |
| 101 #endif |
98 } | 102 } |
99 | 103 |
100 #if defined(OS_MACOSX) | 104 #if defined(OS_MACOSX) |
101 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( | 105 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( |
102 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { | 106 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { |
103 // TRACE_EVENT for gpu tests: | 107 // TRACE_EVENT for gpu tests: |
104 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", | 108 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", |
105 TRACE_EVENT_SCOPE_THREAD, | 109 TRACE_EVENT_SCOPE_THREAD, |
106 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), | 110 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
107 "width", params.size.width()); | 111 "width", params.size.width()); |
(...skipping 29 matching lines...) Expand all Loading... |
137 return stub_->decoder(); | 141 return stub_->decoder(); |
138 } | 142 } |
139 | 143 |
140 #if defined(OS_MACOSX) | 144 #if defined(OS_MACOSX) |
141 void ImageTransportHelper::OnBufferPresented( | 145 void ImageTransportHelper::OnBufferPresented( |
142 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { | 146 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { |
143 surface_->OnBufferPresented(params); | 147 surface_->OnBufferPresented(params); |
144 } | 148 } |
145 #endif | 149 #endif |
146 | 150 |
147 void ImageTransportHelper::OnWakeUpGpu() { | |
148 surface_->WakeUpGpu(); | |
149 } | |
150 | |
151 void ImageTransportHelper::Resize(gfx::Size size, float scale_factor) { | 151 void ImageTransportHelper::Resize(gfx::Size size, float scale_factor) { |
152 surface_->OnResize(size, scale_factor); | 152 surface_->OnResize(size, scale_factor); |
153 | 153 |
154 #if defined(OS_ANDROID) | 154 #if defined(OS_ANDROID) |
155 manager_->gpu_memory_manager()->ScheduleManage( | 155 manager_->gpu_memory_manager()->ScheduleManage( |
156 GpuMemoryManager::kScheduleManageNow); | 156 GpuMemoryManager::kScheduleManageNow); |
157 #endif | 157 #endif |
158 } | 158 } |
159 | 159 |
160 void ImageTransportHelper::SetLatencyInfo( | 160 void ImageTransportHelper::SetLatencyInfo( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 void PassThroughImageTransportSurface::OnResize(gfx::Size size, | 274 void PassThroughImageTransportSurface::OnResize(gfx::Size size, |
275 float scale_factor) { | 275 float scale_factor) { |
276 Resize(size); | 276 Resize(size); |
277 } | 277 } |
278 | 278 |
279 gfx::Size PassThroughImageTransportSurface::GetSize() { | 279 gfx::Size PassThroughImageTransportSurface::GetSize() { |
280 return GLSurfaceAdapter::GetSize(); | 280 return GLSurfaceAdapter::GetSize(); |
281 } | 281 } |
282 | 282 |
283 void PassThroughImageTransportSurface::WakeUpGpu() { | |
284 NOTREACHED(); | |
285 } | |
286 | |
287 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} | 283 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} |
288 | 284 |
289 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 285 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
290 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 286 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
291 if (vsync_provider) { | 287 if (vsync_provider) { |
292 vsync_provider->GetVSyncParameters( | 288 vsync_provider->GetVSyncParameters( |
293 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, | 289 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, |
294 helper_->stub()->AsWeakPtr())); | 290 helper_->stub()->AsWeakPtr())); |
295 } | 291 } |
296 } | 292 } |
297 | 293 |
298 } // namespace content | 294 } // namespace content |
OLD | NEW |