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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkBitmap::Config config) { |
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 = ((config == SkBitmap::kRGB_565_Config) || |
126 (config == SkBitmap::kARGB_8888_Config)); | 126 (config == SkBitmap::kARGB_8888_Config)); |
127 if (!format_support) { | 127 DCHECK(format_support); |
128 DCHECK(format_support); | |
129 callback.Run(false, SkBitmap()); | |
130 return; | |
131 } | |
132 if (!CanCopyToBitmap()) { | 128 if (!CanCopyToBitmap()) { |
133 callback.Run(false, SkBitmap()); | 129 callback.Run(false, SkBitmap()); |
134 return; | 130 return; |
135 } | 131 } |
136 | 132 |
137 const gfx::Size& dst_size_in_pixel = client_->ConvertViewSizeToPixel( | 133 const gfx::Size& dst_size_in_pixel = |
138 dst_size); | 134 client_->ConvertViewSizeToPixel(dst_size); |
139 scoped_ptr<cc::CopyOutputRequest> request = | 135 scoped_ptr<cc::CopyOutputRequest> request = |
140 cc::CopyOutputRequest::CreateRequest(base::Bind( | 136 cc::CopyOutputRequest::CreateRequest(base::Bind( |
141 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, | 137 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, |
142 dst_size_in_pixel, | 138 dst_size_in_pixel, |
143 config, | 139 config, |
144 callback)); | 140 callback)); |
145 gfx::Rect src_subrect_in_pixel = | 141 gfx::Rect src_subrect_in_pixel = |
146 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect); | 142 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect); |
147 request->set_area(src_subrect_in_pixel); | 143 request->set_area(src_subrect_in_pixel); |
148 client_->RequestCopyOfOutput(request.Pass()); | 144 client_->RequestCopyOfOutput(request.Pass()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 264 } |
269 } | 265 } |
270 } | 266 } |
271 | 267 |
272 void DelegatedFrameHost::SwapDelegatedFrame( | 268 void DelegatedFrameHost::SwapDelegatedFrame( |
273 uint32 output_surface_id, | 269 uint32 output_surface_id, |
274 scoped_ptr<cc::DelegatedFrameData> frame_data, | 270 scoped_ptr<cc::DelegatedFrameData> frame_data, |
275 float frame_device_scale_factor, | 271 float frame_device_scale_factor, |
276 const std::vector<ui::LatencyInfo>& latency_info) { | 272 const std::vector<ui::LatencyInfo>& latency_info) { |
277 RenderWidgetHostImpl* host = client_->GetHost(); | 273 RenderWidgetHostImpl* host = client_->GetHost(); |
278 DCHECK_NE(0u, frame_data->render_pass_list.size()); | 274 DCHECK(!frame_data->render_pass_list.empty()); |
279 | 275 |
280 cc::RenderPass* root_pass = frame_data->render_pass_list.back(); | 276 cc::RenderPass* root_pass = frame_data->render_pass_list.back(); |
281 | 277 |
282 gfx::Size frame_size = root_pass->output_rect.size(); | 278 gfx::Size frame_size = root_pass->output_rect.size(); |
283 gfx::Size frame_size_in_dip = | 279 gfx::Size frame_size_in_dip = |
284 ConvertSizeToDIP(frame_device_scale_factor, frame_size); | 280 ConvertSizeToDIP(frame_device_scale_factor, frame_size); |
285 | 281 |
286 gfx::Rect damage_rect = gfx::ToEnclosingRect(root_pass->damage_rect); | 282 gfx::Rect damage_rect = gfx::ToEnclosingRect(root_pass->damage_rect); |
287 damage_rect.Intersect(gfx::Rect(frame_size)); | 283 damage_rect.Intersect(gfx::Rect(frame_size)); |
288 gfx::Rect damage_rect_in_dip = | 284 gfx::Rect damage_rect_in_dip = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 resource_collection_->SetClient(NULL); | 325 resource_collection_->SetClient(NULL); |
330 | 326 |
331 if (resource_collection_->LoseAllResources()) | 327 if (resource_collection_->LoseAllResources()) |
332 SendReturnedDelegatedResources(last_output_surface_id_); | 328 SendReturnedDelegatedResources(last_output_surface_id_); |
333 | 329 |
334 resource_collection_ = NULL; | 330 resource_collection_ = NULL; |
335 } | 331 } |
336 last_output_surface_id_ = output_surface_id; | 332 last_output_surface_id_ = output_surface_id; |
337 } | 333 } |
338 if (frame_size.IsEmpty()) { | 334 if (frame_size.IsEmpty()) { |
339 DCHECK_EQ(0u, frame_data->resource_list.size()); | 335 DCHECK(frame_data->resource_list.empty()); |
340 EvictDelegatedFrame(); | 336 EvictDelegatedFrame(); |
341 } else { | 337 } else { |
342 if (!resource_collection_) { | 338 if (!resource_collection_) { |
343 resource_collection_ = new cc::DelegatedFrameResourceCollection; | 339 resource_collection_ = new cc::DelegatedFrameResourceCollection; |
344 resource_collection_->SetClient(this); | 340 resource_collection_->SetClient(this); |
345 } | 341 } |
346 // If the physical frame size changes, we need a new |frame_provider_|. If | 342 // If the physical frame size changes, we need a new |frame_provider_|. If |
347 // the physical frame size is the same, but the size in DIP changed, we | 343 // the physical frame size is the same, but the size in DIP changed, we |
348 // need to adjust the scale at which the frames will be drawn, and we do | 344 // need to adjust the scale at which the frames will be drawn, and we do |
349 // this by making a new |frame_provider_| also to ensure the scale change | 345 // this by making a new |frame_provider_| also to ensure the scale change |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 return; | 493 return; |
498 | 494 |
499 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 495 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
500 new SkAutoLockPixels(*bitmap)); | 496 new SkAutoLockPixels(*bitmap)); |
501 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 497 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
502 | 498 |
503 cc::TextureMailbox texture_mailbox; | 499 cc::TextureMailbox texture_mailbox; |
504 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 500 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
505 result->TakeTexture(&texture_mailbox, &release_callback); | 501 result->TakeTexture(&texture_mailbox, &release_callback); |
506 DCHECK(texture_mailbox.IsTexture()); | 502 DCHECK(texture_mailbox.IsTexture()); |
507 if (!texture_mailbox.IsTexture()) | |
508 return; | |
509 | 503 |
510 ignore_result(scoped_callback_runner.Release()); | 504 ignore_result(scoped_callback_runner.Release()); |
511 | 505 |
512 gl_helper->CropScaleReadbackAndCleanMailbox( | 506 gl_helper->CropScaleReadbackAndCleanMailbox( |
513 texture_mailbox.mailbox(), | 507 texture_mailbox.mailbox(), |
514 texture_mailbox.sync_point(), | 508 texture_mailbox.sync_point(), |
515 result->size(), | 509 result->size(), |
516 gfx::Rect(result->size()), | 510 gfx::Rect(result->size()), |
517 dst_size_in_pixel, | 511 dst_size_in_pixel, |
518 pixels, | 512 pixels, |
(...skipping 11 matching lines...) Expand all Loading... |
530 const gfx::Size& dst_size_in_pixel, | 524 const gfx::Size& dst_size_in_pixel, |
531 const SkBitmap::Config config, | 525 const SkBitmap::Config config, |
532 const base::Callback<void(bool, const SkBitmap&)>& callback, | 526 const base::Callback<void(bool, const SkBitmap&)>& callback, |
533 scoped_ptr<cc::CopyOutputResult> result) { | 527 scoped_ptr<cc::CopyOutputResult> result) { |
534 if (config != SkBitmap::kARGB_8888_Config) { | 528 if (config != SkBitmap::kARGB_8888_Config) { |
535 NOTIMPLEMENTED(); | 529 NOTIMPLEMENTED(); |
536 callback.Run(false, SkBitmap()); | 530 callback.Run(false, SkBitmap()); |
537 return; | 531 return; |
538 } | 532 } |
539 DCHECK(result->HasBitmap()); | 533 DCHECK(result->HasBitmap()); |
540 base::ScopedClosureRunner scoped_callback_runner( | |
541 base::Bind(callback, false, SkBitmap())); | |
542 | |
543 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | 534 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
544 DCHECK(source); | 535 DCHECK(source); |
545 if (!source) | |
546 return; | |
547 | |
548 ignore_result(scoped_callback_runner.Release()); | |
549 | |
550 SkBitmap bitmap = skia::ImageOperations::Resize( | 536 SkBitmap bitmap = skia::ImageOperations::Resize( |
551 *source, | 537 *source, |
552 skia::ImageOperations::RESIZE_BEST, | 538 skia::ImageOperations::RESIZE_BEST, |
553 dst_size_in_pixel.width(), | 539 dst_size_in_pixel.width(), |
554 dst_size_in_pixel.height()); | 540 dst_size_in_pixel.height()); |
555 callback.Run(true, bitmap); | 541 callback.Run(true, bitmap); |
556 } | 542 } |
557 | 543 |
558 // static | 544 // static |
559 void DelegatedFrameHost::ReturnSubscriberTexture( | 545 void DelegatedFrameHost::ReturnSubscriberTexture( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 GLHelper* gl_helper = factory->GetGLHelper(); | 652 GLHelper* gl_helper = factory->GetGLHelper(); |
667 if (!gl_helper) | 653 if (!gl_helper) |
668 return; | 654 return; |
669 if (subscriber_texture.get() && !subscriber_texture->texture_id()) | 655 if (subscriber_texture.get() && !subscriber_texture->texture_id()) |
670 return; | 656 return; |
671 | 657 |
672 cc::TextureMailbox texture_mailbox; | 658 cc::TextureMailbox texture_mailbox; |
673 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 659 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
674 result->TakeTexture(&texture_mailbox, &release_callback); | 660 result->TakeTexture(&texture_mailbox, &release_callback); |
675 DCHECK(texture_mailbox.IsTexture()); | 661 DCHECK(texture_mailbox.IsTexture()); |
676 if (!texture_mailbox.IsTexture()) | |
677 return; | |
678 | 662 |
679 gfx::Rect result_rect(result->size()); | 663 gfx::Rect result_rect(result->size()); |
680 | 664 |
681 content::ReadbackYUVInterface* yuv_readback_pipeline = | 665 content::ReadbackYUVInterface* yuv_readback_pipeline = |
682 dfh->yuv_readback_pipeline_.get(); | 666 dfh->yuv_readback_pipeline_.get(); |
683 if (yuv_readback_pipeline == NULL || | 667 if (yuv_readback_pipeline == NULL || |
684 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || | 668 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || |
685 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || | 669 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || |
686 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { | 670 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { |
687 GLHelper::ScalerQuality quality = GLHelper::SCALER_QUALITY_FAST; | 671 GLHelper::ScalerQuality quality = GLHelper::SCALER_QUALITY_FAST; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 // that should keep our frame. old_layer will be returned to the | 860 // that should keep our frame. old_layer will be returned to the |
877 // RecreateLayer caller, and should have a copy. | 861 // RecreateLayer caller, and should have a copy. |
878 if (frame_provider_.get()) { | 862 if (frame_provider_.get()) { |
879 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 863 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
880 current_frame_size_in_dip_); | 864 current_frame_size_in_dip_); |
881 } | 865 } |
882 } | 866 } |
883 | 867 |
884 } // namespace content | 868 } // namespace content |
885 | 869 |
OLD | NEW |