Chromium Code Reviews| 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 6fbc7e7b0ec29f2500d410f75c20f6a4e1fe5b50..366eb3d5d8de156f1025ad923408f0d2f05833d2 100644 |
| --- a/content/renderer/gpu/gpu_benchmarking_extension.cc |
| +++ b/content/renderer/gpu/gpu_benchmarking_extension.cc |
| @@ -38,13 +38,18 @@ |
| #include "third_party/WebKit/public/web/WebImageCache.h" |
| #include "third_party/WebKit/public/web/WebKit.h" |
| #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| +#include "third_party/WebKit/public/web/WebPrintParams.h" |
| #include "third_party/WebKit/public/web/WebView.h" |
| #include "third_party/skia/include/core/SkData.h" |
| #include "third_party/skia/include/core/SkGraphics.h" |
| #include "third_party/skia/include/core/SkPicture.h" |
| +#include "third_party/skia/include/core/SkPictureRecorder.h" |
| #include "third_party/skia/include/core/SkPixelRef.h" |
| #include "third_party/skia/include/core/SkPixelSerializer.h" |
| #include "third_party/skia/include/core/SkStream.h" |
| +// Note that headers in third_party/skia/src are fragile. This is |
| +// an experimental, fragile, and diagnostic-only document type. |
| +#include "third_party/skia/src/utils/SkMultiPictureDocument.h" |
| #include "ui/gfx/codec/png_codec.h" |
| #include "v8/include/v8.h" |
| @@ -486,6 +491,8 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( |
| .SetMethod("setRasterizeOnlyVisibleContent", |
| &GpuBenchmarking::SetRasterizeOnlyVisibleContent) |
| .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) |
| + .SetMethod("printPagesToSkPictures", |
| + &GpuBenchmarking::PrintPagesToSkPictures) |
| .SetValue("DEFAULT_INPUT", 0) |
| .SetValue("TOUCH_INPUT", 1) |
| .SetValue("MOUSE_INPUT", 2) |
| @@ -528,6 +535,45 @@ void GpuBenchmarking::SetRasterizeOnlyVisibleContent() { |
| context.compositor()->SetRasterizeOnlyVisibleContent(); |
| } |
| +void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate, |
| + const std::string& filename) { |
| + 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; |
| + } |
| + const int width = 612; // 8.5 inch |
|
Lei Zhang
2016/08/19 16:33:11
kFoo
hal.canary
2016/08/19 16:43:30
Done.
|
| + const int height = 792; // 11 inch |
| + const int margin_top = 29; // 0.40 inch |
| + const int margin_left = 29; // 0.40 inch |
| + const int content_width = 555; // 7.71 inch |
| + const int content_height = 735; // 10.21 inch |
| + blink::WebPrintParams params(blink::WebSize(width, height)); |
| + params.printerDPI = 72; |
| + params.printScalingOption = blink::WebPrintScalingOptionSourceSize; |
| + params.printContentArea = |
| + blink::WebRect(margin_left, margin_top, content_width, content_height); |
| + SkFILEWStream wStream(path.MaybeAsASCII().c_str()); |
| + sk_sp<SkDocument> doc = SkMakeMultiPictureDocument(&wStream); |
| + int pageCount = context.web_frame()->printBegin(params); |
|
Lei Zhang
2016/08/19 16:33:11
page_count
hal.canary
2016/08/19 16:43:30
Done.
|
| + for (int i = 0; i < pageCount; ++i) { |
| + SkCanvas* canvas = |
| + doc->beginPage(SkIntToScalar(width), SkIntToScalar(height)); |
| + SkAutoCanvasRestore auto_restore(canvas, true); |
| + canvas->translate(SkIntToScalar(margin_left), SkIntToScalar(margin_top)); |
| + context.web_frame()->printPage(i, canvas); |
| + } |
| + context.web_frame()->printEnd(); |
| + doc->close(); |
| +} |
| + |
| void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate, |
| const std::string& dirname) { |
| GpuBenchmarkingContext context; |