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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 scoped_refptr<cc::ContextProvider> provider_; | 102 scoped_refptr<cc::ContextProvider> provider_; |
103 GLuint texture_id_; | 103 GLuint texture_id_; |
104 | 104 |
105 private: | 105 private: |
106 DISALLOW_COPY_AND_ASSIGN(OwnedTexture); | 106 DISALLOW_COPY_AND_ASSIGN(OwnedTexture); |
107 }; | 107 }; |
108 | 108 |
109 class ImageTransportClientTexture : public OwnedTexture { | |
110 public: | |
111 ImageTransportClientTexture(const scoped_refptr<ContextProvider>& provider, | |
112 float device_scale_factor, | |
113 GLuint texture_id) | |
114 : OwnedTexture(provider, | |
115 gfx::Size(0, 0), | |
116 device_scale_factor, | |
117 texture_id) {} | |
118 | |
119 virtual void Consume(const gpu::Mailbox& mailbox, | |
120 const gfx::Size& new_size) OVERRIDE { | |
121 mailbox_ = mailbox; | |
122 if (mailbox.IsZero()) | |
123 return; | |
124 | |
125 DCHECK(provider_ && texture_id_); | |
126 GLES2Interface* gl = provider_->ContextGL(); | |
127 gl->BindTexture(GL_TEXTURE_2D, texture_id_); | |
128 gl->ConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
129 size_ = new_size; | |
130 gl->ShallowFlushCHROMIUM(); | |
131 } | |
132 | |
133 virtual gpu::Mailbox Produce() OVERRIDE { return mailbox_; } | |
134 | |
135 protected: | |
136 virtual ~ImageTransportClientTexture() {} | |
137 | |
138 private: | |
139 gpu::Mailbox mailbox_; | |
140 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); | |
141 }; | |
142 | |
143 GpuProcessTransportFactory::GpuProcessTransportFactory() | 109 GpuProcessTransportFactory::GpuProcessTransportFactory() |
144 : callback_factory_(this), offscreen_content_bound_to_other_thread_(false) { | 110 : callback_factory_(this), offscreen_content_bound_to_other_thread_(false) { |
145 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( | 111 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( |
146 &output_surface_map_); | 112 &output_surface_map_); |
147 } | 113 } |
148 | 114 |
149 GpuProcessTransportFactory::~GpuProcessTransportFactory() { | 115 GpuProcessTransportFactory::~GpuProcessTransportFactory() { |
150 DCHECK(per_compositor_data_.empty()); | 116 DCHECK(per_compositor_data_.empty()); |
151 | 117 |
152 // Make sure the lost context callback doesn't try to run during destruction. | 118 // Make sure the lost context callback doesn't try to run during destruction. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 283 } |
318 | 284 |
319 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { | 285 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { |
320 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 286 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
321 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); | 287 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); |
322 handle.parent_client_id = | 288 handle.parent_client_id = |
323 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); | 289 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); |
324 return handle; | 290 return handle; |
325 } | 291 } |
326 | 292 |
327 scoped_refptr<ui::Texture> GpuProcessTransportFactory::CreateTransportClient( | |
328 float device_scale_factor) { | |
329 scoped_refptr<cc::ContextProvider> provider = | |
330 SharedMainThreadContextProvider(); | |
331 if (!provider.get()) | |
332 return NULL; | |
333 GLuint texture_id = 0; | |
334 provider->ContextGL()->GenTextures(1, &texture_id); | |
335 scoped_refptr<ImageTransportClientTexture> image( | |
336 new ImageTransportClientTexture( | |
337 provider, device_scale_factor, texture_id)); | |
338 return image; | |
339 } | |
340 | |
341 scoped_refptr<ui::Texture> GpuProcessTransportFactory::CreateOwnedTexture( | 293 scoped_refptr<ui::Texture> GpuProcessTransportFactory::CreateOwnedTexture( |
342 const gfx::Size& size, | 294 const gfx::Size& size, |
343 float device_scale_factor, | 295 float device_scale_factor, |
344 unsigned int texture_id) { | 296 unsigned int texture_id) { |
345 scoped_refptr<cc::ContextProvider> provider = | 297 scoped_refptr<cc::ContextProvider> provider = |
346 SharedMainThreadContextProvider(); | 298 SharedMainThreadContextProvider(); |
347 if (!provider.get()) | 299 if (!provider.get()) |
348 return NULL; | 300 return NULL; |
349 scoped_refptr<OwnedTexture> image(new OwnedTexture( | 301 scoped_refptr<OwnedTexture> image(new OwnedTexture( |
350 provider, size, device_scale_factor, texture_id)); | 302 provider, size, device_scale_factor, texture_id)); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 observer_list_, | 446 observer_list_, |
495 OnLostResources()); | 447 OnLostResources()); |
496 | 448 |
497 // Kill things that use the shared context before killing the shared context. | 449 // Kill things that use the shared context before killing the shared context. |
498 lost_gl_helper.reset(); | 450 lost_gl_helper.reset(); |
499 lost_offscreen_compositor_contexts = NULL; | 451 lost_offscreen_compositor_contexts = NULL; |
500 lost_shared_main_thread_contexts = NULL; | 452 lost_shared_main_thread_contexts = NULL; |
501 } | 453 } |
502 | 454 |
503 } // namespace content | 455 } // namespace content |
OLD | NEW |