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 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback_helpers.h" | |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
20 #include "cc/input/input_handler.h" | 21 #include "cc/input/input_handler.h" |
21 #include "cc/layers/layer.h" | 22 #include "cc/layers/layer.h" |
22 #include "cc/output/compositor_frame.h" | 23 #include "cc/output/compositor_frame.h" |
23 #include "cc/output/context_provider.h" | 24 #include "cc/output/context_provider.h" |
24 #include "cc/output/output_surface.h" | 25 #include "cc/output/output_surface.h" |
25 #include "cc/resources/scoped_ui_resource.h" | 26 #include "cc/resources/scoped_ui_resource.h" |
26 #include "cc/resources/ui_resource_bitmap.h" | 27 #include "cc/resources/ui_resource_bitmap.h" |
27 #include "cc/trees/layer_tree_host.h" | 28 #include "cc/trees/layer_tree_host.h" |
29 #include "content/browser/android/transient_ui_resource.h" | |
28 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 30 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
29 #include "content/browser/gpu/gpu_surface_tracker.h" | 31 #include "content/browser/gpu/gpu_surface_tracker.h" |
30 #include "content/common/gpu/client/command_buffer_proxy_impl.h" | 32 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
31 #include "content/common/gpu/client/context_provider_command_buffer.h" | 33 #include "content/common/gpu/client/context_provider_command_buffer.h" |
32 #include "content/common/gpu/client/gl_helper.h" | 34 #include "content/common/gpu/client/gl_helper.h" |
33 #include "content/common/gpu/client/gpu_channel_host.h" | 35 #include "content/common/gpu/client/gpu_channel_host.h" |
34 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 36 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
35 #include "content/common/gpu/gpu_process_launch_causes.h" | 37 #include "content/common/gpu/gpu_process_launch_causes.h" |
36 #include "content/public/browser/android/compositor_client.h" | 38 #include "content/public/browser/android/compositor_client.h" |
37 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 if (host_) | 265 if (host_) |
264 return host_->CompositeAndReadback(pixels, rect); | 266 return host_->CompositeAndReadback(pixels, rect); |
265 else | 267 else |
266 return false; | 268 return false; |
267 } | 269 } |
268 | 270 |
269 cc::UIResourceId CompositorImpl::GenerateUIResource( | 271 cc::UIResourceId CompositorImpl::GenerateUIResource( |
270 const cc::UIResourceBitmap& bitmap) { | 272 const cc::UIResourceBitmap& bitmap) { |
271 if (!host_) | 273 if (!host_) |
272 return 0; | 274 return 0; |
273 scoped_ptr<cc::ScopedUIResource> ui_resource = | 275 scoped_ptr<cc::UIResourceClient> ui_resource; |
274 cc::ScopedUIResource::Create(host_.get(), bitmap); | 276 cc::UIResourceId id = 0; |
275 cc::UIResourceId id = ui_resource->id(); | 277 if (bitmap.GetFormat() == cc::UIResourceBitmap::RGBA8) { |
278 scoped_ptr<cc::ScopedUIResource> scoped = | |
279 cc::ScopedUIResource::Create(host_.get(), bitmap); | |
280 id = scoped->id(); | |
281 ui_resource.reset(scoped.release()); | |
282 } else if (bitmap.GetFormat() == cc::UIResourceBitmap::ETC1) { | |
283 scoped_ptr<TransientUIResource> transient = | |
284 TransientUIResource::Create(host_.get(), bitmap); | |
285 id = transient->id(); | |
286 ui_resource.reset(transient.release()); | |
287 } else { | |
288 NOTREACHED(); | |
289 } | |
290 | |
276 ui_resource_map_.set(id, ui_resource.Pass()); | 291 ui_resource_map_.set(id, ui_resource.Pass()); |
277 return id; | 292 return id; |
278 } | 293 } |
279 | 294 |
280 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { | 295 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { |
281 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); | 296 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); |
282 if (it != ui_resource_map_.end()) | 297 if (it != ui_resource_map_.end()) |
283 ui_resource_map_.erase(it); | 298 ui_resource_map_.erase(it); |
284 } | 299 } |
285 | 300 |
286 GLuint CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { | 301 void CompositorImpl::SetNeedsCommit() { |
287 unsigned int texture_id = BuildBasicTexture(); | 302 if (host_) { |
288 gpu::gles2::GLES2Interface* gl = | 303 host_->SetNeedsCommit(); |
289 ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); | 304 } |
290 if (texture_id == 0u) | |
291 return 0u; | |
292 GLenum format = GetGLFormatForBitmap(bitmap); | |
293 GLenum type = GetGLTypeForBitmap(bitmap); | |
294 | |
295 gl->TexImage2D(GL_TEXTURE_2D, | |
296 0, | |
297 format, | |
298 bitmap.size().width(), | |
299 bitmap.size().height(), | |
300 0, | |
301 format, | |
302 type, | |
303 bitmap.pixels()); | |
304 gl->ShallowFlushCHROMIUM(); | |
305 return texture_id; | |
306 } | |
307 | |
308 GLuint CompositorImpl::GenerateCompressedTexture(gfx::Size& size, | |
309 int data_size, | |
310 void* data) { | |
311 unsigned int texture_id = BuildBasicTexture(); | |
312 gpu::gles2::GLES2Interface* gl = | |
313 ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); | |
314 if (texture_id == 0u) | |
315 return 0u; | |
316 gl->CompressedTexImage2D(GL_TEXTURE_2D, | |
317 0, | |
318 GL_ETC1_RGB8_OES, | |
319 size.width(), | |
320 size.height(), | |
321 0, | |
322 data_size, | |
323 data); | |
324 gl->ShallowFlushCHROMIUM(); | |
325 return texture_id; | |
326 } | |
327 | |
328 void CompositorImpl::DeleteTexture(GLuint texture_id) { | |
329 gpu::gles2::GLES2Interface* gl = | |
330 ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); | |
331 gl->DeleteTextures(1, &texture_id); | |
332 gl->ShallowFlushCHROMIUM(); | |
333 } | |
334 | |
335 bool CompositorImpl::CopyTextureToBitmap(GLuint texture_id, | |
336 gfx::JavaBitmap& bitmap) { | |
337 return CopyTextureToBitmap(texture_id, gfx::Rect(bitmap.size()), bitmap); | |
338 } | |
339 | |
340 bool CompositorImpl::CopyTextureToBitmap(GLuint texture_id, | |
341 const gfx::Rect& sub_rect, | |
342 gfx::JavaBitmap& bitmap) { | |
343 // The sub_rect should match the bitmap size. | |
344 DCHECK(bitmap.size() == sub_rect.size()); | |
345 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; | |
346 | |
347 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | |
348 helper->ReadbackTextureSync(texture_id, | |
349 sub_rect, | |
350 static_cast<unsigned char*> (bitmap.pixels()), | |
351 SkBitmap::kARGB_8888_Config); | |
352 return true; | |
353 } | 305 } |
354 | 306 |
355 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 307 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
356 CreateGpuProcessViewContext( | 308 CreateGpuProcessViewContext( |
357 const blink::WebGraphicsContext3D::Attributes attributes, | 309 const blink::WebGraphicsContext3D::Attributes attributes, |
358 int surface_id) { | 310 int surface_id) { |
359 BrowserGpuChannelHostFactory* factory = | 311 BrowserGpuChannelHostFactory* factory = |
360 BrowserGpuChannelHostFactory::instance(); | 312 BrowserGpuChannelHostFactory::instance(); |
361 CauseForGpuLaunch cause = | 313 CauseForGpuLaunch cause = |
362 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 314 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 void CompositorImpl::DidPostSwapBuffers() { | 388 void CompositorImpl::DidPostSwapBuffers() { |
437 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); | 389 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); |
438 client_->OnSwapBuffersPosted(); | 390 client_->OnSwapBuffersPosted(); |
439 } | 391 } |
440 | 392 |
441 void CompositorImpl::DidAbortSwapBuffers() { | 393 void CompositorImpl::DidAbortSwapBuffers() { |
442 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 394 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
443 client_->OnSwapBuffersCompleted(); | 395 client_->OnSwapBuffersCompleted(); |
444 } | 396 } |
445 | 397 |
446 GLuint CompositorImpl::BuildBasicTexture() { | 398 GLuint CompositorImpl::BuildBasicTexture() { |
no sievers
2014/01/28 20:47:21
remove this function
powei
2014/01/29 13:53:17
Done.
| |
447 gpu::gles2::GLES2Interface* gl = | 399 gpu::gles2::GLES2Interface* gl = |
448 ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); | 400 ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); |
449 GLuint texture_id = 0u; | 401 GLuint texture_id = 0u; |
450 gl->GenTextures(1, &texture_id); | 402 gl->GenTextures(1, &texture_id); |
451 gl->BindTexture(GL_TEXTURE_2D, texture_id); | 403 gl->BindTexture(GL_TEXTURE_2D, texture_id); |
452 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 404 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
453 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 405 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
454 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 406 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
455 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 407 gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
456 return texture_id; | 408 return texture_id; |
457 } | 409 } |
458 | 410 |
459 GLenum CompositorImpl::GetGLFormatForBitmap(gfx::JavaBitmap& bitmap) { | 411 GLenum CompositorImpl::GetGLFormatForBitmap(gfx::JavaBitmap& bitmap) { |
no sievers
2014/01/28 20:47:21
remove this function
powei
2014/01/29 13:53:17
Done.
| |
460 switch (bitmap.format()) { | 412 switch (bitmap.format()) { |
461 case ANDROID_BITMAP_FORMAT_A_8: | 413 case ANDROID_BITMAP_FORMAT_A_8: |
462 return GL_ALPHA; | 414 return GL_ALPHA; |
463 break; | 415 break; |
464 case ANDROID_BITMAP_FORMAT_RGBA_4444: | 416 case ANDROID_BITMAP_FORMAT_RGBA_4444: |
465 return GL_RGBA; | 417 return GL_RGBA; |
466 break; | 418 break; |
467 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 419 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
468 return GL_RGBA; | 420 return GL_RGBA; |
469 break; | 421 break; |
470 case ANDROID_BITMAP_FORMAT_RGB_565: | 422 case ANDROID_BITMAP_FORMAT_RGB_565: |
471 default: | 423 default: |
472 return GL_RGB; | 424 return GL_RGB; |
473 } | 425 } |
474 } | 426 } |
475 | 427 |
476 GLenum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) { | 428 GLenum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) { |
no sievers
2014/01/28 20:47:21
remove this function
powei
2014/01/29 13:53:17
Done.
| |
477 switch (bitmap.format()) { | 429 switch (bitmap.format()) { |
478 case ANDROID_BITMAP_FORMAT_A_8: | 430 case ANDROID_BITMAP_FORMAT_A_8: |
479 return GL_UNSIGNED_BYTE; | 431 return GL_UNSIGNED_BYTE; |
480 break; | 432 break; |
481 case ANDROID_BITMAP_FORMAT_RGBA_4444: | 433 case ANDROID_BITMAP_FORMAT_RGBA_4444: |
482 return GL_UNSIGNED_SHORT_4_4_4_4; | 434 return GL_UNSIGNED_SHORT_4_4_4_4; |
483 break; | 435 break; |
484 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 436 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
485 return GL_UNSIGNED_BYTE; | 437 return GL_UNSIGNED_BYTE; |
486 break; | 438 break; |
487 case ANDROID_BITMAP_FORMAT_RGB_565: | 439 case ANDROID_BITMAP_FORMAT_RGB_565: |
488 default: | 440 default: |
489 return GL_UNSIGNED_SHORT_5_6_5; | 441 return GL_UNSIGNED_SHORT_5_6_5; |
490 } | 442 } |
491 } | 443 } |
492 | 444 |
493 void CompositorImpl::DidCommit() { | 445 void CompositorImpl::DidCommit() { |
494 root_window_->OnCompositingDidCommit(); | 446 root_window_->OnCompositingDidCommit(); |
495 } | 447 } |
496 | 448 |
497 } // namespace content | 449 } // namespace content |
OLD | NEW |