| 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/paint/paint_canvas.h" |
| 20 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
| 21 #include "content/common/child_process_messages.h" | 22 #include "content/common/child_process_messages.h" |
| 22 #include "content/common/input/synthetic_gesture_params.h" | 23 #include "content/common/input/synthetic_gesture_params.h" |
| 23 #include "content/common/input/synthetic_pinch_gesture_params.h" | 24 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 24 #include "content/common/input/synthetic_pointer_action_list_params.h" | 25 #include "content/common/input/synthetic_pointer_action_list_params.h" |
| 25 #include "content/common/input/synthetic_pointer_action_params.h" | 26 #include "content/common/input/synthetic_pointer_action_params.h" |
| 26 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 27 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
| 27 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 28 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 28 #include "content/common/input/synthetic_tap_gesture_params.h" | 29 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 29 #include "content/public/child/v8_value_converter.h" | 30 #include "content/public/child/v8_value_converter.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Let skia register known effect subclasses. This basically enables | 132 // Let skia register known effect subclasses. This basically enables |
| 132 // reflection on those subclasses required for picture serialization. | 133 // reflection on those subclasses required for picture serialization. |
| 133 SkiaBenchmarking::Initialize(); | 134 SkiaBenchmarking::Initialize(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 // Recursively serializes the layer tree. | 137 // Recursively serializes the layer tree. |
| 137 // Each layer in the tree is serialized into a separate skp file | 138 // Each layer in the tree is serialized into a separate skp file |
| 138 // in the given directory. | 139 // in the given directory. |
| 139 void Serialize(const cc::Layer* root_layer) { | 140 void Serialize(const cc::Layer* root_layer) { |
| 140 for (auto* layer : *root_layer->layer_tree_host()) { | 141 for (auto* layer : *root_layer->layer_tree_host()) { |
| 141 sk_sp<SkPicture> picture = layer->GetPicture(); | 142 sk_sp<SkPicture> picture = cc::ToSkPicture(layer->GetPicture()); |
| 142 if (!picture) | 143 if (!picture) |
| 143 continue; | 144 continue; |
| 144 | 145 |
| 145 // Serialize picture to file. | 146 // Serialize picture to file. |
| 146 // TODO(alokp): Note that for this to work Chrome needs to be launched | 147 // TODO(alokp): Note that for this to work Chrome needs to be launched |
| 147 // with | 148 // with |
| 148 // --no-sandbox command-line flag. Get rid of this limitation. | 149 // --no-sandbox command-line flag. Get rid of this limitation. |
| 149 // CRBUG: 139640. | 150 // CRBUG: 139640. |
| 150 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; | 151 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; |
| 151 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); | 152 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 const float kPageWidth = 612.0f; // 8.5 inch | 467 const float kPageWidth = 612.0f; // 8.5 inch |
| 467 const float kPageHeight = 792.0f; // 11 inch | 468 const float kPageHeight = 792.0f; // 11 inch |
| 468 const float kMarginTop = 29.0f; // 0.40 inch | 469 const float kMarginTop = 29.0f; // 0.40 inch |
| 469 const float kMarginLeft = 29.0f; // 0.40 inch | 470 const float kMarginLeft = 29.0f; // 0.40 inch |
| 470 const int kContentWidth = 555; // 7.71 inch | 471 const int kContentWidth = 555; // 7.71 inch |
| 471 const int kContentHeight = 735; // 10.21 inch | 472 const int kContentHeight = 735; // 10.21 inch |
| 472 blink::WebPrintParams params(blink::WebSize(kContentWidth, kContentHeight)); | 473 blink::WebPrintParams params(blink::WebSize(kContentWidth, kContentHeight)); |
| 473 params.printerDPI = 300; | 474 params.printerDPI = 300; |
| 474 int page_count = frame->printBegin(params); | 475 int page_count = frame->printBegin(params); |
| 475 for (int i = 0; i < page_count; ++i) { | 476 for (int i = 0; i < page_count; ++i) { |
| 476 SkCanvas* canvas = doc->beginPage(kPageWidth, kPageHeight); | 477 SkCanvas* sk_canvas = doc->beginPage(kPageWidth, kPageHeight); |
| 477 SkAutoCanvasRestore auto_restore(canvas, true); | 478 cc::PaintCanvasPassThrough canvas(sk_canvas); |
| 478 canvas->translate(kMarginLeft, kMarginTop); | 479 cc::PaintCanvasAutoRestore auto_restore(&canvas, true); |
| 480 canvas.translate(kMarginLeft, kMarginTop); |
| 479 | 481 |
| 480 #if defined(OS_WIN) || defined(OS_MACOSX) | 482 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 481 float page_shrink = frame->getPrintPageShrink(i); | 483 float page_shrink = frame->getPrintPageShrink(i); |
| 482 DCHECK(page_shrink > 0); | 484 DCHECK(page_shrink > 0); |
| 483 canvas->scale(page_shrink, page_shrink); | 485 canvas.scale(page_shrink, page_shrink); |
| 484 #endif | 486 #endif |
| 485 | 487 |
| 486 frame->printPage(i, canvas); | 488 frame->printPage(i, &canvas); |
| 487 } | 489 } |
| 488 frame->printEnd(); | 490 frame->printEnd(); |
| 489 } | 491 } |
| 490 | 492 |
| 491 static void PrintDocumentTofile(v8::Isolate* isolate, | 493 static void PrintDocumentTofile(v8::Isolate* isolate, |
| 492 const std::string& filename, | 494 const std::string& filename, |
| 493 sk_sp<SkDocument> (*make_doc)(SkWStream*)) { | 495 sk_sp<SkDocument> (*make_doc)(SkWStream*)) { |
| 494 GpuBenchmarkingContext context; | 496 GpuBenchmarkingContext context; |
| 495 if (!context.Init(true)) | 497 if (!context.Init(true)) |
| 496 return; | 498 return; |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 &gpu_driver_bug_workarounds))) { | 1100 &gpu_driver_bug_workarounds))) { |
| 1099 return; | 1101 return; |
| 1100 } | 1102 } |
| 1101 | 1103 |
| 1102 v8::Local<v8::Value> result; | 1104 v8::Local<v8::Value> result; |
| 1103 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) | 1105 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) |
| 1104 args->Return(result); | 1106 args->Return(result); |
| 1105 } | 1107 } |
| 1106 | 1108 |
| 1107 } // namespace content | 1109 } // namespace content |
| OLD | NEW |