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

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

Issue 6665046: Unfork VectorPlatformCanvas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 preview_params.metafile_data_handle, 187 preview_params.metafile_data_handle,
188 &preview_params.metafile_data_handle))) { 188 &preview_params.metafile_data_handle))) {
189 NOTREACHED() << "Send message failed."; 189 NOTREACHED() << "Send message failed.";
190 } 190 }
191 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params)); 191 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params));
192 } 192 }
193 193
194 void PrintWebViewHelper::RenderPage( 194 void PrintWebViewHelper::RenderPage(
195 const ViewMsg_Print_Params& params, float* scale_factor, int page_number, 195 const ViewMsg_Print_Params& params, float* scale_factor, int page_number,
196 WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) { 196 WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) {
197 HDC hdc = (*metafile)->context(); 197 DCHECK(metafile->get()->context());
198 DCHECK(hdc);
199 198
200 double content_width_in_points; 199 double content_width_in_points;
201 double content_height_in_points; 200 double content_height_in_points;
202 GetPageSizeAndMarginsInPoints(frame, page_number, params, 201 GetPageSizeAndMarginsInPoints(frame, page_number, params,
203 &content_width_in_points, &content_height_in_points, NULL, NULL, NULL, 202 &content_width_in_points, &content_height_in_points, NULL, NULL, NULL,
204 NULL); 203 NULL);
205 204
206 // 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
207 // 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).
208 // PrintContext will then set the correct clipping region. 207 // PrintContext will then set the correct clipping region.
209 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);
210 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);
211 210
212 bool result = (*metafile)->StartPage(); 211 gfx::Size page_size(width, height);
213 DCHECK(result); 212 gfx::Point content_origin;
214 213 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas(
215 #if 0 214 page_size, content_origin, 1.0f);
216 // TODO(maruel): This code is kept for testing until the 100% GDI drawing 215 DCHECK(device);
217 // code is stable. maruels use this code's output as a reference when the 216 skia::VectorCanvas canvas(device);
218 // GDI drawing code fails.
219
220 // Mix of Skia and GDI based.
221 skia::PlatformCanvas canvas(width, height, true);
222 canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
223 float webkit_scale_factor = frame->printPage(page_number, &canvas); 217 float webkit_scale_factor = frame->printPage(page_number, &canvas);
224 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { 218 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
225 NOTREACHED() << "Printing page " << page_number << " failed."; 219 NOTREACHED() << "Printing page " << page_number << " failed.";
226 } else {
227 // Update the dpi adjustment with the "page |scale_factor|" calculated in
228 // webkit.
229 *scale_factor /= webkit_scale_factor;
230 }
231
232 // Create a BMP v4 header that we can serialize.
233 BITMAPV4HEADER bitmap_header;
234 gfx::CreateBitmapV4Header(width, height, &bitmap_header);
235 const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true);
236 SkAutoLockPixels src_lock(src_bmp);
237 int retval = StretchDIBits(hdc,
238 0,
239 0,
240 width, height,
241 0, 0,
242 width, height,
243 src_bmp.getPixels(),
244 reinterpret_cast<BITMAPINFO*>(&bitmap_header),
245 DIB_RGB_COLORS,
246 SRCCOPY);
247 DCHECK(retval != GDI_ERROR);
248 #else
249 // 100% GDI based.
250 skia::VectorCanvas canvas(hdc, width, height);
251 float webkit_scale_factor = frame->printPage(page_number, &canvas);
252 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
253 NOTREACHED() << "Printing page " << page_number << " failed.";
254 } else { 220 } else {
255 // Update the dpi adjustment with the "page |scale_factor|" calculated in 221 // Update the dpi adjustment with the "page |scale_factor|" calculated in
256 // webkit. 222 // webkit.
257 *scale_factor /= webkit_scale_factor; 223 *scale_factor /= webkit_scale_factor;
258 } 224 }
259 #endif
260 225
261 result = (*metafile)->FinishPage(); 226 bool result = (*metafile)->FinishPage();
262 DCHECK(result); 227 DCHECK(result);
263 228
264 skia::VectorPlatformDevice* platform_device = 229 skia::VectorPlatformDevice* platform_device =
265 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); 230 static_cast<skia::VectorPlatformDevice*>(device);
266 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { 231 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) {
267 // Close the device context to retrieve the compiled metafile. 232 // Close the device context to retrieve the compiled metafile.
268 if (!(*metafile)->Close()) 233 if (!(*metafile)->Close())
269 NOTREACHED(); 234 NOTREACHED();
270 235
271 scoped_ptr<printing::NativeMetafile> metafile2( 236 scoped_ptr<printing::NativeMetafile> metafile2(
272 printing::NativeMetafileFactory::CreateMetafile()); 237 printing::NativeMetafileFactory::CreateMetafile());
273 // Page used alpha blend, but printer doesn't support it. Rewrite the 238 // Page used alpha blend, but printer doesn't support it. Rewrite the
274 // metafile and flatten out the transparency. 239 // metafile and flatten out the transparency.
275 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); 240 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // Copy the bits into shared memory. 297 // Copy the bits into shared memory.
333 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 298 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
334 NOTREACHED() << "GetData() failed"; 299 NOTREACHED() << "GetData() failed";
335 shared_buf.Unmap(); 300 shared_buf.Unmap();
336 return false; 301 return false;
337 } 302 }
338 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 303 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
339 shared_buf.Unmap(); 304 shared_buf.Unmap();
340 return true; 305 return true;
341 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698