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/debug/trace_event.h" | 10 #include "base/debug/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/common/gpu/sync_point_manager.h" | 16 #include "content/common/gpu/sync_point_manager.h" |
16 #include "content/common/gpu/texture_image_transport_surface.h" | |
17 #include "gpu/command_buffer/service/gpu_scheduler.h" | 17 #include "gpu/command_buffer/service/gpu_scheduler.h" |
18 #include "ui/gfx/vsync_provider.h" | 18 #include "ui/gfx/vsync_provider.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 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
23 #include "ui/base/win/shell.h" | 23 #include "ui/base/win/shell.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 ImageTransportSurface::ImageTransportSurface() {} | 28 ImageTransportSurface::ImageTransportSurface() {} |
29 | 29 |
30 ImageTransportSurface::~ImageTransportSurface() {} | 30 ImageTransportSurface::~ImageTransportSurface() {} |
31 | 31 |
32 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 32 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
33 GpuChannelManager* manager, | 33 GpuChannelManager* manager, |
34 GpuCommandBufferStub* stub, | 34 GpuCommandBufferStub* stub, |
35 const gfx::GLSurfaceHandle& handle) { | 35 const gfx::GLSurfaceHandle& handle) { |
36 scoped_refptr<gfx::GLSurface> surface; | 36 scoped_refptr<gfx::GLSurface> surface; |
37 if (handle.transport_type == gfx::TEXTURE_TRANSPORT) | 37 if (handle.transport_type == gfx::NULL_TRANSPORT) |
38 surface = new TextureImageTransportSurface(manager, stub, handle); | 38 surface = new NullTransportSurface(manager, stub, handle); |
39 else | 39 else |
40 surface = CreateNativeSurface(manager, stub, handle); | 40 surface = CreateNativeSurface(manager, stub, handle); |
41 | 41 |
42 if (!surface.get() || !surface->Initialize()) | 42 if (!surface.get() || !surface->Initialize()) |
43 return NULL; | 43 return NULL; |
44 return surface; | 44 return surface; |
45 } | 45 } |
46 | 46 |
47 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, | 47 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, |
48 GpuChannelManager* manager, | 48 GpuChannelManager* manager, |
(...skipping 27 matching lines...) Expand all Loading... |
76 stub_->SetLatencyInfoCallback( | 76 stub_->SetLatencyInfoCallback( |
77 base::Bind(&ImageTransportHelper::SetLatencyInfo, | 77 base::Bind(&ImageTransportHelper::SetLatencyInfo, |
78 base::Unretained(this))); | 78 base::Unretained(this))); |
79 | 79 |
80 manager_->Send(new GpuHostMsg_AcceleratedSurfaceInitialized( | 80 manager_->Send(new GpuHostMsg_AcceleratedSurfaceInitialized( |
81 stub_->surface_id(), route_id_)); | 81 stub_->surface_id(), route_id_)); |
82 | 82 |
83 return true; | 83 return true; |
84 } | 84 } |
85 | 85 |
86 void ImageTransportHelper::Destroy() {} | |
87 | |
88 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { | 86 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
89 bool handled = true; | 87 bool handled = true; |
90 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) | 88 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
91 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, | 89 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, |
92 OnBufferPresented) | 90 OnBufferPresented) |
93 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_WakeUpGpu, OnWakeUpGpu); | 91 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_WakeUpGpu, OnWakeUpGpu); |
94 IPC_MESSAGE_UNHANDLED(handled = false) | 92 IPC_MESSAGE_UNHANDLED(handled = false) |
95 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
96 return handled; | 94 return handled; |
97 } | 95 } |
98 | 96 |
99 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( | 97 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( |
100 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { | 98 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { |
101 // TRACE_EVENT for gpu tests: | 99 // TRACE_EVENT for gpu tests: |
102 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", | 100 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", |
103 TRACE_EVENT_SCOPE_THREAD, | 101 TRACE_EVENT_SCOPE_THREAD, |
104 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), | 102 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
105 "width", params.size.width()); | 103 "width", params.size.width()); |
106 params.surface_id = stub_->surface_id(); | 104 params.surface_id = stub_->surface_id(); |
107 params.route_id = route_id_; | 105 params.route_id = route_id_; |
108 manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | 106 manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); |
109 } | 107 } |
110 | 108 |
111 void ImageTransportHelper::SendAcceleratedSurfacePostSubBuffer( | |
112 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params) { | |
113 params.surface_id = stub_->surface_id(); | |
114 params.route_id = route_id_; | |
115 manager_->Send(new GpuHostMsg_AcceleratedSurfacePostSubBuffer(params)); | |
116 } | |
117 | |
118 void ImageTransportHelper::SendAcceleratedSurfaceRelease() { | |
119 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | |
120 params.surface_id = stub_->surface_id(); | |
121 manager_->Send(new GpuHostMsg_AcceleratedSurfaceRelease(params)); | |
122 } | |
123 | |
124 void ImageTransportHelper::SendUpdateVSyncParameters( | 109 void ImageTransportHelper::SendUpdateVSyncParameters( |
125 base::TimeTicks timebase, base::TimeDelta interval) { | 110 base::TimeTicks timebase, base::TimeDelta interval) { |
126 manager_->Send(new GpuHostMsg_UpdateVSyncParameters(stub_->surface_id(), | 111 manager_->Send(new GpuHostMsg_UpdateVSyncParameters(stub_->surface_id(), |
127 timebase, | 112 timebase, |
128 interval)); | 113 interval)); |
129 } | 114 } |
130 | 115 |
131 void ImageTransportHelper::SendLatencyInfo( | 116 void ImageTransportHelper::SendLatencyInfo( |
132 const std::vector<ui::LatencyInfo>& latency_info) { | 117 const std::vector<ui::LatencyInfo>& latency_info) { |
133 manager_->Send(new GpuHostMsg_FrameDrawn(latency_info)); | 118 manager_->Send(new GpuHostMsg_FrameDrawn(latency_info)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 context->SetSwapInterval(0); | 153 context->SetSwapInterval(0); |
169 return; | 154 return; |
170 } | 155 } |
171 #endif | 156 #endif |
172 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) | 157 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) |
173 context->SetSwapInterval(0); | 158 context->SetSwapInterval(0); |
174 else | 159 else |
175 context->SetSwapInterval(1); | 160 context->SetSwapInterval(1); |
176 } | 161 } |
177 | 162 |
178 void ImageTransportHelper::Suspend() { | |
179 manager_->Send(new GpuHostMsg_AcceleratedSurfaceSuspend(stub_->surface_id())); | |
180 } | |
181 | |
182 gpu::GpuScheduler* ImageTransportHelper::Scheduler() { | 163 gpu::GpuScheduler* ImageTransportHelper::Scheduler() { |
183 if (!stub_.get()) | 164 if (!stub_.get()) |
184 return NULL; | 165 return NULL; |
185 return stub_->scheduler(); | 166 return stub_->scheduler(); |
186 } | 167 } |
187 | 168 |
188 gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { | 169 gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { |
189 if (!stub_.get()) | 170 if (!stub_.get()) |
190 return NULL; | 171 return NULL; |
191 return stub_->decoder(); | 172 return stub_->decoder(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 stub, | 206 stub, |
226 gfx::kNullPluginWindow)); | 207 gfx::kNullPluginWindow)); |
227 } | 208 } |
228 | 209 |
229 bool PassThroughImageTransportSurface::Initialize() { | 210 bool PassThroughImageTransportSurface::Initialize() { |
230 // The surface is assumed to have already been initialized. | 211 // The surface is assumed to have already been initialized. |
231 return helper_->Initialize(); | 212 return helper_->Initialize(); |
232 } | 213 } |
233 | 214 |
234 void PassThroughImageTransportSurface::Destroy() { | 215 void PassThroughImageTransportSurface::Destroy() { |
235 helper_->Destroy(); | |
236 GLSurfaceAdapter::Destroy(); | 216 GLSurfaceAdapter::Destroy(); |
237 } | 217 } |
238 | 218 |
239 void PassThroughImageTransportSurface::SetLatencyInfo( | 219 void PassThroughImageTransportSurface::SetLatencyInfo( |
240 const std::vector<ui::LatencyInfo>& latency_info) { | 220 const std::vector<ui::LatencyInfo>& latency_info) { |
241 for (size_t i = 0; i < latency_info.size(); i++) | 221 for (size_t i = 0; i < latency_info.size(); i++) |
242 latency_info_.push_back(latency_info[i]); | 222 latency_info_.push_back(latency_info[i]); |
243 } | 223 } |
244 | 224 |
245 bool PassThroughImageTransportSurface::SwapBuffers() { | 225 bool PassThroughImageTransportSurface::SwapBuffers() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 282 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
303 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 283 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
304 if (vsync_provider) { | 284 if (vsync_provider) { |
305 vsync_provider->GetVSyncParameters( | 285 vsync_provider->GetVSyncParameters( |
306 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, | 286 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, |
307 helper_->AsWeakPtr())); | 287 helper_->AsWeakPtr())); |
308 } | 288 } |
309 } | 289 } |
310 | 290 |
311 } // namespace content | 291 } // namespace content |
OLD | NEW |