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

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

Issue 10689108: Aura: Have ui::Layer implement WebKit::WebExternalTextureLayerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nuke TestImageTransportFactory. Created 8 years, 5 months 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/observer_list.h" 13 #include "base/observer_list.h"
14 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 14 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
15 #include "content/browser/gpu/gpu_surface_tracker.h" 15 #include "content/browser/gpu/gpu_surface_tracker.h"
16 #include "content/browser/renderer_host/image_transport_client.h"
17 #include "content/common/gpu/client/gl_helper.h" 16 #include "content/common/gpu/client/gl_helper.h"
18 #include "content/common/gpu/client/gpu_channel_host.h" 17 #include "content/common/gpu/client/gpu_channel_host.h"
19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 18 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
20 #include "content/common/gpu/gpu_process_launch_causes.h" 19 #include "content/common/gpu/gpu_process_launch_causes.h"
21 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
22 #include "gpu/ipc/command_buffer_proxy.h" 21 #include "gpu/ipc/command_buffer_proxy.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h"
24 #include "ui/compositor/compositor.h" 23 #include "ui/compositor/compositor.h"
25 #include "ui/compositor/compositor_setup.h" 24 #include "ui/compositor/compositor_setup.h"
25 #include "ui/compositor/test_web_graphics_context_3d.h"
26 #include "ui/gfx/native_widget_types.h" 26 #include "ui/gfx/native_widget_types.h"
27 #include "ui/gfx/size.h" 27 #include "ui/gfx/size.h"
28 #include "ui/gl/scoped_make_current.h" 28 #include "ui/gl/scoped_make_current.h"
29 29
30 using content::BrowserGpuChannelHostFactory; 30 using content::BrowserGpuChannelHostFactory;
31 using content::GLHelper; 31 using content::GLHelper;
32 32
33 namespace { 33 namespace {
34 34
35 ImageTransportFactory* g_factory; 35 ImageTransportFactory* g_factory;
(...skipping 12 matching lines...) Expand all
48 48
49 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle( 49 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle(
50 ui::Compositor* compositor) OVERRIDE { 50 ui::Compositor* compositor) OVERRIDE {
51 return gfx::GLSurfaceHandle(); 51 return gfx::GLSurfaceHandle();
52 } 52 }
53 53
54 virtual void DestroySharedSurfaceHandle( 54 virtual void DestroySharedSurfaceHandle(
55 gfx::GLSurfaceHandle surface) OVERRIDE { 55 gfx::GLSurfaceHandle surface) OVERRIDE {
56 } 56 }
57 57
58 virtual scoped_refptr<ImageTransportClient> CreateTransportClient( 58 virtual scoped_refptr<ui::Texture> CreateTransportClient(
59 const gfx::Size& size, 59 const gfx::Size& size,
60 uint64* transport_handle) OVERRIDE { 60 uint64* transport_handle,
61 ui::Compositor* compositor) OVERRIDE {
61 return NULL; 62 return NULL;
62 } 63 }
63 64
64 virtual GLHelper* GetGLHelper(ui::Compositor* compositor) OVERRIDE { 65 virtual GLHelper* GetGLHelper(ui::Compositor* compositor) OVERRIDE {
65 return NULL; 66 return NULL;
66 } 67 }
67 68
68 virtual uint32 InsertSyncPoint(ui::Compositor* compositor) OVERRIDE { 69 virtual uint32 InsertSyncPoint(ui::Compositor* compositor) OVERRIDE {
69 return 0; 70 return 0;
70 } 71 }
71 72
72 virtual gfx::ScopedMakeCurrent* GetScopedMakeCurrent() OVERRIDE {
73 return NULL;
74 }
75
76 // We don't generate lost context events, so we don't need to keep track of 73 // We don't generate lost context events, so we don't need to keep track of
77 // observers 74 // observers
78 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE { 75 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE {
79 } 76 }
80 77
81 virtual void RemoveObserver( 78 virtual void RemoveObserver(
82 ImageTransportFactoryObserver* observer) OVERRIDE { 79 ImageTransportFactoryObserver* observer) OVERRIDE {
83 } 80 }
84 81
85 private: 82 private:
86 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); 83 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory);
87 }; 84 };
88 85
89 class TestTransportFactory : public DefaultTransportFactory { 86 class ImageTransportClientTexture : public ui::Texture {
90 public: 87 public:
91 TestTransportFactory() {} 88 ImageTransportClientTexture(
92 89 WebKit::WebGraphicsContext3D* host_context,
93 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle( 90 const gfx::Size& size,
94 ui::Compositor* compositor) OVERRIDE { 91 uint64 surface_id)
95 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true); 92 : ui::Texture(true, size),
93 host_context_(host_context) {
94 set_texture_id(surface_id);
96 } 95 }
97 96
98 virtual scoped_refptr<ImageTransportClient> CreateTransportClient( 97 virtual WebKit::WebGraphicsContext3D* HostContext3D() {
99 const gfx::Size& size, 98 return host_context_;
100 uint64* transport_handle) OVERRIDE {
101 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
102 scoped_refptr<ImageTransportClient> surface(
103 ImageTransportClient::Create(this, size));
104 if (!surface || !surface->Initialize(transport_handle)) {
105 LOG(ERROR) << "Failed to create ImageTransportClient";
106 return NULL;
107 }
108 return surface;
109 #else
110 return NULL;
111 #endif
112 }
113
114 private:
115 DISALLOW_COPY_AND_ASSIGN(TestTransportFactory);
116 };
117
118 class ImageTransportClientTexture : public ImageTransportClient {
119 public:
120 explicit ImageTransportClientTexture(const gfx::Size& size)
121 : ImageTransportClient(true, size) {
122 }
123
124 virtual bool Initialize(uint64* surface_id) OVERRIDE {
125 set_texture_id(*surface_id);
126 return true;
127 }
128
129 virtual void Update() OVERRIDE {}
130 virtual TransportDIB::Handle Handle() const OVERRIDE {
131 return TransportDIB::DefaultHandleValue();
132 } 99 }
133 100
134 protected: 101 protected:
135 virtual ~ImageTransportClientTexture() {} 102 virtual ~ImageTransportClientTexture() {}
136 103
137 private: 104 private:
105 // A raw pointer. This |ImageTransportClientTexture| will be destroyed
106 // before the |host_context_| via
107 // |ImageTransportFactoryObserver::OnLostContext()| handlers.
108 WebKit::WebGraphicsContext3D* host_context_;
109
138 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); 110 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture);
139 }; 111 };
140 112
141 class GpuProcessTransportFactory; 113 class GpuProcessTransportFactory;
142 114
143 class CompositorSwapClient 115 class CompositorSwapClient
144 : public base::SupportsWeakPtr<CompositorSwapClient>, 116 : public base::SupportsWeakPtr<CompositorSwapClient>,
145 public WebGraphicsContext3DSwapBuffersClient { 117 public WebGraphicsContext3DSwapBuffersClient {
146 public: 118 public:
147 CompositorSwapClient(ui::Compositor* compositor, 119 CompositorSwapClient(ui::Compositor* compositor,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 surface.parent_client_id == client_id && 212 surface.parent_client_id == client_id &&
241 surface.parent_context_id == context_id) { 213 surface.parent_context_id == context_id) {
242 data->shared_context->deleteTexture(surface.parent_texture_id[0]); 214 data->shared_context->deleteTexture(surface.parent_texture_id[0]);
243 data->shared_context->deleteTexture(surface.parent_texture_id[1]); 215 data->shared_context->deleteTexture(surface.parent_texture_id[1]);
244 data->shared_context->flush(); 216 data->shared_context->flush();
245 break; 217 break;
246 } 218 }
247 } 219 }
248 } 220 }
249 221
250 virtual scoped_refptr<ImageTransportClient> CreateTransportClient( 222 virtual scoped_refptr<ui::Texture> CreateTransportClient(
251 const gfx::Size& size, 223 const gfx::Size& size,
252 uint64* transport_handle) { 224 uint64* transport_handle,
225 ui::Compositor* compositor) {
226 PerCompositorData* data = per_compositor_data_[compositor];
227 DCHECK(data);
253 scoped_refptr<ImageTransportClientTexture> image( 228 scoped_refptr<ImageTransportClientTexture> image(
254 new ImageTransportClientTexture(size)); 229 new ImageTransportClientTexture(data->shared_context.get(),
255 image->Initialize(transport_handle); 230 size, *transport_handle));
256 return image; 231 return image;
257 } 232 }
258 233
259 virtual GLHelper* GetGLHelper(ui::Compositor* compositor) { 234 virtual GLHelper* GetGLHelper(ui::Compositor* compositor) {
260 PerCompositorData* data = per_compositor_data_[compositor]; 235 PerCompositorData* data = per_compositor_data_[compositor];
261 if (!data) 236 if (!data)
262 data = CreatePerCompositorData(compositor); 237 data = CreatePerCompositorData(compositor);
263 if (!data->gl_helper.get()) { 238 if (!data->gl_helper.get()) {
264 WebKit::WebGraphicsContext3D* context_for_thread = 239 WebKit::WebGraphicsContext3D* context_for_thread =
265 CreateContextCommon(compositor, true); 240 CreateContextCommon(compositor, true);
266 if (!context_for_thread) 241 if (!context_for_thread)
267 return NULL; 242 return NULL;
268 data->gl_helper.reset(new GLHelper(data->shared_context.get(), 243 data->gl_helper.reset(new GLHelper(data->shared_context.get(),
269 context_for_thread)); 244 context_for_thread));
270 } 245 }
271 return data->gl_helper.get(); 246 return data->gl_helper.get();
272 } 247 }
273 248
274 virtual uint32 InsertSyncPoint(ui::Compositor* compositor) OVERRIDE { 249 virtual uint32 InsertSyncPoint(ui::Compositor* compositor) OVERRIDE {
275 PerCompositorData* data = per_compositor_data_[compositor]; 250 PerCompositorData* data = per_compositor_data_[compositor];
276 if (!data) 251 if (!data)
277 data = CreatePerCompositorData(compositor); 252 data = CreatePerCompositorData(compositor);
278 return data->shared_context->insertSyncPoint(); 253 return data->shared_context->insertSyncPoint();
279 } 254 }
280 255
281 virtual gfx::ScopedMakeCurrent* GetScopedMakeCurrent() { return NULL; }
282
283 virtual void AddObserver(ImageTransportFactoryObserver* observer) { 256 virtual void AddObserver(ImageTransportFactoryObserver* observer) {
284 observer_list_.AddObserver(observer); 257 observer_list_.AddObserver(observer);
285 } 258 }
286 259
287 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { 260 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) {
288 observer_list_.RemoveObserver(observer); 261 observer_list_.RemoveObserver(observer);
289 } 262 }
290 263
291 void OnLostContext(ui::Compositor* compositor) { 264 void OnLostContext(ui::Compositor* compositor) {
292 LOG(ERROR) << "Lost UI compositor context."; 265 LOG(ERROR) << "Lost UI compositor context.";
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 376
404 } // anonymous namespace 377 } // anonymous namespace
405 378
406 // static 379 // static
407 void ImageTransportFactory::Initialize() { 380 void ImageTransportFactory::Initialize() {
408 CommandLine* command_line = CommandLine::ForCurrentProcess(); 381 CommandLine* command_line = CommandLine::ForCurrentProcess();
409 if (command_line->HasSwitch(switches::kTestCompositor)) { 382 if (command_line->HasSwitch(switches::kTestCompositor)) {
410 ui::SetupTestCompositor(); 383 ui::SetupTestCompositor();
411 } 384 }
412 if (ui::IsTestCompositorEnabled()) { 385 if (ui::IsTestCompositorEnabled()) {
413 g_factory = new TestTransportFactory(); 386 g_factory = new DefaultTransportFactory();
414 } else { 387 } else {
415 #if defined(OS_WIN) 388 #if defined(OS_WIN)
416 g_factory = new DefaultTransportFactory(); 389 g_factory = new DefaultTransportFactory();
417 #else 390 #else
418 g_factory = new GpuProcessTransportFactory(); 391 g_factory = new GpuProcessTransportFactory();
419 #endif 392 #endif
420 } 393 }
421 ui::ContextFactory::SetInstance(g_factory->AsContextFactory()); 394 ui::ContextFactory::SetInstance(g_factory->AsContextFactory());
422 } 395 }
423 396
424 // static 397 // static
425 void ImageTransportFactory::Terminate() { 398 void ImageTransportFactory::Terminate() {
426 ui::ContextFactory::SetInstance(NULL); 399 ui::ContextFactory::SetInstance(NULL);
427 delete g_factory; 400 delete g_factory;
428 g_factory = NULL; 401 g_factory = NULL;
429 } 402 }
430 403
431 // static 404 // static
432 ImageTransportFactory* ImageTransportFactory::GetInstance() { 405 ImageTransportFactory* ImageTransportFactory::GetInstance() {
433 return g_factory; 406 return g_factory;
434 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698