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

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
6 #include "content/renderer/render_view_impl.h" 7 #include "content/renderer/render_view_impl.h"
8 #include "third_party/skia/include/core/SkPicture.h"
9 #include "third_party/skia/include/core/SkStream.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
7 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h " 11 #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" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h"
11 #include "v8/include/v8.h" 14 #include "v8/include/v8.h"
12 15
16 using WebKit::WebCanvas;
13 using WebKit::WebFrame; 17 using WebKit::WebFrame;
14 using WebKit::WebRenderingStats; 18 using WebKit::WebRenderingStats;
19 using WebKit::WebSize;
15 using WebKit::WebView; 20 using WebKit::WebView;
21 using WebKit::WebViewBenchmarkSupport;
16 22
17 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; 23 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking";
18 24
19 using WebKit::WebFrame; 25 namespace {
piman 2012/07/27 17:55:58 nit: blank line below
alokp 2012/07/27 18:32:44 Done.
20 using WebKit::WebView; 26 class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient {
27 public:
28 explicit SkPictureRecorder(const std::string& dirname) :
piman 2012/07/27 17:55:58 nit: style - ':' goes on next line
alokp 2012/07/27 18:32:44 Done.
29 dirname_(dirname),
30 layer_id_(0) {
31 }
32
33 virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE {
jamesr 2012/07/27 17:54:36 If you are implementing something from the WebKit
alokp 2012/07/27 18:32:44 Done.
34 return picture_.beginRecording(size.width, size.height);
35 }
piman 2012/07/27 17:55:58 nit: blank line below
alokp 2012/07/27 18:32:44 Done.
36 virtual void didPaint(WebCanvas* canvas) OVERRIDE {
jamesr 2012/07/27 17:54:36 newline before new function
jamesr 2012/07/27 17:54:36 No OVERRIDE
alokp 2012/07/27 18:32:44 Done.
alokp 2012/07/27 18:32:44 Done.
37 DCHECK(canvas == picture_.getRecordingCanvas());
38 picture_.endRecording();
39 // Serialize picture to file.
40 // Note that for this to work Chrome needs to be launched with
41 // --no-sandbox command-line flag.
piman 2012/07/27 17:55:58 What could we do to remove that restriction?
alokp 2012/07/27 18:32:44 The benchmarks could also be run on a picture seri
piman 2012/07/27 20:59:31 For example, using the file picker. I won't block
alokp 2012/07/30 18:05:12 May be I am missing something. The issue here is w
42 std::ostringstream stream;
jamesr 2012/07/27 17:54:36 chromium style is to not use streams for things li
alokp 2012/07/27 18:32:44 Done.
43 stream << dirname_ << '/' << "layer_" << layer_id_++ << ".skp";
piman 2012/07/27 17:55:58 use FilePath instead of streams (prohibited) to co
alokp 2012/07/27 18:32:44 FilePath may be an overkill for this use-case. I s
piman 2012/07/27 20:59:31 http://www.chromium.org/developers/coding-style ex
alokp 2012/07/30 18:05:12 Done.
44 std::string filepath = stream.str();
45 SkFILEWStream file(filepath.c_str());
46 picture_.serialize(&file);
47 }
48
49 private:
50 std::string dirname_;
51 int layer_id_;
52 SkPicture picture_;
53 };
piman 2012/07/27 17:55:58 nit: blank line below
alokp 2012/07/27 18:32:44 Done.
54 } // namespace
21 55
22 namespace content { 56 namespace content {
23 57
24 class GpuBenchmarkingWrapper : public v8::Extension { 58 class GpuBenchmarkingWrapper : public v8::Extension {
25 public: 59 public:
26 GpuBenchmarkingWrapper() : 60 GpuBenchmarkingWrapper() :
27 v8::Extension(kGpuBenchmarkingExtensionName, 61 v8::Extension(kGpuBenchmarkingExtensionName,
28 "if (typeof(chrome) == 'undefined') {" 62 "if (typeof(chrome) == 'undefined') {"
29 " chrome = {};" 63 " chrome = {};"
30 "};" 64 "};"
31 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" 65 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {"
32 " chrome.gpuBenchmarking = {};" 66 " chrome.gpuBenchmarking = {};"
33 "};" 67 "};"
34 "chrome.gpuBenchmarking.renderingStats = function() {" 68 "chrome.gpuBenchmarking.renderingStats = function() {"
35 " native function GetRenderingStats();" 69 " native function GetRenderingStats();"
36 " return GetRenderingStats();" 70 " return GetRenderingStats();"
37 "};" 71 "};"
72 "chrome.gpuBenchmarking.printToSkPicture = function(dirname) {"
73 " native function PrintToSkPicture();"
74 " return PrintToSkPicture(dirname);"
75 "};"
38 "chrome.gpuBenchmarking.beginSmoothScrollDown = " 76 "chrome.gpuBenchmarking.beginSmoothScrollDown = "
39 " function(scroll_far) {" 77 " function(scroll_far) {"
40 " scroll_far = scroll_far || false;" 78 " scroll_far = scroll_far || false;"
41 " native function BeginSmoothScroll();" 79 " native function BeginSmoothScroll();"
42 " return BeginSmoothScroll(true, scroll_far);" 80 " return BeginSmoothScroll(true, scroll_far);"
43 "};" 81 "};"
44 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {" 82 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {"
45 " scroll_far = scroll_far || false;" 83 " scroll_far = scroll_far || false;"
46 " native function BeginSmoothScroll();" 84 " native function BeginSmoothScroll();"
47 " return BeginSmoothScroll(false, scroll_far);" 85 " return BeginSmoothScroll(false, scroll_far);"
48 "};") {} 86 "};") {}
49 87
50 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 88 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
51 v8::Handle<v8::String> name) { 89 v8::Handle<v8::String> name) {
52 if (name->Equals(v8::String::New("GetRenderingStats"))) 90 if (name->Equals(v8::String::New("GetRenderingStats")))
53 return v8::FunctionTemplate::New(GetRenderingStats); 91 return v8::FunctionTemplate::New(GetRenderingStats);
92 if (name->Equals(v8::String::New("PrintToSkPicture")))
93 return v8::FunctionTemplate::New(PrintToSkPicture);
54 if (name->Equals(v8::String::New("BeginSmoothScroll"))) 94 if (name->Equals(v8::String::New("BeginSmoothScroll")))
55 return v8::FunctionTemplate::New(BeginSmoothScroll); 95 return v8::FunctionTemplate::New(BeginSmoothScroll);
56 96
57 return v8::Handle<v8::FunctionTemplate>(); 97 return v8::Handle<v8::FunctionTemplate>();
58 } 98 }
59 99
60 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { 100 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) {
61 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 101 WebFrame* web_frame = WebFrame::frameForEnteredContext();
62 if (!web_frame) 102 if (!web_frame)
63 return v8::Undefined(); 103 return v8::Undefined();
(...skipping 10 matching lines...) Expand all
74 stats_object->Set(v8::String::New("numAnimationFrames"), 114 stats_object->Set(v8::String::New("numAnimationFrames"),
75 v8::Integer::New(stats.numAnimationFrames), 115 v8::Integer::New(stats.numAnimationFrames),
76 v8::ReadOnly); 116 v8::ReadOnly);
77 if (stats.numFramesSentToScreen) 117 if (stats.numFramesSentToScreen)
78 stats_object->Set(v8::String::New("numFramesSentToScreen"), 118 stats_object->Set(v8::String::New("numFramesSentToScreen"),
79 v8::Integer::New(stats.numFramesSentToScreen), 119 v8::Integer::New(stats.numFramesSentToScreen),
80 v8::ReadOnly); 120 v8::ReadOnly);
81 return stats_object; 121 return stats_object;
82 } 122 }
83 123
124 static v8::Handle<v8::Value> PrintToSkPicture(const v8::Arguments& args) {
125 if (args.Length() != 1)
126 return v8::Undefined();
127
128 v8::String::AsciiValue dirname(args[0]);
129 if (dirname.length() == 0)
130 return v8::Undefined();
131
132 WebFrame* web_frame = WebFrame::frameForEnteredContext();
133 if (!web_frame)
134 return v8::Undefined();
135
136 WebView* web_view = web_frame->view();
137 if (!web_view)
138 return v8::Undefined();
139
140 WebViewBenchmarkSupport* benchmark_support = web_view->benchmarkSupport();
141 if (!benchmark_support)
142 return v8::Undefined();
143
144 SkPictureRecorder recorder(*dirname);
145 benchmark_support->paint(&recorder,
146 WebViewBenchmarkSupport::PaintModeEverything);
147 return v8::Undefined();
148 }
149
84 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { 150 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) {
85 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 151 WebFrame* web_frame = WebFrame::frameForEnteredContext();
86 if (!web_frame) 152 if (!web_frame)
87 return v8::Undefined(); 153 return v8::Undefined();
88 154
89 WebView* web_view = web_frame->view(); 155 WebView* web_view = web_frame->view();
90 if (!web_view) 156 if (!web_view)
91 return v8::Undefined(); 157 return v8::Undefined();
92 158
93 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); 159 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view);
94 if (!render_view_impl) 160 if (!render_view_impl)
95 return v8::Undefined(); 161 return v8::Undefined();
96 162
97 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean()) 163 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
98 return v8::False(); 164 return v8::False();
99 165
100 bool scroll_down = args[0]->BooleanValue(); 166 bool scroll_down = args[0]->BooleanValue();
101 bool scroll_far = args[1]->BooleanValue(); 167 bool scroll_far = args[1]->BooleanValue();
102 168
103 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); 169 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far);
104 return v8::True(); 170 return v8::True();
105 } 171 }
106 }; 172 };
107 173
108 v8::Extension* GpuBenchmarkingExtension::Get() { 174 v8::Extension* GpuBenchmarkingExtension::Get() {
109 return new GpuBenchmarkingWrapper(); 175 return new GpuBenchmarkingWrapper();
110 } 176 }
111 177
112 } // namespace content 178 } // 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