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