| 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 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
| 20 #include "cc/trees/layer_tree_host.h" |
| 20 #include "content/common/child_process_messages.h" | 21 #include "content/common/child_process_messages.h" |
| 21 #include "content/common/input/synthetic_gesture_params.h" | 22 #include "content/common/input/synthetic_gesture_params.h" |
| 22 #include "content/common/input/synthetic_pinch_gesture_params.h" | 23 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 23 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 24 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
| 24 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 25 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 25 #include "content/common/input/synthetic_tap_gesture_params.h" | 26 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 26 #include "content/public/child/v8_value_converter.h" | 27 #include "content/public/child/v8_value_converter.h" |
| 27 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
| 28 #include "content/public/renderer/chrome_object_extensions_utils.h" | 29 #include "content/public/renderer/chrome_object_extensions_utils.h" |
| 29 #include "content/public/renderer/render_thread.h" | 30 #include "content/public/renderer/render_thread.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 : dirpath_(dirpath), | 118 : dirpath_(dirpath), |
| 118 layer_id_(0) { | 119 layer_id_(0) { |
| 119 // Let skia register known effect subclasses. This basically enables | 120 // Let skia register known effect subclasses. This basically enables |
| 120 // reflection on those subclasses required for picture serialization. | 121 // reflection on those subclasses required for picture serialization. |
| 121 SkiaBenchmarking::Initialize(); | 122 SkiaBenchmarking::Initialize(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 // Recursively serializes the layer tree. | 125 // Recursively serializes the layer tree. |
| 125 // Each layer in the tree is serialized into a separate skp file | 126 // Each layer in the tree is serialized into a separate skp file |
| 126 // in the given directory. | 127 // in the given directory. |
| 127 void Serialize(const cc::Layer* layer) { | 128 void Serialize(const cc::Layer* root_layer) { |
| 128 const cc::LayerList& children = layer->children(); | 129 for (auto* layer : *root_layer->layer_tree_host()) { |
| 129 for (size_t i = 0; i < children.size(); ++i) { | 130 sk_sp<SkPicture> picture = layer->GetPicture(); |
| 130 Serialize(children[i].get()); | 131 if (!picture) |
| 132 continue; |
| 133 |
| 134 // Serialize picture to file. |
| 135 // TODO(alokp): Note that for this to work Chrome needs to be launched |
| 136 // with |
| 137 // --no-sandbox command-line flag. Get rid of this limitation. |
| 138 // CRBUG: 139640. |
| 139 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; |
| 140 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); |
| 141 DCHECK(!filepath.empty()); |
| 142 SkFILEWStream file(filepath.c_str()); |
| 143 DCHECK(file.isValid()); |
| 144 |
| 145 EncodingSerializer serializer; |
| 146 picture->serialize(&file, &serializer); |
| 147 file.fsync(); |
| 131 } | 148 } |
| 132 | |
| 133 sk_sp<SkPicture> picture = layer->GetPicture(); | |
| 134 if (!picture) | |
| 135 return; | |
| 136 | |
| 137 // Serialize picture to file. | |
| 138 // TODO(alokp): Note that for this to work Chrome needs to be launched with | |
| 139 // --no-sandbox command-line flag. Get rid of this limitation. | |
| 140 // CRBUG: 139640. | |
| 141 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; | |
| 142 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); | |
| 143 DCHECK(!filepath.empty()); | |
| 144 SkFILEWStream file(filepath.c_str()); | |
| 145 DCHECK(file.isValid()); | |
| 146 | |
| 147 EncodingSerializer serializer; | |
| 148 picture->serialize(&file, &serializer); | |
| 149 file.fsync(); | |
| 150 } | 149 } |
| 151 | 150 |
| 152 private: | 151 private: |
| 153 base::FilePath dirpath_; | 152 base::FilePath dirpath_; |
| 154 int layer_id_; | 153 int layer_id_; |
| 155 }; | 154 }; |
| 156 | 155 |
| 157 template <typename T> | 156 template <typename T> |
| 158 bool GetArg(gin::Arguments* args, T* value) { | 157 bool GetArg(gin::Arguments* args, T* value) { |
| 159 if (!args->GetNext(value)) { | 158 if (!args->GetNext(value)) { |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 &gpu_driver_bug_workarounds))) { | 959 &gpu_driver_bug_workarounds))) { |
| 961 return; | 960 return; |
| 962 } | 961 } |
| 963 | 962 |
| 964 v8::Local<v8::Value> result; | 963 v8::Local<v8::Value> result; |
| 965 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) | 964 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) |
| 966 args->Return(result); | 965 args->Return(result); |
| 967 } | 966 } |
| 968 | 967 |
| 969 } // namespace content | 968 } // namespace content |
| OLD | NEW |