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

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

Issue 2374203002: PrintPagesToSkPictures: observe WebFrame::getPrintPageShrink() (Closed)
Patch Set: work on macos Created 4 years, 2 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 // progress, we will leak the callback and context. This needs to be fixed, 447 // progress, we will leak the callback and context. This needs to be fixed,
448 // somehow. 448 // somehow.
449 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( 449 context.render_view_impl()->GetWidget()->QueueSyntheticGesture(
450 std::move(gesture_params), 450 std::move(gesture_params),
451 base::Bind(&OnSyntheticGestureCompleted, 451 base::Bind(&OnSyntheticGestureCompleted,
452 base::RetainedRef(callback_and_context))); 452 base::RetainedRef(callback_and_context)));
453 453
454 return true; 454 return true;
455 } 455 }
456 456
457 static void PrintDocument(blink::WebFrame* frame, SkDocument* doc) {
458 const float kPageWidth = 612.0f; // 8.5 inch
459 const float kPageHeight = 792.0f; // 11 inch
460 const float kMarginTop = 29.0f; // 0.40 inch
461 const float kMarginLeft = 29.0f; // 0.40 inch
462 const int kContentWidth = 555; // 7.71 inch
463 const int kContentHeight = 735; // 10.21 inch
464 blink::WebPrintParams params(blink::WebSize(kContentWidth, kContentHeight));
465 params.printerDPI = 300;
466 int page_count = frame->printBegin(params);
467 for (int i = 0; i < page_count; ++i) {
468 SkCanvas* canvas = doc->beginPage(kPageWidth, kPageHeight);
469 SkAutoCanvasRestore auto_restore(canvas, true);
470 canvas->translate(kMarginLeft, kMarginTop);
471
472 #if defined(OS_WIN) || defined(OS_MACOSX)
473 float page_shrink = frame->getPrintPageShrink(i);
474 DCHECK(page_shrink > 0);
475 canvas->scale(page_shrink, page_shrink);
476 #endif
477
478 frame->printPage(i, canvas);
479 }
480 frame->printEnd();
481 }
482
457 } // namespace 483 } // namespace
458 484
459 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; 485 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin};
460 486
461 // static 487 // static
462 void GpuBenchmarking::Install(blink::WebFrame* frame) { 488 void GpuBenchmarking::Install(blink::WebFrame* frame) {
463 v8::Isolate* isolate = blink::mainThreadIsolate(); 489 v8::Isolate* isolate = blink::mainThreadIsolate();
464 v8::HandleScope handle_scope(isolate); 490 v8::HandleScope handle_scope(isolate);
465 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 491 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
466 if (context.IsEmpty()) 492 if (context.IsEmpty())
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 return; 569 return;
544 570
545 base::FilePath path = base::FilePath::FromUTF8Unsafe(filename); 571 base::FilePath path = base::FilePath::FromUTF8Unsafe(filename);
546 if (!base::PathIsWritable(path.DirName())) { 572 if (!base::PathIsWritable(path.DirName())) {
547 std::string msg("Path is not writable: "); 573 std::string msg("Path is not writable: ");
548 msg.append(path.DirName().MaybeAsASCII()); 574 msg.append(path.DirName().MaybeAsASCII());
549 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( 575 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(
550 isolate, msg.c_str(), v8::String::kNormalString, msg.length()))); 576 isolate, msg.c_str(), v8::String::kNormalString, msg.length())));
551 return; 577 return;
552 } 578 }
553 const int kWidth = 612; // 8.5 inch
554 const int kHeight = 792; // 11 inch
555 const int kMarginTop = 29; // 0.40 inch
556 const int kMarginLeft = 29; // 0.40 inch
557 const int kContentWidth = 555; // 7.71 inch
558 const int kContentHeight = 735; // 10.21 inch
559 blink::WebPrintParams params(blink::WebSize(kWidth, kHeight));
560 params.printerDPI = 72;
561 params.printScalingOption = blink::WebPrintScalingOptionSourceSize;
562 params.printContentArea =
563 blink::WebRect(kMarginLeft, kMarginTop, kContentWidth, kContentHeight);
564 SkFILEWStream wStream(path.MaybeAsASCII().c_str()); 579 SkFILEWStream wStream(path.MaybeAsASCII().c_str());
565 sk_sp<SkDocument> doc = SkMakeMultiPictureDocument(&wStream); 580 sk_sp<SkDocument> doc = SkMakeMultiPictureDocument(&wStream);
566 context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true); 581 context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true);
567 int page_count = context.web_frame()->printBegin(params); 582 PrintDocument(context.web_frame(), doc.get());
568 for (int i = 0; i < page_count; ++i) {
569 SkCanvas* canvas =
570 doc->beginPage(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
571 SkAutoCanvasRestore auto_restore(canvas, true);
572 canvas->translate(SkIntToScalar(kMarginLeft), SkIntToScalar(kMarginTop));
573 context.web_frame()->printPage(i, canvas);
574 }
575 context.web_frame()->printEnd();
576 doc->close(); 583 doc->close();
577 } 584 }
578 585
579 void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate, 586 void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate,
580 const std::string& dirname) { 587 const std::string& dirname) {
581 GpuBenchmarkingContext context; 588 GpuBenchmarkingContext context;
582 if (!context.Init(true)) 589 if (!context.Init(true))
583 return; 590 return;
584 591
585 const cc::Layer* root_layer = context.compositor()->GetRootLayer(); 592 const cc::Layer* root_layer = context.compositor()->GetRootLayer();
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 &gpu_driver_bug_workarounds))) { 1015 &gpu_driver_bug_workarounds))) {
1009 return; 1016 return;
1010 } 1017 }
1011 1018
1012 v8::Local<v8::Value> result; 1019 v8::Local<v8::Value> result;
1013 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) 1020 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result))
1014 args->Return(result); 1021 args->Return(result);
1015 } 1022 }
1016 1023
1017 } // namespace content 1024 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698