| Index: content/renderer/gpu/gpu_benchmarking_extension.cc
|
| diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc
|
| index 9605aced430b45548169f8706742cf7344ccf557..b4aadc1821371c8c2cb537cb04af6c68f50f3049 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<SkDocument> (*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<SkDocument> 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<SkDocument> 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,
|
|
|