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

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: rebased, fixed post sub buffer, use multiple mailbox names Created 8 years, 1 month 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 "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"
30 #include "ui/compositor/compositor.h" 31 #include "ui/compositor/compositor.h"
31 #include "ui/compositor/compositor_setup.h" 32 #include "ui/compositor/compositor_setup.h"
32 #include "ui/compositor/test_web_graphics_context_3d.h" 33 #include "ui/compositor/test_web_graphics_context_3d.h"
33 #include "ui/gfx/native_widget_types.h" 34 #include "ui/gfx/native_widget_types.h"
34 #include "ui/gfx/size.h" 35 #include "ui/gfx/size.h"
36 #include "third_party/khronos/GLES2/gl2.h"
apatrick_chromium 2012/11/09 19:19:04 For historical reasons, we've been using Mesa's GL
no sievers 2012/11/09 21:53:02 Youmean third_party/angle/include? So that means
37 #include "third_party/khronos/GLES2/gl2ext.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
40 namespace content { 43 namespace content {
41 namespace { 44 namespace {
42 45
43 ImageTransportFactory* g_factory; 46 ImageTransportFactory* g_factory;
44 47
(...skipping 13 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::vector<signed char>& 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::vector<signed char>& 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 (host_context_) {
piman 2012/11/09 22:02:01 I would make that a DCHECK. Bad things would happe
no sievers 2012/11/19 20:30:44 Done.
169 DCHECK(texture_id_);
170 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_);
171 host_context_->consumeTextureCHROMIUM(
172 GL_TEXTURE_2D, mailbox_name_.data());
piman 2012/11/09 22:02:01 As you mentioned on chat, you need a flush() here.
no sievers 2012/11/19 20:30:44 Done.
173 size_ = new_size;
174 }
175 }
176
177 virtual void Produce() OVERRIDE {
178 if (host_context_) {
179 DCHECK(texture_id_);
180 host_context_->bindTexture(GL_TEXTURE_2D, texture_id_);
181 host_context_->produceTextureCHROMIUM(
182 GL_TEXTURE_2D, mailbox_name_.data());
jonathan.backer 2012/11/12 16:52:15 No flush() because of sync point?
no sievers 2012/11/19 20:30:44 Yes. I *think* implying this makes sense in this c
piman 2012/11/19 22:31:54 My thoughts as well. Inserting the sync point will
183 }
184 }
185
186 protected:
187 virtual ~ImageTransportClientTexture() {}
188
189 private:
190 std::vector<signed char> mailbox_name_;
191 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture);
192 };
193
183 class GpuProcessTransportFactory; 194 class GpuProcessTransportFactory;
184 195
185 class CompositorSwapClient 196 class CompositorSwapClient
186 : public base::SupportsWeakPtr<CompositorSwapClient>, 197 : public base::SupportsWeakPtr<CompositorSwapClient>,
187 public WebGraphicsContext3DSwapBuffersClient { 198 public WebGraphicsContext3DSwapBuffersClient {
188 public: 199 public:
189 CompositorSwapClient(ui::Compositor* compositor, 200 CompositorSwapClient(ui::Compositor* compositor,
190 GpuProcessTransportFactory* factory) 201 GpuProcessTransportFactory* factory)
191 : compositor_(compositor), 202 : compositor_(compositor),
192 factory_(factory) { 203 factory_(factory) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 412
402 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { 413 virtual ui::ContextFactory* AsContextFactory() OVERRIDE {
403 return this; 414 return this;
404 } 415 }
405 416
406 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { 417 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE {
407 CreateSharedContextLazy(); 418 CreateSharedContextLazy();
408 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( 419 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle(
409 gfx::kNullPluginWindow, true); 420 gfx::kNullPluginWindow, true);
410 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); 421 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 422
417 return handle; 423 return handle;
418 } 424 }
419 425
420 virtual void DestroySharedSurfaceHandle( 426 virtual void DestroySharedSurfaceHandle(
421 gfx::GLSurfaceHandle surface) OVERRIDE { 427 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 } 428 }
435 429
436 virtual scoped_refptr<ui::Texture> CreateTransportClient( 430 virtual scoped_refptr<ui::Texture> CreateTransportClient(
437 const gfx::Size& size, 431 const gfx::Size& size,
438 float device_scale_factor, 432 float device_scale_factor,
439 uint64 transport_handle) { 433 const std::vector<signed char>& mailbox_name) {
440 if (!shared_context_.get()) 434 if (!shared_context_.get())
441 return NULL; 435 return NULL;
442 scoped_refptr<ImageTransportClientTexture> image( 436 scoped_refptr<ImageTransportClientTexture> image(
443 new ImageTransportClientTexture(shared_context_.get(), 437 new ImageTransportClientTexture(shared_context_.get(),
444 size, device_scale_factor, 438 size, device_scale_factor,
445 transport_handle)); 439 mailbox_name));
446 return image; 440 return image;
447 } 441 }
448 442
449 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( 443 virtual scoped_refptr<ui::Texture> CreateOwnedTexture(
450 const gfx::Size& size, 444 const gfx::Size& size,
451 float device_scale_factor, 445 float device_scale_factor,
452 unsigned int texture_id) OVERRIDE { 446 unsigned int texture_id) OVERRIDE {
453 if (!shared_context_.get()) 447 if (!shared_context_.get())
454 return NULL; 448 return NULL;
455 scoped_refptr<OwnedTexture> image( 449 scoped_refptr<OwnedTexture> image(
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 delete g_factory; 638 delete g_factory;
645 g_factory = NULL; 639 g_factory = NULL;
646 } 640 }
647 641
648 // static 642 // static
649 ImageTransportFactory* ImageTransportFactory::GetInstance() { 643 ImageTransportFactory* ImageTransportFactory::GetInstance() {
650 return g_factory; 644 return g_factory;
651 } 645 }
652 646
653 } // namespace content 647 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698