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/compositor_impl_android.h" | 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
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/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "cc/font_atlas.h" |
| 15 #include "cc/input_handler.h" |
| 16 #include "cc/layer.h" |
| 17 #include "cc/layer_tree_host.h" |
| 18 #include "cc/thread_impl.h" |
14 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 19 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
15 #include "content/browser/gpu/gpu_surface_tracker.h" | 20 #include "content/browser/gpu/gpu_surface_tracker.h" |
16 #include "content/browser/renderer_host/image_transport_factory_android.h" | 21 #include "content/browser/renderer_host/image_transport_factory_android.h" |
17 #include "content/common/gpu/client/gl_helper.h" | 22 #include "content/common/gpu/client/gl_helper.h" |
18 #include "content/common/gpu/client/gpu_channel_host.h" | 23 #include "content/common/gpu/client/gpu_channel_host.h" |
19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 24 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
20 #include "content/common/gpu/gpu_process_launch_causes.h" | 25 #include "content/common/gpu/gpu_process_launch_causes.h" |
21 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
22 #include "third_party/khronos/GLES2/gl2.h" | 27 #include "third_party/khronos/GLES2/gl2.h" |
23 #include "third_party/khronos/GLES2/gl2ext.h" | 28 #include "third_party/khronos/GLES2/gl2ext.h" |
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput
Surface.h" | 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput
Surface.h" |
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.
h" | |
27 #include "ui/gfx/android/java_bitmap.h" | 31 #include "ui/gfx/android/java_bitmap.h" |
28 #include "webkit/compositor_bindings/web_compositor_support_impl.h" | |
29 #include "webkit/glue/webthread_impl.h" | 32 #include "webkit/glue/webthread_impl.h" |
30 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" | 33 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
31 | 34 |
32 using webkit::WebCompositorSupportImpl; | |
33 | |
34 namespace gfx { | 35 namespace gfx { |
35 class JavaBitmap; | 36 class JavaBitmap; |
36 } | 37 } |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 static bool g_initialized = false; | 41 static bool g_initialized = false; |
41 static base::LazyInstance<WebCompositorSupportImpl> g_compositor_support = | 42 static webkit_glue::WebThreadImpl* g_impl_thread = NULL; |
42 LAZY_INSTANCE_INITIALIZER; | |
43 static WebKit::WebThread* g_impl_thread = NULL; | |
44 static bool g_use_direct_gl = false; | 43 static bool g_use_direct_gl = false; |
45 | 44 |
46 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. | 45 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. |
47 class WebGraphicsContextToOutputSurfaceAdapter : | 46 class WebGraphicsContextToOutputSurfaceAdapter : |
48 public WebKit::WebCompositorOutputSurface { | 47 public WebKit::WebCompositorOutputSurface { |
49 public: | 48 public: |
50 explicit WebGraphicsContextToOutputSurfaceAdapter( | 49 explicit WebGraphicsContextToOutputSurfaceAdapter( |
51 WebKit::WebGraphicsContext3D* context) | 50 WebKit::WebGraphicsContext3D* context) |
52 : m_context3D(context) | 51 : m_context3D(context) |
53 , m_client(0) | 52 , m_client(0) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 namespace content { | 89 namespace content { |
91 | 90 |
92 // static | 91 // static |
93 Compositor* Compositor::Create(Client* client) { | 92 Compositor* Compositor::Create(Client* client) { |
94 return client ? new CompositorImpl(client) : NULL; | 93 return client ? new CompositorImpl(client) : NULL; |
95 } | 94 } |
96 | 95 |
97 // static | 96 // static |
98 void Compositor::Initialize() { | 97 void Compositor::Initialize() { |
99 DCHECK(!CompositorImpl::IsInitialized()); | 98 DCHECK(!CompositorImpl::IsInitialized()); |
100 g_compositor_support.Get().initialize(g_impl_thread); | |
101 g_initialized = true; | 99 g_initialized = true; |
102 } | 100 } |
103 | 101 |
104 // static | 102 // static |
105 void Compositor::InitializeWithFlags(uint32 flags) { | 103 void Compositor::InitializeWithFlags(uint32 flags) { |
106 g_use_direct_gl = flags & DIRECT_CONTEXT_ON_DRAW_THREAD; | 104 g_use_direct_gl = flags & DIRECT_CONTEXT_ON_DRAW_THREAD; |
107 if (flags & ENABLE_COMPOSITOR_THREAD) | 105 if (flags & ENABLE_COMPOSITOR_THREAD) { |
| 106 TRACE_EVENT_INSTANT0("test_gpu", "ThreadedCompositingInitialization"); |
108 g_impl_thread = new webkit_glue::WebThreadImpl("Browser Compositor"); | 107 g_impl_thread = new webkit_glue::WebThreadImpl("Browser Compositor"); |
| 108 } |
109 Compositor::Initialize(); | 109 Compositor::Initialize(); |
110 } | 110 } |
111 | 111 |
112 // static | 112 // static |
113 WebCompositorSupportImpl* CompositorImpl::CompositorSupport() { | |
114 DCHECK(g_initialized); | |
115 return g_compositor_support.Pointer(); | |
116 } | |
117 | |
118 // static | |
119 bool CompositorImpl::IsInitialized() { | 113 bool CompositorImpl::IsInitialized() { |
120 return g_initialized; | 114 return g_initialized; |
121 } | 115 } |
122 | 116 |
123 // static | 117 // static |
| 118 bool CompositorImpl::IsThreadingEnabled() { |
| 119 return g_impl_thread; |
| 120 } |
| 121 |
| 122 // static |
124 bool CompositorImpl::UsesDirectGL() { | 123 bool CompositorImpl::UsesDirectGL() { |
125 return g_use_direct_gl; | 124 return g_use_direct_gl; |
126 } | 125 } |
127 | 126 |
128 CompositorImpl::CompositorImpl(Compositor::Client* client) | 127 CompositorImpl::CompositorImpl(Compositor::Client* client) |
129 : window_(NULL), | 128 : root_layer_(cc::Layer::create()), |
| 129 window_(NULL), |
130 surface_id_(0), | 130 surface_id_(0), |
131 client_(client), | 131 client_(client), |
132 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 132 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
133 DCHECK(client); | 133 DCHECK(client); |
134 root_layer_.reset(g_compositor_support.Get().createLayer()); | |
135 } | 134 } |
136 | 135 |
137 CompositorImpl::~CompositorImpl() { | 136 CompositorImpl::~CompositorImpl() { |
138 } | 137 } |
139 | 138 |
140 void CompositorImpl::Composite() { | 139 void CompositorImpl::Composite() { |
141 if (host_.get()) | 140 if (host_.get()) |
142 host_->composite(); | 141 host_->composite(); |
143 } | 142 } |
144 | 143 |
145 void CompositorImpl::SetRootLayer(WebKit::WebLayer* root_layer) { | 144 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
146 root_layer_->removeAllChildren(); | 145 root_layer_->removeAllChildren(); |
147 root_layer_->addChild(root_layer); | 146 root_layer_->addChild(root_layer); |
148 } | 147 } |
149 | 148 |
150 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { | 149 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { |
151 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 150 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
152 | 151 |
153 if (window_) { | 152 if (window_) { |
154 tracker->RemoveSurface(surface_id_); | 153 tracker->RemoveSurface(surface_id_); |
155 ANativeWindow_release(window_); | 154 ANativeWindow_release(window_); |
(...skipping 10 matching lines...) Expand all Loading... |
166 surface_id_, | 165 surface_id_, |
167 gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false)); | 166 gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false)); |
168 SetVisible(true); | 167 SetVisible(true); |
169 } | 168 } |
170 } | 169 } |
171 | 170 |
172 void CompositorImpl::SetVisible(bool visible) { | 171 void CompositorImpl::SetVisible(bool visible) { |
173 if (!visible) { | 172 if (!visible) { |
174 host_.reset(); | 173 host_.reset(); |
175 } else if (!host_.get()) { | 174 } else if (!host_.get()) { |
176 WebKit::WebLayerTreeView::Settings settings; | 175 cc::LayerTreeSettings settings; |
177 settings.refreshRate = 60.0; | 176 settings.refreshRate = 60.0; |
178 host_.reset(g_compositor_support.Get().createLayerTreeView( | 177 |
179 this, *root_layer_, settings)); | 178 scoped_ptr<cc::Thread> impl_thread; |
| 179 if (g_impl_thread) |
| 180 impl_thread = cc::ThreadImpl::createForDifferentThread( |
| 181 g_impl_thread->message_loop()->message_loop_proxy()); |
| 182 |
| 183 host_ = cc::LayerTreeHost::create(this, settings, impl_thread.Pass()); |
| 184 host_->setRootLayer(root_layer_); |
| 185 |
180 host_->setVisible(true); | 186 host_->setVisible(true); |
181 host_->setSurfaceReady(); | 187 host_->setSurfaceReady(); |
182 host_->setViewportSize(size_); | 188 host_->setViewportSize(size_, size_); |
183 } | 189 } |
184 } | 190 } |
185 | 191 |
186 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 192 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
187 if (size_ == size) | 193 if (size_ == size) |
188 return; | 194 return; |
189 | 195 |
190 size_ = size; | 196 size_ = size; |
191 if (host_) | 197 if (host_) |
192 host_->setViewportSize(size); | 198 host_->setViewportSize(size, size); |
193 root_layer_->setBounds(size); | 199 root_layer_->setBounds(size); |
194 } | 200 } |
195 | 201 |
196 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { | 202 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { |
197 if (host_.get()) | 203 if (host_.get()) |
198 return host_->compositeAndReadback(pixels, rect); | 204 return host_->compositeAndReadback(pixels, rect); |
199 else | 205 else |
200 return false; | 206 return false; |
201 } | 207 } |
202 | 208 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 261 } |
256 | 262 |
257 void CompositorImpl::CopyTextureToBitmap(WebKit::WebGLId texture_id, | 263 void CompositorImpl::CopyTextureToBitmap(WebKit::WebGLId texture_id, |
258 gfx::JavaBitmap& bitmap) { | 264 gfx::JavaBitmap& bitmap) { |
259 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 265 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
260 helper->ReadbackTextureSync(texture_id, | 266 helper->ReadbackTextureSync(texture_id, |
261 bitmap.size(), | 267 bitmap.size(), |
262 static_cast<unsigned char*> (bitmap.pixels())); | 268 static_cast<unsigned char*> (bitmap.pixels())); |
263 } | 269 } |
264 | 270 |
265 void CompositorImpl::updateAnimations(double frameBeginTime) { | 271 void CompositorImpl::animate(double monotonicFrameBeginTime) { |
266 } | 272 } |
267 | 273 |
268 void CompositorImpl::layout() { | 274 void CompositorImpl::layout() { |
269 } | 275 } |
270 | 276 |
271 void CompositorImpl::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 277 void CompositorImpl::applyScrollAndScale(gfx::Vector2d scrollDelta, |
272 float scaleFactor) { | 278 float pageScale) { |
273 } | 279 } |
274 | 280 |
275 WebKit::WebCompositorOutputSurface* CompositorImpl::createOutputSurface() { | 281 scoped_ptr<WebKit::WebCompositorOutputSurface> |
| 282 CompositorImpl::createOutputSurface() { |
276 if (g_use_direct_gl) { | 283 if (g_use_direct_gl) { |
277 WebKit::WebGraphicsContext3D::Attributes attrs; | 284 WebKit::WebGraphicsContext3D::Attributes attrs; |
278 attrs.shareResources = false; | 285 attrs.shareResources = false; |
279 attrs.noAutomaticFlushes = true; | 286 attrs.noAutomaticFlushes = true; |
280 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context( | 287 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context( |
281 webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWindow( | 288 webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWindow( |
282 attrs, | 289 attrs, |
283 window_, | 290 window_, |
284 NULL)); | 291 NULL)); |
285 return new WebGraphicsContextToOutputSurfaceAdapter(context.release()); | 292 return scoped_ptr<WebKit::WebCompositorOutputSurface>( |
| 293 new WebGraphicsContextToOutputSurfaceAdapter(context.release())); |
286 } else { | 294 } else { |
287 DCHECK(window_ && surface_id_); | 295 DCHECK(window_ && surface_id_); |
288 WebKit::WebGraphicsContext3D::Attributes attrs; | 296 WebKit::WebGraphicsContext3D::Attributes attrs; |
289 attrs.shareResources = true; | 297 attrs.shareResources = true; |
290 attrs.noAutomaticFlushes = true; | 298 attrs.noAutomaticFlushes = true; |
291 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); | 299 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); |
292 GURL url("chrome://gpu/Compositor::createContext3D"); | 300 GURL url("chrome://gpu/Compositor::createContext3D"); |
293 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 301 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
294 new WebGraphicsContext3DCommandBufferImpl(surface_id_, | 302 new WebGraphicsContext3DCommandBufferImpl(surface_id_, |
295 url, | 303 url, |
296 factory, | 304 factory, |
297 weak_factory_.GetWeakPtr())); | 305 weak_factory_.GetWeakPtr())); |
298 if (!context->Initialize( | 306 if (!context->Initialize( |
299 attrs, | 307 attrs, |
300 false, | 308 false, |
301 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
{ | 309 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
{ |
302 LOG(ERROR) << "Failed to create 3D context for compositor."; | 310 LOG(ERROR) << "Failed to create 3D context for compositor."; |
303 return NULL; | 311 return scoped_ptr<WebKit::WebCompositorOutputSurface>(); |
304 } | 312 } |
305 return new WebGraphicsContextToOutputSurfaceAdapter(context.release()); | 313 return scoped_ptr<WebKit::WebCompositorOutputSurface>( |
| 314 new WebGraphicsContextToOutputSurfaceAdapter(context.release())); |
306 } | 315 } |
307 } | 316 } |
308 | 317 |
| 318 scoped_ptr<cc::InputHandler> CompositorImpl::createInputHandler() { |
| 319 return scoped_ptr<cc::InputHandler>(); |
| 320 } |
| 321 |
309 void CompositorImpl::didRecreateOutputSurface(bool success) { | 322 void CompositorImpl::didRecreateOutputSurface(bool success) { |
310 } | 323 } |
311 | 324 |
312 void CompositorImpl::didCommit() { | 325 void CompositorImpl::didCommit() { |
313 } | 326 } |
314 | 327 |
315 void CompositorImpl::didCommitAndDrawFrame() { | 328 void CompositorImpl::didCommitAndDrawFrame() { |
316 } | 329 } |
317 | 330 |
318 void CompositorImpl::didCompleteSwapBuffers() { | 331 void CompositorImpl::didCompleteSwapBuffers() { |
319 client_->OnSwapBuffersCompleted(); | 332 client_->OnSwapBuffersCompleted(); |
320 } | 333 } |
321 | 334 |
322 void CompositorImpl::scheduleComposite() { | 335 void CompositorImpl::scheduleComposite() { |
323 client_->ScheduleComposite(); | 336 client_->ScheduleComposite(); |
324 } | 337 } |
325 | 338 |
| 339 scoped_ptr<cc::FontAtlas> CompositorImpl::createFontAtlas() { |
| 340 return scoped_ptr<cc::FontAtlas>(); |
| 341 } |
| 342 |
326 void CompositorImpl::OnViewContextSwapBuffersPosted() { | 343 void CompositorImpl::OnViewContextSwapBuffersPosted() { |
327 TRACE_EVENT0("compositor", "CompositorImpl::OnViewContextSwapBuffersPosted"); | 344 TRACE_EVENT0("compositor", "CompositorImpl::OnViewContextSwapBuffersPosted"); |
328 } | 345 } |
329 | 346 |
330 void CompositorImpl::OnViewContextSwapBuffersComplete() { | 347 void CompositorImpl::OnViewContextSwapBuffersComplete() { |
331 TRACE_EVENT0("compositor", | 348 TRACE_EVENT0("compositor", |
332 "CompositorImpl::OnViewContextSwapBuffersComplete"); | 349 "CompositorImpl::OnViewContextSwapBuffersComplete"); |
333 client_->OnSwapBuffersCompleted(); | 350 client_->OnSwapBuffersCompleted(); |
334 } | 351 } |
335 | 352 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 399 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
383 return GL_UNSIGNED_BYTE; | 400 return GL_UNSIGNED_BYTE; |
384 break; | 401 break; |
385 case ANDROID_BITMAP_FORMAT_RGB_565: | 402 case ANDROID_BITMAP_FORMAT_RGB_565: |
386 default: | 403 default: |
387 return GL_UNSIGNED_SHORT_5_6_5; | 404 return GL_UNSIGNED_SHORT_5_6_5; |
388 } | 405 } |
389 } | 406 } |
390 | 407 |
391 } // namespace content | 408 } // namespace content |
OLD | NEW |