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 20 matching lines...) Expand all Loading... |
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 "third_party/WebKit/public/web/WebImageCache.h" | 38 #include "third_party/WebKit/public/web/WebImageCache.h" |
39 #include "third_party/WebKit/public/web/WebKit.h" | 39 #include "third_party/WebKit/public/web/WebKit.h" |
40 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 40 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 41 #include "third_party/WebKit/public/web/WebPrintParams.h" |
41 #include "third_party/WebKit/public/web/WebView.h" | 42 #include "third_party/WebKit/public/web/WebView.h" |
42 #include "third_party/skia/include/core/SkData.h" | 43 #include "third_party/skia/include/core/SkData.h" |
43 #include "third_party/skia/include/core/SkGraphics.h" | 44 #include "third_party/skia/include/core/SkGraphics.h" |
44 #include "third_party/skia/include/core/SkPicture.h" | 45 #include "third_party/skia/include/core/SkPicture.h" |
| 46 #include "third_party/skia/include/core/SkPictureRecorder.h" |
45 #include "third_party/skia/include/core/SkPixelRef.h" | 47 #include "third_party/skia/include/core/SkPixelRef.h" |
46 #include "third_party/skia/include/core/SkPixelSerializer.h" | 48 #include "third_party/skia/include/core/SkPixelSerializer.h" |
47 #include "third_party/skia/include/core/SkStream.h" | 49 #include "third_party/skia/include/core/SkStream.h" |
| 50 // Note that headers in third_party/skia/src are fragile. This is |
| 51 // an experimental, fragile, and diagnostic-only document type. |
| 52 #include "third_party/skia/src/utils/SkMultiPictureDocument.h" |
48 #include "ui/gfx/codec/png_codec.h" | 53 #include "ui/gfx/codec/png_codec.h" |
49 #include "v8/include/v8.h" | 54 #include "v8/include/v8.h" |
50 | 55 |
51 using blink::WebCanvas; | 56 using blink::WebCanvas; |
52 using blink::WebLocalFrame; | 57 using blink::WebLocalFrame; |
53 using blink::WebImageCache; | 58 using blink::WebImageCache; |
54 using blink::WebPrivatePtr; | 59 using blink::WebPrivatePtr; |
55 using blink::WebSize; | 60 using blink::WebSize; |
56 using blink::WebView; | 61 using blink::WebView; |
57 | 62 |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 } | 484 } |
480 | 485 |
481 gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( | 486 gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( |
482 v8::Isolate* isolate) { | 487 v8::Isolate* isolate) { |
483 return gin::Wrappable<GpuBenchmarking>::GetObjectTemplateBuilder(isolate) | 488 return gin::Wrappable<GpuBenchmarking>::GetObjectTemplateBuilder(isolate) |
484 .SetMethod("setNeedsDisplayOnAllLayers", | 489 .SetMethod("setNeedsDisplayOnAllLayers", |
485 &GpuBenchmarking::SetNeedsDisplayOnAllLayers) | 490 &GpuBenchmarking::SetNeedsDisplayOnAllLayers) |
486 .SetMethod("setRasterizeOnlyVisibleContent", | 491 .SetMethod("setRasterizeOnlyVisibleContent", |
487 &GpuBenchmarking::SetRasterizeOnlyVisibleContent) | 492 &GpuBenchmarking::SetRasterizeOnlyVisibleContent) |
488 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) | 493 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) |
| 494 .SetMethod("printPagesToSkPictures", |
| 495 &GpuBenchmarking::PrintPagesToSkPictures) |
489 .SetValue("DEFAULT_INPUT", 0) | 496 .SetValue("DEFAULT_INPUT", 0) |
490 .SetValue("TOUCH_INPUT", 1) | 497 .SetValue("TOUCH_INPUT", 1) |
491 .SetValue("MOUSE_INPUT", 2) | 498 .SetValue("MOUSE_INPUT", 2) |
492 .SetMethod("gestureSourceTypeSupported", | 499 .SetMethod("gestureSourceTypeSupported", |
493 &GpuBenchmarking::GestureSourceTypeSupported) | 500 &GpuBenchmarking::GestureSourceTypeSupported) |
494 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) | 501 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) |
495 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag) | 502 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag) |
496 .SetMethod("swipe", &GpuBenchmarking::Swipe) | 503 .SetMethod("swipe", &GpuBenchmarking::Swipe) |
497 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) | 504 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) |
498 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) | 505 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) |
(...skipping 22 matching lines...) Expand all Loading... |
521 } | 528 } |
522 | 529 |
523 void GpuBenchmarking::SetRasterizeOnlyVisibleContent() { | 530 void GpuBenchmarking::SetRasterizeOnlyVisibleContent() { |
524 GpuBenchmarkingContext context; | 531 GpuBenchmarkingContext context; |
525 if (!context.Init(true)) | 532 if (!context.Init(true)) |
526 return; | 533 return; |
527 | 534 |
528 context.compositor()->SetRasterizeOnlyVisibleContent(); | 535 context.compositor()->SetRasterizeOnlyVisibleContent(); |
529 } | 536 } |
530 | 537 |
| 538 void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate, |
| 539 const std::string& filename) { |
| 540 GpuBenchmarkingContext context; |
| 541 if (!context.Init(true)) |
| 542 return; |
| 543 |
| 544 base::FilePath path = base::FilePath::FromUTF8Unsafe(filename); |
| 545 if (!base::PathIsWritable(path.DirName())) { |
| 546 std::string msg("Path is not writable: "); |
| 547 msg.append(path.DirName().MaybeAsASCII()); |
| 548 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( |
| 549 isolate, msg.c_str(), v8::String::kNormalString, msg.length()))); |
| 550 return; |
| 551 } |
| 552 const int kWidth = 612; // 8.5 inch |
| 553 const int kHeight = 792; // 11 inch |
| 554 const int kMarginTop = 29; // 0.40 inch |
| 555 const int kMarginLeft = 29; // 0.40 inch |
| 556 const int kContentWidth = 555; // 7.71 inch |
| 557 const int kContentHeight = 735; // 10.21 inch |
| 558 blink::WebPrintParams params(blink::WebSize(kWidth, kHeight)); |
| 559 params.printerDPI = 72; |
| 560 params.printScalingOption = blink::WebPrintScalingOptionSourceSize; |
| 561 params.printContentArea = |
| 562 blink::WebRect(kMarginLeft, kMarginTop, kContentWidth, kContentHeight); |
| 563 SkFILEWStream wStream(path.MaybeAsASCII().c_str()); |
| 564 sk_sp<SkDocument> doc = SkMakeMultiPictureDocument(&wStream); |
| 565 int page_count = context.web_frame()->printBegin(params); |
| 566 for (int i = 0; i < page_count; ++i) { |
| 567 SkCanvas* canvas = |
| 568 doc->beginPage(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); |
| 569 SkAutoCanvasRestore auto_restore(canvas, true); |
| 570 canvas->translate(SkIntToScalar(kMarginLeft), SkIntToScalar(kMarginTop)); |
| 571 context.web_frame()->printPage(i, canvas); |
| 572 } |
| 573 context.web_frame()->printEnd(); |
| 574 doc->close(); |
| 575 } |
| 576 |
531 void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate, | 577 void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate, |
532 const std::string& dirname) { | 578 const std::string& dirname) { |
533 GpuBenchmarkingContext context; | 579 GpuBenchmarkingContext context; |
534 if (!context.Init(true)) | 580 if (!context.Init(true)) |
535 return; | 581 return; |
536 | 582 |
537 const cc::Layer* root_layer = context.compositor()->GetRootLayer(); | 583 const cc::Layer* root_layer = context.compositor()->GetRootLayer(); |
538 if (!root_layer) | 584 if (!root_layer) |
539 return; | 585 return; |
540 | 586 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 &gpu_driver_bug_workarounds))) { | 1006 &gpu_driver_bug_workarounds))) { |
961 return; | 1007 return; |
962 } | 1008 } |
963 | 1009 |
964 v8::Local<v8::Value> result; | 1010 v8::Local<v8::Value> result; |
965 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) | 1011 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) |
966 args->Return(result); | 1012 args->Return(result); |
967 } | 1013 } |
968 | 1014 |
969 } // namespace content | 1015 } // namespace content |
OLD | NEW |