OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor/delegated_frame_host.h" | 5 #include "content/browser/compositor/delegated_frame_host.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 void DelegatedFrameHost::RequestCopyOfOutput( | 114 void DelegatedFrameHost::RequestCopyOfOutput( |
115 scoped_ptr<cc::CopyOutputRequest> request) { | 115 scoped_ptr<cc::CopyOutputRequest> request) { |
116 client_->GetLayer()->RequestCopyOfOutput(request.Pass()); | 116 client_->GetLayer()->RequestCopyOfOutput(request.Pass()); |
117 } | 117 } |
118 | 118 |
119 void DelegatedFrameHost::CopyFromCompositingSurface( | 119 void DelegatedFrameHost::CopyFromCompositingSurface( |
120 const gfx::Rect& src_subrect, | 120 const gfx::Rect& src_subrect, |
121 const gfx::Size& dst_size, | 121 const gfx::Size& dst_size, |
122 const base::Callback<void(bool, const SkBitmap&)>& callback, | 122 const base::Callback<void(bool, const SkBitmap&)>& callback, |
123 const SkBitmap::Config config) { | 123 const SkColorType color_type) { |
124 // Only ARGB888 and RGB565 supported as of now. | 124 // Only ARGB888 and RGB565 supported as of now. |
125 bool format_support = ((config == SkBitmap::kRGB_565_Config) || | 125 bool format_support = ((color_type == kRGB_565_SkColorType) || |
126 (config == SkBitmap::kARGB_8888_Config)); | 126 (color_type == kN32_SkColorType)); |
127 DCHECK(format_support); | 127 DCHECK(format_support); |
128 if (!CanCopyToBitmap()) { | 128 if (!CanCopyToBitmap()) { |
129 callback.Run(false, SkBitmap()); | 129 callback.Run(false, SkBitmap()); |
130 return; | 130 return; |
131 } | 131 } |
132 | 132 |
133 const gfx::Size& dst_size_in_pixel = | 133 const gfx::Size& dst_size_in_pixel = |
134 client_->ConvertViewSizeToPixel(dst_size); | 134 client_->ConvertViewSizeToPixel(dst_size); |
135 scoped_ptr<cc::CopyOutputRequest> request = | 135 scoped_ptr<cc::CopyOutputRequest> request = |
136 cc::CopyOutputRequest::CreateRequest(base::Bind( | 136 cc::CopyOutputRequest::CreateRequest(base::Bind( |
137 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, | 137 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, |
138 dst_size_in_pixel, | 138 dst_size_in_pixel, |
139 config, | 139 color_type, |
140 callback)); | 140 callback)); |
141 gfx::Rect src_subrect_in_pixel = | 141 gfx::Rect src_subrect_in_pixel = |
142 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect); | 142 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect); |
143 request->set_area(src_subrect_in_pixel); | 143 request->set_area(src_subrect_in_pixel); |
144 client_->RequestCopyOfOutput(request.Pass()); | 144 client_->RequestCopyOfOutput(request.Pass()); |
145 } | 145 } |
146 | 146 |
147 void DelegatedFrameHost::CopyFromCompositingSurfaceToVideoFrame( | 147 void DelegatedFrameHost::CopyFromCompositingSurfaceToVideoFrame( |
148 const gfx::Rect& src_subrect, | 148 const gfx::Rect& src_subrect, |
149 const scoped_refptr<media::VideoFrame>& target, | 149 const scoped_refptr<media::VideoFrame>& target, |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 422 |
423 void DelegatedFrameHost::EvictDelegatedFrame() { | 423 void DelegatedFrameHost::EvictDelegatedFrame() { |
424 client_->GetLayer()->SetShowPaintedContent(); | 424 client_->GetLayer()->SetShowPaintedContent(); |
425 frame_provider_ = NULL; | 425 frame_provider_ = NULL; |
426 delegated_frame_evictor_->DiscardedFrame(); | 426 delegated_frame_evictor_->DiscardedFrame(); |
427 } | 427 } |
428 | 428 |
429 // static | 429 // static |
430 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( | 430 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( |
431 const gfx::Size& dst_size_in_pixel, | 431 const gfx::Size& dst_size_in_pixel, |
432 const SkBitmap::Config config, | 432 const SkColorType color_type, |
433 const base::Callback<void(bool, const SkBitmap&)>& callback, | 433 const base::Callback<void(bool, const SkBitmap&)>& callback, |
434 scoped_ptr<cc::CopyOutputResult> result) { | 434 scoped_ptr<cc::CopyOutputResult> result) { |
435 if (result->IsEmpty() || result->size().IsEmpty()) { | 435 if (result->IsEmpty() || result->size().IsEmpty()) { |
436 callback.Run(false, SkBitmap()); | 436 callback.Run(false, SkBitmap()); |
437 return; | 437 return; |
438 } | 438 } |
439 | 439 |
440 if (result->HasTexture()) { | 440 if (result->HasTexture()) { |
441 PrepareTextureCopyOutputResult(dst_size_in_pixel, config, | 441 PrepareTextureCopyOutputResult(dst_size_in_pixel, color_type, |
442 callback, | 442 callback, |
443 result.Pass()); | 443 result.Pass()); |
444 return; | 444 return; |
445 } | 445 } |
446 | 446 |
447 DCHECK(result->HasBitmap()); | 447 DCHECK(result->HasBitmap()); |
448 PrepareBitmapCopyOutputResult(dst_size_in_pixel, config, callback, | 448 PrepareBitmapCopyOutputResult(dst_size_in_pixel, color_type, callback, |
449 result.Pass()); | 449 result.Pass()); |
450 } | 450 } |
451 | 451 |
452 static void CopyFromCompositingSurfaceFinished( | 452 static void CopyFromCompositingSurfaceFinished( |
453 const base::Callback<void(bool, const SkBitmap&)>& callback, | 453 const base::Callback<void(bool, const SkBitmap&)>& callback, |
454 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 454 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
455 scoped_ptr<SkBitmap> bitmap, | 455 scoped_ptr<SkBitmap> bitmap, |
456 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 456 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
457 bool result) { | 457 bool result) { |
458 bitmap_pixels_lock.reset(); | 458 bitmap_pixels_lock.reset(); |
459 | 459 |
460 uint32 sync_point = 0; | 460 uint32 sync_point = 0; |
461 if (result) { | 461 if (result) { |
462 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 462 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
463 sync_point = gl_helper->InsertSyncPoint(); | 463 sync_point = gl_helper->InsertSyncPoint(); |
464 } | 464 } |
465 bool lost_resource = sync_point == 0; | 465 bool lost_resource = sync_point == 0; |
466 release_callback->Run(sync_point, lost_resource); | 466 release_callback->Run(sync_point, lost_resource); |
467 | 467 |
468 callback.Run(result, *bitmap); | 468 callback.Run(result, *bitmap); |
469 } | 469 } |
470 | 470 |
471 // static | 471 // static |
472 void DelegatedFrameHost::PrepareTextureCopyOutputResult( | 472 void DelegatedFrameHost::PrepareTextureCopyOutputResult( |
473 const gfx::Size& dst_size_in_pixel, | 473 const gfx::Size& dst_size_in_pixel, |
474 const SkBitmap::Config config, | 474 const SkColorType color_type, |
475 const base::Callback<void(bool, const SkBitmap&)>& callback, | 475 const base::Callback<void(bool, const SkBitmap&)>& callback, |
476 scoped_ptr<cc::CopyOutputResult> result) { | 476 scoped_ptr<cc::CopyOutputResult> result) { |
477 DCHECK(result->HasTexture()); | 477 DCHECK(result->HasTexture()); |
478 base::ScopedClosureRunner scoped_callback_runner( | 478 base::ScopedClosureRunner scoped_callback_runner( |
479 base::Bind(callback, false, SkBitmap())); | 479 base::Bind(callback, false, SkBitmap())); |
480 | 480 |
481 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 481 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
482 SkColorType color_type = SkBitmapConfigToColorType(config); | |
483 if (!bitmap->allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 482 if (!bitmap->allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), |
484 dst_size_in_pixel.height(), | 483 dst_size_in_pixel.height(), |
485 color_type, | 484 color_type, |
486 kOpaque_SkAlphaType))) | 485 kOpaque_SkAlphaType))) |
487 return; | 486 return; |
488 | 487 |
489 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 488 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
490 GLHelper* gl_helper = factory->GetGLHelper(); | 489 GLHelper* gl_helper = factory->GetGLHelper(); |
491 if (!gl_helper) | 490 if (!gl_helper) |
492 return; | 491 return; |
493 | 492 |
494 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 493 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
495 new SkAutoLockPixels(*bitmap)); | 494 new SkAutoLockPixels(*bitmap)); |
496 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 495 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
497 | 496 |
498 cc::TextureMailbox texture_mailbox; | 497 cc::TextureMailbox texture_mailbox; |
499 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 498 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
500 result->TakeTexture(&texture_mailbox, &release_callback); | 499 result->TakeTexture(&texture_mailbox, &release_callback); |
501 DCHECK(texture_mailbox.IsTexture()); | 500 DCHECK(texture_mailbox.IsTexture()); |
502 | 501 |
503 ignore_result(scoped_callback_runner.Release()); | 502 ignore_result(scoped_callback_runner.Release()); |
504 | 503 |
505 gl_helper->CropScaleReadbackAndCleanMailbox( | 504 gl_helper->CropScaleReadbackAndCleanMailbox( |
506 texture_mailbox.mailbox(), | 505 texture_mailbox.mailbox(), |
507 texture_mailbox.sync_point(), | 506 texture_mailbox.sync_point(), |
508 result->size(), | 507 result->size(), |
509 gfx::Rect(result->size()), | 508 gfx::Rect(result->size()), |
510 dst_size_in_pixel, | 509 dst_size_in_pixel, |
511 pixels, | 510 pixels, |
512 config, | 511 color_type, |
513 base::Bind(&CopyFromCompositingSurfaceFinished, | 512 base::Bind(&CopyFromCompositingSurfaceFinished, |
514 callback, | 513 callback, |
515 base::Passed(&release_callback), | 514 base::Passed(&release_callback), |
516 base::Passed(&bitmap), | 515 base::Passed(&bitmap), |
517 base::Passed(&bitmap_pixels_lock)), | 516 base::Passed(&bitmap_pixels_lock)), |
518 GLHelper::SCALER_QUALITY_FAST); | 517 GLHelper::SCALER_QUALITY_FAST); |
519 } | 518 } |
520 | 519 |
521 // static | 520 // static |
522 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( | 521 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( |
523 const gfx::Size& dst_size_in_pixel, | 522 const gfx::Size& dst_size_in_pixel, |
524 const SkBitmap::Config config, | 523 const SkColorType color_type, |
525 const base::Callback<void(bool, const SkBitmap&)>& callback, | 524 const base::Callback<void(bool, const SkBitmap&)>& callback, |
526 scoped_ptr<cc::CopyOutputResult> result) { | 525 scoped_ptr<cc::CopyOutputResult> result) { |
527 if (config != SkBitmap::kARGB_8888_Config) { | 526 if (color_type != kN32_SkColorType) { |
528 NOTIMPLEMENTED(); | 527 NOTIMPLEMENTED(); |
529 callback.Run(false, SkBitmap()); | 528 callback.Run(false, SkBitmap()); |
530 return; | 529 return; |
531 } | 530 } |
532 DCHECK(result->HasBitmap()); | 531 DCHECK(result->HasBitmap()); |
533 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | 532 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
534 DCHECK(source); | 533 DCHECK(source); |
535 SkBitmap bitmap = skia::ImageOperations::Resize( | 534 SkBitmap bitmap = skia::ImageOperations::Resize( |
536 *source, | 535 *source, |
537 skia::ImageOperations::RESIZE_BEST, | 536 skia::ImageOperations::RESIZE_BEST, |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 // that should keep our frame. old_layer will be returned to the | 843 // that should keep our frame. old_layer will be returned to the |
845 // RecreateLayer caller, and should have a copy. | 844 // RecreateLayer caller, and should have a copy. |
846 if (frame_provider_.get()) { | 845 if (frame_provider_.get()) { |
847 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 846 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
848 current_frame_size_in_dip_); | 847 current_frame_size_in_dip_); |
849 } | 848 } |
850 } | 849 } |
851 | 850 |
852 } // namespace content | 851 } // namespace content |
853 | 852 |
OLD | NEW |