Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: content/browser/compositor/delegated_frame_host.cc

Issue 384453002: wip: Improving GestureNav screenshotting performance Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "cc/output/copy_output_request.h" 11 #include "cc/output/copy_output_request.h"
12 #include "cc/resources/single_release_callback.h" 12 #include "cc/resources/single_release_callback.h"
13 #include "cc/resources/texture_mailbox.h" 13 #include "cc/resources/texture_mailbox.h"
14 #include "content/browser/compositor/resize_lock.h" 14 #include "content/browser/compositor/resize_lock.h"
15 #include "content/common/gpu/client/gl_helper.h" 15 #include "content/common/gpu/client/gl_helper.h"
16 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 16 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
17 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
18 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
19 #include "media/base/video_util.h" 19 #include "media/base/video_util.h"
20 #include "skia/ext/image_operations.h" 20 #include "skia/ext/image_operations.h"
21 #include "third_party/skia/include/core/SkCanvas.h"
22 #include "third_party/skia/include/core/SkPaint.h"
23 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
24
21 25
22 namespace content { 26 namespace content {
23 27
24 //////////////////////////////////////////////////////////////////////////////// 28 ////////////////////////////////////////////////////////////////////////////////
25 // DelegatedFrameHostClient 29 // DelegatedFrameHostClient
26 30
27 bool DelegatedFrameHostClient::ShouldCreateResizeLock() { 31 bool DelegatedFrameHostClient::ShouldCreateResizeLock() {
28 // On Windows and Linux, holding pointer moves will not help throttling 32 // On Windows and Linux, holding pointer moves will not help throttling
29 // resizes. 33 // resizes.
30 // TODO(piman): on Windows we need to block (nested message loop?) the 34 // TODO(piman): on Windows we need to block (nested message loop?) the
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 scoped_ptr<cc::CopyOutputRequest> request) { 119 scoped_ptr<cc::CopyOutputRequest> request) {
116 client_->GetLayer()->RequestCopyOfOutput(request.Pass()); 120 client_->GetLayer()->RequestCopyOfOutput(request.Pass());
117 } 121 }
118 122
119 void DelegatedFrameHost::CopyFromCompositingSurface( 123 void DelegatedFrameHost::CopyFromCompositingSurface(
120 const gfx::Rect& src_subrect, 124 const gfx::Rect& src_subrect,
121 const gfx::Size& dst_size, 125 const gfx::Size& dst_size,
122 const base::Callback<void(bool, const SkBitmap&)>& callback, 126 const base::Callback<void(bool, const SkBitmap&)>& callback,
123 const SkBitmap::Config config) { 127 const SkBitmap::Config config) {
124 // Only ARGB888 and RGB565 supported as of now. 128 // Only ARGB888 and RGB565 supported as of now.
125 bool format_support = ((config == SkBitmap::kRGB_565_Config) || 129 bool format_support = ((config == SkBitmap::kA8_Config) ||
130 (config == SkBitmap::kRGB_565_Config) ||
126 (config == SkBitmap::kARGB_8888_Config)); 131 (config == SkBitmap::kARGB_8888_Config));
127 DCHECK(format_support); 132 DCHECK(format_support);
128 if (!CanCopyToBitmap()) { 133 if (!CanCopyToBitmap()) {
129 callback.Run(false, SkBitmap()); 134 callback.Run(false, SkBitmap());
130 return; 135 return;
131 } 136 }
132 137
133 const gfx::Size& dst_size_in_pixel = 138 const gfx::Size& dst_size_in_pixel =
134 client_->ConvertViewSizeToPixel(dst_size); 139 client_->ConvertViewSizeToPixel(dst_size);
135 scoped_ptr<cc::CopyOutputRequest> request = 140 scoped_ptr<cc::CopyOutputRequest> request =
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 const gfx::Size& dst_size_in_pixel, 436 const gfx::Size& dst_size_in_pixel,
432 const SkBitmap::Config config, 437 const SkBitmap::Config config,
433 const base::Callback<void(bool, const SkBitmap&)>& callback, 438 const base::Callback<void(bool, const SkBitmap&)>& callback,
434 scoped_ptr<cc::CopyOutputResult> result) { 439 scoped_ptr<cc::CopyOutputResult> result) {
435 if (result->IsEmpty() || result->size().IsEmpty()) { 440 if (result->IsEmpty() || result->size().IsEmpty()) {
436 callback.Run(false, SkBitmap()); 441 callback.Run(false, SkBitmap());
437 return; 442 return;
438 } 443 }
439 444
440 if (result->HasTexture()) { 445 if (result->HasTexture()) {
446 LOG(ERROR) << "result->HasTexture()";
441 PrepareTextureCopyOutputResult(dst_size_in_pixel, config, 447 PrepareTextureCopyOutputResult(dst_size_in_pixel, config,
442 callback, 448 callback,
443 result.Pass()); 449 result.Pass());
444 return; 450 return;
445 } 451 }
446 452
447 DCHECK(result->HasBitmap()); 453 DCHECK(result->HasBitmap());
454 LOG(ERROR) << "result->HasBitmap()";
448 PrepareBitmapCopyOutputResult(dst_size_in_pixel, config, callback, 455 PrepareBitmapCopyOutputResult(dst_size_in_pixel, config, callback,
449 result.Pass()); 456 result.Pass());
450 } 457 }
451 458
452 static void CopyFromCompositingSurfaceFinished( 459 static void CopyFromCompositingSurfaceFinished(
453 const base::Callback<void(bool, const SkBitmap&)>& callback, 460 const base::Callback<void(bool, const SkBitmap&)>& callback,
454 scoped_ptr<cc::SingleReleaseCallback> release_callback, 461 scoped_ptr<cc::SingleReleaseCallback> release_callback,
455 scoped_ptr<SkBitmap> bitmap, 462 scoped_ptr<SkBitmap> bitmap,
456 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, 463 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock,
457 bool result) { 464 bool result) {
465 LOG(ERROR) << "CopyFromCompositingSurfaceFinished";
458 bitmap_pixels_lock.reset(); 466 bitmap_pixels_lock.reset();
459 467
460 uint32 sync_point = 0; 468 uint32 sync_point = 0;
461 if (result) { 469 if (result) {
462 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); 470 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
463 sync_point = gl_helper->InsertSyncPoint(); 471 sync_point = gl_helper->InsertSyncPoint();
464 } 472 }
465 bool lost_resource = sync_point == 0; 473 bool lost_resource = sync_point == 0;
466 release_callback->Run(sync_point, lost_resource); 474 release_callback->Run(sync_point, lost_resource);
467 475
468 callback.Run(result, *bitmap); 476 callback.Run(result, *bitmap);
477 LOG(ERROR) << "=== CopyFromCompositingSurfaceFinished EXITING";
469 } 478 }
470 479
471 // static 480 // static
472 void DelegatedFrameHost::PrepareTextureCopyOutputResult( 481 void DelegatedFrameHost::PrepareTextureCopyOutputResult(
473 const gfx::Size& dst_size_in_pixel, 482 const gfx::Size& dst_size_in_pixel,
474 const SkBitmap::Config config, 483 const SkBitmap::Config config,
475 const base::Callback<void(bool, const SkBitmap&)>& callback, 484 const base::Callback<void(bool, const SkBitmap&)>& callback,
476 scoped_ptr<cc::CopyOutputResult> result) { 485 scoped_ptr<cc::CopyOutputResult> result) {
486 LOG(ERROR) << "DelegatedFrameHost::PrepareTextureCopyOutputResult"
487 << ", bitmap config=" << config;
488
477 DCHECK(result->HasTexture()); 489 DCHECK(result->HasTexture());
478 base::ScopedClosureRunner scoped_callback_runner( 490 base::ScopedClosureRunner scoped_callback_runner(
479 base::Bind(callback, false, SkBitmap())); 491 base::Bind(callback, false, SkBitmap()));
480 492
481 scoped_ptr<SkBitmap> bitmap(new SkBitmap); 493 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
482 bitmap->setConfig(config, 494 bitmap->setConfig(config,
483 dst_size_in_pixel.width(), dst_size_in_pixel.height(), 495 dst_size_in_pixel.width(), dst_size_in_pixel.height(),
484 0, kOpaque_SkAlphaType); 496 0, kOpaque_SkAlphaType);
485 if (!bitmap->allocPixels()) 497 if (!bitmap->allocPixels())
486 return; 498 return;
(...skipping 29 matching lines...) Expand all
516 base::Passed(&bitmap_pixels_lock)), 528 base::Passed(&bitmap_pixels_lock)),
517 GLHelper::SCALER_QUALITY_FAST); 529 GLHelper::SCALER_QUALITY_FAST);
518 } 530 }
519 531
520 // static 532 // static
521 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( 533 void DelegatedFrameHost::PrepareBitmapCopyOutputResult(
522 const gfx::Size& dst_size_in_pixel, 534 const gfx::Size& dst_size_in_pixel,
523 const SkBitmap::Config config, 535 const SkBitmap::Config config,
524 const base::Callback<void(bool, const SkBitmap&)>& callback, 536 const base::Callback<void(bool, const SkBitmap&)>& callback,
525 scoped_ptr<cc::CopyOutputResult> result) { 537 scoped_ptr<cc::CopyOutputResult> result) {
526 if (config != SkBitmap::kARGB_8888_Config) { 538 if (config != SkBitmap::kARGB_8888_Config && config != SkBitmap::kA8_Config) {
mfomitchev 2014/07/09 18:02:10 Any tips for testing this code path? How do I make
danakj 2014/07/10 19:13:02 Software compositing. https://code.google.com/p/ch
mfomitchev 2014/07/11 19:46:07 It uses --disable-gpu, but when I try to launch ch
mfomitchev 2014/07/11 20:47:50 Ah, looks like I can call force_bitmap_result() on
danakj 2014/07/11 20:52:16 I'm planning to remove that. You want --ui-disable
mfomitchev 2014/07/11 21:06:51 Ok, thanks. Does this path actually have value?
danakj 2014/07/11 21:15:03 We don't use software compositing on chromeos. We
mfomitchev 2014/07/14 14:30:28 Got it, thanks. On a related note, do you think it
danakj 2014/07/14 14:51:06 I was thinking about removing it actually, since t
mfomitchev 2014/07/14 15:00:40 Are you talking about force_bitmap_result()? Speci
danakj 2014/07/14 15:01:52 Yep I'm talking about that. The bitmap output woul
mfomitchev 2014/07/14 15:06:33 Right, and as you said software compositing may be
527 NOTIMPLEMENTED(); 539 NOTIMPLEMENTED();
528 callback.Run(false, SkBitmap()); 540 callback.Run(false, SkBitmap());
529 return; 541 return;
530 } 542 }
531 DCHECK(result->HasBitmap()); 543 DCHECK(result->HasBitmap());
532 scoped_ptr<SkBitmap> source = result->TakeBitmap(); 544 scoped_ptr<SkBitmap> source = result->TakeBitmap();
533 DCHECK(source); 545 DCHECK(source);
534 SkBitmap bitmap = skia::ImageOperations::Resize( 546 SkBitmap scaledBitmap;
danakj 2014/07/10 19:13:02 scaled_bitmap
mfomitchev 2014/07/11 19:46:07 Done.
535 *source, 547 if (source->width() != dst_size_in_pixel.width() ||
536 skia::ImageOperations::RESIZE_BEST, 548 source->height() != dst_size_in_pixel.height()) {
danakj 2014/07/10 19:13:02 if they are == you want to return the original bit
mfomitchev 2014/07/11 19:46:07 Oops. Done.
537 dst_size_in_pixel.width(), 549 scaledBitmap = skia::ImageOperations::Resize(
538 dst_size_in_pixel.height()); 550 *source,
539 callback.Run(true, bitmap); 551 skia::ImageOperations::RESIZE_BEST,
552 dst_size_in_pixel.width(),
553 dst_size_in_pixel.height());
554 }
555 if (config == SkBitmap::kARGB_8888_Config) {
556 callback.Run(true, scaledBitmap);
557 return;
558 }
559 // Else - |config| is kA8_Config.
danakj 2014/07/10 19:13:02 how about DCHECK_EQ(config, kA8_Config) instead of
mfomitchev 2014/07/11 19:46:07 Done.
560 // Paint |scaledBitmap| to alpha-only |a8Bitmap|.
561 SkBitmap a8Bitmap;
danakj 2014/07/10 19:13:02 grayscale_bitmap
562 a8Bitmap.setConfig(SkBitmap::kA8_Config,
danakj 2014/07/10 19:13:02 setConfig is deprecated. Use an SkImageInfo that y
mfomitchev 2014/07/11 19:46:07 Done.
563 scaledBitmap.width(),
564 scaledBitmap.height(),
565 0);
566 a8Bitmap.allocPixels();
567 SkCanvas canvas(a8Bitmap);
568 SkPaint paint;
569 SkColorFilter* filter = SkLumaColorFilter::Create();
570 paint.setColorFilter(filter);
571 filter->unref();
danakj 2014/07/10 19:13:02 no manual refcounting. use skia::RefPtr instead
mfomitchev 2014/07/11 19:46:07 Neat! Done.
572 canvas.drawBitmap(scaledBitmap, SkIntToScalar(0), SkIntToScalar(0), &paint);
573 callback.Run(true, a8Bitmap);
540 } 574 }
541 575
542 // static 576 // static
543 void DelegatedFrameHost::ReturnSubscriberTexture( 577 void DelegatedFrameHost::ReturnSubscriberTexture(
544 base::WeakPtr<DelegatedFrameHost> dfh, 578 base::WeakPtr<DelegatedFrameHost> dfh,
545 scoped_refptr<OwnedMailbox> subscriber_texture, 579 scoped_refptr<OwnedMailbox> subscriber_texture,
546 uint32 sync_point) { 580 uint32 sync_point) {
547 if (!subscriber_texture.get()) 581 if (!subscriber_texture.get())
548 return; 582 return;
549 if (!dfh) 583 if (!dfh)
550 return; 584 return;
551 585
552 subscriber_texture->UpdateSyncPoint(sync_point); 586 subscriber_texture->UpdateSyncPoint(sync_point);
553 587
554 if (dfh->frame_subscriber_ && subscriber_texture->texture_id()) 588 if (dfh->frame_subscriber_ && subscriber_texture->texture_id())
555 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); 589 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture);
556 } 590 }
557 591
592 // static
558 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( 593 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo(
559 base::WeakPtr<DelegatedFrameHost> dfh, 594 base::WeakPtr<DelegatedFrameHost> dfh,
560 const base::Callback<void(bool)>& callback, 595 const base::Callback<void(bool)>& callback,
561 scoped_refptr<OwnedMailbox> subscriber_texture, 596 scoped_refptr<OwnedMailbox> subscriber_texture,
562 scoped_ptr<cc::SingleReleaseCallback> release_callback, 597 scoped_ptr<cc::SingleReleaseCallback> release_callback,
563 bool result) { 598 bool result) {
564 callback.Run(result); 599 callback.Run(result);
565 600
566 uint32 sync_point = 0; 601 uint32 sync_point = 0;
567 if (result) { 602 if (result) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 // that should keep our frame. old_layer will be returned to the 878 // that should keep our frame. old_layer will be returned to the
844 // RecreateLayer caller, and should have a copy. 879 // RecreateLayer caller, and should have a copy.
845 if (frame_provider_.get()) { 880 if (frame_provider_.get()) {
846 new_layer->SetShowDelegatedContent(frame_provider_.get(), 881 new_layer->SetShowDelegatedContent(frame_provider_.get(),
847 current_frame_size_in_dip_); 882 current_frame_size_in_dip_);
848 } 883 }
849 } 884 }
850 885
851 } // namespace content 886 } // namespace content
852 887
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698