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 <stddef.h> | 7 #include <stddef.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/command_line.h" | |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
17 #include "content/common/gpu/gpu_messages.h" | 18 #include "content/common/gpu/gpu_messages.h" |
18 #include "content/common/input/synthetic_gesture_params.h" | 19 #include "content/common/input/synthetic_gesture_params.h" |
19 #include "content/common/input/synthetic_pinch_gesture_params.h" | 20 #include "content/common/input/synthetic_pinch_gesture_params.h" |
20 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 21 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
21 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 22 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
22 #include "content/common/input/synthetic_tap_gesture_params.h" | 23 #include "content/common/input/synthetic_tap_gesture_params.h" |
23 #include "content/public/child/v8_value_converter.h" | 24 #include "content/public/child/v8_value_converter.h" |
25 #include "content/public/common/content_switches.h" | |
24 #include "content/public/renderer/chrome_object_extensions_utils.h" | 26 #include "content/public/renderer/chrome_object_extensions_utils.h" |
25 #include "content/public/renderer/render_thread.h" | 27 #include "content/public/renderer/render_thread.h" |
26 #include "content/renderer/gpu/render_widget_compositor.h" | 28 #include "content/renderer/gpu/render_widget_compositor.h" |
27 #include "content/renderer/render_thread_impl.h" | 29 #include "content/renderer/render_thread_impl.h" |
28 #include "content/renderer/render_view_impl.h" | 30 #include "content/renderer/render_view_impl.h" |
29 #include "content/renderer/skia_benchmarking_extension.h" | 31 #include "content/renderer/skia_benchmarking_extension.h" |
30 #include "gin/arguments.h" | 32 #include "gin/arguments.h" |
31 #include "gin/handle.h" | 33 #include "gin/handle.h" |
32 #include "gin/object_template_builder.h" | 34 #include "gin/object_template_builder.h" |
33 #include "third_party/WebKit/public/web/WebImageCache.h" | 35 #include "third_party/WebKit/public/web/WebImageCache.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
47 using blink::WebLocalFrame; | 49 using blink::WebLocalFrame; |
48 using blink::WebImageCache; | 50 using blink::WebImageCache; |
49 using blink::WebPrivatePtr; | 51 using blink::WebPrivatePtr; |
50 using blink::WebSize; | 52 using blink::WebSize; |
51 using blink::WebView; | 53 using blink::WebView; |
52 | 54 |
53 namespace content { | 55 namespace content { |
54 | 56 |
55 namespace { | 57 namespace { |
56 | 58 |
57 class PNGSerializer : public SkPixelSerializer { | 59 class EncodingSerializer : public SkPixelSerializer { |
58 protected: | 60 protected: |
59 bool onUseEncodedData(const void* data, size_t len) override { return true; } | 61 bool onUseEncodedData(const void* data, size_t len) override { return true; } |
60 | 62 |
61 SkData* onEncode(const SkPixmap& pixmap) override { | 63 SkData* onEncode(const SkPixmap& pixmap) override { |
62 SkBitmap bm; | 64 SkBitmap bm; |
63 // The const_cast is fine, since we only read from the bitmap. | 65 // The const_cast is fine, since we only read from the bitmap. |
64 if (bm.installPixels(pixmap.info(), | 66 if (bm.installPixels(pixmap.info(), |
65 const_cast<void*>(pixmap.addr()), | 67 const_cast<void*>(pixmap.addr()), |
66 pixmap.rowBytes())) { | 68 pixmap.rowBytes())) { |
67 std::vector<unsigned char> vector; | 69 std::vector<unsigned char> vector; |
68 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { | 70 |
71 const base::CommandLine& commandLine = | |
72 *base::CommandLine::ForCurrentProcess(); | |
73 if (commandLine.HasSwitch(switches::kSkipReencodingOnSKPCapture)) { | |
74 // In this case, we just want to store some useful information | |
75 // about the image to replace the missing encoded data. | |
76 | |
77 // First make sure that the data does not accidentally match any | |
78 // image signatures. | |
79 vector.push_back(0xFF); | |
80 vector.push_back(0xFF); | |
81 vector.push_back(0xFF); | |
82 vector.push_back(0xFF); | |
83 | |
84 // Save the width and height. | |
85 uint32_t width = bm.width(); | |
scroggo
2016/02/17 23:13:30
I think you can get all this info from the pixmap
msarett
2016/02/18 16:44:39
Restructured the code to check the flag before ins
| |
86 uint32_t height = bm.height(); | |
87 vector.push_back(width & 0xFF); | |
88 vector.push_back((width >> 8) & 0xFF); | |
89 vector.push_back((width >> 16) & 0xFF); | |
90 vector.push_back((width >> 24) & 0xFF); | |
91 vector.push_back(height & 0xFF); | |
92 vector.push_back((height >> 8) & 0xFF); | |
93 vector.push_back((height >> 16) & 0xFF); | |
94 vector.push_back((height >> 24) & 0xFF); | |
95 | |
96 // Save any additional information about the bitmap that may be | |
97 // interesting. | |
98 vector.push_back(bm.colorType()); | |
99 vector.push_back(bm.alphaType()); | |
69 return SkData::NewWithCopy(&vector.front(), vector.size()); | 100 return SkData::NewWithCopy(&vector.front(), vector.size()); |
101 } else { | |
102 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { | |
103 return SkData::NewWithCopy(&vector.front(), vector.size()); | |
104 } | |
70 } | 105 } |
71 } | 106 } |
72 return nullptr; | 107 return nullptr; |
73 } | 108 } |
74 }; | 109 }; |
75 | 110 |
76 class SkPictureSerializer { | 111 class SkPictureSerializer { |
77 public: | 112 public: |
78 explicit SkPictureSerializer(const base::FilePath& dirpath) | 113 explicit SkPictureSerializer(const base::FilePath& dirpath) |
79 : dirpath_(dirpath), | 114 : dirpath_(dirpath), |
(...skipping 19 matching lines...) Expand all Loading... | |
99 // Serialize picture to file. | 134 // Serialize picture to file. |
100 // TODO(alokp): Note that for this to work Chrome needs to be launched with | 135 // TODO(alokp): Note that for this to work Chrome needs to be launched with |
101 // --no-sandbox command-line flag. Get rid of this limitation. | 136 // --no-sandbox command-line flag. Get rid of this limitation. |
102 // CRBUG: 139640. | 137 // CRBUG: 139640. |
103 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; | 138 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; |
104 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); | 139 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); |
105 DCHECK(!filepath.empty()); | 140 DCHECK(!filepath.empty()); |
106 SkFILEWStream file(filepath.c_str()); | 141 SkFILEWStream file(filepath.c_str()); |
107 DCHECK(file.isValid()); | 142 DCHECK(file.isValid()); |
108 | 143 |
109 PNGSerializer serializer; | 144 EncodingSerializer serializer; |
110 picture->serialize(&file, &serializer); | 145 picture->serialize(&file, &serializer); |
111 file.fsync(); | 146 file.fsync(); |
112 } | 147 } |
113 | 148 |
114 private: | 149 private: |
115 base::FilePath dirpath_; | 150 base::FilePath dirpath_; |
116 int layer_id_; | 151 int layer_id_; |
117 }; | 152 }; |
118 | 153 |
119 template <typename T> | 154 template <typename T> |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
878 bool GpuBenchmarking::HasGpuProcess() { | 913 bool GpuBenchmarking::HasGpuProcess() { |
879 bool has_gpu_process = false; | 914 bool has_gpu_process = false; |
880 if (!RenderThreadImpl::current()->Send( | 915 if (!RenderThreadImpl::current()->Send( |
881 new GpuHostMsg_HasGpuProcess(&has_gpu_process))) | 916 new GpuHostMsg_HasGpuProcess(&has_gpu_process))) |
882 return false; | 917 return false; |
883 | 918 |
884 return has_gpu_process; | 919 return has_gpu_process; |
885 } | 920 } |
886 | 921 |
887 } // namespace content | 922 } // namespace content |
OLD | NEW |