Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 | 41 |
| 42 namespace gfx { | 42 namespace gfx { |
| 43 class JavaBitmap; | 43 class JavaBitmap; |
| 44 } | 44 } |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 // Used for drawing directly to the screen. Bypasses resizing and swaps. | 48 // Used for drawing directly to the screen. Bypasses resizing and swaps. |
| 49 class DirectOutputSurface : public cc::OutputSurface { | 49 class DirectOutputSurface : public cc::OutputSurface { |
| 50 public: | 50 public: |
| 51 DirectOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | 51 DirectOutputSurface( |
| 52 : cc::OutputSurface(context3d.Pass()) { | 52 const scoped_refptr<cc::ContextProvider>& context_provider) |
| 53 : cc::OutputSurface(context_provider) { | |
| 53 capabilities_.adjust_deadline_for_parent = false; | 54 capabilities_.adjust_deadline_for_parent = false; |
| 54 } | 55 } |
| 55 | 56 |
| 56 virtual void Reshape(gfx::Size size, float scale_factor) OVERRIDE { | 57 virtual void Reshape(gfx::Size size, float scale_factor) OVERRIDE { |
| 57 surface_size_ = size; | 58 surface_size_ = size; |
| 58 } | 59 } |
| 59 virtual void SwapBuffers(cc::CompositorFrame*) OVERRIDE { | 60 virtual void SwapBuffers(cc::CompositorFrame*) OVERRIDE { |
| 60 context3d()->shallowFlushCHROMIUM(); | 61 context_provider_->Context3d()->shallowFlushCHROMIUM(); |
| 61 } | 62 } |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 // Used to override capabilities_.adjust_deadline_for_parent to false | 65 // Used to override capabilities_.adjust_deadline_for_parent to false |
| 65 class OutputSurfaceWithoutParent : public cc::OutputSurface { | 66 class OutputSurfaceWithoutParent : public cc::OutputSurface { |
| 66 public: | 67 public: |
| 67 OutputSurfaceWithoutParent(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | 68 OutputSurfaceWithoutParent( |
| 68 : cc::OutputSurface(context3d.Pass()) { | 69 const scoped_refptr<ContextProviderCommandBuffer>& context_provider) |
| 70 : cc::OutputSurface(context_provider), | |
| 71 command_buffer_context_(context_provider->Context3d()) { | |
| 69 capabilities_.adjust_deadline_for_parent = false; | 72 capabilities_.adjust_deadline_for_parent = false; |
| 70 } | 73 } |
| 71 | 74 |
| 72 virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE { | 75 virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE { |
| 73 content::WebGraphicsContext3DCommandBufferImpl* command_buffer = | |
| 74 static_cast<content::WebGraphicsContext3DCommandBufferImpl*>(context3d()); | |
| 75 content::CommandBufferProxyImpl* command_buffer_proxy = | 76 content::CommandBufferProxyImpl* command_buffer_proxy = |
| 76 command_buffer->GetCommandBufferProxy(); | 77 command_buffer_context_->GetCommandBufferProxy(); |
| 77 DCHECK(command_buffer_proxy); | 78 DCHECK(command_buffer_proxy); |
| 78 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | 79 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
| 79 | 80 |
| 80 OutputSurface::SwapBuffers(frame); | 81 OutputSurface::SwapBuffers(frame); |
| 81 } | 82 } |
| 83 | |
| 84 private: | |
| 85 WebGraphicsContext3DCommandBufferImpl* command_buffer_context_; | |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 static bool g_initialized = false; | 88 static bool g_initialized = false; |
| 85 static base::Thread* g_impl_thread = NULL; | 89 static base::Thread* g_impl_thread = NULL; |
| 86 static bool g_use_direct_gl = false; | 90 static bool g_use_direct_gl = false; |
| 87 | 91 |
| 88 } // anonymous namespace | 92 } // anonymous namespace |
| 89 | 93 |
| 90 namespace content { | 94 namespace content { |
| 91 | 95 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 DCHECK(bitmap.size() == sub_rect.size()); | 355 DCHECK(bitmap.size() == sub_rect.size()); |
| 352 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; | 356 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; |
| 353 | 357 |
| 354 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 358 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
| 355 helper->ReadbackTextureSync(texture_id, | 359 helper->ReadbackTextureSync(texture_id, |
| 356 sub_rect, | 360 sub_rect, |
| 357 static_cast<unsigned char*> (bitmap.pixels())); | 361 static_cast<unsigned char*> (bitmap.pixels())); |
| 358 return true; | 362 return true; |
| 359 } | 363 } |
| 360 | 364 |
| 365 static scoped_ptr<WebKit::WebGraphicsContext3D> CreateInProcessViewContext( | |
| 366 const WebKit::WebGraphicsContext3D::Attributes attributes | |
| 367 ANativeWindow* window) { | |
| 368 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
| 369 return WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | |
| 370 attributes, window).PassAs<WebKit::WebGraphicsContext3D>(); | |
| 371 } | |
| 372 | |
| 373 static scoped_ptr<WebKit::WebGraphicsContext3D> CreateGpuProcessViewContext( | |
| 374 const WebKit::WebGraphicsContext3D::Attributes attributes | |
| 375 int surface_id) { | |
| 376 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); | |
| 377 GURL url("chrome://gpu/Compositor::createContext3D"); | |
| 378 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | |
| 379 new WebGraphicsContext3DCommandBufferImpl(surface_id_, | |
| 380 url, | |
| 381 factory, | |
| 382 weak_factory_.GetWeakPtr())); | |
| 383 static const size_t kBytesPerPixel = 4; | |
| 384 gfx::DeviceDisplayInfo display_info; | |
| 385 size_t full_screen_texture_size_in_bytes = | |
| 386 display_info.GetDisplayHeight() * | |
| 387 display_info.GetDisplayWidth() * | |
| 388 kBytesPerPixel; | |
| 389 if (!context->Initialize( | |
| 390 attrs, | |
| 391 false, | |
| 392 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, | |
| 393 64 * 1024, // command buffer size | |
| 394 std::min(full_screen_texture_size_in_bytes, | |
| 395 kDefaultStartTransferBufferSize), | |
| 396 kDefaultMinTransferBufferSize, | |
| 397 std::min(3 * full_screen_texture_size_in_bytes, | |
| 398 kDefaultMaxTransferBufferSize))) { | |
| 399 LOG(ERROR) << "Failed to create 3D context for compositor."; | |
| 400 return scoped_ptr<WebKit::WebGraphicsContext3D>(); | |
| 401 } | |
| 402 return context.PassAs<WebKit::WebGraphicsContext3D>(); | |
| 403 } | |
| 404 | |
| 361 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 405 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
| 362 bool fallback) { | 406 bool fallback) { |
| 363 WebKit::WebGraphicsContext3D::Attributes attrs; | 407 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 364 attrs.shareResources = true; | 408 attrs.shareResources = true; |
| 365 attrs.noAutomaticFlushes = true; | 409 attrs.noAutomaticFlushes = true; |
| 366 | 410 |
| 367 if (g_use_direct_gl) { | 411 if (g_use_direct_gl) { |
| 368 scoped_ptr<WebKit::WebGraphicsContext3D> context( | 412 scoped_refptr<webkit::gpu::ContextProviderInProcess> context_provider = |
| 369 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl:: | 413 webkit::gpu::ContextProviderInProcess::Create( |
| 370 CreateViewContext(attrs, window_)); | 414 base::Bind(&CreateInProcessViewContext, attrs, window_)); |
| 371 if (!window_) { | |
| 372 return scoped_ptr<cc::OutputSurface>( | |
| 373 new DirectOutputSurface(context.Pass())); | |
| 374 } | |
| 375 | 415 |
| 376 return make_scoped_ptr(new cc::OutputSurface(context.Pass())); | 416 scoped_ptr<cc::OutputSurface> output_surface; |
| 377 } else { | 417 if (!window_) |
| 378 DCHECK(window_ && surface_id_); | 418 output_surface.reset(new DirectOutputSurface(context_provider)); |
| 379 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); | 419 else |
| 380 GURL url("chrome://gpu/Compositor::createContext3D"); | 420 output_surface.reset(new cc::OutputSurface(context_provider)); |
| 381 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 421 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 } | 422 } |
| 423 | |
| 424 DCHECK(window_ && surface_id_); | |
|
aelias_OOO_until_Jul13
2013/08/14 21:44:10
nit: split into two DCHECKs
danakj
2013/08/14 21:46:07
Absolutely.
| |
| 425 | |
| 426 scoped_refptr<ContextProviderCommandBuffer> context_provider = | |
| 427 ContextProviderCommandBuffer::Create( | |
| 428 base::Bind(&CreateGpuProcessViewContext, attrs, surface_id_)); | |
| 429 if (!context_provider.get()) { | |
| 430 LOG(ERROR) << "Failed to create 3D context for compositor."; | |
| 431 return scoped_ptr<cc::OutputSurface>(); | |
| 432 } | |
| 433 return scoped_ptr<cc::OutputSurface>( | |
| 434 new OutputSurfaceWithoutParent(context_provider)); | |
| 409 } | 435 } |
| 410 | 436 |
| 411 void CompositorImpl::OnLostResources() { | 437 void CompositorImpl::OnLostResources() { |
| 412 client_->DidLoseResources(); | 438 client_->DidLoseResources(); |
| 413 } | 439 } |
| 414 | 440 |
| 415 void CompositorImpl::DidCompleteSwapBuffers() { | 441 void CompositorImpl::DidCompleteSwapBuffers() { |
| 416 client_->OnSwapBuffersCompleted(); | 442 client_->OnSwapBuffersCompleted(); |
| 417 } | 443 } |
| 418 | 444 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 523 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 498 return GL_UNSIGNED_BYTE; | 524 return GL_UNSIGNED_BYTE; |
| 499 break; | 525 break; |
| 500 case ANDROID_BITMAP_FORMAT_RGB_565: | 526 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 501 default: | 527 default: |
| 502 return GL_UNSIGNED_SHORT_5_6_5; | 528 return GL_UNSIGNED_SHORT_5_6_5; |
| 503 } | 529 } |
| 504 } | 530 } |
| 505 | 531 |
| 506 } // namespace content | 532 } // namespace content |
| OLD | NEW |