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 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 DCHECK(bitmap.size() == sub_rect.size()); | 351 DCHECK(bitmap.size() == sub_rect.size()); |
352 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; | 352 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; |
353 | 353 |
354 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 354 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
355 helper->ReadbackTextureSync(texture_id, | 355 helper->ReadbackTextureSync(texture_id, |
356 sub_rect, | 356 sub_rect, |
357 static_cast<unsigned char*> (bitmap.pixels())); | 357 static_cast<unsigned char*> (bitmap.pixels())); |
358 return true; | 358 return true; |
359 } | 359 } |
360 | 360 |
361 static scoped_ptr<WebKit::WebGraphicsContext3D> CreateInProcessViewContext( | |
362 const WebKit::WebGraphicsContext3D::Attributes attributes | |
363 ANativeWindow* window) { | |
364 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
365 return WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | |
366 attributes, window).PassAs<WebKit::WebGraphicsContext3D>(); | |
367 } | |
368 | |
369 static scoped_ptr<WebKit::WebGraphicsContext3D> CreateGpuProcessViewContext( | |
370 const WebKit::WebGraphicsContext3D::Attributes attributes | |
371 int surface_id) { | |
372 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); | |
373 GURL url("chrome://gpu/Compositor::createContext3D"); | |
374 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | |
375 new WebGraphicsContext3DCommandBufferImpl(surface_id_, | |
376 url, | |
377 factory, | |
378 weak_factory_.GetWeakPtr())); | |
379 static const size_t kBytesPerPixel = 4; | |
380 gfx::DeviceDisplayInfo display_info; | |
381 size_t full_screen_texture_size_in_bytes = | |
382 display_info.GetDisplayHeight() * | |
383 display_info.GetDisplayWidth() * | |
384 kBytesPerPixel; | |
385 if (!context->Initialize( | |
386 attrs, | |
387 false, | |
388 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, | |
389 64 * 1024, // command buffer size | |
390 std::min(full_screen_texture_size_in_bytes, | |
391 kDefaultStartTransferBufferSize), | |
392 kDefaultMinTransferBufferSize, | |
393 std::min(3 * full_screen_texture_size_in_bytes, | |
394 kDefaultMaxTransferBufferSize))) { | |
395 LOG(ERROR) << "Failed to create 3D context for compositor."; | |
396 return scoped_ptr<WebKit::WebGraphicsContext3D>(); | |
397 } | |
398 return context.PassAs<WebKit::WebGraphicsContext3D>(); | |
399 } | |
400 | |
361 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 401 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
362 bool fallback) { | 402 bool fallback) { |
363 WebKit::WebGraphicsContext3D::Attributes attrs; | 403 WebKit::WebGraphicsContext3D::Attributes attrs; |
364 attrs.shareResources = true; | 404 attrs.shareResources = true; |
365 attrs.noAutomaticFlushes = true; | 405 attrs.noAutomaticFlushes = true; |
366 | 406 |
367 if (g_use_direct_gl) { | 407 if (g_use_direct_gl) { |
368 scoped_ptr<WebKit::WebGraphicsContext3D> context( | 408 scoped_refptr<webkit::gpu::ContextProviderInProcess> context_provider = |
369 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl:: | 409 webkit::gpu::ContextProviderInProcess::Create( |
370 CreateViewContext(attrs, window_)); | 410 base::Bind(&CreateInProcessViewContext, attrs, window_)); |
371 if (!window_) { | |
372 return scoped_ptr<cc::OutputSurface>( | |
373 new DirectOutputSurface(context.Pass())); | |
374 } | |
375 | 411 |
376 return make_scoped_ptr(new cc::OutputSurface(context.Pass())); | 412 scoped_ptr<cc::OutputSurface> output_surface; |
377 } else { | 413 if (!window_) |
378 DCHECK(window_ && surface_id_); | 414 output_surface.reset(new DirectOutputSurface(context_provider)); |
379 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); | 415 else |
380 GURL url("chrome://gpu/Compositor::createContext3D"); | 416 output_surface.reset(new cc::OutputSurface(context_provider)); |
381 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 417 return output_surface.Pass(); |
382 new WebGraphicsContext3DCommandBufferImpl(surface_id_, | |
383 url, | |
384 factory, | |
385 weak_factory_.GetWeakPtr())); | |
386 static const size_t kBytesPerPixel = 4; | |
387 gfx::DeviceDisplayInfo display_info; | |
388 size_t full_screen_texture_size_in_bytes = | |
389 display_info.GetDisplayHeight() * | |
390 display_info.GetDisplayWidth() * | |
391 kBytesPerPixel; | |
392 if (!context->Initialize( | |
393 attrs, | |
394 false, | |
395 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, | |
396 64 * 1024, // command buffer size | |
397 std::min(full_screen_texture_size_in_bytes, | |
398 kDefaultStartTransferBufferSize), | |
399 kDefaultMinTransferBufferSize, | |
400 std::min(3 * full_screen_texture_size_in_bytes, | |
401 kDefaultMaxTransferBufferSize))) { | |
402 LOG(ERROR) << "Failed to create 3D context for compositor."; | |
403 return scoped_ptr<cc::OutputSurface>(); | |
404 } | |
405 return scoped_ptr<cc::OutputSurface>( | |
406 new OutputSurfaceWithoutParent( | |
407 context.PassAs<WebKit::WebGraphicsContext3D>())); | |
408 } | 418 } |
419 | |
420 DCHECK(window_ && surface_id_); | |
421 | |
422 scoped_refptr<ContextProviderCommandBuffer> context_provider = | |
423 ContextProviderCommandBuffer::Create( | |
424 base::Bind(&CreateGpuProcessViewContext, attrs, surface_id_)); | |
425 if (!context_provider.get()) { | |
426 LOG(ERROR) << "Failed to create 3D context for compositor."; | |
427 return scoped_ptr<cc::OutputSurface>(); | |
428 } | |
429 return scoped_ptr<cc::OutputSurface>( | |
no sievers
2013/08/14 20:41:05
Do you need to adjust the constructors for OutputS
danakj
2013/08/14 20:59:35
Oh yes, thanks. Can't get local android checkout t
danakj
2013/08/14 21:06:47
Done.
| |
430 new OutputSurfaceWithoutParent(context_provider)); | |
409 } | 431 } |
410 | 432 |
411 void CompositorImpl::OnLostResources() { | 433 void CompositorImpl::OnLostResources() { |
412 client_->DidLoseResources(); | 434 client_->DidLoseResources(); |
413 } | 435 } |
414 | 436 |
415 void CompositorImpl::DidCompleteSwapBuffers() { | 437 void CompositorImpl::DidCompleteSwapBuffers() { |
416 client_->OnSwapBuffersCompleted(); | 438 client_->OnSwapBuffersCompleted(); |
417 } | 439 } |
418 | 440 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 519 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
498 return GL_UNSIGNED_BYTE; | 520 return GL_UNSIGNED_BYTE; |
499 break; | 521 break; |
500 case ANDROID_BITMAP_FORMAT_RGB_565: | 522 case ANDROID_BITMAP_FORMAT_RGB_565: |
501 default: | 523 default: |
502 return GL_UNSIGNED_SHORT_5_6_5; | 524 return GL_UNSIGNED_SHORT_5_6_5; |
503 } | 525 } |
504 } | 526 } |
505 | 527 |
506 } // namespace content | 528 } // namespace content |
OLD | NEW |