OLD | NEW |
---|---|
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 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "cc/layer_tree_host.h" | |
14 #include "content/common/gpu/gpu_rendering_stats.h" | 15 #include "content/common/gpu/gpu_rendering_stats.h" |
15 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
17 #include "content/public/renderer/v8_value_converter.h" | |
16 #include "content/renderer/all_rendering_benchmarks.h" | 18 #include "content/renderer/all_rendering_benchmarks.h" |
17 #include "content/renderer/render_view_impl.h" | 19 #include "content/renderer/render_view_impl.h" |
18 #include "content/renderer/rendering_benchmark.h" | 20 #include "content/renderer/rendering_benchmark.h" |
19 #include "third_party/skia/include/core/SkGraphics.h" | 21 #include "third_party/skia/include/core/SkGraphics.h" |
20 #include "third_party/skia/include/core/SkPicture.h" | 22 #include "third_party/skia/include/core/SkPicture.h" |
21 #include "third_party/skia/include/core/SkStream.h" | 23 #include "third_party/skia/include/core/SkStream.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h" |
25 #include "v8/include/v8.h" | 27 #include "v8/include/v8.h" |
28 #include "webkit/compositor_bindings/web_layer_tree_view_impl.h" | |
26 #include "webkit/compositor_bindings/web_rendering_stats_impl.h" | 29 #include "webkit/compositor_bindings/web_rendering_stats_impl.h" |
27 | 30 |
28 using WebKit::WebCanvas; | 31 using WebKit::WebCanvas; |
29 using WebKit::WebFrame; | 32 using WebKit::WebFrame; |
33 using WebKit::WebLayerTreeViewImpl; | |
30 using WebKit::WebPrivatePtr; | 34 using WebKit::WebPrivatePtr; |
31 using WebKit::WebRenderingStatsImpl; | 35 using WebKit::WebRenderingStatsImpl; |
32 using WebKit::WebSize; | 36 using WebKit::WebSize; |
33 using WebKit::WebView; | 37 using WebKit::WebView; |
34 using WebKit::WebViewBenchmarkSupport; | 38 using WebKit::WebViewBenchmarkSupport; |
35 | 39 |
36 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; | 40 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
37 | 41 |
38 namespace { | 42 namespace { |
39 | 43 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 " Math.abs(pixels_to_scroll));" | 151 " Math.abs(pixels_to_scroll));" |
148 " }" | 152 " }" |
149 "};" | 153 "};" |
150 "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {" | 154 "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {" |
151 " native function RunRenderingBenchmarks();" | 155 " native function RunRenderingBenchmarks();" |
152 " return RunRenderingBenchmarks(filter);" | 156 " return RunRenderingBenchmarks(filter);" |
153 "};" | 157 "};" |
154 "chrome.gpuBenchmarking.beginWindowSnapshotPNG = function(callback) {" | 158 "chrome.gpuBenchmarking.beginWindowSnapshotPNG = function(callback) {" |
155 " native function BeginWindowSnapshotPNG();" | 159 " native function BeginWindowSnapshotPNG();" |
156 " BeginWindowSnapshotPNG(callback);" | 160 " BeginWindowSnapshotPNG(callback);" |
161 "};" | |
162 "chrome.gpuBenchmarking.layerTreeAsValue = function() {" | |
163 " native function LayerTreeAsValue();" | |
164 " LayerTreeAsValue();" | |
157 "};") {} | 165 "};") {} |
158 | 166 |
159 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 167 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
160 v8::Handle<v8::String> name) { | 168 v8::Handle<v8::String> name) { |
161 if (name->Equals(v8::String::New("GetRenderingStats"))) | 169 if (name->Equals(v8::String::New("GetRenderingStats"))) |
162 return v8::FunctionTemplate::New(GetRenderingStats); | 170 return v8::FunctionTemplate::New(GetRenderingStats); |
163 if (name->Equals(v8::String::New("PrintToSkPicture"))) | 171 if (name->Equals(v8::String::New("PrintToSkPicture"))) |
164 return v8::FunctionTemplate::New(PrintToSkPicture); | 172 return v8::FunctionTemplate::New(PrintToSkPicture); |
165 if (name->Equals(v8::String::New("BeginSmoothScroll"))) | 173 if (name->Equals(v8::String::New("BeginSmoothScroll"))) |
166 return v8::FunctionTemplate::New(BeginSmoothScroll); | 174 return v8::FunctionTemplate::New(BeginSmoothScroll); |
167 if (name->Equals(v8::String::New("RunRenderingBenchmarks"))) | 175 if (name->Equals(v8::String::New("RunRenderingBenchmarks"))) |
168 return v8::FunctionTemplate::New(RunRenderingBenchmarks); | 176 return v8::FunctionTemplate::New(RunRenderingBenchmarks); |
169 if (name->Equals(v8::String::New("BeginWindowSnapshotPNG"))) | 177 if (name->Equals(v8::String::New("BeginWindowSnapshotPNG"))) |
170 return v8::FunctionTemplate::New(BeginWindowSnapshotPNG); | 178 return v8::FunctionTemplate::New(BeginWindowSnapshotPNG); |
179 if (name->Equals(v8::String::New("LayerTreeAsValue"))) | |
180 return v8::FunctionTemplate::New(LayerTreeAsValue); | |
171 | 181 |
172 return v8::Handle<v8::FunctionTemplate>(); | 182 return v8::Handle<v8::FunctionTemplate>(); |
173 } | 183 } |
174 | 184 |
175 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { | 185 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { |
176 | 186 |
177 WebFrame* web_frame = WebFrame::frameForCurrentContext(); | 187 WebFrame* web_frame = WebFrame::frameForCurrentContext(); |
178 if (!web_frame) | 188 if (!web_frame) |
179 return v8::Undefined(); | 189 return v8::Undefined(); |
180 | 190 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 v8::Persistent<v8::Function> callback = | 446 v8::Persistent<v8::Function> callback = |
437 v8::Persistent<v8::Function>::New(callback_local); | 447 v8::Persistent<v8::Function>::New(callback_local); |
438 v8::Persistent<v8::Context> context = | 448 v8::Persistent<v8::Context> context = |
439 v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext()); | 449 v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext()); |
440 | 450 |
441 render_view_impl->GetWindowSnapshot( | 451 render_view_impl->GetWindowSnapshot( |
442 base::Bind(&OnSnapshotCompleted, callback, context)); | 452 base::Bind(&OnSnapshotCompleted, callback, context)); |
443 | 453 |
444 return v8::Undefined(); | 454 return v8::Undefined(); |
445 } | 455 } |
456 | |
457 static v8::Handle<v8::Value> LayerTreeAsValue( | |
458 const v8::Arguments& args) { | |
459 WebFrame* web_frame = WebFrame::frameForCurrentContext(); | |
460 if (!web_frame) | |
461 return v8::Undefined(); | |
462 | |
463 WebView* web_view = web_frame->view(); | |
464 if (!web_view) | |
465 return v8::Undefined(); | |
466 | |
467 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); | |
468 if (!render_view_impl) | |
469 return v8::Undefined(); | |
470 | |
471 WebLayerTreeViewImpl* layer_tree_view_impl = | |
472 static_cast<WebLayerTreeViewImpl*>(render_view_impl->layerTreeView()); | |
piman
2013/02/12 04:55:07
This is a content::RenderWidgetCompositor now... M
| |
473 | |
474 if (!layer_tree_view_impl) | |
475 return v8::Undefined(); | |
476 | |
477 cc::LayerTreeHost* cc_layer_tree_host = | |
478 layer_tree_view_impl->layer_tree_host(); | |
479 if (!cc_layer_tree_host) | |
480 return v8::Undefined(); | |
481 | |
482 scoped_ptr<base::Value> value = cc_layer_tree_host->asValue(); | |
483 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | |
484 v8::Persistent<v8::Context> context = | |
485 v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext()); | |
486 return converter->ToV8Value(value.get(), context); | |
487 } | |
446 }; | 488 }; |
447 | 489 |
448 v8::Extension* GpuBenchmarkingExtension::Get() { | 490 v8::Extension* GpuBenchmarkingExtension::Get() { |
449 return new GpuBenchmarkingWrapper(); | 491 return new GpuBenchmarkingWrapper(); |
450 } | 492 } |
451 | 493 |
452 } // namespace content | 494 } // namespace content |
OLD | NEW |