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

Side by Side Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 10787025: Expose a gpu-benchmark-only measureRecordTime API to JS. This function measures the time it takes t… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/gpu/gpu_benchmarking_extension.h" 5 #include "content/renderer/gpu/gpu_benchmarking_extension.h"
6
7 #include "base/string_number_conversions.h"
6 #include "content/renderer/render_view_impl.h" 8 #include "content/renderer/render_view_impl.h"
9 #include "third_party/skia/include/core/SkPicture.h"
10 #include "third_party/skia/include/core/SkStream.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
7 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h " 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h "
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h"
11 #include "v8/include/v8.h" 15 #include "v8/include/v8.h"
12 16
17 using WebKit::WebCanvas;
13 using WebKit::WebFrame; 18 using WebKit::WebFrame;
14 using WebKit::WebRenderingStats; 19 using WebKit::WebRenderingStats;
20 using WebKit::WebSize;
15 using WebKit::WebView; 21 using WebKit::WebView;
22 using WebKit::WebViewBenchmarkSupport;
16 23
17 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; 24 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking";
18 25
19 using WebKit::WebFrame; 26 namespace {
20 using WebKit::WebView; 27
28 class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient {
29 public:
30 explicit SkPictureRecorder(const std::string& dirname)
31 : dirname_(dirname),
32 layer_id_(0) {
33 }
34
35 virtual WebCanvas* willPaint(const WebSize& size) {
36 return picture_.beginRecording(size.width, size.height);
37 }
38
39 virtual void didPaint(WebCanvas* canvas) {
40 DCHECK(canvas == picture_.getRecordingCanvas());
41 picture_.endRecording();
42 // Serialize picture to file.
43 // Note that for this to work Chrome needs to be launched with
44 // --no-sandbox command-line flag.
45 std::string filepath =
46 dirname_ + "/layer_" + base::IntToString(layer_id_++) + ".skp";
47 SkFILEWStream file(filepath.c_str());
48 picture_.serialize(&file);
49 }
50
51 private:
52 std::string dirname_;
53 int layer_id_;
54 SkPicture picture_;
55 };
56
57 } // namespace
21 58
22 namespace content { 59 namespace content {
23 60
24 class GpuBenchmarkingWrapper : public v8::Extension { 61 class GpuBenchmarkingWrapper : public v8::Extension {
25 public: 62 public:
26 GpuBenchmarkingWrapper() : 63 GpuBenchmarkingWrapper() :
27 v8::Extension(kGpuBenchmarkingExtensionName, 64 v8::Extension(kGpuBenchmarkingExtensionName,
28 "if (typeof(chrome) == 'undefined') {" 65 "if (typeof(chrome) == 'undefined') {"
29 " chrome = {};" 66 " chrome = {};"
30 "};" 67 "};"
31 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" 68 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {"
32 " chrome.gpuBenchmarking = {};" 69 " chrome.gpuBenchmarking = {};"
33 "};" 70 "};"
34 "chrome.gpuBenchmarking.renderingStats = function() {" 71 "chrome.gpuBenchmarking.renderingStats = function() {"
35 " native function GetRenderingStats();" 72 " native function GetRenderingStats();"
36 " return GetRenderingStats();" 73 " return GetRenderingStats();"
37 "};" 74 "};"
75 "chrome.gpuBenchmarking.printToSkPicture = function(dirname) {"
76 " native function PrintToSkPicture();"
77 " return PrintToSkPicture(dirname);"
78 "};"
38 "chrome.gpuBenchmarking.beginSmoothScrollDown = " 79 "chrome.gpuBenchmarking.beginSmoothScrollDown = "
39 " function(scroll_far) {" 80 " function(scroll_far) {"
40 " scroll_far = scroll_far || false;" 81 " scroll_far = scroll_far || false;"
41 " native function BeginSmoothScroll();" 82 " native function BeginSmoothScroll();"
42 " return BeginSmoothScroll(true, scroll_far);" 83 " return BeginSmoothScroll(true, scroll_far);"
43 "};" 84 "};"
44 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {" 85 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {"
45 " scroll_far = scroll_far || false;" 86 " scroll_far = scroll_far || false;"
46 " native function BeginSmoothScroll();" 87 " native function BeginSmoothScroll();"
47 " return BeginSmoothScroll(false, scroll_far);" 88 " return BeginSmoothScroll(false, scroll_far);"
48 "};") {} 89 "};") {}
49 90
50 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 91 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
51 v8::Handle<v8::String> name) { 92 v8::Handle<v8::String> name) {
52 if (name->Equals(v8::String::New("GetRenderingStats"))) 93 if (name->Equals(v8::String::New("GetRenderingStats")))
53 return v8::FunctionTemplate::New(GetRenderingStats); 94 return v8::FunctionTemplate::New(GetRenderingStats);
95 if (name->Equals(v8::String::New("PrintToSkPicture")))
96 return v8::FunctionTemplate::New(PrintToSkPicture);
54 if (name->Equals(v8::String::New("BeginSmoothScroll"))) 97 if (name->Equals(v8::String::New("BeginSmoothScroll")))
55 return v8::FunctionTemplate::New(BeginSmoothScroll); 98 return v8::FunctionTemplate::New(BeginSmoothScroll);
56 99
57 return v8::Handle<v8::FunctionTemplate>(); 100 return v8::Handle<v8::FunctionTemplate>();
58 } 101 }
59 102
60 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { 103 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) {
61 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 104 WebFrame* web_frame = WebFrame::frameForEnteredContext();
62 if (!web_frame) 105 if (!web_frame)
63 return v8::Undefined(); 106 return v8::Undefined();
(...skipping 22 matching lines...) Expand all
86 stats_object->Set(v8::String::New("totalPaintTimeInSeconds"), 129 stats_object->Set(v8::String::New("totalPaintTimeInSeconds"),
87 v8::Number::New(stats.totalPaintTimeInSeconds), 130 v8::Number::New(stats.totalPaintTimeInSeconds),
88 v8::ReadOnly); 131 v8::ReadOnly);
89 if (stats.totalRasterizeTimeInSeconds) 132 if (stats.totalRasterizeTimeInSeconds)
90 stats_object->Set(v8::String::New("totalRasterizeTimeInSeconds"), 133 stats_object->Set(v8::String::New("totalRasterizeTimeInSeconds"),
91 v8::Number::New(stats.totalRasterizeTimeInSeconds), 134 v8::Number::New(stats.totalRasterizeTimeInSeconds),
92 v8::ReadOnly); 135 v8::ReadOnly);
93 return stats_object; 136 return stats_object;
94 } 137 }
95 138
139 static v8::Handle<v8::Value> PrintToSkPicture(const v8::Arguments& args) {
nduca 2012/07/30 17:24:21 We should check if we have been launched with --no
alokp 2012/07/30 20:24:37 DONE (in a slightly different way). I am throwing
140 if (args.Length() != 1)
141 return v8::Undefined();
142
143 v8::String::AsciiValue dirname(args[0]);
144 if (dirname.length() == 0)
145 return v8::Undefined();
146
147 WebFrame* web_frame = WebFrame::frameForEnteredContext();
148 if (!web_frame)
149 return v8::Undefined();
150
151 WebView* web_view = web_frame->view();
152 if (!web_view)
153 return v8::Undefined();
154
155 WebViewBenchmarkSupport* benchmark_support = web_view->benchmarkSupport();
156 if (!benchmark_support)
157 return v8::Undefined();
158
159 SkPictureRecorder recorder(*dirname);
160 benchmark_support->paint(&recorder,
161 WebViewBenchmarkSupport::PaintModeEverything);
162 return v8::Undefined();
163 }
164
96 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { 165 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) {
97 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 166 WebFrame* web_frame = WebFrame::frameForEnteredContext();
98 if (!web_frame) 167 if (!web_frame)
99 return v8::Undefined(); 168 return v8::Undefined();
100 169
101 WebView* web_view = web_frame->view(); 170 WebView* web_view = web_frame->view();
102 if (!web_view) 171 if (!web_view)
103 return v8::Undefined(); 172 return v8::Undefined();
104 173
105 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); 174 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view);
106 if (!render_view_impl) 175 if (!render_view_impl)
107 return v8::Undefined(); 176 return v8::Undefined();
108 177
109 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean()) 178 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
110 return v8::False(); 179 return v8::False();
111 180
112 bool scroll_down = args[0]->BooleanValue(); 181 bool scroll_down = args[0]->BooleanValue();
113 bool scroll_far = args[1]->BooleanValue(); 182 bool scroll_far = args[1]->BooleanValue();
114 183
115 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); 184 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far);
116 return v8::True(); 185 return v8::True();
117 } 186 }
118 }; 187 };
119 188
120 v8::Extension* GpuBenchmarkingExtension::Get() { 189 v8::Extension* GpuBenchmarkingExtension::Get() {
121 return new GpuBenchmarkingWrapper(); 190 return new GpuBenchmarkingWrapper();
122 } 191 }
123 192
124 } // namespace content 193 } // namespace content
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