| 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> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "content/public/renderer/chrome_object_extensions_utils.h" | 28 #include "content/public/renderer/chrome_object_extensions_utils.h" |
| 29 #include "content/public/renderer/render_thread.h" | 29 #include "content/public/renderer/render_thread.h" |
| 30 #include "content/renderer/gpu/render_widget_compositor.h" | 30 #include "content/renderer/gpu/render_widget_compositor.h" |
| 31 #include "content/renderer/render_thread_impl.h" | 31 #include "content/renderer/render_thread_impl.h" |
| 32 #include "content/renderer/render_view_impl.h" | 32 #include "content/renderer/render_view_impl.h" |
| 33 #include "content/renderer/skia_benchmarking_extension.h" | 33 #include "content/renderer/skia_benchmarking_extension.h" |
| 34 #include "gin/arguments.h" | 34 #include "gin/arguments.h" |
| 35 #include "gin/handle.h" | 35 #include "gin/handle.h" |
| 36 #include "gin/object_template_builder.h" | 36 #include "gin/object_template_builder.h" |
| 37 #include "gpu/ipc/common/gpu_messages.h" | 37 #include "gpu/ipc/common/gpu_messages.h" |
| 38 #include "skia/ext/cdl_canvas.h" |
| 38 #include "third_party/WebKit/public/web/WebImageCache.h" | 39 #include "third_party/WebKit/public/web/WebImageCache.h" |
| 39 #include "third_party/WebKit/public/web/WebKit.h" | 40 #include "third_party/WebKit/public/web/WebKit.h" |
| 40 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 41 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 41 #include "third_party/WebKit/public/web/WebPrintParams.h" | 42 #include "third_party/WebKit/public/web/WebPrintParams.h" |
| 42 #include "third_party/WebKit/public/web/WebSettings.h" | 43 #include "third_party/WebKit/public/web/WebSettings.h" |
| 43 #include "third_party/WebKit/public/web/WebView.h" | 44 #include "third_party/WebKit/public/web/WebView.h" |
| 44 #include "third_party/skia/include/core/SkData.h" | 45 #include "third_party/skia/include/core/SkData.h" |
| 45 #include "third_party/skia/include/core/SkGraphics.h" | 46 #include "third_party/skia/include/core/SkGraphics.h" |
| 46 #include "third_party/skia/include/core/SkPicture.h" | 47 #include "third_party/skia/include/core/SkPicture.h" |
| 47 #include "third_party/skia/include/core/SkPictureRecorder.h" | 48 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Let skia register known effect subclasses. This basically enables | 126 // Let skia register known effect subclasses. This basically enables |
| 126 // reflection on those subclasses required for picture serialization. | 127 // reflection on those subclasses required for picture serialization. |
| 127 SkiaBenchmarking::Initialize(); | 128 SkiaBenchmarking::Initialize(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // Recursively serializes the layer tree. | 131 // Recursively serializes the layer tree. |
| 131 // Each layer in the tree is serialized into a separate skp file | 132 // Each layer in the tree is serialized into a separate skp file |
| 132 // in the given directory. | 133 // in the given directory. |
| 133 void Serialize(const cc::Layer* root_layer) { | 134 void Serialize(const cc::Layer* root_layer) { |
| 134 for (auto* layer : *root_layer->GetLayerTree()) { | 135 for (auto* layer : *root_layer->GetLayerTree()) { |
| 135 sk_sp<SkPicture> picture = layer->GetPicture(); | 136 sk_sp<const SkPicture> picture = ToSkPicture(layer->GetPicture().get()); |
| 136 if (!picture) | 137 if (!picture) |
| 137 continue; | 138 continue; |
| 138 | 139 |
| 139 // Serialize picture to file. | 140 // Serialize picture to file. |
| 140 // TODO(alokp): Note that for this to work Chrome needs to be launched | 141 // TODO(alokp): Note that for this to work Chrome needs to be launched |
| 141 // with | 142 // with |
| 142 // --no-sandbox command-line flag. Get rid of this limitation. | 143 // --no-sandbox command-line flag. Get rid of this limitation. |
| 143 // CRBUG: 139640. | 144 // CRBUG: 139640. |
| 144 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; | 145 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; |
| 145 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); | 146 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 const float kPageWidth = 612.0f; // 8.5 inch | 459 const float kPageWidth = 612.0f; // 8.5 inch |
| 459 const float kPageHeight = 792.0f; // 11 inch | 460 const float kPageHeight = 792.0f; // 11 inch |
| 460 const float kMarginTop = 29.0f; // 0.40 inch | 461 const float kMarginTop = 29.0f; // 0.40 inch |
| 461 const float kMarginLeft = 29.0f; // 0.40 inch | 462 const float kMarginLeft = 29.0f; // 0.40 inch |
| 462 const int kContentWidth = 555; // 7.71 inch | 463 const int kContentWidth = 555; // 7.71 inch |
| 463 const int kContentHeight = 735; // 10.21 inch | 464 const int kContentHeight = 735; // 10.21 inch |
| 464 blink::WebPrintParams params(blink::WebSize(kContentWidth, kContentHeight)); | 465 blink::WebPrintParams params(blink::WebSize(kContentWidth, kContentHeight)); |
| 465 params.printerDPI = 300; | 466 params.printerDPI = 300; |
| 466 int page_count = frame->printBegin(params); | 467 int page_count = frame->printBegin(params); |
| 467 for (int i = 0; i < page_count; ++i) { | 468 for (int i = 0; i < page_count; ++i) { |
| 468 SkCanvas* canvas = doc->beginPage(kPageWidth, kPageHeight); | 469 SkCanvas* sk_canvas = doc->beginPage(kPageWidth, kPageHeight); |
| 469 SkAutoCanvasRestore auto_restore(canvas, true); | 470 CdlPassThroughCanvas canvas(sk_canvas); |
| 470 canvas->translate(kMarginLeft, kMarginTop); | 471 CdlAutoCanvasRestore auto_restore(&canvas, true); |
| 472 canvas.translate(kMarginLeft, kMarginTop); |
| 471 | 473 |
| 472 #if defined(OS_WIN) || defined(OS_MACOSX) | 474 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 473 float page_shrink = frame->getPrintPageShrink(i); | 475 float page_shrink = frame->getPrintPageShrink(i); |
| 474 DCHECK(page_shrink > 0); | 476 DCHECK(page_shrink > 0); |
| 475 canvas->scale(page_shrink, page_shrink); | 477 canvas.scale(page_shrink, page_shrink); |
| 476 #endif | 478 #endif |
| 477 | 479 |
| 478 frame->printPage(i, canvas); | 480 frame->printPage(i, &canvas); |
| 479 } | 481 } |
| 480 frame->printEnd(); | 482 frame->printEnd(); |
| 481 } | 483 } |
| 482 | 484 |
| 483 static void PrintDocumentTofile(v8::Isolate* isolate, | 485 static void PrintDocumentTofile(v8::Isolate* isolate, |
| 484 const std::string& filename, | 486 const std::string& filename, |
| 485 sk_sp<SkDocument> (*make_doc)(SkWStream*)) { | 487 sk_sp<SkDocument> (*make_doc)(SkWStream*)) { |
| 486 GpuBenchmarkingContext context; | 488 GpuBenchmarkingContext context; |
| 487 if (!context.Init(true)) | 489 if (!context.Init(true)) |
| 488 return; | 490 return; |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 &gpu_driver_bug_workarounds))) { | 1044 &gpu_driver_bug_workarounds))) { |
| 1043 return; | 1045 return; |
| 1044 } | 1046 } |
| 1045 | 1047 |
| 1046 v8::Local<v8::Value> result; | 1048 v8::Local<v8::Value> result; |
| 1047 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) | 1049 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) |
| 1048 args->Return(result); | 1050 args->Return(result); |
| 1049 } | 1051 } |
| 1050 | 1052 |
| 1051 } // namespace content | 1053 } // namespace content |
| OLD | NEW |