Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Side by Side Diff: content/browser/renderer_host/image_transport_factory.cc

Issue 11194042: Implement TextureImageTransportSurface using texture mailbox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win_aura DCHECK() Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "cc/output_surface.h" 16 #include "cc/output_surface.h"
16 #include "cc/output_surface_client.h" 17 #include "cc/output_surface_client.h"
17 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 18 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
18 #include "content/browser/gpu/gpu_data_manager_impl.h" 19 #include "content/browser/gpu/gpu_data_manager_impl.h"
19 #include "content/browser/gpu/gpu_process_host.h" 20 #include "content/browser/gpu/gpu_process_host.h"
20 #include "content/browser/gpu/gpu_surface_tracker.h" 21 #include "content/browser/gpu/gpu_surface_tracker.h"
21 #include "content/common/gpu/client/gl_helper.h" 22 #include "content/common/gpu/client/gl_helper.h"
22 #include "content/common/gpu/client/gpu_channel_host.h" 23 #include "content/common/gpu/client/gpu_channel_host.h"
23 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 24 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
24 #include "content/common/gpu/gpu_messages.h" 25 #include "content/common/gpu/gpu_messages.h"
25 #include "content/common/gpu/gpu_process_launch_causes.h" 26 #include "content/common/gpu/gpu_process_launch_causes.h"
26 #include "content/common/webkitplatformsupport_impl.h" 27 #include "content/common/webkitplatformsupport_impl.h"
27 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
28 #include "gpu/ipc/command_buffer_proxy.h" 29 #include "gpu/ipc/command_buffer_proxy.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
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
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
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 if (!mailbox_name_.length())
169 return;
170
171 DCHECK(host_context_ && texture_id_);
172 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_);
173 host_context_->consumeTextureCHROMIUM(
174 GL_TEXTURE_2D,
175 reinterpret_cast<const signed char*>(mailbox_name_.c_str()));
176 size_ = new_size;
177 host_context_->flush();
178 }
179
180 virtual void Produce() OVERRIDE {
181 if (!mailbox_name_.length())
182 return;
183
184 DCHECK(host_context_ && texture_id_);
185 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_);
186 host_context_->produceTextureCHROMIUM(
187 GL_TEXTURE_2D,
188 reinterpret_cast<const signed char*>(mailbox_name_.c_str()));
189 }
190
191 protected:
192 virtual ~ImageTransportClientTexture() {}
193
194 private:
195 std::string mailbox_name_;
196 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture);
197 };
198
183 class GpuProcessTransportFactory; 199 class GpuProcessTransportFactory;
184 200
185 class CompositorSwapClient 201 class CompositorSwapClient
186 : public base::SupportsWeakPtr<CompositorSwapClient>, 202 : public base::SupportsWeakPtr<CompositorSwapClient>,
187 public WebGraphicsContext3DSwapBuffersClient { 203 public WebGraphicsContext3DSwapBuffersClient {
188 public: 204 public:
189 CompositorSwapClient(ui::Compositor* compositor, 205 CompositorSwapClient(ui::Compositor* compositor,
190 GpuProcessTransportFactory* factory) 206 GpuProcessTransportFactory* factory)
191 : compositor_(compositor), 207 : compositor_(compositor),
192 factory_(factory) { 208 factory_(factory) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { 418 virtual ui::ContextFactory* AsContextFactory() OVERRIDE {
403 return this; 419 return this;
404 } 420 }
405 421
406 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { 422 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE {
407 CreateSharedContextLazy(); 423 CreateSharedContextLazy();
408 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( 424 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle(
409 gfx::kNullPluginWindow, true); 425 gfx::kNullPluginWindow, true);
410 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); 426 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID();
411 handle.parent_client_id = shared_context_->GetChannelID(); 427 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 428
417 return handle; 429 return handle;
418 } 430 }
419 431
420 virtual void DestroySharedSurfaceHandle( 432 virtual void DestroySharedSurfaceHandle(
421 gfx::GLSurfaceHandle surface) OVERRIDE { 433 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 } 434 }
435 435
436 virtual scoped_refptr<ui::Texture> CreateTransportClient( 436 virtual scoped_refptr<ui::Texture> CreateTransportClient(
437 const gfx::Size& size, 437 const gfx::Size& size,
438 float device_scale_factor, 438 float device_scale_factor,
439 uint64 transport_handle) { 439 const std::string& mailbox_name) {
440 if (!shared_context_.get()) 440 if (!shared_context_.get())
441 return NULL; 441 return NULL;
442 scoped_refptr<ImageTransportClientTexture> image( 442 scoped_refptr<ImageTransportClientTexture> image(
443 new ImageTransportClientTexture(shared_context_.get(), 443 new ImageTransportClientTexture(shared_context_.get(),
444 size, device_scale_factor, 444 size, device_scale_factor,
445 transport_handle)); 445 mailbox_name));
446 return image; 446 return image;
447 } 447 }
448 448
449 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( 449 virtual scoped_refptr<ui::Texture> CreateOwnedTexture(
450 const gfx::Size& size, 450 const gfx::Size& size,
451 float device_scale_factor, 451 float device_scale_factor,
452 unsigned int texture_id) OVERRIDE { 452 unsigned int texture_id) OVERRIDE {
453 if (!shared_context_.get()) 453 if (!shared_context_.get())
454 return NULL; 454 return NULL;
455 scoped_refptr<OwnedTexture> image( 455 scoped_refptr<OwnedTexture> image(
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 delete g_factory; 640 delete g_factory;
641 g_factory = NULL; 641 g_factory = NULL;
642 } 642 }
643 643
644 // static 644 // static
645 ImageTransportFactory* ImageTransportFactory::GetInstance() { 645 ImageTransportFactory* ImageTransportFactory::GetInstance() {
646 return g_factory; 646 return g_factory;
647 } 647 }
648 648
649 } // namespace content 649 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698