OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/renderer/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 return; | 504 return; |
505 } | 505 } |
506 | 506 |
507 // Generate a memory-based EMF file. The EMF will use the current screen's | 507 // Generate a memory-based EMF file. The EMF will use the current screen's |
508 // DPI. | 508 // DPI. |
509 gfx::Emf emf; | 509 gfx::Emf emf; |
510 | 510 |
511 emf.CreateDc(NULL, NULL); | 511 emf.CreateDc(NULL, NULL); |
512 HDC hdc = emf.hdc(); | 512 HDC hdc = emf.hdc(); |
513 DCHECK(hdc); | 513 DCHECK(hdc); |
514 gfx::PlatformDeviceWin::InitializeDC(hdc); | 514 skia::PlatformDeviceWin::InitializeDC(hdc); |
515 | 515 |
516 gfx::Rect rect; | 516 gfx::Rect rect; |
517 frame->GetPageRect(params.page_number, &rect); | 517 frame->GetPageRect(params.page_number, &rect); |
518 DCHECK(rect.height()); | 518 DCHECK(rect.height()); |
519 DCHECK(rect.width()); | 519 DCHECK(rect.width()); |
520 double shrink = static_cast<double>(printed_document_width_) / | 520 double shrink = static_cast<double>(printed_document_width_) / |
521 params.params.printable_size.width(); | 521 params.params.printable_size.width(); |
522 // This check would fire each time the page would get truncated on the | 522 // This check would fire each time the page would get truncated on the |
523 // right. This is not worth a DCHECK() but should be looked into, for | 523 // right. This is not worth a DCHECK() but should be looked into, for |
524 // example, wouldn't be worth trying in landscape? | 524 // example, wouldn't be worth trying in landscape? |
525 // DCHECK_LE(rect.width(), printed_document_width_); | 525 // DCHECK_LE(rect.width(), printed_document_width_); |
526 | 526 |
527 // Buffer one page at a time. | 527 // Buffer one page at a time. |
528 int src_size_x = printed_document_width_; | 528 int src_size_x = printed_document_width_; |
529 int src_size_y = | 529 int src_size_y = |
530 static_cast<int>(ceil(params.params.printable_size.height() * | 530 static_cast<int>(ceil(params.params.printable_size.height() * |
531 shrink)); | 531 shrink)); |
532 #if 0 | 532 #if 0 |
533 // TODO(maruel): This code is kept for testing until the 100% GDI drawing | 533 // TODO(maruel): This code is kept for testing until the 100% GDI drawing |
534 // code is stable. maruels use this code's output as a reference when the | 534 // code is stable. maruels use this code's output as a reference when the |
535 // GDI drawing code fails. | 535 // GDI drawing code fails. |
536 | 536 |
537 // Mix of Skia and GDI based. | 537 // Mix of Skia and GDI based. |
538 gfx::PlatformCanvasWin canvas(src_size_x, src_size_y, true); | 538 skia::PlatformCanvasWin canvas(src_size_x, src_size_y, true); |
539 canvas.drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode); | 539 canvas.drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode); |
540 PlatformContextSkia context(&canvas); | 540 PlatformContextSkia context(&canvas); |
541 if (!frame->SpoolPage(params.page_number, &context)) { | 541 if (!frame->SpoolPage(params.page_number, &context)) { |
542 NOTREACHED() << "Printing page " << params.page_number << " failed."; | 542 NOTREACHED() << "Printing page " << params.page_number << " failed."; |
543 return; | 543 return; |
544 } | 544 } |
545 | 545 |
546 // Create a BMP v4 header that we can serialize. | 546 // Create a BMP v4 header that we can serialize. |
547 BITMAPV4HEADER bitmap_header; | 547 BITMAPV4HEADER bitmap_header; |
548 gfx::CreateBitmapV4Header(src_size_x, src_size_y, &bitmap_header); | 548 gfx::CreateBitmapV4Header(src_size_x, src_size_y, &bitmap_header); |
549 const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true); | 549 const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true); |
550 SkAutoLockPixels src_lock(src_bmp); | 550 SkAutoLockPixels src_lock(src_bmp); |
551 int retval = StretchDIBits(hdc, | 551 int retval = StretchDIBits(hdc, |
552 0, | 552 0, |
553 0, | 553 0, |
554 src_size_x, src_size_y, | 554 src_size_x, src_size_y, |
555 0, 0, | 555 0, 0, |
556 src_size_x, src_size_y, | 556 src_size_x, src_size_y, |
557 src_bmp.getPixels(), | 557 src_bmp.getPixels(), |
558 reinterpret_cast<BITMAPINFO*>(&bitmap_header), | 558 reinterpret_cast<BITMAPINFO*>(&bitmap_header), |
559 DIB_RGB_COLORS, | 559 DIB_RGB_COLORS, |
560 SRCCOPY); | 560 SRCCOPY); |
561 DCHECK(retval != GDI_ERROR); | 561 DCHECK(retval != GDI_ERROR); |
562 #else | 562 #else |
563 // 100% GDI based. | 563 // 100% GDI based. |
564 gfx::VectorCanvas canvas(hdc, src_size_x, src_size_y); | 564 skia::VectorCanvas canvas(hdc, src_size_x, src_size_y); |
565 // Set the clipping region to be sure to not overflow. | 565 // Set the clipping region to be sure to not overflow. |
566 SkRect clip_rect; | 566 SkRect clip_rect; |
567 clip_rect.set(0, 0, SkIntToScalar(src_size_x), SkIntToScalar(src_size_y)); | 567 clip_rect.set(0, 0, SkIntToScalar(src_size_x), SkIntToScalar(src_size_y)); |
568 canvas.clipRect(clip_rect); | 568 canvas.clipRect(clip_rect); |
569 if (!frame->SpoolPage(params.page_number, &canvas)) { | 569 if (!frame->SpoolPage(params.page_number, &canvas)) { |
570 NOTREACHED() << "Printing page " << params.page_number << " failed."; | 570 NOTREACHED() << "Printing page " << params.page_number << " failed."; |
571 return; | 571 return; |
572 } | 572 } |
573 #endif | 573 #endif |
574 | 574 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 748 |
749 bool RenderView::CaptureThumbnail(WebFrame* frame, | 749 bool RenderView::CaptureThumbnail(WebFrame* frame, |
750 int w, | 750 int w, |
751 int h, | 751 int h, |
752 SkBitmap* thumbnail, | 752 SkBitmap* thumbnail, |
753 ThumbnailScore* score) { | 753 ThumbnailScore* score) { |
754 #ifdef TIME_BITMAP_RETRIEVAL | 754 #ifdef TIME_BITMAP_RETRIEVAL |
755 double begin = time_util::GetHighResolutionTimeNow(); | 755 double begin = time_util::GetHighResolutionTimeNow(); |
756 #endif | 756 #endif |
757 | 757 |
758 scoped_ptr<gfx::BitmapPlatformDevice> device; | 758 scoped_ptr<skia::BitmapPlatformDevice> device; |
759 if (!frame->CaptureImage(&device, true)) | 759 if (!frame->CaptureImage(&device, true)) |
760 return false; | 760 return false; |
761 | 761 |
762 const SkBitmap& src_bmp = device->accessBitmap(false); | 762 const SkBitmap& src_bmp = device->accessBitmap(false); |
763 | 763 |
764 SkRect dest_rect; | 764 SkRect dest_rect; |
765 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); | 765 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); |
766 float dest_aspect = dest_rect.width() / dest_rect.height(); | 766 float dest_aspect = dest_rect.width() / dest_rect.height(); |
767 | 767 |
768 // Get the src rect so that we can preserve the aspect ratio while filling | 768 // Get the src rect so that we can preserve the aspect ratio while filling |
(...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2739 template_resource_id)); | 2739 template_resource_id)); |
2740 | 2740 |
2741 if (template_html.empty()) { | 2741 if (template_html.empty()) { |
2742 NOTREACHED() << "unable to load template. ID: " << template_resource_id; | 2742 NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
2743 return ""; | 2743 return ""; |
2744 } | 2744 } |
2745 // "t" is the id of the templates root node. | 2745 // "t" is the id of the templates root node. |
2746 return jstemplate_builder::GetTemplateHtml( | 2746 return jstemplate_builder::GetTemplateHtml( |
2747 template_html, &error_strings, "t"); | 2747 template_html, &error_strings, "t"); |
2748 } | 2748 } |
OLD | NEW |