OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/compositor/gpu_process_transport_factory.h" | 5 #include "content/browser/compositor/gpu_process_transport_factory.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "cc/output/compositor_frame.h" | 15 #include "cc/output/compositor_frame.h" |
16 #include "cc/output/output_surface.h" | 16 #include "cc/output/output_surface.h" |
| 17 #include "cc/surfaces/surface_manager.h" |
17 #include "content/browser/compositor/browser_compositor_output_surface.h" | 18 #include "content/browser/compositor/browser_compositor_output_surface.h" |
18 #include "content/browser/compositor/browser_compositor_output_surface_proxy.h" | 19 #include "content/browser/compositor/browser_compositor_output_surface_proxy.h" |
19 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" | 20 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
| 21 #include "content/browser/compositor/onscreen_display_client.h" |
20 #include "content/browser/compositor/reflector_impl.h" | 22 #include "content/browser/compositor/reflector_impl.h" |
21 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" | 23 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" |
| 24 #include "content/browser/compositor/surface_display_output_surface.h" |
22 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 25 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
23 #include "content/browser/gpu/gpu_data_manager_impl.h" | 26 #include "content/browser/gpu/gpu_data_manager_impl.h" |
24 #include "content/browser/gpu/gpu_surface_tracker.h" | 27 #include "content/browser/gpu/gpu_surface_tracker.h" |
25 #include "content/browser/renderer_host/render_widget_host_impl.h" | 28 #include "content/browser/renderer_host/render_widget_host_impl.h" |
26 #include "content/common/gpu/client/context_provider_command_buffer.h" | 29 #include "content/common/gpu/client/context_provider_command_buffer.h" |
27 #include "content/common/gpu/client/gl_helper.h" | 30 #include "content/common/gpu/client/gl_helper.h" |
28 #include "content/common/gpu/client/gpu_channel_host.h" | 31 #include "content/common/gpu/client/gpu_channel_host.h" |
29 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 32 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
30 #include "content/common/gpu/gpu_process_launch_causes.h" | 33 #include "content/common/gpu/gpu_process_launch_causes.h" |
31 #include "content/common/host_shared_bitmap_manager.h" | 34 #include "content/common/host_shared_bitmap_manager.h" |
| 35 #include "content/public/common/content_switches.h" |
32 #include "gpu/GLES2/gl2extchromium.h" | 36 #include "gpu/GLES2/gl2extchromium.h" |
33 #include "gpu/command_buffer/client/gles2_interface.h" | 37 #include "gpu/command_buffer/client/gles2_interface.h" |
34 #include "gpu/command_buffer/common/mailbox.h" | 38 #include "gpu/command_buffer/common/mailbox.h" |
35 #include "third_party/khronos/GLES2/gl2.h" | 39 #include "third_party/khronos/GLES2/gl2.h" |
36 #include "ui/compositor/compositor.h" | 40 #include "ui/compositor/compositor.h" |
37 #include "ui/compositor/compositor_constants.h" | 41 #include "ui/compositor/compositor_constants.h" |
38 #include "ui/compositor/compositor_switches.h" | 42 #include "ui/compositor/compositor_switches.h" |
39 #include "ui/gfx/native_widget_types.h" | 43 #include "ui/gfx/native_widget_types.h" |
40 #include "ui/gfx/size.h" | 44 #include "ui/gfx/size.h" |
41 | 45 |
(...skipping 10 matching lines...) Expand all Loading... |
52 #endif | 56 #endif |
53 | 57 |
54 using cc::ContextProvider; | 58 using cc::ContextProvider; |
55 using gpu::gles2::GLES2Interface; | 59 using gpu::gles2::GLES2Interface; |
56 | 60 |
57 namespace content { | 61 namespace content { |
58 | 62 |
59 struct GpuProcessTransportFactory::PerCompositorData { | 63 struct GpuProcessTransportFactory::PerCompositorData { |
60 int surface_id; | 64 int surface_id; |
61 scoped_refptr<ReflectorImpl> reflector; | 65 scoped_refptr<ReflectorImpl> reflector; |
| 66 scoped_ptr<OnscreenDisplayClient> display_client; |
62 }; | 67 }; |
63 | 68 |
64 GpuProcessTransportFactory::GpuProcessTransportFactory() | 69 GpuProcessTransportFactory::GpuProcessTransportFactory() |
65 : callback_factory_(this) { | 70 : callback_factory_(this) { |
66 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( | 71 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( |
67 &output_surface_map_); | 72 &output_surface_map_); |
68 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
69 bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch( | 74 bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch( |
70 switches::kUIDisableThreadedCompositing); | 75 switches::kUIDisableThreadedCompositing); |
71 #else | 76 #else |
72 bool use_thread = false; | 77 bool use_thread = false; |
73 #endif | 78 #endif |
74 if (use_thread) { | 79 if (use_thread) { |
75 compositor_thread_.reset(new base::Thread("Browser Compositor")); | 80 compositor_thread_.reset(new base::Thread("Browser Compositor")); |
76 compositor_thread_->Start(); | 81 compositor_thread_->Start(); |
77 } | 82 } |
| 83 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 84 switches::kUseSurfaces)) { |
| 85 surface_manager_ = make_scoped_ptr(new cc::SurfaceManager); |
| 86 } |
78 } | 87 } |
79 | 88 |
80 GpuProcessTransportFactory::~GpuProcessTransportFactory() { | 89 GpuProcessTransportFactory::~GpuProcessTransportFactory() { |
81 DCHECK(per_compositor_data_.empty()); | 90 DCHECK(per_compositor_data_.empty()); |
82 | 91 |
83 // Make sure the lost context callback doesn't try to run during destruction. | 92 // Make sure the lost context callback doesn't try to run during destruction. |
84 callback_factory_.InvalidateWeakPtrs(); | 93 callback_factory_.InvalidateWeakPtrs(); |
85 } | 94 } |
86 | 95 |
87 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 96 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // Software fallback does not happen on Chrome OS. | 143 // Software fallback does not happen on Chrome OS. |
135 create_software_renderer = false; | 144 create_software_renderer = false; |
136 #elif defined(OS_WIN) | 145 #elif defined(OS_WIN) |
137 if (::GetProp(compositor->widget(), kForceSoftwareCompositor)) { | 146 if (::GetProp(compositor->widget(), kForceSoftwareCompositor)) { |
138 if (::RemoveProp(compositor->widget(), kForceSoftwareCompositor)) | 147 if (::RemoveProp(compositor->widget(), kForceSoftwareCompositor)) |
139 create_software_renderer = true; | 148 create_software_renderer = true; |
140 } | 149 } |
141 #endif | 150 #endif |
142 | 151 |
143 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 152 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 153 |
144 if (!create_software_renderer) { | 154 if (!create_software_renderer) { |
145 context_provider = ContextProviderCommandBuffer::Create( | 155 context_provider = ContextProviderCommandBuffer::Create( |
146 GpuProcessTransportFactory::CreateContextCommon(data->surface_id), | 156 GpuProcessTransportFactory::CreateContextCommon(data->surface_id), |
147 "Compositor"); | 157 "Compositor"); |
148 } | 158 } |
149 | 159 |
150 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", !!context_provider); | 160 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", !!context_provider); |
151 | 161 |
| 162 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 163 switches::kUseSurfaces)) { |
| 164 if (!context_provider.get()) |
| 165 LOG(FATAL) << "Surfaces do not support software compositing yet"; |
| 166 // This gets a bit confusing. Here we have a ContextProvider configured to |
| 167 // render directly to this widget. We need to make an OnscreenDisplayClient |
| 168 // associated with this context, then return a SurfaceDisplayOutputSurface |
| 169 // set up to draw to the display's surface. |
| 170 cc::SurfaceManager* manager = surface_manager_.get(); |
| 171 scoped_ptr<OnscreenDisplayClient> display_client( |
| 172 new OnscreenDisplayClient(context_provider, manager)); |
| 173 // TODO(jamesr): Need to set up filtering for the |
| 174 // GpuHostMsg_UpdateVSyncParameters message. |
| 175 |
| 176 scoped_refptr<cc::ContextProvider> offscreen_context_provider = |
| 177 ContextProviderCommandBuffer::Create( |
| 178 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(), |
| 179 "Offscreen-MainThread"); |
| 180 scoped_ptr<cc::SoftwareOutputDevice> software_device; |
| 181 scoped_ptr<SurfaceDisplayOutputSurface> output_surface( |
| 182 new SurfaceDisplayOutputSurface(display_client->display(), |
| 183 manager, |
| 184 offscreen_context_provider, |
| 185 software_device.Pass())); |
| 186 data->display_client = display_client.Pass(); |
| 187 return output_surface.PassAs<cc::OutputSurface>(); |
| 188 } |
| 189 |
152 if (!context_provider.get()) { | 190 if (!context_provider.get()) { |
153 if (compositor_thread_.get()) { | 191 if (compositor_thread_.get()) { |
154 LOG(FATAL) << "Failed to create UI context, but can't use software" | 192 LOG(FATAL) << "Failed to create UI context, but can't use software" |
155 " compositing with browser threaded compositing. Aborting."; | 193 " compositing with browser threaded compositing. Aborting."; |
156 } | 194 } |
157 | 195 |
158 scoped_ptr<SoftwareBrowserCompositorOutputSurface> surface( | 196 scoped_ptr<SoftwareBrowserCompositorOutputSurface> surface( |
159 new SoftwareBrowserCompositorOutputSurface( | 197 new SoftwareBrowserCompositorOutputSurface( |
160 output_surface_proxy_, | 198 output_surface_proxy_, |
161 CreateSoftwareOutputDevice(compositor), | 199 CreateSoftwareOutputDevice(compositor), |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 416 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
379 observer_list_, | 417 observer_list_, |
380 OnLostResources()); | 418 OnLostResources()); |
381 | 419 |
382 // Kill things that use the shared context before killing the shared context. | 420 // Kill things that use the shared context before killing the shared context. |
383 lost_gl_helper.reset(); | 421 lost_gl_helper.reset(); |
384 lost_shared_main_thread_contexts = NULL; | 422 lost_shared_main_thread_contexts = NULL; |
385 } | 423 } |
386 | 424 |
387 } // namespace content | 425 } // namespace content |
OLD | NEW |