From f35e994096cf339e54acd9b6883b6d3cf1e5b846 Mon Sep 17 00:00:00 2001 From: halcanary Date: Thu, 3 Nov 2016 12:08:42 -0700 Subject: [PATCH] chrome.gpuBenchmarking.printPagesToXPS BUG=chromium:616763 Review-Url: https://codereview.chromium.org/2413753003 Cr-Commit-Position: refs/heads/master@{#429662} --- .../gpu/gpu_benchmarking_extension.cc | 47 ++++++++++++------- .../renderer/gpu/gpu_benchmarking_extension.h | 2 + skia/BUILD.gn | 6 ++- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc index 9605aced430b45..b4aadc1821371c 100644 --- a/content/renderer/gpu/gpu_benchmarking_extension.cc +++ b/content/renderer/gpu/gpu_benchmarking_extension.cc @@ -480,6 +480,29 @@ static void PrintDocument(blink::WebFrame* frame, SkDocument* doc) { frame->printEnd(); } +static void PrintDocumentTofile(v8::Isolate* isolate, + const std::string& filename, + sk_sp (*make_doc)(SkWStream*)) { + GpuBenchmarkingContext context; + if (!context.Init(true)) + return; + + base::FilePath path = base::FilePath::FromUTF8Unsafe(filename); + if (!base::PathIsWritable(path.DirName())) { + std::string msg("Path is not writable: "); + msg.append(path.DirName().MaybeAsASCII()); + isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( + isolate, msg.c_str(), v8::String::kNormalString, msg.length()))); + return; + } + SkFILEWStream wStream(path.MaybeAsASCII().c_str()); + sk_sp doc = make_doc(&wStream); + if (doc) { + context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true); + PrintDocument(context.web_frame(), doc.get()); + doc->close(); + } +} } // namespace gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; @@ -520,6 +543,8 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) .SetMethod("printPagesToSkPictures", &GpuBenchmarking::PrintPagesToSkPictures) + .SetMethod("printPagesToXPS", + &GpuBenchmarking::PrintPagesToXPS) .SetValue("DEFAULT_INPUT", 0) .SetValue("TOUCH_INPUT", 1) .SetValue("MOUSE_INPUT", 2) @@ -564,23 +589,13 @@ void GpuBenchmarking::SetRasterizeOnlyVisibleContent() { void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate, const std::string& filename) { - GpuBenchmarkingContext context; - if (!context.Init(true)) - return; + PrintDocumentTofile(isolate, filename, &SkMakeMultiPictureDocument); +} - base::FilePath path = base::FilePath::FromUTF8Unsafe(filename); - if (!base::PathIsWritable(path.DirName())) { - std::string msg("Path is not writable: "); - msg.append(path.DirName().MaybeAsASCII()); - isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( - isolate, msg.c_str(), v8::String::kNormalString, msg.length()))); - return; - } - SkFILEWStream wStream(path.MaybeAsASCII().c_str()); - sk_sp doc = SkMakeMultiPictureDocument(&wStream); - context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true); - PrintDocument(context.web_frame(), doc.get()); - doc->close(); +void GpuBenchmarking::PrintPagesToXPS(v8::Isolate* isolate, + const std::string& filename) { + PrintDocumentTofile(isolate, filename, + [](SkWStream* s) { return SkDocument::MakeXPS(s); }); } void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate, diff --git a/content/renderer/gpu/gpu_benchmarking_extension.h b/content/renderer/gpu/gpu_benchmarking_extension.h index 8aad53b0dd18df..64299528453a36 100644 --- a/content/renderer/gpu/gpu_benchmarking_extension.h +++ b/content/renderer/gpu/gpu_benchmarking_extension.h @@ -44,6 +44,8 @@ class GpuBenchmarking : public gin::Wrappable { void PrintToSkPicture(v8::Isolate* isolate, const std::string& dirname); void PrintPagesToSkPictures(v8::Isolate* isolate, const std::string& filename); + void PrintPagesToXPS(v8::Isolate* isolate, + const std::string& filename); bool GestureSourceTypeSupported(int gesture_source_type); bool SmoothScrollBy(gin::Arguments* args); bool SmoothDrag(gin::Arguments* args); diff --git a/skia/BUILD.gn b/skia/BUILD.gn index 6a4129d6436bb7..37c26fbeda757d 100644 --- a/skia/BUILD.gn +++ b/skia/BUILD.gn @@ -268,6 +268,9 @@ component("skia") { "//third_party/skia/src/ports/SkTypeface_win_dw.cpp", "//third_party/skia/src/sfnt/SkOTTable_name.cpp", "//third_party/skia/src/sfnt/SkOTUtils.cpp", + "//third_party/skia/src/xps/SkDocument_XPS.cpp", + "//third_party/skia/src/xps/SkDocument_XPS_None.cpp", + "//third_party/skia/src/xps/SkXPSDevice.cpp", ] if (is_mac) { @@ -309,6 +312,7 @@ component("skia") { # Keeping _win.cpp "//third_party/skia/src/utils/SkThreadUtils_pthread.cpp", ] + libs = [ "fontsub.lib" ] } else { sources -= [ # Keeping _pthread.cpp @@ -321,8 +325,6 @@ component("skia") { if (is_win) { sources -= [ #windows - "//third_party/skia/src/utils/win/SkAutoCoInitialize.cpp", - "//third_party/skia/src/utils/win/SkIStream.cpp", "//third_party/skia/src/utils/win/SkWGL_win.cpp", ] }