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

Side by Side Diff: chrome/renderer/print_web_view_helper_win.cc

Issue 6708046: Revert 78812 - Unfork VectorPlatformCanvas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/emf_win.h » ('j') | 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) 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 preview_params.metafile_data_handle, 190 preview_params.metafile_data_handle,
191 &preview_params.metafile_data_handle))) { 191 &preview_params.metafile_data_handle))) {
192 NOTREACHED() << "Send message failed."; 192 NOTREACHED() << "Send message failed.";
193 } 193 }
194 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params)); 194 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params));
195 } 195 }
196 196
197 void PrintWebViewHelper::RenderPage( 197 void PrintWebViewHelper::RenderPage(
198 const ViewMsg_Print_Params& params, float* scale_factor, int page_number, 198 const ViewMsg_Print_Params& params, float* scale_factor, int page_number,
199 WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) { 199 WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) {
200 DCHECK(metafile->get()->context()); 200 HDC hdc = (*metafile)->context();
201 DCHECK(hdc);
201 202
202 double content_width_in_points; 203 double content_width_in_points;
203 double content_height_in_points; 204 double content_height_in_points;
204 double margin_top_in_points; 205 double margin_top_in_points;
205 double margin_left_in_points; 206 double margin_left_in_points;
206 GetPageSizeAndMarginsInPoints(frame, page_number, params, 207 GetPageSizeAndMarginsInPoints(frame, page_number, params,
207 &content_width_in_points, 208 &content_width_in_points,
208 &content_height_in_points, 209 &content_height_in_points,
209 &margin_top_in_points, NULL, NULL, 210 &margin_top_in_points, NULL, NULL,
210 &margin_left_in_points); 211 &margin_left_in_points);
211 212
212 // Since WebKit extends the page width depending on the magical scale factor 213 // Since WebKit extends the page width depending on the magical scale factor
213 // we make sure the canvas covers the worst case scenario (x2.0 currently). 214 // we make sure the canvas covers the worst case scenario (x2.0 currently).
214 // PrintContext will then set the correct clipping region. 215 // PrintContext will then set the correct clipping region.
215 int width = static_cast<int>(content_width_in_points * params.max_shrink); 216 int width = static_cast<int>(content_width_in_points * params.max_shrink);
216 int height = static_cast<int>(content_height_in_points * params.max_shrink); 217 int height = static_cast<int>(content_height_in_points * params.max_shrink);
217 218
218 gfx::Size page_size(width, height); 219 bool result = (*metafile)->StartPage(
219 gfx::Point content_origin(static_cast<int>(margin_left_in_points), 220 gfx::Size(width, height),
220 static_cast<int>(margin_top_in_points)); 221 gfx::Point(static_cast<int>(margin_top_in_points),
221 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( 222 static_cast<int>(margin_left_in_points)),
222 page_size, content_origin, 1.0f); 223 *scale_factor);
223 DCHECK(device); 224 DCHECK(result);
224 skia::VectorCanvas canvas(device);
225 225
226 #if 0
227 // TODO(maruel): This code is kept for testing until the 100% GDI drawing
228 // code is stable. maruels use this code's output as a reference when the
229 // GDI drawing code fails.
230
231 // Mix of Skia and GDI based.
232 skia::PlatformCanvas canvas(width, height, true);
233 canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
226 float webkit_scale_factor = frame->printPage(page_number, &canvas); 234 float webkit_scale_factor = frame->printPage(page_number, &canvas);
227 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { 235 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
228 NOTREACHED() << "Printing page " << page_number << " failed."; 236 NOTREACHED() << "Printing page " << page_number << " failed.";
229 } else { 237 } else {
230 // Update the dpi adjustment with the "page |scale_factor|" calculated in 238 // Update the dpi adjustment with the "page |scale_factor|" calculated in
231 // webkit. 239 // webkit.
232 *scale_factor /= webkit_scale_factor; 240 *scale_factor /= webkit_scale_factor;
233 } 241 }
234 242
235 bool result = (*metafile)->FinishPage(); 243 // Create a BMP v4 header that we can serialize.
244 BITMAPV4HEADER bitmap_header;
245 gfx::CreateBitmapV4Header(width, height, &bitmap_header);
246 const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true);
247 SkAutoLockPixels src_lock(src_bmp);
248 int retval = StretchDIBits(hdc,
249 0,
250 0,
251 width, height,
252 0, 0,
253 width, height,
254 src_bmp.getPixels(),
255 reinterpret_cast<BITMAPINFO*>(&bitmap_header),
256 DIB_RGB_COLORS,
257 SRCCOPY);
258 DCHECK(retval != GDI_ERROR);
259 #else
260 // 100% GDI based.
261 skia::VectorCanvas canvas(hdc, width, height);
262 float webkit_scale_factor = frame->printPage(page_number, &canvas);
263 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
264 NOTREACHED() << "Printing page " << page_number << " failed.";
265 } else {
266 // Update the dpi adjustment with the "page |scale_factor|" calculated in
267 // webkit.
268 *scale_factor /= webkit_scale_factor;
269 }
270 #endif
271
272 result = (*metafile)->FinishPage();
236 DCHECK(result); 273 DCHECK(result);
237 274
238 skia::VectorPlatformDevice* platform_device = 275 skia::VectorPlatformDevice* platform_device =
239 static_cast<skia::VectorPlatformDevice*>(device); 276 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice());
240 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { 277 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) {
241 // Close the device context to retrieve the compiled metafile. 278 // Close the device context to retrieve the compiled metafile.
242 if (!(*metafile)->FinishDocument()) 279 if (!(*metafile)->FinishDocument())
243 NOTREACHED(); 280 NOTREACHED();
244 281
245 scoped_ptr<printing::NativeMetafile> metafile2( 282 scoped_ptr<printing::NativeMetafile> metafile2(
246 printing::NativeMetafileFactory::Create()); 283 printing::NativeMetafileFactory::Create());
247 // Page used alpha blend, but printer doesn't support it. Rewrite the 284 // Page used alpha blend, but printer doesn't support it. Rewrite the
248 // metafile and flatten out the transparency. 285 // metafile and flatten out the transparency.
249 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); 286 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // Copy the bits into shared memory. 343 // Copy the bits into shared memory.
307 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 344 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
308 NOTREACHED() << "GetData() failed"; 345 NOTREACHED() << "GetData() failed";
309 shared_buf.Unmap(); 346 shared_buf.Unmap();
310 return false; 347 return false;
311 } 348 }
312 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 349 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
313 shared_buf.Unmap(); 350 shared_buf.Unmap();
314 return true; 351 return true;
315 } 352 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/emf_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698