| 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 "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
| 15 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 16 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 16 #include "content/browser/gpu/gpu_data_manager_impl.h" | 17 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 17 #include "content/browser/gpu/gpu_process_host.h" | 18 #include "content/browser/gpu/gpu_process_host.h" |
| 18 #include "content/browser/gpu/gpu_surface_tracker.h" | 19 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 19 #include "content/common/gpu/client/gl_helper.h" | 20 #include "content/common/gpu/client/gl_helper.h" |
| 20 #include "content/common/gpu/client/gpu_channel_host.h" | 21 #include "content/common/gpu/client/gpu_channel_host.h" |
| 21 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 22 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 22 #include "content/common/gpu/gpu_messages.h" | 23 #include "content/common/gpu/gpu_messages.h" |
| 23 #include "content/common/gpu/gpu_process_launch_causes.h" | 24 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 24 #include "content/common/webkitplatformsupport_impl.h" | 25 #include "content/common/webkitplatformsupport_impl.h" |
| 25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 26 #include "gpu/ipc/command_buffer_proxy.h" | 27 #include "gpu/ipc/command_buffer_proxy.h" |
| 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput
Surface.h" | 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput
Surface.h" |
| 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput
SurfaceClient.h" | 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput
SurfaceClient.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC
ontext3D.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC
ontext3D.h" |
| 31 #include "third_party/khronos/GLES2/gl2.h" |
| 32 #include "third_party/khronos/GLES2/gl2ext.h" |
| 30 #include "ui/compositor/compositor.h" | 33 #include "ui/compositor/compositor.h" |
| 31 #include "ui/compositor/compositor_setup.h" | 34 #include "ui/compositor/compositor_setup.h" |
| 32 #include "ui/compositor/test_web_graphics_context_3d.h" | 35 #include "ui/compositor/test_web_graphics_context_3d.h" |
| 33 #include "ui/gfx/native_widget_types.h" | 36 #include "ui/gfx/native_widget_types.h" |
| 34 #include "ui/gfx/size.h" | 37 #include "ui/gfx/size.h" |
| 35 | 38 |
| 36 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 37 #include "ui/surface/accelerated_surface_win.h" | 40 #include "ui/surface/accelerated_surface_win.h" |
| 38 #endif | 41 #endif |
| 39 | 42 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 return gfx::GLSurfaceHandle(); | 61 return gfx::GLSurfaceHandle(); |
| 59 } | 62 } |
| 60 | 63 |
| 61 virtual void DestroySharedSurfaceHandle( | 64 virtual void DestroySharedSurfaceHandle( |
| 62 gfx::GLSurfaceHandle surface) OVERRIDE { | 65 gfx::GLSurfaceHandle surface) OVERRIDE { |
| 63 } | 66 } |
| 64 | 67 |
| 65 virtual scoped_refptr<ui::Texture> CreateTransportClient( | 68 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
| 66 const gfx::Size& size, | 69 const gfx::Size& size, |
| 67 float device_scale_factor, | 70 float device_scale_factor, |
| 68 uint64 transport_handle) OVERRIDE { | 71 const std::string& mailbox_name) OVERRIDE { |
| 69 return NULL; | 72 return NULL; |
| 70 } | 73 } |
| 71 | 74 |
| 72 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( | 75 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( |
| 73 const gfx::Size& size, | 76 const gfx::Size& size, |
| 74 float device_scale_factor, | 77 float device_scale_factor, |
| 75 unsigned int texture_id) OVERRIDE { | 78 unsigned int texture_id) OVERRIDE { |
| 76 return NULL; | 79 return NULL; |
| 77 } | 80 } |
| 78 | 81 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 } | 93 } |
| 91 | 94 |
| 92 virtual void RemoveObserver( | 95 virtual void RemoveObserver( |
| 93 ImageTransportFactoryObserver* observer) OVERRIDE { | 96 ImageTransportFactoryObserver* observer) OVERRIDE { |
| 94 } | 97 } |
| 95 | 98 |
| 96 private: | 99 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); | 100 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); |
| 98 }; | 101 }; |
| 99 | 102 |
| 100 class ImageTransportClientTexture : public ui::Texture { | |
| 101 public: | |
| 102 ImageTransportClientTexture( | |
| 103 WebKit::WebGraphicsContext3D* host_context, | |
| 104 const gfx::Size& size, | |
| 105 float device_scale_factor, | |
| 106 uint64 surface_id) | |
| 107 : ui::Texture(true, size, device_scale_factor), | |
| 108 host_context_(host_context), | |
| 109 texture_id_(surface_id) { | |
| 110 } | |
| 111 | |
| 112 // ui::Texture overrides: | |
| 113 virtual unsigned int PrepareTexture() OVERRIDE { | |
| 114 return texture_id_; | |
| 115 } | |
| 116 | |
| 117 virtual WebKit::WebGraphicsContext3D* HostContext3D() OVERRIDE { | |
| 118 return host_context_; | |
| 119 } | |
| 120 | |
| 121 protected: | |
| 122 virtual ~ImageTransportClientTexture() {} | |
| 123 | |
| 124 private: | |
| 125 // A raw pointer. This |ImageTransportClientTexture| will be destroyed | |
| 126 // before the |host_context_| via | |
| 127 // |ImageTransportFactoryObserver::OnLostContext()| handlers. | |
| 128 WebKit::WebGraphicsContext3D* host_context_; | |
| 129 unsigned texture_id_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); | |
| 132 }; | |
| 133 | |
| 134 class OwnedTexture : public ui::Texture, ImageTransportFactoryObserver { | 103 class OwnedTexture : public ui::Texture, ImageTransportFactoryObserver { |
| 135 public: | 104 public: |
| 136 OwnedTexture(WebKit::WebGraphicsContext3D* host_context, | 105 OwnedTexture(WebKit::WebGraphicsContext3D* host_context, |
| 137 const gfx::Size& size, | 106 const gfx::Size& size, |
| 138 float device_scale_factor, | 107 float device_scale_factor, |
| 139 unsigned int texture_id) | 108 unsigned int texture_id) |
| 140 : ui::Texture(true, size, device_scale_factor), | 109 : ui::Texture(true, size, device_scale_factor), |
| 141 host_context_(host_context), | 110 host_context_(host_context), |
| 142 texture_id_(texture_id) { | 111 texture_id_(texture_id) { |
| 143 ImageTransportFactory::GetInstance()->AddObserver(this); | 112 ImageTransportFactory::GetInstance()->AddObserver(this); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 virtual void OnLostResources() OVERRIDE { | 125 virtual void OnLostResources() OVERRIDE { |
| 157 DeleteTexture(); | 126 DeleteTexture(); |
| 158 } | 127 } |
| 159 | 128 |
| 160 protected: | 129 protected: |
| 161 virtual ~OwnedTexture() { | 130 virtual ~OwnedTexture() { |
| 162 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 131 ImageTransportFactory::GetInstance()->RemoveObserver(this); |
| 163 DeleteTexture(); | 132 DeleteTexture(); |
| 164 } | 133 } |
| 165 | 134 |
| 166 private: | 135 protected: |
| 167 void DeleteTexture() { | 136 void DeleteTexture() { |
| 168 if (texture_id_) { | 137 if (texture_id_) { |
| 169 host_context_->deleteTexture(texture_id_); | 138 host_context_->deleteTexture(texture_id_); |
| 170 texture_id_ = 0; | 139 texture_id_ = 0; |
| 171 } | 140 } |
| 172 } | 141 } |
| 173 | 142 |
| 174 // A raw pointer. This |ImageTransportClientTexture| will be destroyed | 143 // A raw pointer. This |ImageTransportClientTexture| will be destroyed |
| 175 // before the |host_context_| via | 144 // before the |host_context_| via |
| 176 // |ImageTransportFactoryObserver::OnLostContext()| handlers. | 145 // |ImageTransportFactoryObserver::OnLostContext()| handlers. |
| 177 WebKit::WebGraphicsContext3D* host_context_; | 146 WebKit::WebGraphicsContext3D* host_context_; |
| 178 unsigned texture_id_; | 147 unsigned texture_id_; |
| 179 | 148 |
| 180 DISALLOW_COPY_AND_ASSIGN(OwnedTexture); | 149 DISALLOW_COPY_AND_ASSIGN(OwnedTexture); |
| 181 }; | 150 }; |
| 182 | 151 |
| 152 class ImageTransportClientTexture : public OwnedTexture { |
| 153 public: |
| 154 ImageTransportClientTexture( |
| 155 WebKit::WebGraphicsContext3D* host_context, |
| 156 const gfx::Size& size, |
| 157 float device_scale_factor, |
| 158 const std::string& mailbox_name) |
| 159 : OwnedTexture(host_context, |
| 160 size, |
| 161 device_scale_factor, |
| 162 host_context->createTexture()), |
| 163 mailbox_name_(mailbox_name) { |
| 164 DCHECK(mailbox_name.size() == GL_MAILBOX_SIZE_CHROMIUM); |
| 165 } |
| 166 |
| 167 virtual void Consume(const gfx::Size& new_size) OVERRIDE { |
| 168 DCHECK(host_context_ && texture_id_); |
| 169 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_); |
| 170 host_context_->consumeTextureCHROMIUM( |
| 171 GL_TEXTURE_2D, |
| 172 reinterpret_cast<const signed char*>(mailbox_name_.c_str())); |
| 173 size_ = new_size; |
| 174 host_context_->flush(); |
| 175 } |
| 176 |
| 177 virtual void Produce() OVERRIDE { |
| 178 DCHECK(host_context_ && texture_id_); |
| 179 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_); |
| 180 host_context_->produceTextureCHROMIUM( |
| 181 GL_TEXTURE_2D, |
| 182 reinterpret_cast<const signed char*>(mailbox_name_.c_str())); |
| 183 } |
| 184 |
| 185 protected: |
| 186 virtual ~ImageTransportClientTexture() {} |
| 187 |
| 188 private: |
| 189 std::string mailbox_name_; |
| 190 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); |
| 191 }; |
| 192 |
| 183 class GpuProcessTransportFactory; | 193 class GpuProcessTransportFactory; |
| 184 | 194 |
| 185 class CompositorSwapClient | 195 class CompositorSwapClient |
| 186 : public base::SupportsWeakPtr<CompositorSwapClient>, | 196 : public base::SupportsWeakPtr<CompositorSwapClient>, |
| 187 public WebGraphicsContext3DSwapBuffersClient { | 197 public WebGraphicsContext3DSwapBuffersClient { |
| 188 public: | 198 public: |
| 189 CompositorSwapClient(ui::Compositor* compositor, | 199 CompositorSwapClient(ui::Compositor* compositor, |
| 190 GpuProcessTransportFactory* factory) | 200 GpuProcessTransportFactory* factory) |
| 191 : compositor_(compositor), | 201 : compositor_(compositor), |
| 192 factory_(factory) { | 202 factory_(factory) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 411 |
| 402 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { | 412 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { |
| 403 return this; | 413 return this; |
| 404 } | 414 } |
| 405 | 415 |
| 406 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { | 416 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { |
| 407 CreateSharedContextLazy(); | 417 CreateSharedContextLazy(); |
| 408 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 418 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
| 409 gfx::kNullPluginWindow, true); | 419 gfx::kNullPluginWindow, true); |
| 410 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); | 420 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); |
| 411 handle.parent_client_id = shared_context_->GetChannelID(); | |
| 412 handle.parent_context_id = shared_context_->GetContextID(); | |
| 413 handle.parent_texture_id[0] = shared_context_->createTexture(); | |
| 414 handle.parent_texture_id[1] = shared_context_->createTexture(); | |
| 415 handle.sync_point = shared_context_->insertSyncPoint(); | |
| 416 | 421 |
| 417 return handle; | 422 return handle; |
| 418 } | 423 } |
| 419 | 424 |
| 420 virtual void DestroySharedSurfaceHandle( | 425 virtual void DestroySharedSurfaceHandle( |
| 421 gfx::GLSurfaceHandle surface) OVERRIDE { | 426 gfx::GLSurfaceHandle surface) OVERRIDE { |
| 422 if (!shared_context_.get()) | |
| 423 return; | |
| 424 uint32 channel_id = shared_context_->GetChannelID(); | |
| 425 uint32 context_id = shared_context_->GetContextID(); | |
| 426 if (surface.parent_gpu_process_id != shared_context_->GetGPUProcessID() || | |
| 427 surface.parent_client_id != channel_id || | |
| 428 surface.parent_context_id != context_id) | |
| 429 return; | |
| 430 | |
| 431 shared_context_->deleteTexture(surface.parent_texture_id[0]); | |
| 432 shared_context_->deleteTexture(surface.parent_texture_id[1]); | |
| 433 shared_context_->flush(); | |
| 434 } | 427 } |
| 435 | 428 |
| 436 virtual scoped_refptr<ui::Texture> CreateTransportClient( | 429 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
| 437 const gfx::Size& size, | 430 const gfx::Size& size, |
| 438 float device_scale_factor, | 431 float device_scale_factor, |
| 439 uint64 transport_handle) { | 432 const std::string& mailbox_name) { |
| 440 if (!shared_context_.get()) | 433 if (!shared_context_.get()) |
| 441 return NULL; | 434 return NULL; |
| 442 scoped_refptr<ImageTransportClientTexture> image( | 435 scoped_refptr<ImageTransportClientTexture> image( |
| 443 new ImageTransportClientTexture(shared_context_.get(), | 436 new ImageTransportClientTexture(shared_context_.get(), |
| 444 size, device_scale_factor, | 437 size, device_scale_factor, |
| 445 transport_handle)); | 438 mailbox_name)); |
| 446 return image; | 439 return image; |
| 447 } | 440 } |
| 448 | 441 |
| 449 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( | 442 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( |
| 450 const gfx::Size& size, | 443 const gfx::Size& size, |
| 451 float device_scale_factor, | 444 float device_scale_factor, |
| 452 unsigned int texture_id) OVERRIDE { | 445 unsigned int texture_id) OVERRIDE { |
| 453 if (!shared_context_.get()) | 446 if (!shared_context_.get()) |
| 454 return NULL; | 447 return NULL; |
| 455 scoped_refptr<OwnedTexture> image( | 448 scoped_refptr<OwnedTexture> image( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 delete g_factory; | 633 delete g_factory; |
| 641 g_factory = NULL; | 634 g_factory = NULL; |
| 642 } | 635 } |
| 643 | 636 |
| 644 // static | 637 // static |
| 645 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 638 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
| 646 return g_factory; | 639 return g_factory; |
| 647 } | 640 } |
| 648 | 641 |
| 649 } // namespace content | 642 } // namespace content |
| OLD | NEW |