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

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

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

Powered by Google App Engine
This is Rietveld 408576698