OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/common/render_messages_params.h" | 10 #include "chrome/common/render_messages_params.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 GetPageSizeAndMarginsInPoints(frame, page_number, params, | 201 GetPageSizeAndMarginsInPoints(frame, page_number, params, |
202 &content_width_in_points, &content_height_in_points, NULL, NULL, NULL, | 202 &content_width_in_points, &content_height_in_points, NULL, NULL, NULL, |
203 NULL); | 203 NULL); |
204 | 204 |
205 // Since WebKit extends the page width depending on the magical scale factor | 205 // Since WebKit extends the page width depending on the magical scale factor |
206 // we make sure the canvas covers the worst case scenario (x2.0 currently). | 206 // we make sure the canvas covers the worst case scenario (x2.0 currently). |
207 // PrintContext will then set the correct clipping region. | 207 // PrintContext will then set the correct clipping region. |
208 int width = static_cast<int>(content_width_in_points * params.max_shrink); | 208 int width = static_cast<int>(content_width_in_points * params.max_shrink); |
209 int height = static_cast<int>(content_height_in_points * params.max_shrink); | 209 int height = static_cast<int>(content_height_in_points * params.max_shrink); |
210 | 210 |
211 DCHECK((*metafile)->StartPage()); | |
vandebo (ex-Chrome)
2011/03/15 20:41:39
Better to do bool foo = action; DCHECK(foo);
dpapad
2011/03/15 20:56:44
Done.
| |
212 | |
211 #if 0 | 213 #if 0 |
212 // TODO(maruel): This code is kept for testing until the 100% GDI drawing | 214 // TODO(maruel): This code is kept for testing until the 100% GDI drawing |
213 // code is stable. maruels use this code's output as a reference when the | 215 // code is stable. maruels use this code's output as a reference when the |
214 // GDI drawing code fails. | 216 // GDI drawing code fails. |
215 | 217 |
216 // Mix of Skia and GDI based. | 218 // Mix of Skia and GDI based. |
217 skia::PlatformCanvas canvas(width, height, true); | 219 skia::PlatformCanvas canvas(width, height, true); |
218 canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); | 220 canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); |
219 float webkit_scale_factor = frame->printPage(page_number, &canvas); | 221 float webkit_scale_factor = frame->printPage(page_number, &canvas); |
220 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { | 222 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { |
(...skipping 26 matching lines...) Expand all Loading... | |
247 float webkit_scale_factor = frame->printPage(page_number, &canvas); | 249 float webkit_scale_factor = frame->printPage(page_number, &canvas); |
248 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { | 250 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { |
249 NOTREACHED() << "Printing page " << page_number << " failed."; | 251 NOTREACHED() << "Printing page " << page_number << " failed."; |
250 } else { | 252 } else { |
251 // Update the dpi adjustment with the "page |scale_factor|" calculated in | 253 // Update the dpi adjustment with the "page |scale_factor|" calculated in |
252 // webkit. | 254 // webkit. |
253 *scale_factor /= webkit_scale_factor; | 255 *scale_factor /= webkit_scale_factor; |
254 } | 256 } |
255 #endif | 257 #endif |
256 | 258 |
259 DCHECK((*metafile)->EndPage()); | |
257 skia::VectorPlatformDevice* platform_device = | 260 skia::VectorPlatformDevice* platform_device = |
258 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); | 261 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); |
259 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { | 262 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { |
260 // Close the device context to retrieve the compiled metafile. | 263 // Close the device context to retrieve the compiled metafile. |
261 if (!(*metafile)->CloseDc()) | 264 if (!(*metafile)->CloseDc()) |
262 NOTREACHED(); | 265 NOTREACHED(); |
263 | 266 |
264 scoped_ptr<printing::NativeMetafile> metafile2( | 267 scoped_ptr<printing::NativeMetafile> metafile2( |
265 printing::NativeMetafileFactory::CreateMetafile()); | 268 printing::NativeMetafileFactory::CreateMetafile()); |
266 // Page used alpha blend, but printer doesn't support it. Rewrite the | 269 // Page used alpha blend, but printer doesn't support it. Rewrite the |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 // Copy the bits into shared memory. | 328 // Copy the bits into shared memory. |
326 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 329 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
327 NOTREACHED() << "GetData() failed"; | 330 NOTREACHED() << "GetData() failed"; |
328 shared_buf.Unmap(); | 331 shared_buf.Unmap(); |
329 return false; | 332 return false; |
330 } | 333 } |
331 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 334 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
332 shared_buf.Unmap(); | 335 shared_buf.Unmap(); |
333 return true; | 336 return true; |
334 } | 337 } |
OLD | NEW |