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

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, 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 | 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 #include "content/renderer/render_view_impl.h" 6 #include "content/renderer/render_view_impl.h"
7 #include "third_party/skia/include/core/SkPicture.h"
8 #include "third_party/skia/include/core/SkStream.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
7 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h " 10 #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" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h"
11 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
12 14
13 using WebKit::WebFrame; 15 using WebKit::WebFrame;
14 using WebKit::WebRenderingStats; 16 using WebKit::WebRenderingStats;
15 using WebKit::WebView; 17 using WebKit::WebView;
16 18
17 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; 19 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking";
18 20
21 using WebKit::WebCanvas;
19 using WebKit::WebFrame; 22 using WebKit::WebFrame;
23 using WebKit::WebSize;
20 using WebKit::WebView; 24 using WebKit::WebView;
25 using WebKit::WebViewBenchmarkSupport;
26
27 namespace {
28 class SkPictureRecordingController
29 : public WebViewBenchmarkSupport::PaintingController {
30 public:
31 SkPictureRecordingController(SkPicture* picture) : picture_(picture) { }
32
33 // WebViewBenchmarkSupport::PaintingController overrides.
34 virtual WebCanvas* createCanvas(const WebSize& size) {
35 return picture_->beginRecording(size.width, size.height);
36 }
nduca 2012/07/18 06:17:47 do we use the OVERRIDE convention yet in chromium?
alokp 2012/07/18 16:00:49 Will check.
37 virtual void paintingComplete(const WebCanvas&) {
38 picture_->endRecording();
39 }
40
41 private:
42 SkPicture* picture_;
43 };
nduca 2012/07/18 06:17:47 Is this the right way to handle layers? You're goi
alokp 2012/07/18 16:00:49 We can do it in any number of ways: 1. multiple la
44 } // namespace
21 45
22 namespace content { 46 namespace content {
23 47
24 class GpuBenchmarkingWrapper : public v8::Extension { 48 class GpuBenchmarkingWrapper : public v8::Extension {
25 public: 49 public:
26 GpuBenchmarkingWrapper() : 50 GpuBenchmarkingWrapper() :
27 v8::Extension(kGpuBenchmarkingExtensionName, 51 v8::Extension(kGpuBenchmarkingExtensionName,
28 "if (typeof(chrome) == 'undefined') {" 52 "if (typeof(chrome) == 'undefined') {"
29 " chrome = {};" 53 " chrome = {};"
30 "};" 54 "};"
31 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" 55 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {"
32 " chrome.gpuBenchmarking = {};" 56 " chrome.gpuBenchmarking = {};"
33 "};" 57 "};"
34 "chrome.gpuBenchmarking.renderingStats = function() {" 58 "chrome.gpuBenchmarking.renderingStats = function() {"
35 " native function GetRenderingStats();" 59 " native function GetRenderingStats();"
36 " return GetRenderingStats();" 60 " return GetRenderingStats();"
37 "};" 61 "};"
62 "chrome.gpuBenchmarking.printToSkPicture = function(filename) {"
63 " native function PrintToSkPicture();"
64 " return PrintToSkPicture(filename);"
65 "};"
38 "chrome.gpuBenchmarking.beginSmoothScrollDown = " 66 "chrome.gpuBenchmarking.beginSmoothScrollDown = "
39 " function(scroll_far) {" 67 " function(scroll_far) {"
40 " scroll_far = scroll_far || false;" 68 " scroll_far = scroll_far || false;"
41 " native function BeginSmoothScroll();" 69 " native function BeginSmoothScroll();"
42 " return BeginSmoothScroll(true, scroll_far);" 70 " return BeginSmoothScroll(true, scroll_far);"
43 "};" 71 "};"
44 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {" 72 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {"
45 " scroll_far = scroll_far || false;" 73 " scroll_far = scroll_far || false;"
46 " native function BeginSmoothScroll();" 74 " native function BeginSmoothScroll();"
47 " return BeginSmoothScroll(false, scroll_far);" 75 " return BeginSmoothScroll(false, scroll_far);"
48 "};") {} 76 "};") {}
49 77
50 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 78 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
51 v8::Handle<v8::String> name) { 79 v8::Handle<v8::String> name) {
52 if (name->Equals(v8::String::New("GetRenderingStats"))) 80 if (name->Equals(v8::String::New("GetRenderingStats")))
53 return v8::FunctionTemplate::New(GetRenderingStats); 81 return v8::FunctionTemplate::New(GetRenderingStats);
82 if (name->Equals(v8::String::New("PrintToSkPicture")))
83 return v8::FunctionTemplate::New(PrintToSkPicture);
54 if (name->Equals(v8::String::New("BeginSmoothScroll"))) 84 if (name->Equals(v8::String::New("BeginSmoothScroll")))
55 return v8::FunctionTemplate::New(BeginSmoothScroll); 85 return v8::FunctionTemplate::New(BeginSmoothScroll);
56 86
57 return v8::Handle<v8::FunctionTemplate>(); 87 return v8::Handle<v8::FunctionTemplate>();
58 } 88 }
59 89
60 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { 90 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) {
61 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 91 WebFrame* web_frame = WebFrame::frameForEnteredContext();
62 if (!web_frame) 92 if (!web_frame)
63 return v8::Undefined(); 93 return v8::Undefined();
(...skipping 10 matching lines...) Expand all
74 stats_object->Set(v8::String::New("numAnimationFrames"), 104 stats_object->Set(v8::String::New("numAnimationFrames"),
75 v8::Integer::New(stats.numAnimationFrames), 105 v8::Integer::New(stats.numAnimationFrames),
76 v8::ReadOnly); 106 v8::ReadOnly);
77 if (stats.numFramesSentToScreen) 107 if (stats.numFramesSentToScreen)
78 stats_object->Set(v8::String::New("numFramesSentToScreen"), 108 stats_object->Set(v8::String::New("numFramesSentToScreen"),
79 v8::Integer::New(stats.numFramesSentToScreen), 109 v8::Integer::New(stats.numFramesSentToScreen),
80 v8::ReadOnly); 110 v8::ReadOnly);
81 return stats_object; 111 return stats_object;
82 } 112 }
83 113
114 static v8::Handle<v8::Value> PrintToSkPicture(const v8::Arguments& args) {
115 if (args.Length() != 1)
116 return v8::Undefined();
117
118 v8::String::AsciiValue filename(args[0]);
119 if (filename.length() == 0)
120 return v8::Undefined();
121
122 WebFrame* web_frame = WebFrame::frameForEnteredContext();
123 if (!web_frame)
124 return v8::Undefined();
125
126 WebView* web_view = web_frame->view();
127 if (!web_view)
128 return v8::Undefined();
129
130 WebViewBenchmarkSupport* benchmark_support = web_view->benchmarkSupport();
131 if (!benchmark_support)
132 return v8::Undefined();
133
134 SkPicture picture;
135 SkPictureRecordingController controller(&picture);
136 double record_time = benchmark_support->paint(
137 controller,
138 WebViewBenchmarkSupport::PaintModeEverything);
139
140 // Open the file into which recorded SkPicture will be dumped.
141 // Note that for this to work Chrome needs to be launched with
142 // --no-sandbox command-line flag.
143 SkFILEWStream file(*filename);
nduca 2012/07/18 06:17:47 We definitely want to file a bug with skia to allo
alokp 2012/07/18 16:00:49 They already have this feature. We should sync up
144 picture.serialize(&file);
145 return v8::Number::New(record_time);
nduca 2012/07/18 06:17:47 Any reason we need to even return this variable? S
alokp 2012/07/18 16:00:49 The same reason WebViewBenchmarkSupport::paint() r
146 }
147
84 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { 148 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) {
85 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 149 WebFrame* web_frame = WebFrame::frameForEnteredContext();
86 if (!web_frame) 150 if (!web_frame)
87 return v8::Undefined(); 151 return v8::Undefined();
88 152
89 WebView* web_view = web_frame->view(); 153 WebView* web_view = web_frame->view();
90 if (!web_view) 154 if (!web_view)
91 return v8::Undefined(); 155 return v8::Undefined();
92 156
93 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); 157 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view);
94 if (!render_view_impl) 158 if (!render_view_impl)
95 return v8::Undefined(); 159 return v8::Undefined();
96 160
97 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean()) 161 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
98 return v8::False(); 162 return v8::False();
99 163
100 bool scroll_down = args[0]->BooleanValue(); 164 bool scroll_down = args[0]->BooleanValue();
101 bool scroll_far = args[1]->BooleanValue(); 165 bool scroll_far = args[1]->BooleanValue();
102 166
103 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); 167 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far);
104 return v8::True(); 168 return v8::True();
105 } 169 }
106 }; 170 };
107 171
108 v8::Extension* GpuBenchmarkingExtension::Get() { 172 v8::Extension* GpuBenchmarkingExtension::Get() {
109 return new GpuBenchmarkingWrapper(); 173 return new GpuBenchmarkingWrapper();
110 } 174 }
111 175
112 } // namespace content 176 } // 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