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

Side by Side Diff: chrome/renderer/chrome_render_view_observer.cc

Issue 8359021: Add trace events for renderer thumbnailer, it can be quite expensive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/renderer/chrome_render_view_observer.h" 5 #include "chrome/renderer/chrome_render_view_observer.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "chrome/common/chrome_constants.h" 12 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/icon_messages.h" 14 #include "chrome/common/icon_messages.h"
14 #include "chrome/common/render_messages.h" 15 #include "chrome/common/render_messages.h"
15 #include "chrome/common/thumbnail_score.h" 16 #include "chrome/common/thumbnail_score.h"
16 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
17 #include "chrome/renderer/about_handler.h" 18 #include "chrome/renderer/about_handler.h"
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // reload, in-page navigation, or some other load type where we don't want to 832 // reload, in-page navigation, or some other load type where we don't want to
832 // reindex. Note: subframe navigations after onload increment the page id, 833 // reindex. Note: subframe navigations after onload increment the page id,
833 // so these will trigger a reindex. 834 // so these will trigger a reindex.
834 GURL stripped_url(StripRef(url)); 835 GURL stripped_url(StripRef(url));
835 if (same_page_id && stripped_url == last_indexed_url_) 836 if (same_page_id && stripped_url == last_indexed_url_)
836 return; 837 return;
837 838
838 if (!preliminary_capture) 839 if (!preliminary_capture)
839 last_indexed_url_ = stripped_url; 840 last_indexed_url_ = stripped_url;
840 841
842 TRACE_EVENT0("renderer", "ChromeRenderViewObserver::CapturePageInfo");
843
841 // Retrieve the frame's full text. 844 // Retrieve the frame's full text.
842 string16 contents; 845 string16 contents;
843 CaptureText(main_frame, &contents); 846 CaptureText(main_frame, &contents);
844 if (translate_helper_) 847 if (translate_helper_)
845 translate_helper_->PageCaptured(contents); 848 translate_helper_->PageCaptured(contents);
846 if (contents.size()) { 849 if (contents.size()) {
847 // Send the text to the browser for indexing (the browser might decide not 850 // Send the text to the browser for indexing (the browser might decide not
848 // to index, if the URL is HTTPS for instance) and language discovery. 851 // to index, if the URL is HTTPS for instance) and language discovery.
849 Send(new ChromeViewHostMsg_PageContents(routing_id(), url, load_id, 852 Send(new ChromeViewHostMsg_PageContents(routing_id(), url, load_id,
850 contents)); 853 contents));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 return; 905 return;
903 906
904 // get the URL for this page 907 // get the URL for this page
905 GURL url(main_frame->document().url()); 908 GURL url(main_frame->document().url());
906 if (url.is_empty()) 909 if (url.is_empty())
907 return; 910 return;
908 911
909 if (render_view()->GetSize().IsEmpty()) 912 if (render_view()->GetSize().IsEmpty())
910 return; // Don't create an empty thumbnail! 913 return; // Don't create an empty thumbnail!
911 914
915 TRACE_EVENT0("renderer", "ChromeRenderViewObserver::CaptureThumbnail");
916
912 ThumbnailScore score; 917 ThumbnailScore score;
913 SkBitmap thumbnail; 918 SkBitmap thumbnail;
914 if (!CaptureFrameThumbnail(render_view()->GetWebView(), kThumbnailWidth, 919 if (!CaptureFrameThumbnail(render_view()->GetWebView(), kThumbnailWidth,
915 kThumbnailHeight, &thumbnail, &score)) 920 kThumbnailHeight, &thumbnail, &score))
916 return; 921 return;
917 922
918 // send the thumbnail message to the browser process 923 // send the thumbnail message to the browser process
919 Send(new ChromeViewHostMsg_Thumbnail(routing_id(), url, score, thumbnail)); 924 Send(new ChromeViewHostMsg_Thumbnail(routing_id(), url, score, thumbnail));
920 } 925 }
921 926
922 bool ChromeRenderViewObserver::CaptureFrameThumbnail(WebView* view, 927 bool ChromeRenderViewObserver::CaptureFrameThumbnail(WebView* view,
923 int w, 928 int w,
924 int h, 929 int h,
925 SkBitmap* thumbnail, 930 SkBitmap* thumbnail,
926 ThumbnailScore* score) { 931 ThumbnailScore* score) {
927 base::TimeTicks beginning_time = base::TimeTicks::Now(); 932 base::TimeTicks beginning_time = base::TimeTicks::Now();
928 933
929 skia::PlatformCanvas canvas; 934 skia::PlatformCanvas canvas;
930 935
931 // Paint |view| into |canvas|. 936 {
932 if (!PaintViewIntoCanvas(view, canvas)) 937 TRACE_EVENT0("renderer",
933 return false; 938 "ChromeRenderViewObserver::CaptureFrameThumbnail::PaintViewIntoCanvas");
939 // Paint |view| into |canvas|.
940 if (!PaintViewIntoCanvas(view, canvas))
941 return false;
942 }
934 943
935 SkDevice* device = skia::GetTopDevice(canvas); 944 SkDevice* device = skia::GetTopDevice(canvas);
936 945
937 const SkBitmap& src_bmp = device->accessBitmap(false); 946 const SkBitmap& src_bmp = device->accessBitmap(false);
938 // Cut off the vertical scrollbars (if any). 947 // Cut off the vertical scrollbars (if any).
939 int src_bmp_width = view->mainFrame()->contentsSize().width; 948 int src_bmp_width = view->mainFrame()->contentsSize().width;
940 949
941 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; 950 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
942 float dest_aspect = dest_rect.width() / dest_rect.height(); 951 float dest_aspect = dest_rect.width() / dest_rect.height();
943 952
(...skipping 22 matching lines...) Expand all
966 static_cast<S16CPU>(src_bmp_width / dest_aspect)); 975 static_cast<S16CPU>(src_bmp_width / dest_aspect));
967 score->good_clipping = true; 976 score->good_clipping = true;
968 } 977 }
969 } 978 }
970 979
971 score->at_top = (view->mainFrame()->scrollOffset().height == 0); 980 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
972 981
973 SkBitmap subset; 982 SkBitmap subset;
974 device->accessBitmap(false).extractSubset(&subset, src_rect); 983 device->accessBitmap(false).extractSubset(&subset, src_rect);
975 984
985 TRACE_EVENT_BEGIN0("renderer",
986 "ChromeRenderViewObserver::CaptureFrameThumbnail::DownsampleByTwo");
976 // First do a fast downsample by powers of two to get close to the final size. 987 // First do a fast downsample by powers of two to get close to the final size.
977 SkBitmap downsampled_subset = 988 SkBitmap downsampled_subset =
978 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h); 989 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
990 TRACE_EVENT_END0("renderer",
991 "ChromeRenderViewObserver::CaptureFrameThumbnail::DownsampleByTwo");
979 992
980 // Do a high-quality resize from the downscaled size to the final size. 993 {
981 *thumbnail = skia::ImageOperations::Resize( 994 TRACE_EVENT0("renderer",
982 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); 995 "ChromeRenderViewObserver::CaptureFrameThumbnail::DownsampleLanczos3");
996 // Do a high-quality resize from the downscaled size to the final size.
997 *thumbnail = skia::ImageOperations::Resize(
998 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
999 }
983 1000
984 score->boring_score = CalculateBoringScore(thumbnail); 1001 score->boring_score = CalculateBoringScore(thumbnail);
985 1002
986 HISTOGRAM_TIMES("Renderer4.Thumbnail", 1003 HISTOGRAM_TIMES("Renderer4.Thumbnail",
987 base::TimeTicks::Now() - beginning_time); 1004 base::TimeTicks::Now() - beginning_time);
988 1005
989 return true; 1006 return true;
990 } 1007 }
991 1008
992 bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, 1009 bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 // Decode the favicon using WebKit's image decoder. 1086 // Decode the favicon using WebKit's image decoder.
1070 webkit_glue::ImageDecoder decoder( 1087 webkit_glue::ImageDecoder decoder(
1071 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); 1088 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize));
1072 const unsigned char* src_data = 1089 const unsigned char* src_data =
1073 reinterpret_cast<const unsigned char*>(&data[0]); 1090 reinterpret_cast<const unsigned char*>(&data[0]);
1074 1091
1075 return decoder.Decode(src_data, data.size()); 1092 return decoder.Decode(src_data, data.size());
1076 } 1093 }
1077 return SkBitmap(); 1094 return SkBitmap();
1078 } 1095 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698