Chromium Code Reviews| 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/browser/renderer_host/image_transport_factory.h" | 5 #include "content/browser/renderer_host/image_transport_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 14 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 15 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 15 #include "content/browser/gpu/gpu_data_manager_impl.h" | 16 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 16 #include "content/browser/gpu/gpu_surface_tracker.h" | 17 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 17 #include "content/common/gpu/client/gl_helper.h" | 18 #include "content/common/gpu/client/gl_helper.h" |
| 18 #include "content/common/gpu/client/gpu_channel_host.h" | 19 #include "content/common/gpu/client/gpu_channel_host.h" |
| 19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 20 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 20 #include "content/common/gpu/gpu_process_launch_causes.h" | 21 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 21 #include "content/common/webkitplatformsupport_impl.h" | 22 #include "content/common/webkitplatformsupport_impl.h" |
| 22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 23 #include "gpu/ipc/command_buffer_proxy.h" | 24 #include "gpu/ipc/command_buffer_proxy.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h" |
| 25 #include "ui/compositor/compositor.h" | 26 #include "ui/compositor/compositor.h" |
| 26 #include "ui/compositor/compositor_setup.h" | 27 #include "ui/compositor/compositor_setup.h" |
| 27 #include "ui/compositor/test_web_graphics_context_3d.h" | 28 #include "ui/compositor/test_web_graphics_context_3d.h" |
| 28 #include "ui/gfx/native_widget_types.h" | 29 #include "ui/gfx/native_widget_types.h" |
| 29 #include "ui/gfx/size.h" | 30 #include "ui/gfx/size.h" |
| 31 #include "third_party/khronos/GLES2/gl2.h" | |
| 32 #include "third_party/khronos/GLES2/gl2ext.h" | |
| 30 | 33 |
| 31 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 32 #include "ui/surface/accelerated_surface_win.h" | 35 #include "ui/surface/accelerated_surface_win.h" |
| 33 #endif | 36 #endif |
| 34 | 37 |
| 35 using content::BrowserGpuChannelHostFactory; | 38 using content::BrowserGpuChannelHostFactory; |
| 36 using content::GLHelper; | 39 using content::GLHelper; |
| 37 using content::GpuChannelHostFactory; | 40 using content::GpuChannelHostFactory; |
| 38 using content::GpuSurfaceTracker; | 41 using content::GpuSurfaceTracker; |
| 39 using content::WebGraphicsContext3DCommandBufferImpl; | 42 using content::WebGraphicsContext3DCommandBufferImpl; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 59 return gfx::GLSurfaceHandle(); | 62 return gfx::GLSurfaceHandle(); |
| 60 } | 63 } |
| 61 | 64 |
| 62 virtual void DestroySharedSurfaceHandle( | 65 virtual void DestroySharedSurfaceHandle( |
| 63 gfx::GLSurfaceHandle surface) OVERRIDE { | 66 gfx::GLSurfaceHandle surface) OVERRIDE { |
| 64 } | 67 } |
| 65 | 68 |
| 66 virtual scoped_refptr<ui::Texture> CreateTransportClient( | 69 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
| 67 const gfx::Size& size, | 70 const gfx::Size& size, |
| 68 float device_scale_factor, | 71 float device_scale_factor, |
| 69 uint64 transport_handle) OVERRIDE { | 72 const std::vector<signed char>& mailbox_name) OVERRIDE { |
| 70 return NULL; | 73 return NULL; |
| 71 } | 74 } |
| 72 | 75 |
| 73 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( | 76 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( |
| 74 const gfx::Size& size, | 77 const gfx::Size& size, |
| 75 float device_scale_factor, | 78 float device_scale_factor, |
| 76 unsigned int texture_id) OVERRIDE { | 79 unsigned int texture_id) OVERRIDE { |
| 77 return NULL; | 80 return NULL; |
| 78 } | 81 } |
| 79 | 82 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 91 } | 94 } |
| 92 | 95 |
| 93 virtual void RemoveObserver( | 96 virtual void RemoveObserver( |
| 94 ImageTransportFactoryObserver* observer) OVERRIDE { | 97 ImageTransportFactoryObserver* observer) OVERRIDE { |
| 95 } | 98 } |
| 96 | 99 |
| 97 private: | 100 private: |
| 98 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); | 101 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); |
| 99 }; | 102 }; |
| 100 | 103 |
| 101 class ImageTransportClientTexture : public ui::Texture { | |
| 102 public: | |
| 103 ImageTransportClientTexture( | |
| 104 WebKit::WebGraphicsContext3D* host_context, | |
| 105 const gfx::Size& size, | |
| 106 float device_scale_factor, | |
| 107 uint64 surface_id) | |
| 108 : ui::Texture(true, size, device_scale_factor), | |
| 109 host_context_(host_context), | |
| 110 texture_id_(surface_id) { | |
| 111 } | |
| 112 | |
| 113 // ui::Texture overrides: | |
| 114 virtual unsigned int PrepareTexture() OVERRIDE { | |
| 115 return texture_id_; | |
| 116 } | |
| 117 | |
| 118 virtual WebKit::WebGraphicsContext3D* HostContext3D() OVERRIDE { | |
| 119 return host_context_; | |
| 120 } | |
| 121 | |
| 122 protected: | |
| 123 virtual ~ImageTransportClientTexture() {} | |
| 124 | |
| 125 private: | |
| 126 // A raw pointer. This |ImageTransportClientTexture| will be destroyed | |
| 127 // before the |host_context_| via | |
| 128 // |ImageTransportFactoryObserver::OnLostContext()| handlers. | |
| 129 WebKit::WebGraphicsContext3D* host_context_; | |
| 130 unsigned texture_id_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); | |
| 133 }; | |
| 134 | |
| 135 class OwnedTexture : public ui::Texture, ImageTransportFactoryObserver { | 104 class OwnedTexture : public ui::Texture, ImageTransportFactoryObserver { |
| 136 public: | 105 public: |
| 137 OwnedTexture(WebKit::WebGraphicsContext3D* host_context, | 106 OwnedTexture(WebKit::WebGraphicsContext3D* host_context, |
| 138 const gfx::Size& size, | 107 const gfx::Size& size, |
| 139 float device_scale_factor, | 108 float device_scale_factor, |
| 140 unsigned int texture_id) | 109 unsigned int texture_id) |
| 141 : ui::Texture(true, size, device_scale_factor), | 110 : ui::Texture(true, size, device_scale_factor), |
| 142 host_context_(host_context), | 111 host_context_(host_context), |
| 143 texture_id_(texture_id) { | 112 texture_id_(texture_id) { |
| 144 ImageTransportFactory::GetInstance()->AddObserver(this); | 113 ImageTransportFactory::GetInstance()->AddObserver(this); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 157 virtual void OnLostResources() OVERRIDE { | 126 virtual void OnLostResources() OVERRIDE { |
| 158 DeleteTexture(); | 127 DeleteTexture(); |
| 159 } | 128 } |
| 160 | 129 |
| 161 protected: | 130 protected: |
| 162 virtual ~OwnedTexture() { | 131 virtual ~OwnedTexture() { |
| 163 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 132 ImageTransportFactory::GetInstance()->RemoveObserver(this); |
| 164 DeleteTexture(); | 133 DeleteTexture(); |
| 165 } | 134 } |
| 166 | 135 |
| 167 private: | 136 protected: |
| 168 void DeleteTexture() { | 137 void DeleteTexture() { |
| 169 if (texture_id_) { | 138 if (texture_id_) { |
| 170 host_context_->deleteTexture(texture_id_); | 139 host_context_->deleteTexture(texture_id_); |
| 171 texture_id_ = 0; | 140 texture_id_ = 0; |
| 172 } | 141 } |
| 173 } | 142 } |
| 174 | 143 |
| 175 // A raw pointer. This |ImageTransportClientTexture| will be destroyed | 144 // A raw pointer. This |ImageTransportClientTexture| will be destroyed |
| 176 // before the |host_context_| via | 145 // before the |host_context_| via |
| 177 // |ImageTransportFactoryObserver::OnLostContext()| handlers. | 146 // |ImageTransportFactoryObserver::OnLostContext()| handlers. |
| 178 WebKit::WebGraphicsContext3D* host_context_; | 147 WebKit::WebGraphicsContext3D* host_context_; |
| 179 unsigned texture_id_; | 148 unsigned texture_id_; |
| 180 | 149 |
| 181 DISALLOW_COPY_AND_ASSIGN(OwnedTexture); | 150 DISALLOW_COPY_AND_ASSIGN(OwnedTexture); |
| 182 }; | 151 }; |
| 183 | 152 |
| 153 class ImageTransportClientTexture : public OwnedTexture { | |
| 154 public: | |
| 155 ImageTransportClientTexture( | |
| 156 WebKit::WebGraphicsContext3D* host_context, | |
| 157 const gfx::Size& size, | |
| 158 float device_scale_factor, | |
| 159 const std::vector<signed char>& mailbox_name) | |
| 160 : OwnedTexture(host_context, | |
| 161 size, | |
| 162 device_scale_factor, | |
| 163 host_context->createTexture()), | |
| 164 mailbox_name_(mailbox_name) { | |
| 165 DCHECK(mailbox_name.size() == GL_MAILBOX_SIZE_CHROMIUM); | |
| 166 } | |
| 167 | |
| 168 virtual void Consume(const gfx::Size& new_size) OVERRIDE { | |
| 169 if (host_context_) { | |
| 170 DCHECK(texture_id_); | |
| 171 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_); | |
| 172 host_context_->consumeTextureCHROMIUM( | |
| 173 GL_TEXTURE_2D, mailbox_name_.data()); | |
| 174 size_ = new_size; | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 virtual void Produce() OVERRIDE { | |
| 179 if (host_context_) { | |
| 180 DCHECK(texture_id_); | |
| 181 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_); | |
| 182 host_context_->produceTextureCHROMIUM( | |
| 183 GL_TEXTURE_2D, mailbox_name_.data()); | |
|
jonathan.backer
2012/11/12 16:52:14
cppreference.com says that std::vector::data is a
| |
| 184 } | |
| 185 } | |
| 186 | |
| 187 protected: | |
| 188 virtual ~ImageTransportClientTexture() {} | |
| 189 | |
| 190 private: | |
| 191 std::vector<signed char> mailbox_name_; | |
| 192 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); | |
| 193 }; | |
| 194 | |
| 184 class GpuProcessTransportFactory; | 195 class GpuProcessTransportFactory; |
| 185 | 196 |
| 186 class CompositorSwapClient | 197 class CompositorSwapClient |
| 187 : public base::SupportsWeakPtr<CompositorSwapClient>, | 198 : public base::SupportsWeakPtr<CompositorSwapClient>, |
| 188 public WebGraphicsContext3DSwapBuffersClient { | 199 public WebGraphicsContext3DSwapBuffersClient { |
| 189 public: | 200 public: |
| 190 CompositorSwapClient(ui::Compositor* compositor, | 201 CompositorSwapClient(ui::Compositor* compositor, |
| 191 GpuProcessTransportFactory* factory) | 202 GpuProcessTransportFactory* factory) |
| 192 : compositor_(compositor), | 203 : compositor_(compositor), |
| 193 factory_(factory) { | 204 factory_(factory) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 277 |
| 267 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { | 278 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { |
| 268 return this; | 279 return this; |
| 269 } | 280 } |
| 270 | 281 |
| 271 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { | 282 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { |
| 272 CreateSharedContextLazy(); | 283 CreateSharedContextLazy(); |
| 273 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 284 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
| 274 gfx::kNullPluginWindow, true); | 285 gfx::kNullPluginWindow, true); |
| 275 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); | 286 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); |
| 276 handle.parent_client_id = shared_context_->GetChannelID(); | |
| 277 handle.parent_context_id = shared_context_->GetContextID(); | |
| 278 handle.parent_texture_id[0] = shared_context_->createTexture(); | |
| 279 handle.parent_texture_id[1] = shared_context_->createTexture(); | |
| 280 handle.sync_point = shared_context_->insertSyncPoint(); | |
| 281 | 287 |
| 282 return handle; | 288 return handle; |
| 283 } | 289 } |
| 284 | 290 |
| 285 virtual void DestroySharedSurfaceHandle( | 291 virtual void DestroySharedSurfaceHandle( |
| 286 gfx::GLSurfaceHandle surface) OVERRIDE { | 292 gfx::GLSurfaceHandle surface) OVERRIDE { |
| 287 if (!shared_context_.get()) | |
| 288 return; | |
| 289 uint32 channel_id = shared_context_->GetChannelID(); | |
| 290 uint32 context_id = shared_context_->GetContextID(); | |
| 291 if (surface.parent_gpu_process_id != shared_context_->GetGPUProcessID() || | |
| 292 surface.parent_client_id != channel_id || | |
| 293 surface.parent_context_id != context_id) | |
| 294 return; | |
| 295 | |
| 296 shared_context_->deleteTexture(surface.parent_texture_id[0]); | |
| 297 shared_context_->deleteTexture(surface.parent_texture_id[1]); | |
| 298 shared_context_->flush(); | |
| 299 } | 293 } |
| 300 | 294 |
| 301 virtual scoped_refptr<ui::Texture> CreateTransportClient( | 295 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
| 302 const gfx::Size& size, | 296 const gfx::Size& size, |
| 303 float device_scale_factor, | 297 float device_scale_factor, |
| 304 uint64 transport_handle) { | 298 const std::vector<signed char>& mailbox_name) { |
| 305 if (!shared_context_.get()) | 299 if (!shared_context_.get()) |
| 306 return NULL; | 300 return NULL; |
| 307 scoped_refptr<ImageTransportClientTexture> image( | 301 scoped_refptr<ImageTransportClientTexture> image( |
| 308 new ImageTransportClientTexture(shared_context_.get(), | 302 new ImageTransportClientTexture(shared_context_.get(), |
| 309 size, device_scale_factor, | 303 size, device_scale_factor, |
| 310 transport_handle)); | 304 mailbox_name)); |
| 311 return image; | 305 return image; |
| 312 } | 306 } |
| 313 | 307 |
| 314 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( | 308 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( |
| 315 const gfx::Size& size, | 309 const gfx::Size& size, |
| 316 float device_scale_factor, | 310 float device_scale_factor, |
| 317 unsigned int texture_id) OVERRIDE { | 311 unsigned int texture_id) OVERRIDE { |
| 318 if (!shared_context_.get()) | 312 if (!shared_context_.get()) |
| 319 return NULL; | 313 return NULL; |
| 320 scoped_refptr<OwnedTexture> image( | 314 scoped_refptr<OwnedTexture> image( |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 void ImageTransportFactory::Terminate() { | 500 void ImageTransportFactory::Terminate() { |
| 507 ui::ContextFactory::SetInstance(NULL); | 501 ui::ContextFactory::SetInstance(NULL); |
| 508 delete g_factory; | 502 delete g_factory; |
| 509 g_factory = NULL; | 503 g_factory = NULL; |
| 510 } | 504 } |
| 511 | 505 |
| 512 // static | 506 // static |
| 513 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 507 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
| 514 return g_factory; | 508 return g_factory; |
| 515 } | 509 } |
| OLD | NEW |