Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 2413753003: chrome.gpuBenchmarking.printPagesToXPS (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 float page_shrink = frame->getPrintPageShrink(i); 473 float page_shrink = frame->getPrintPageShrink(i);
474 DCHECK(page_shrink > 0); 474 DCHECK(page_shrink > 0);
475 canvas->scale(page_shrink, page_shrink); 475 canvas->scale(page_shrink, page_shrink);
476 #endif 476 #endif
477 477
478 frame->printPage(i, canvas); 478 frame->printPage(i, canvas);
479 } 479 }
480 frame->printEnd(); 480 frame->printEnd();
481 } 481 }
482 482
483 static void PrintDocumentTofile(v8::Isolate* isolate,
484 const std::string& filename,
485 sk_sp<SkDocument> (*make_doc)(SkWStream*)) {
486 GpuBenchmarkingContext context;
487 if (!context.Init(true))
488 return;
489
490 base::FilePath path = base::FilePath::FromUTF8Unsafe(filename);
491 if (!base::PathIsWritable(path.DirName())) {
492 std::string msg("Path is not writable: ");
493 msg.append(path.DirName().MaybeAsASCII());
494 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(
495 isolate, msg.c_str(), v8::String::kNormalString, msg.length())));
496 return;
497 }
498 SkFILEWStream wStream(path.MaybeAsASCII().c_str());
499 sk_sp<SkDocument> doc = make_doc(&wStream);
500 if (doc) {
501 context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true);
502 PrintDocument(context.web_frame(), doc.get());
503 doc->close();
504 }
505 }
483 } // namespace 506 } // namespace
484 507
485 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; 508 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin};
486 509
487 // static 510 // static
488 void GpuBenchmarking::Install(blink::WebFrame* frame) { 511 void GpuBenchmarking::Install(blink::WebFrame* frame) {
489 v8::Isolate* isolate = blink::mainThreadIsolate(); 512 v8::Isolate* isolate = blink::mainThreadIsolate();
490 v8::HandleScope handle_scope(isolate); 513 v8::HandleScope handle_scope(isolate);
491 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 514 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
492 if (context.IsEmpty()) 515 if (context.IsEmpty())
(...skipping 20 matching lines...) Expand all
513 gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( 536 gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder(
514 v8::Isolate* isolate) { 537 v8::Isolate* isolate) {
515 return gin::Wrappable<GpuBenchmarking>::GetObjectTemplateBuilder(isolate) 538 return gin::Wrappable<GpuBenchmarking>::GetObjectTemplateBuilder(isolate)
516 .SetMethod("setNeedsDisplayOnAllLayers", 539 .SetMethod("setNeedsDisplayOnAllLayers",
517 &GpuBenchmarking::SetNeedsDisplayOnAllLayers) 540 &GpuBenchmarking::SetNeedsDisplayOnAllLayers)
518 .SetMethod("setRasterizeOnlyVisibleContent", 541 .SetMethod("setRasterizeOnlyVisibleContent",
519 &GpuBenchmarking::SetRasterizeOnlyVisibleContent) 542 &GpuBenchmarking::SetRasterizeOnlyVisibleContent)
520 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) 543 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture)
521 .SetMethod("printPagesToSkPictures", 544 .SetMethod("printPagesToSkPictures",
522 &GpuBenchmarking::PrintPagesToSkPictures) 545 &GpuBenchmarking::PrintPagesToSkPictures)
546 .SetMethod("printPagesToXPS",
547 &GpuBenchmarking::PrintPagesToXPS)
523 .SetValue("DEFAULT_INPUT", 0) 548 .SetValue("DEFAULT_INPUT", 0)
524 .SetValue("TOUCH_INPUT", 1) 549 .SetValue("TOUCH_INPUT", 1)
525 .SetValue("MOUSE_INPUT", 2) 550 .SetValue("MOUSE_INPUT", 2)
526 .SetMethod("gestureSourceTypeSupported", 551 .SetMethod("gestureSourceTypeSupported",
527 &GpuBenchmarking::GestureSourceTypeSupported) 552 &GpuBenchmarking::GestureSourceTypeSupported)
528 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) 553 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy)
529 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag) 554 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag)
530 .SetMethod("swipe", &GpuBenchmarking::Swipe) 555 .SetMethod("swipe", &GpuBenchmarking::Swipe)
531 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) 556 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce)
532 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) 557 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy)
(...skipping 24 matching lines...) Expand all
557 void GpuBenchmarking::SetRasterizeOnlyVisibleContent() { 582 void GpuBenchmarking::SetRasterizeOnlyVisibleContent() {
558 GpuBenchmarkingContext context; 583 GpuBenchmarkingContext context;
559 if (!context.Init(true)) 584 if (!context.Init(true))
560 return; 585 return;
561 586
562 context.compositor()->SetRasterizeOnlyVisibleContent(); 587 context.compositor()->SetRasterizeOnlyVisibleContent();
563 } 588 }
564 589
565 void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate, 590 void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate,
566 const std::string& filename) { 591 const std::string& filename) {
567 GpuBenchmarkingContext context; 592 PrintDocumentTofile(isolate, filename, &SkMakeMultiPictureDocument);
568 if (!context.Init(true)) 593 }
569 return;
570 594
571 base::FilePath path = base::FilePath::FromUTF8Unsafe(filename); 595 void GpuBenchmarking::PrintPagesToXPS(v8::Isolate* isolate,
572 if (!base::PathIsWritable(path.DirName())) { 596 const std::string& filename) {
573 std::string msg("Path is not writable: "); 597 PrintDocumentTofile(isolate, filename,
574 msg.append(path.DirName().MaybeAsASCII()); 598 [](SkWStream* s) { return SkDocument::MakeXPS(s); });
575 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(
576 isolate, msg.c_str(), v8::String::kNormalString, msg.length())));
577 return;
578 }
579 SkFILEWStream wStream(path.MaybeAsASCII().c_str());
580 sk_sp<SkDocument> doc = SkMakeMultiPictureDocument(&wStream);
581 context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true);
582 PrintDocument(context.web_frame(), doc.get());
583 doc->close();
584 } 599 }
585 600
586 void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate, 601 void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate,
587 const std::string& dirname) { 602 const std::string& dirname) {
588 GpuBenchmarkingContext context; 603 GpuBenchmarkingContext context;
589 if (!context.Init(true)) 604 if (!context.Init(true))
590 return; 605 return;
591 606
592 const cc::Layer* root_layer = context.compositor()->GetRootLayer(); 607 const cc::Layer* root_layer = context.compositor()->GetRootLayer();
593 if (!root_layer) 608 if (!root_layer)
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 &gpu_driver_bug_workarounds))) { 1042 &gpu_driver_bug_workarounds))) {
1028 return; 1043 return;
1029 } 1044 }
1030 1045
1031 v8::Local<v8::Value> result; 1046 v8::Local<v8::Value> result;
1032 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) 1047 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result))
1033 args->Return(result); 1048 args->Return(result);
1034 } 1049 }
1035 1050
1036 } // namespace content 1051 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698