summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/print_web_view_helper_win.cc
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 06:21:43 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 06:21:43 +0000
commit5209d8e2e3fc95777a988503018781bd0c6f9ec2 (patch)
tree995ea052b0f6dfda09266b6a022d909b3404cb38 /chrome/renderer/print_web_view_helper_win.cc
parentd03154499968cd317de9fc722ed2b39563bf3265 (diff)
downloadchromium_src-5209d8e2e3fc95777a988503018781bd0c6f9ec2.zip
chromium_src-5209d8e2e3fc95777a988503018781bd0c6f9ec2.tar.gz
chromium_src-5209d8e2e3fc95777a988503018781bd0c6f9ec2.tar.bz2
Revert 78859 - Unfork VectorPlatformCanvas.
Unfork VectorPlatformCanvas by making NativeMetafile know how to create an appropriate VectorPlatformDevice. This will also be useful when we have multiple NativeMetafile implemenations (each requiring a different VectorPlatformDevices). BUG=NONE TEST=NONE Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78662 Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=78663 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78812 Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=78815 Review URL: http://codereview.chromium.org/6665046 TBR=vandebo@chromium.org Review URL: http://codereview.chromium.org/6711067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/print_web_view_helper_win.cc')
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc57
1 files changed, 47 insertions, 10 deletions
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index 2e87939..d4b37db 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -197,7 +197,8 @@ void PrintWebViewHelper::CreatePreviewDocument(
void PrintWebViewHelper::RenderPage(
const ViewMsg_Print_Params& params, float* scale_factor, int page_number,
WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) {
- DCHECK(metafile->get()->context());
+ HDC hdc = (*metafile)->context();
+ DCHECK(hdc);
double content_width_in_points;
double content_height_in_points;
@@ -215,14 +216,49 @@ void PrintWebViewHelper::RenderPage(
int width = static_cast<int>(content_width_in_points * params.max_shrink);
int height = static_cast<int>(content_height_in_points * params.max_shrink);
- gfx::Size page_size(width, height);
- gfx::Point content_origin(static_cast<int>(margin_left_in_points),
- static_cast<int>(margin_top_in_points));
- skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas(
- page_size, content_origin, 1.0f);
- DCHECK(device);
- skia::VectorCanvas canvas(device);
+ bool result = (*metafile)->StartPage(
+ gfx::Size(width, height),
+ gfx::Point(static_cast<int>(margin_top_in_points),
+ static_cast<int>(margin_left_in_points)),
+ *scale_factor);
+ DCHECK(result);
+
+#if 0
+ // TODO(maruel): This code is kept for testing until the 100% GDI drawing
+ // code is stable. maruels use this code's output as a reference when the
+ // GDI drawing code fails.
+
+ // Mix of Skia and GDI based.
+ skia::PlatformCanvas canvas(width, height, true);
+ canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
+ float webkit_scale_factor = frame->printPage(page_number, &canvas);
+ if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
+ NOTREACHED() << "Printing page " << page_number << " failed.";
+ } else {
+ // Update the dpi adjustment with the "page |scale_factor|" calculated in
+ // webkit.
+ *scale_factor /= webkit_scale_factor;
+ }
+ // Create a BMP v4 header that we can serialize.
+ BITMAPV4HEADER bitmap_header;
+ gfx::CreateBitmapV4Header(width, height, &bitmap_header);
+ const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true);
+ SkAutoLockPixels src_lock(src_bmp);
+ int retval = StretchDIBits(hdc,
+ 0,
+ 0,
+ width, height,
+ 0, 0,
+ width, height,
+ src_bmp.getPixels(),
+ reinterpret_cast<BITMAPINFO*>(&bitmap_header),
+ DIB_RGB_COLORS,
+ SRCCOPY);
+ DCHECK(retval != GDI_ERROR);
+#else
+ // 100% GDI based.
+ skia::VectorCanvas canvas(hdc, width, height);
float webkit_scale_factor = frame->printPage(page_number, &canvas);
if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
NOTREACHED() << "Printing page " << page_number << " failed.";
@@ -231,12 +267,13 @@ void PrintWebViewHelper::RenderPage(
// webkit.
*scale_factor /= webkit_scale_factor;
}
+#endif
- bool result = (*metafile)->FinishPage();
+ result = (*metafile)->FinishPage();
DCHECK(result);
skia::VectorPlatformDevice* platform_device =
- static_cast<skia::VectorPlatformDevice*>(device);
+ static_cast<skia::VectorPlatformDevice*>(canvas.getDevice());
if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) {
// Close the device context to retrieve the compiled metafile.
if (!(*metafile)->FinishDocument())