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

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

Issue 389683002: Improving GestureNav screenshotting performance - part 2 - GestureNav (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@slow_readback_final_GL_HELPER
Patch Set: Comment Created 6 years, 3 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
« no previous file with comments | « no previous file | content/browser/frame_host/navigation_entry_screenshot_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "cc/surfaces/surface_factory.h" 14 #include "cc/surfaces/surface_factory.h"
15 #include "content/browser/compositor/resize_lock.h" 15 #include "content/browser/compositor/resize_lock.h"
16 #include "content/common/gpu/client/gl_helper.h" 16 #include "content/common/gpu/client/gl_helper.h"
17 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 17 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #include "media/base/video_frame.h" 19 #include "media/base/video_frame.h"
20 #include "media/base/video_util.h" 20 #include "media/base/video_util.h"
21 #include "skia/ext/image_operations.h" 21 #include "skia/ext/image_operations.h"
22 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkPaint.h"
24 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
22 #include "ui/gfx/frame_time.h" 25 #include "ui/gfx/frame_time.h"
23 26
24 namespace content { 27 namespace content {
25 28
26 //////////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////////
27 // DelegatedFrameHostClient 30 // DelegatedFrameHostClient
28 31
29 bool DelegatedFrameHostClient::ShouldCreateResizeLock() { 32 bool DelegatedFrameHostClient::ShouldCreateResizeLock() {
30 // On Windows and Linux, holding pointer moves will not help throttling 33 // On Windows and Linux, holding pointer moves will not help throttling
31 // resizes. 34 // resizes.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 scoped_ptr<cc::CopyOutputRequest> request) { 132 scoped_ptr<cc::CopyOutputRequest> request) {
130 client_->GetLayer()->RequestCopyOfOutput(request.Pass()); 133 client_->GetLayer()->RequestCopyOfOutput(request.Pass());
131 } 134 }
132 135
133 void DelegatedFrameHost::CopyFromCompositingSurface( 136 void DelegatedFrameHost::CopyFromCompositingSurface(
134 const gfx::Rect& src_subrect, 137 const gfx::Rect& src_subrect,
135 const gfx::Size& output_size, 138 const gfx::Size& output_size,
136 const base::Callback<void(bool, const SkBitmap&)>& callback, 139 const base::Callback<void(bool, const SkBitmap&)>& callback,
137 const SkColorType color_type) { 140 const SkColorType color_type) {
138 // Only ARGB888 and RGB565 supported as of now. 141 // Only ARGB888 and RGB565 supported as of now.
139 bool format_support = ((color_type == kRGB_565_SkColorType) || 142 bool format_support = ((color_type == kAlpha_8_SkColorType) ||
143 (color_type == kRGB_565_SkColorType) ||
140 (color_type == kN32_SkColorType)); 144 (color_type == kN32_SkColorType));
141 DCHECK(format_support); 145 DCHECK(format_support);
142 if (!CanCopyToBitmap()) { 146 if (!CanCopyToBitmap()) {
143 callback.Run(false, SkBitmap()); 147 callback.Run(false, SkBitmap());
144 return; 148 return;
145 } 149 }
146 150
147 scoped_ptr<cc::CopyOutputRequest> request = 151 scoped_ptr<cc::CopyOutputRequest> request =
148 cc::CopyOutputRequest::CreateRequest(base::Bind( 152 cc::CopyOutputRequest::CreateRequest(base::Bind(
149 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, 153 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult,
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 color_type, 583 color_type,
580 base::Bind(&CopyFromCompositingSurfaceFinished, 584 base::Bind(&CopyFromCompositingSurfaceFinished,
581 callback, 585 callback,
582 base::Passed(&release_callback), 586 base::Passed(&release_callback),
583 base::Passed(&bitmap), 587 base::Passed(&bitmap),
584 base::Passed(&bitmap_pixels_lock)), 588 base::Passed(&bitmap_pixels_lock)),
585 GLHelper::SCALER_QUALITY_FAST); 589 GLHelper::SCALER_QUALITY_FAST);
586 } 590 }
587 591
588 // static 592 // static
589 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( 593 void DelegatedFrameHost::PrepareBitmapCopyOutputResult(
no sievers 2014/08/25 21:45:12 This is only for the software renderer, right? Bec
mfomitchev 2014/08/25 22:38:35 Yup. We used to paint the bitmap to A8 bitmap in S
590 const gfx::Size& dst_size_in_pixel, 594 const gfx::Size& dst_size_in_pixel,
591 const SkColorType color_type, 595 const SkColorType color_type,
592 const base::Callback<void(bool, const SkBitmap&)>& callback, 596 const base::Callback<void(bool, const SkBitmap&)>& callback,
593 scoped_ptr<cc::CopyOutputResult> result) { 597 scoped_ptr<cc::CopyOutputResult> result) {
594 if (color_type != kN32_SkColorType) { 598 if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) {
595 NOTIMPLEMENTED(); 599 NOTIMPLEMENTED();
596 callback.Run(false, SkBitmap()); 600 callback.Run(false, SkBitmap());
597 return; 601 return;
598 } 602 }
599 DCHECK(result->HasBitmap()); 603 DCHECK(result->HasBitmap());
600 scoped_ptr<SkBitmap> source = result->TakeBitmap(); 604 scoped_ptr<SkBitmap> source = result->TakeBitmap();
601 DCHECK(source); 605 DCHECK(source);
602 SkBitmap bitmap = skia::ImageOperations::Resize( 606 SkBitmap scaled_bitmap;
603 *source, 607 if (source->width() != dst_size_in_pixel.width() ||
604 skia::ImageOperations::RESIZE_BEST, 608 source->height() != dst_size_in_pixel.height()) {
605 dst_size_in_pixel.width(), 609 scaled_bitmap =
606 dst_size_in_pixel.height()); 610 skia::ImageOperations::Resize(*source,
607 callback.Run(true, bitmap); 611 skia::ImageOperations::RESIZE_BEST,
612 dst_size_in_pixel.width(),
613 dst_size_in_pixel.height());
614 } else {
615 scaled_bitmap = *source;
616 }
617 if (color_type == kN32_SkColorType) {
618 DCHECK(scaled_bitmap.colorType() == kN32_SkColorType);
619 callback.Run(true, scaled_bitmap);
620 return;
621 }
622 DCHECK_EQ(color_type, kAlpha_8_SkColorType);
no sievers 2014/08/25 21:45:12 It's a bit unfortunate that all over the place we
mfomitchev 2014/08/25 22:38:35 Using kUnknown_SkColorType seems pretty hacky to m
623 if (scaled_bitmap.colorType() == kAlpha_8_SkColorType) {
624 callback.Run(true, scaled_bitmap);
no sievers 2014/08/25 21:45:12 How can we end up here? Who converted the bitmap?
mfomitchev 2014/08/25 22:38:35 I don't think we can currently. However kAlpha_8_
no sievers 2014/08/25 23:05:47 Or maybe put a DCHECK(scaled_bitmap.colorType() !=
625 return;
626 }
627 // Paint |scaledBitmap| to alpha-only |a8Bitmap|.
628 SkBitmap grayscale_bitmap;
629 bool success = grayscale_bitmap.allocPixels(
630 SkImageInfo::MakeA8(scaled_bitmap.width(), scaled_bitmap.height()));
631 if (!success) {
632 callback.Run(false, SkBitmap());
633 return;
634 }
635 SkCanvas canvas(grayscale_bitmap);
636 SkPaint paint;
637 skia::RefPtr<SkColorFilter> filter =
no sievers 2014/08/25 21:45:12 So if we wanted to scale and filter in one pass, w
mfomitchev 2014/08/25 22:38:35 I am not sure. Do you know how would one resize an
no sievers 2014/08/25 23:05:47 I *think* if you make the canvas smaller/bigger it
638 skia::AdoptRef(SkLumaColorFilter::Create());
639 paint.setColorFilter(filter.get());
640 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint);
641 callback.Run(true, grayscale_bitmap);
608 } 642 }
609 643
610 // static 644 // static
611 void DelegatedFrameHost::ReturnSubscriberTexture( 645 void DelegatedFrameHost::ReturnSubscriberTexture(
612 base::WeakPtr<DelegatedFrameHost> dfh, 646 base::WeakPtr<DelegatedFrameHost> dfh,
613 scoped_refptr<OwnedMailbox> subscriber_texture, 647 scoped_refptr<OwnedMailbox> subscriber_texture,
614 uint32 sync_point) { 648 uint32 sync_point) {
615 if (!subscriber_texture.get()) 649 if (!subscriber_texture.get())
616 return; 650 return;
617 if (!dfh) 651 if (!dfh)
618 return; 652 return;
619 653
620 subscriber_texture->UpdateSyncPoint(sync_point); 654 subscriber_texture->UpdateSyncPoint(sync_point);
621 655
622 if (dfh->frame_subscriber_ && subscriber_texture->texture_id()) 656 if (dfh->frame_subscriber_ && subscriber_texture->texture_id())
623 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); 657 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture);
624 } 658 }
625 659
660 // static
626 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( 661 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo(
627 base::WeakPtr<DelegatedFrameHost> dfh, 662 base::WeakPtr<DelegatedFrameHost> dfh,
628 const base::Callback<void(bool)>& callback, 663 const base::Callback<void(bool)>& callback,
629 scoped_refptr<OwnedMailbox> subscriber_texture, 664 scoped_refptr<OwnedMailbox> subscriber_texture,
630 scoped_ptr<cc::SingleReleaseCallback> release_callback, 665 scoped_ptr<cc::SingleReleaseCallback> release_callback,
631 bool result) { 666 bool result) {
632 callback.Run(result); 667 callback.Run(result);
633 668
634 uint32 sync_point = 0; 669 uint32 sync_point = 0;
635 if (result) { 670 if (result) {
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 if (frame_provider_.get()) { 953 if (frame_provider_.get()) {
919 new_layer->SetShowDelegatedContent(frame_provider_.get(), 954 new_layer->SetShowDelegatedContent(frame_provider_.get(),
920 current_frame_size_in_dip_); 955 current_frame_size_in_dip_);
921 } 956 }
922 if (!surface_id_.is_null()) { 957 if (!surface_id_.is_null()) {
923 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); 958 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_);
924 } 959 }
925 } 960 }
926 961
927 } // namespace content 962 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigation_entry_screenshot_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698