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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "content/public/renderer/render_thread.h" | 13 #include "content/public/renderer/render_thread.h" |
14 #include "content/renderer/all_rendering_benchmarks.h" | 14 #include "content/renderer/all_rendering_benchmarks.h" |
15 #include "content/renderer/render_view_impl.h" | 15 #include "content/renderer/render_view_impl.h" |
16 #include "content/renderer/rendering_benchmark.h" | 16 #include "content/renderer/rendering_benchmark.h" |
17 #include "content/renderer/rendering_benchmark_results.h" | 17 #include "content/renderer/rendering_benchmark_results.h" |
| 18 #include "third_party/skia/include/core/SkGraphics.h" |
18 #include "third_party/skia/include/core/SkPicture.h" | 19 #include "third_party/skia/include/core/SkPicture.h" |
19 #include "third_party/skia/include/core/SkStream.h" | 20 #include "third_party/skia/include/core/SkStream.h" |
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h
" | 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h
" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo
rt.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo
rt.h" |
24 #include "v8/include/v8.h" | 25 #include "v8/include/v8.h" |
25 | 26 |
26 using WebKit::WebCanvas; | 27 using WebKit::WebCanvas; |
27 using WebKit::WebFrame; | 28 using WebKit::WebFrame; |
28 using WebKit::WebPrivatePtr; | 29 using WebKit::WebPrivatePtr; |
29 using WebKit::WebRenderingStats; | 30 using WebKit::WebRenderingStats; |
30 using WebKit::WebSize; | 31 using WebKit::WebSize; |
31 using WebKit::WebView; | 32 using WebKit::WebView; |
32 using WebKit::WebViewBenchmarkSupport; | 33 using WebKit::WebViewBenchmarkSupport; |
33 | 34 |
34 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; | 35 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
| 39 // Always called on the main render thread. |
| 40 // Does not need to be thread-safe. |
| 41 void InitSkGraphics() { |
| 42 static bool init = false; |
| 43 if (!init) { |
| 44 SkGraphics::Init(); |
| 45 init = true; |
| 46 } |
| 47 } |
| 48 |
38 class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient { | 49 class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient { |
39 public: | 50 public: |
40 explicit SkPictureRecorder(const FilePath& dirpath) | 51 explicit SkPictureRecorder(const FilePath& dirpath) |
41 : dirpath_(dirpath), | 52 : dirpath_(dirpath), |
42 layer_id_(0) { | 53 layer_id_(0) { |
| 54 // Let skia register known effect subclasses. This basically enables |
| 55 // reflection on those subclasses required for picture serialization. |
| 56 InitSkGraphics(); |
43 } | 57 } |
44 | 58 |
45 virtual WebCanvas* willPaint(const WebSize& size) { | 59 virtual WebCanvas* willPaint(const WebSize& size) { |
46 return picture_.beginRecording(size.width, size.height); | 60 return picture_.beginRecording(size.width, size.height); |
47 } | 61 } |
48 | 62 |
49 virtual void didPaint(WebCanvas* canvas) { | 63 virtual void didPaint(WebCanvas* canvas) { |
50 DCHECK(canvas == picture_.getRecordingCanvas()); | 64 DCHECK(canvas == picture_.getRecordingCanvas()); |
51 picture_.endRecording(); | 65 picture_.endRecording(); |
52 // Serialize picture to file. | 66 // Serialize picture to file. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 312 |
299 return results.results_array(); | 313 return results.results_array(); |
300 } | 314 } |
301 }; | 315 }; |
302 | 316 |
303 v8::Extension* GpuBenchmarkingExtension::Get() { | 317 v8::Extension* GpuBenchmarkingExtension::Get() { |
304 return new GpuBenchmarkingWrapper(); | 318 return new GpuBenchmarkingWrapper(); |
305 } | 319 } |
306 | 320 |
307 } // namespace content | 321 } // namespace content |
OLD | NEW |