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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 using cc::ContextProvider; | 50 using cc::ContextProvider; |
51 using gpu::gles2::GLES2Interface; | 51 using gpu::gles2::GLES2Interface; |
52 | 52 |
53 namespace content { | 53 namespace content { |
54 | 54 |
55 struct GpuProcessTransportFactory::PerCompositorData { | 55 struct GpuProcessTransportFactory::PerCompositorData { |
56 int surface_id; | 56 int surface_id; |
57 scoped_refptr<ReflectorImpl> reflector; | 57 scoped_refptr<ReflectorImpl> reflector; |
58 }; | 58 }; |
59 | 59 |
60 class OwnedTexture : public ui::Texture, ImageTransportFactoryObserver { | |
61 public: | |
62 OwnedTexture(const scoped_refptr<ContextProvider>& provider, | |
63 const gfx::Size& size, | |
64 float device_scale_factor, | |
65 GLuint texture_id) | |
66 : ui::Texture(true, size, device_scale_factor), | |
67 provider_(provider), | |
68 texture_id_(texture_id) { | |
69 ImageTransportFactory::GetInstance()->AddObserver(this); | |
70 } | |
71 | |
72 // ui::Texture overrides: | |
73 virtual unsigned int PrepareTexture() OVERRIDE { | |
74 // It's possible that we may have lost the context owning our | |
75 // texture but not yet fired the OnLostResources callback, so poll to see if | |
76 // it's still valid. | |
77 if (provider_ && provider_->IsContextLost()) | |
78 texture_id_ = 0u; | |
79 return texture_id_; | |
80 } | |
81 | |
82 // ImageTransportFactory overrides: | |
83 virtual void OnLostResources() OVERRIDE { | |
84 DeleteTexture(); | |
85 provider_ = NULL; | |
86 } | |
87 | |
88 protected: | |
89 virtual ~OwnedTexture() { | |
90 ImageTransportFactory::GetInstance()->RemoveObserver(this); | |
91 DeleteTexture(); | |
92 } | |
93 | |
94 protected: | |
95 void DeleteTexture() { | |
96 if (texture_id_) { | |
97 provider_->ContextGL()->DeleteTextures(1, &texture_id_); | |
98 texture_id_ = 0; | |
99 } | |
100 } | |
101 | |
102 scoped_refptr<cc::ContextProvider> provider_; | |
103 GLuint texture_id_; | |
104 | |
105 private: | |
106 DISALLOW_COPY_AND_ASSIGN(OwnedTexture); | |
107 }; | |
108 | |
109 GpuProcessTransportFactory::GpuProcessTransportFactory() | 60 GpuProcessTransportFactory::GpuProcessTransportFactory() |
110 : callback_factory_(this), offscreen_content_bound_to_other_thread_(false) { | 61 : callback_factory_(this), offscreen_content_bound_to_other_thread_(false) { |
111 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( | 62 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( |
112 &output_surface_map_); | 63 &output_surface_map_); |
113 } | 64 } |
114 | 65 |
115 GpuProcessTransportFactory::~GpuProcessTransportFactory() { | 66 GpuProcessTransportFactory::~GpuProcessTransportFactory() { |
116 DCHECK(per_compositor_data_.empty()); | 67 DCHECK(per_compositor_data_.empty()); |
117 | 68 |
118 // Make sure the lost context callback doesn't try to run during destruction. | 69 // Make sure the lost context callback doesn't try to run during destruction. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 177 |
227 return surface.PassAs<cc::OutputSurface>(); | 178 return surface.PassAs<cc::OutputSurface>(); |
228 } | 179 } |
229 | 180 |
230 scoped_refptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 181 scoped_refptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
231 ui::Compositor* source, | 182 ui::Compositor* source, |
232 ui::Layer* target) { | 183 ui::Layer* target) { |
233 PerCompositorData* data = per_compositor_data_[source]; | 184 PerCompositorData* data = per_compositor_data_[source]; |
234 DCHECK(data); | 185 DCHECK(data); |
235 | 186 |
236 if (data->reflector.get()) | |
237 RemoveObserver(data->reflector.get()); | |
238 | |
239 data->reflector = new ReflectorImpl( | 187 data->reflector = new ReflectorImpl( |
240 source, target, &output_surface_map_, data->surface_id); | 188 source, target, &output_surface_map_, data->surface_id); |
241 AddObserver(data->reflector.get()); | |
242 return data->reflector; | 189 return data->reflector; |
243 } | 190 } |
244 | 191 |
245 void GpuProcessTransportFactory::RemoveReflector( | 192 void GpuProcessTransportFactory::RemoveReflector( |
246 scoped_refptr<ui::Reflector> reflector) { | 193 scoped_refptr<ui::Reflector> reflector) { |
247 ReflectorImpl* reflector_impl = | 194 ReflectorImpl* reflector_impl = |
248 static_cast<ReflectorImpl*>(reflector.get()); | 195 static_cast<ReflectorImpl*>(reflector.get()); |
249 PerCompositorData* data = | 196 PerCompositorData* data = |
250 per_compositor_data_[reflector_impl->mirrored_compositor()]; | 197 per_compositor_data_[reflector_impl->mirrored_compositor()]; |
251 DCHECK(data); | 198 DCHECK(data); |
252 RemoveObserver(reflector_impl); | |
253 data->reflector->Shutdown(); | 199 data->reflector->Shutdown(); |
254 data->reflector = NULL; | 200 data->reflector = NULL; |
255 } | 201 } |
256 | 202 |
257 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { | 203 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { |
258 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 204 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
259 if (it == per_compositor_data_.end()) | 205 if (it == per_compositor_data_.end()) |
260 return; | 206 return; |
261 PerCompositorData* data = it->second; | 207 PerCompositorData* data = it->second; |
262 DCHECK(data); | 208 DCHECK(data); |
(...skipping 20 matching lines...) Expand all Loading... |
283 } | 229 } |
284 | 230 |
285 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { | 231 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { |
286 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 232 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
287 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); | 233 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); |
288 handle.parent_client_id = | 234 handle.parent_client_id = |
289 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); | 235 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); |
290 return handle; | 236 return handle; |
291 } | 237 } |
292 | 238 |
293 scoped_refptr<ui::Texture> GpuProcessTransportFactory::CreateOwnedTexture( | |
294 const gfx::Size& size, | |
295 float device_scale_factor, | |
296 unsigned int texture_id) { | |
297 scoped_refptr<cc::ContextProvider> provider = | |
298 SharedMainThreadContextProvider(); | |
299 if (!provider.get()) | |
300 return NULL; | |
301 scoped_refptr<OwnedTexture> image(new OwnedTexture( | |
302 provider, size, device_scale_factor, texture_id)); | |
303 return image; | |
304 } | |
305 | |
306 GLHelper* GpuProcessTransportFactory::GetGLHelper() { | 239 GLHelper* GpuProcessTransportFactory::GetGLHelper() { |
307 if (!gl_helper_ && !per_compositor_data_.empty()) { | 240 if (!gl_helper_ && !per_compositor_data_.empty()) { |
308 scoped_refptr<cc::ContextProvider> provider = | 241 scoped_refptr<cc::ContextProvider> provider = |
309 SharedMainThreadContextProvider(); | 242 SharedMainThreadContextProvider(); |
310 if (provider.get()) | 243 if (provider.get()) |
311 gl_helper_.reset(new GLHelper(provider->ContextGL(), | 244 gl_helper_.reset(new GLHelper(provider->ContextGL(), |
312 provider->ContextSupport())); | 245 provider->ContextSupport())); |
313 } | 246 } |
314 return gl_helper_.get(); | 247 return gl_helper_.get(); |
315 } | 248 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 observer_list_, | 379 observer_list_, |
447 OnLostResources()); | 380 OnLostResources()); |
448 | 381 |
449 // Kill things that use the shared context before killing the shared context. | 382 // Kill things that use the shared context before killing the shared context. |
450 lost_gl_helper.reset(); | 383 lost_gl_helper.reset(); |
451 lost_offscreen_compositor_contexts = NULL; | 384 lost_offscreen_compositor_contexts = NULL; |
452 lost_shared_main_thread_contexts = NULL; | 385 lost_shared_main_thread_contexts = NULL; |
453 } | 386 } |
454 | 387 |
455 } // namespace content | 388 } // namespace content |
OLD | NEW |