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/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 Loading... | |
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 virtual gfx::ScopedMakeCurrent* GetScopedMakeCurrent() OVERRIDE { |
73 return NULL; | 74 return NULL; |
74 } | 75 } |
75 | 76 |
76 // We don't generate lost context events, so we don't need to keep track of | 77 // We don't generate lost context events, so we don't need to keep track of |
77 // observers | 78 // observers |
78 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE { | 79 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE { |
79 } | 80 } |
80 | 81 |
81 virtual void RemoveObserver( | 82 virtual void RemoveObserver( |
82 ImageTransportFactoryObserver* observer) OVERRIDE { | 83 ImageTransportFactoryObserver* observer) OVERRIDE { |
83 } | 84 } |
84 | 85 |
85 private: | 86 private: |
86 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); | 87 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); |
87 }; | 88 }; |
88 | 89 |
90 class TestTransportTexture : public ui::Texture { | |
91 public: | |
92 TestTransportTexture( | |
93 const gfx::Size& size, | |
94 uint64 surface_id) | |
95 : ui::Texture(true, size), | |
96 host_context_(new ui::TestWebGraphicsContext3D()) { | |
97 set_texture_id(surface_id); | |
98 } | |
99 | |
100 virtual WebKit::WebGraphicsContext3D* HostContext3D() { | |
101 return host_context_.get(); | |
102 } | |
103 | |
104 protected: | |
105 virtual ~TestTransportTexture() {} | |
106 | |
107 private: | |
108 scoped_ptr<WebKit::WebGraphicsContext3D> host_context_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(TestTransportTexture); | |
111 }; | |
112 | |
89 class TestTransportFactory : public DefaultTransportFactory { | 113 class TestTransportFactory : public DefaultTransportFactory { |
90 public: | 114 public: |
91 TestTransportFactory() {} | 115 TestTransportFactory() {} |
92 | 116 |
93 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle( | 117 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle( |
94 ui::Compositor* compositor) OVERRIDE { | 118 ui::Compositor* compositor) OVERRIDE { |
95 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true); | 119 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true); |
96 } | 120 } |
97 | 121 |
98 virtual scoped_refptr<ImageTransportClient> CreateTransportClient( | 122 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
99 const gfx::Size& size, | 123 const gfx::Size& size, |
100 uint64* transport_handle) OVERRIDE { | 124 uint64* transport_handle, |
101 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 125 ui::Compositor* compositor) OVERRIDE { |
102 scoped_refptr<ImageTransportClient> surface( | 126 return new TestTransportTexture(size, *transport_handle); |
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 } | 127 } |
113 | 128 |
114 private: | 129 private: |
115 DISALLOW_COPY_AND_ASSIGN(TestTransportFactory); | 130 DISALLOW_COPY_AND_ASSIGN(TestTransportFactory); |
116 }; | 131 }; |
117 | 132 |
118 class ImageTransportClientTexture : public ImageTransportClient { | 133 class ImageTransportClientTexture : public ui::Texture { |
119 public: | 134 public: |
120 explicit ImageTransportClientTexture(const gfx::Size& size) | 135 ImageTransportClientTexture( |
121 : ImageTransportClient(true, size) { | 136 WebKit::WebGraphicsContext3D* host_context, |
137 const gfx::Size& size, | |
138 uint64 surface_id) | |
139 : ui::Texture(true, size), | |
140 host_context_(host_context) { | |
141 set_texture_id(surface_id); | |
122 } | 142 } |
123 | 143 |
124 virtual bool Initialize(uint64* surface_id) OVERRIDE { | 144 virtual WebKit::WebGraphicsContext3D* HostContext3D() { |
125 set_texture_id(*surface_id); | 145 return host_context_; |
126 return true; | |
127 } | |
128 | |
129 virtual void Update() OVERRIDE {} | |
130 virtual TransportDIB::Handle Handle() const OVERRIDE { | |
131 return TransportDIB::DefaultHandleValue(); | |
132 } | 146 } |
133 | 147 |
134 protected: | 148 protected: |
135 virtual ~ImageTransportClientTexture() {} | 149 virtual ~ImageTransportClientTexture() {} |
136 | 150 |
137 private: | 151 private: |
152 // A weak pointer. This |ImageTransportClientTexture| will be destroyed | |
piman
2012/07/12 17:42:27
Nit: s/weak/raw/ to avoid confusion with WeakPtr
jonathan.backer
2012/07/13 13:26:24
Done.
| |
153 // before the |host_context_| via | |
154 // |ImageTransportFactoryObserver::OnLostContext()| handlers. | |
155 WebKit::WebGraphicsContext3D* host_context_; | |
156 | |
138 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); | 157 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); |
139 }; | 158 }; |
140 | 159 |
141 class GpuProcessTransportFactory; | 160 class GpuProcessTransportFactory; |
142 | 161 |
143 class CompositorSwapClient | 162 class CompositorSwapClient |
144 : public base::SupportsWeakPtr<CompositorSwapClient>, | 163 : public base::SupportsWeakPtr<CompositorSwapClient>, |
145 public WebGraphicsContext3DSwapBuffersClient { | 164 public WebGraphicsContext3DSwapBuffersClient { |
146 public: | 165 public: |
147 CompositorSwapClient(ui::Compositor* compositor, | 166 CompositorSwapClient(ui::Compositor* compositor, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 surface.parent_client_id == client_id && | 259 surface.parent_client_id == client_id && |
241 surface.parent_context_id == context_id) { | 260 surface.parent_context_id == context_id) { |
242 data->shared_context->deleteTexture(surface.parent_texture_id[0]); | 261 data->shared_context->deleteTexture(surface.parent_texture_id[0]); |
243 data->shared_context->deleteTexture(surface.parent_texture_id[1]); | 262 data->shared_context->deleteTexture(surface.parent_texture_id[1]); |
244 data->shared_context->flush(); | 263 data->shared_context->flush(); |
245 break; | 264 break; |
246 } | 265 } |
247 } | 266 } |
248 } | 267 } |
249 | 268 |
250 virtual scoped_refptr<ImageTransportClient> CreateTransportClient( | 269 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
251 const gfx::Size& size, | 270 const gfx::Size& size, |
252 uint64* transport_handle) { | 271 uint64* transport_handle, |
272 ui::Compositor* compositor) { | |
273 PerCompositorData* data = per_compositor_data_[compositor]; | |
274 DCHECK(data); | |
253 scoped_refptr<ImageTransportClientTexture> image( | 275 scoped_refptr<ImageTransportClientTexture> image( |
254 new ImageTransportClientTexture(size)); | 276 new ImageTransportClientTexture(data->shared_context.get(), |
255 image->Initialize(transport_handle); | 277 size, *transport_handle)); |
256 return image; | 278 return image; |
257 } | 279 } |
258 | 280 |
259 virtual GLHelper* GetGLHelper(ui::Compositor* compositor) { | 281 virtual GLHelper* GetGLHelper(ui::Compositor* compositor) { |
260 PerCompositorData* data = per_compositor_data_[compositor]; | 282 PerCompositorData* data = per_compositor_data_[compositor]; |
261 if (!data) | 283 if (!data) |
262 data = CreatePerCompositorData(compositor); | 284 data = CreatePerCompositorData(compositor); |
263 if (!data->gl_helper.get()) { | 285 if (!data->gl_helper.get()) { |
264 WebKit::WebGraphicsContext3D* context_for_thread = | 286 WebKit::WebGraphicsContext3D* context_for_thread = |
265 CreateContextCommon(compositor, true); | 287 CreateContextCommon(compositor, true); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 void ImageTransportFactory::Terminate() { | 447 void ImageTransportFactory::Terminate() { |
426 ui::ContextFactory::SetInstance(NULL); | 448 ui::ContextFactory::SetInstance(NULL); |
427 delete g_factory; | 449 delete g_factory; |
428 g_factory = NULL; | 450 g_factory = NULL; |
429 } | 451 } |
430 | 452 |
431 // static | 453 // static |
432 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 454 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
433 return g_factory; | 455 return g_factory; |
434 } | 456 } |
OLD | NEW |