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_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.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 "content/common/gpu/gpu_rendering_stats.h" | 14 #include "content/common/gpu/gpu_rendering_stats.h" |
15 #include "content/public/renderer/render_thread.h" | 15 #include "content/public/renderer/render_thread.h" |
16 #include "content/renderer/all_rendering_benchmarks.h" | 16 #include "content/renderer/all_rendering_benchmarks.h" |
17 #include "content/renderer/gpu/render_widget_compositor.h" | 17 #include "content/renderer/gpu/render_widget_compositor.h" |
18 #include "content/renderer/render_view_impl.h" | 18 #include "content/renderer/render_view_impl.h" |
19 #include "content/renderer/rendering_benchmark.h" | 19 #include "content/renderer/rendering_benchmark.h" |
20 #include "content/renderer/skia_benchmarking_extension.h" | 20 #include "content/renderer/skia_benchmarking_extension.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h" |
24 #include "third_party/skia/include/core/SkData.h" | |
24 #include "third_party/skia/include/core/SkGraphics.h" | 25 #include "third_party/skia/include/core/SkGraphics.h" |
25 #include "third_party/skia/include/core/SkPicture.h" | 26 #include "third_party/skia/include/core/SkPicture.h" |
27 #include "third_party/skia/include/core/SkPixelRef.h" | |
26 #include "third_party/skia/include/core/SkStream.h" | 28 #include "third_party/skia/include/core/SkStream.h" |
27 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
28 #include "v8/include/v8.h" | 30 #include "v8/include/v8.h" |
29 #include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h" | 31 #include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h" |
30 | 32 |
31 using WebKit::WebCanvas; | 33 using WebKit::WebCanvas; |
32 using WebKit::WebFrame; | 34 using WebKit::WebFrame; |
33 using WebKit::WebPrivatePtr; | 35 using WebKit::WebPrivatePtr; |
34 using WebKit::WebRenderingStatsImpl; | 36 using WebKit::WebRenderingStatsImpl; |
35 using WebKit::WebSize; | 37 using WebKit::WebSize; |
36 using WebKit::WebView; | 38 using WebKit::WebView; |
37 using WebKit::WebViewBenchmarkSupport; | 39 using WebKit::WebViewBenchmarkSupport; |
38 | 40 |
39 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; | 41 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
40 | 42 |
41 static bool PNGEncodeBitmapToStream(SkWStream* stream, const SkBitmap& bm) { | 43 static SkData* EncodeBitmapToData(size_t* offset, const SkBitmap& bm) { |
44 SkPixelRef* pr = bm.pixelRef(); | |
vmpstr
2013/05/21 18:48:27
I was under the impression that SkOrderedWriteBuff
scroggo
2013/05/21 18:58:36
You are correct; writeBitmap DID do that check, bu
| |
45 if (pr != NULL) { | |
46 SkData* data = pr->refEncodedData(); | |
47 if (data != NULL) { | |
48 *offset = bm.pixelRefOffset(); | |
49 return data; | |
50 } | |
51 } | |
42 std::vector<unsigned char> vector; | 52 std::vector<unsigned char> vector; |
43 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, true, &vector)) { | 53 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, true, &vector)) { |
44 if (stream->write(&vector.front() , vector.size())) | 54 return SkData::NewWithCopy(&vector.front() , vector.size()); |
45 return true; | |
46 } | 55 } |
47 return false; | 56 return NULL; |
48 } | 57 } |
49 | 58 |
50 namespace { | 59 namespace { |
51 | 60 |
52 class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient { | 61 class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient { |
53 public: | 62 public: |
54 explicit SkPictureRecorder(const base::FilePath& dirpath) | 63 explicit SkPictureRecorder(const base::FilePath& dirpath) |
55 : dirpath_(dirpath), | 64 : dirpath_(dirpath), |
56 layer_id_(0) { | 65 layer_id_(0) { |
57 // Let skia register known effect subclasses. This basically enables | 66 // Let skia register known effect subclasses. This basically enables |
(...skipping 10 matching lines...) Expand all Loading... | |
68 picture_.endRecording(); | 77 picture_.endRecording(); |
69 // Serialize picture to file. | 78 // Serialize picture to file. |
70 // TODO(alokp): Note that for this to work Chrome needs to be launched with | 79 // TODO(alokp): Note that for this to work Chrome needs to be launched with |
71 // --no-sandbox command-line flag. Get rid of this limitation. | 80 // --no-sandbox command-line flag. Get rid of this limitation. |
72 // CRBUG: 139640. | 81 // CRBUG: 139640. |
73 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; | 82 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; |
74 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); | 83 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); |
75 DCHECK(!filepath.empty()); | 84 DCHECK(!filepath.empty()); |
76 SkFILEWStream file(filepath.c_str()); | 85 SkFILEWStream file(filepath.c_str()); |
77 DCHECK(file.isValid()); | 86 DCHECK(file.isValid()); |
78 picture_.serialize(&file, &PNGEncodeBitmapToStream); | 87 picture_.serialize(&file, &EncodeBitmapToData); |
79 } | 88 } |
80 | 89 |
81 private: | 90 private: |
82 base::FilePath dirpath_; | 91 base::FilePath dirpath_; |
83 int layer_id_; | 92 int layer_id_; |
84 SkPicture picture_; | 93 SkPicture picture_; |
85 }; | 94 }; |
86 | 95 |
87 class RenderingStatsEnumerator : public cc::RenderingStats::Enumerator { | 96 class RenderingStatsEnumerator : public cc::RenderingStats::Enumerator { |
88 public: | 97 public: |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 514 |
506 return v8::Undefined(); | 515 return v8::Undefined(); |
507 } | 516 } |
508 }; | 517 }; |
509 | 518 |
510 v8::Extension* GpuBenchmarkingExtension::Get() { | 519 v8::Extension* GpuBenchmarkingExtension::Get() { |
511 return new GpuBenchmarkingWrapper(); | 520 return new GpuBenchmarkingWrapper(); |
512 } | 521 } |
513 | 522 |
514 } // namespace content | 523 } // namespace content |
OLD | NEW |