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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "content/common/gpu/gpu_channel.h" | 15 #include "content/common/gpu/gpu_channel.h" |
16 #include "content/common/gpu/gpu_channel_manager.h" | 16 #include "content/common/gpu/gpu_channel_manager.h" |
17 #include "content/common/gpu/gpu_channel_manager_delegate.h" | |
18 #include "content/common/gpu/gpu_command_buffer_stub.h" | 17 #include "content/common/gpu/gpu_command_buffer_stub.h" |
19 #include "content/common/gpu/gpu_messages.h" | 18 #include "content/common/gpu/gpu_messages.h" |
20 #include "gpu/command_buffer/service/sync_point_manager.h" | 19 #include "gpu/command_buffer/service/sync_point_manager.h" |
21 #include "ui/gfx/vsync_provider.h" | 20 #include "ui/gfx/vsync_provider.h" |
22 #include "ui/gl/gl_context.h" | 21 #include "ui/gl/gl_context.h" |
23 #include "ui/gl/gl_implementation.h" | 22 #include "ui/gl/gl_implementation.h" |
24 #include "ui/gl/gl_switches.h" | 23 #include "ui/gl/gl_switches.h" |
25 | 24 |
26 #if defined(OS_MACOSX) | |
27 #include "content/common/gpu/accelerated_surface_buffers_swapped_params_mac.h" | |
28 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" | |
29 #endif | |
30 | |
31 namespace content { | 25 namespace content { |
32 | 26 |
33 ImageTransportSurface::ImageTransportSurface() {} | 27 ImageTransportSurface::ImageTransportSurface() {} |
34 | 28 |
35 ImageTransportSurface::~ImageTransportSurface() {} | 29 ImageTransportSurface::~ImageTransportSurface() {} |
36 | 30 |
37 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 31 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
38 GpuChannelManager* manager, | 32 GpuChannelManager* manager, |
39 GpuCommandBufferStub* stub, | 33 GpuCommandBufferStub* stub, |
40 const gfx::GLSurfaceHandle& handle, | 34 const gfx::GLSurfaceHandle& handle, |
(...skipping 11 matching lines...) Expand all Loading... |
52 } | 46 } |
53 | 47 |
54 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, | 48 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, |
55 GpuChannelManager* manager, | 49 GpuChannelManager* manager, |
56 GpuCommandBufferStub* stub, | 50 GpuCommandBufferStub* stub, |
57 gfx::PluginWindowHandle handle) | 51 gfx::PluginWindowHandle handle) |
58 : surface_(surface), | 52 : surface_(surface), |
59 manager_(manager), | 53 manager_(manager), |
60 stub_(stub->AsWeakPtr()), | 54 stub_(stub->AsWeakPtr()), |
61 handle_(handle) { | 55 handle_(handle) { |
62 #if defined(OS_MACOSX) | 56 route_id_ = manager_->GenerateRouteID(); |
63 manager_->AddImageTransportSurface(handle_, this); | 57 manager_->AddRoute(route_id_, this); |
64 #endif | |
65 } | 58 } |
66 | 59 |
67 ImageTransportHelper::~ImageTransportHelper() { | 60 ImageTransportHelper::~ImageTransportHelper() { |
68 if (stub_.get()) { | 61 if (stub_.get()) { |
69 stub_->SetLatencyInfoCallback( | 62 stub_->SetLatencyInfoCallback( |
70 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); | 63 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); |
71 } | 64 } |
72 #if defined(OS_MACOSX) | 65 manager_->RemoveRoute(route_id_); |
73 manager_->RemoveImageTransportSurface(handle_); | |
74 #endif | |
75 } | 66 } |
76 | 67 |
77 bool ImageTransportHelper::Initialize(gfx::GLSurface::Format format) { | 68 bool ImageTransportHelper::Initialize(gfx::GLSurface::Format format) { |
78 gpu::gles2::GLES2Decoder* decoder = Decoder(); | 69 gpu::gles2::GLES2Decoder* decoder = Decoder(); |
79 | 70 |
80 if (!decoder) | 71 if (!decoder) |
81 return false; | 72 return false; |
82 | 73 |
83 stub_->SetLatencyInfoCallback( | 74 stub_->SetLatencyInfoCallback( |
84 base::Bind(&ImageTransportHelper::SetLatencyInfo, | 75 base::Bind(&ImageTransportHelper::SetLatencyInfo, |
85 base::Unretained(this))); | 76 base::Unretained(this))); |
86 | 77 |
87 return true; | 78 return true; |
88 } | 79 } |
89 | 80 |
| 81 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
90 #if defined(OS_MACOSX) | 82 #if defined(OS_MACOSX) |
91 void ImageTransportHelper::BufferPresented( | 83 bool handled = true; |
92 const BufferPresentedParams& params) { | 84 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
93 surface_->BufferPresented(params); | 85 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, |
| 86 OnBufferPresented) |
| 87 IPC_MESSAGE_UNHANDLED(handled = false) |
| 88 IPC_END_MESSAGE_MAP() |
| 89 return handled; |
| 90 #else |
| 91 NOTREACHED(); |
| 92 return false; |
| 93 #endif |
94 } | 94 } |
95 | 95 |
| 96 #if defined(OS_MACOSX) |
96 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( | 97 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( |
97 AcceleratedSurfaceBuffersSwappedParams params) { | 98 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { |
98 // TRACE_EVENT for gpu tests: | 99 // TRACE_EVENT for gpu tests: |
99 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", | 100 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", |
100 TRACE_EVENT_SCOPE_THREAD, | 101 TRACE_EVENT_SCOPE_THREAD, |
101 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), | 102 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
102 "width", params.size.width()); | 103 "width", params.size.width()); |
103 // On mac, handle_ is a surface id. See | 104 // On mac, handle_ is a surface id. See |
104 // GpuProcessTransportFactory::CreatePerCompositorData | 105 // GpuProcessTransportFactory::CreatePerCompositorData |
105 params.surface_id = handle_; | 106 params.surface_id = handle_; |
106 manager_->delegate()->SendAcceleratedSurfaceBuffersSwapped(params); | 107 params.route_id = route_id_; |
| 108 manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); |
107 } | 109 } |
108 #endif | 110 #endif |
109 | 111 |
110 bool ImageTransportHelper::MakeCurrent() { | 112 bool ImageTransportHelper::MakeCurrent() { |
111 gpu::gles2::GLES2Decoder* decoder = Decoder(); | 113 gpu::gles2::GLES2Decoder* decoder = Decoder(); |
112 if (!decoder) | 114 if (!decoder) |
113 return false; | 115 return false; |
114 return decoder->MakeCurrent(); | 116 return decoder->MakeCurrent(); |
115 } | 117 } |
116 | 118 |
117 void ImageTransportHelper::SetSwapInterval(gfx::GLContext* context) { | 119 void ImageTransportHelper::SetSwapInterval(gfx::GLContext* context) { |
118 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 120 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
119 switches::kDisableGpuVsync)) | 121 switches::kDisableGpuVsync)) |
120 context->ForceSwapIntervalZero(true); | 122 context->ForceSwapIntervalZero(true); |
121 else | 123 else |
122 context->SetSwapInterval(1); | 124 context->SetSwapInterval(1); |
123 } | 125 } |
124 | 126 |
125 gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { | 127 gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { |
126 if (!stub_.get()) | 128 if (!stub_.get()) |
127 return NULL; | 129 return NULL; |
128 return stub_->decoder(); | 130 return stub_->decoder(); |
129 } | 131 } |
130 | 132 |
| 133 #if defined(OS_MACOSX) |
| 134 void ImageTransportHelper::OnBufferPresented( |
| 135 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { |
| 136 surface_->OnBufferPresented(params); |
| 137 } |
| 138 #endif |
| 139 |
131 void ImageTransportHelper::SetLatencyInfo( | 140 void ImageTransportHelper::SetLatencyInfo( |
132 const std::vector<ui::LatencyInfo>& latency_info) { | 141 const std::vector<ui::LatencyInfo>& latency_info) { |
133 surface_->SetLatencyInfo(latency_info); | 142 surface_->SetLatencyInfo(latency_info); |
134 } | 143 } |
135 | 144 |
136 PassThroughImageTransportSurface::PassThroughImageTransportSurface( | 145 PassThroughImageTransportSurface::PassThroughImageTransportSurface( |
137 GpuChannelManager* manager, | 146 GpuChannelManager* manager, |
138 GpuCommandBufferStub* stub, | 147 GpuCommandBufferStub* stub, |
139 gfx::GLSurface* surface) | 148 gfx::GLSurface* surface) |
140 : GLSurfaceAdapter(surface), | 149 : GLSurfaceAdapter(surface), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 233 |
225 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 234 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
226 if (!did_set_swap_interval_) { | 235 if (!did_set_swap_interval_) { |
227 ImageTransportHelper::SetSwapInterval(context); | 236 ImageTransportHelper::SetSwapInterval(context); |
228 did_set_swap_interval_ = true; | 237 did_set_swap_interval_ = true; |
229 } | 238 } |
230 return true; | 239 return true; |
231 } | 240 } |
232 | 241 |
233 #if defined(OS_MACOSX) | 242 #if defined(OS_MACOSX) |
234 void PassThroughImageTransportSurface::BufferPresented( | 243 void PassThroughImageTransportSurface::OnBufferPresented( |
235 const BufferPresentedParams& /* params */) { | 244 const AcceleratedSurfaceMsg_BufferPresented_Params& /* params */) { |
236 NOTREACHED(); | 245 NOTREACHED(); |
237 } | 246 } |
238 #endif | 247 #endif |
239 | 248 |
240 gfx::Size PassThroughImageTransportSurface::GetSize() { | 249 gfx::Size PassThroughImageTransportSurface::GetSize() { |
241 return GLSurfaceAdapter::GetSize(); | 250 return GLSurfaceAdapter::GetSize(); |
242 } | 251 } |
243 | 252 |
244 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} | 253 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} |
245 | 254 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 295 |
287 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( | 296 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( |
288 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info, | 297 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info, |
289 GLSurface::SwapCompletionCallback callback, | 298 GLSurface::SwapCompletionCallback callback, |
290 gfx::SwapResult result) { | 299 gfx::SwapResult result) { |
291 FinishSwapBuffers(std::move(latency_info), result); | 300 FinishSwapBuffers(std::move(latency_info), result); |
292 callback.Run(result); | 301 callback.Run(result); |
293 } | 302 } |
294 | 303 |
295 } // namespace content | 304 } // namespace content |
OLD | NEW |