Chromium Code Reviews| 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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 #include "printing/metafile.h" | 69 #include "printing/metafile.h" |
| 70 #include "printing/metafile_skia_wrapper.h" | 70 #include "printing/metafile_skia_wrapper.h" |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
| 74 #include "skia/ext/vector_platform_device_emf_win.h" | 74 #include "skia/ext/vector_platform_device_emf_win.h" |
| 75 #include "ui/gfx/codec/jpeg_codec.h" | 75 #include "ui/gfx/codec/jpeg_codec.h" |
| 76 #include "ui/gfx/gdi_util.h" | 76 #include "ui/gfx/gdi_util.h" |
| 77 #endif | 77 #endif |
| 78 | 78 |
| 79 #if defined(OS_MACOSX) && defined(USE_SKIA) | |
| 80 #include "skia/ext/skia_utils_mac.h" | |
| 81 #endif | |
| 82 | |
| 79 using WebKit::WebBindings; | 83 using WebKit::WebBindings; |
| 80 using WebKit::WebCanvas; | 84 using WebKit::WebCanvas; |
| 81 using WebKit::WebCursorInfo; | 85 using WebKit::WebCursorInfo; |
| 82 using WebKit::WebDocument; | 86 using WebKit::WebDocument; |
| 83 using WebKit::WebFrame; | 87 using WebKit::WebFrame; |
| 84 using WebKit::WebInputEvent; | 88 using WebKit::WebInputEvent; |
| 85 using WebKit::WebPluginContainer; | 89 using WebKit::WebPluginContainer; |
| 86 using WebKit::WebString; | 90 using WebKit::WebString; |
| 87 using WebKit::WebURLRequest; | 91 using WebKit::WebURLRequest; |
| 88 using WebKit::WebView; | 92 using WebKit::WebView; |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 printing::Metafile* metafile = | 1209 printing::Metafile* metafile = |
| 1206 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); | 1210 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); |
| 1207 DCHECK(metafile != NULL); | 1211 DCHECK(metafile != NULL); |
| 1208 if (metafile) | 1212 if (metafile) |
| 1209 ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size()); | 1213 ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size()); |
| 1210 #elif defined(OS_MACOSX) | 1214 #elif defined(OS_MACOSX) |
| 1211 printing::NativeMetafile metafile; | 1215 printing::NativeMetafile metafile; |
| 1212 // Create a PDF metafile and render from there into the passed in context. | 1216 // Create a PDF metafile and render from there into the passed in context. |
| 1213 if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) { | 1217 if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) { |
| 1214 // Flip the transform. | 1218 // Flip the transform. |
| 1215 CGContextSaveGState(canvas); | 1219 #if defined(USE_SKIA) |
| 1216 CGContextTranslateCTM(canvas, 0, | 1220 gfx::SkiaBitLocker bitLocker(canvas); |
|
stuartmorgan
2011/04/12 17:35:51
Indentation is wrong on this whole block
_cary
2011/04/12 21:03:55
Done.
| |
| 1221 CGContextRef cgContext = bitLocker.cgContext(); | |
| 1222 #else | |
| 1223 CGContextRef cgContext = canvas; | |
| 1224 #endif | |
| 1225 CGContextSaveGState(cgContext); | |
| 1226 CGContextTranslateCTM(cgContext, 0, | |
| 1217 current_print_settings_.printable_area.size.height); | 1227 current_print_settings_.printable_area.size.height); |
| 1218 CGContextScaleCTM(canvas, 1.0, -1.0); | 1228 CGContextScaleCTM(cgContext, 1.0, -1.0); |
| 1219 CGRect page_rect; | 1229 CGRect page_rect; |
| 1220 page_rect.origin.x = current_print_settings_.printable_area.point.x; | 1230 page_rect.origin.x = current_print_settings_.printable_area.point.x; |
| 1221 page_rect.origin.y = current_print_settings_.printable_area.point.y; | 1231 page_rect.origin.y = current_print_settings_.printable_area.point.y; |
| 1222 page_rect.size.width = current_print_settings_.printable_area.size.width; | 1232 page_rect.size.width = current_print_settings_.printable_area.size.width; |
| 1223 page_rect.size.height = current_print_settings_.printable_area.size.height; | 1233 page_rect.size.height = current_print_settings_.printable_area.size.height; |
| 1224 | 1234 |
| 1225 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true); | 1235 ret = metafile.RenderPage(1, cgContext, page_rect, true, false, true, true); |
| 1226 CGContextRestoreGState(canvas); | 1236 CGContextRestoreGState(cgContext); |
| 1227 } | 1237 } |
| 1228 #elif defined(OS_WIN) | 1238 #elif defined(OS_WIN) |
| 1229 // On Windows, we now need to render the PDF to the DC that backs the | 1239 // On Windows, we now need to render the PDF to the DC that backs the |
| 1230 // supplied canvas. | 1240 // supplied canvas. |
| 1231 HDC dc = skia::BeginPlatformPaint(canvas); | 1241 HDC dc = skia::BeginPlatformPaint(canvas); |
| 1232 gfx::Size size_in_pixels; | 1242 gfx::Size size_in_pixels; |
| 1233 size_in_pixels.set_width( | 1243 size_in_pixels.set_width( |
| 1234 printing::ConvertUnit(current_print_settings_.printable_area.size.width, | 1244 printing::ConvertUnit(current_print_settings_.printable_area.size.width, |
| 1235 static_cast<int>(printing::kPointsPerInch), | 1245 static_cast<int>(printing::kPointsPerInch), |
| 1236 current_print_settings_.dpi)); | 1246 current_print_settings_.dpi)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1301 #endif // defined(OS_WIN) | 1311 #endif // defined(OS_WIN) |
| 1302 #if defined(OS_MACOSX) | 1312 #if defined(OS_MACOSX) |
| 1303 draw_to_canvas = false; | 1313 draw_to_canvas = false; |
| 1304 DrawSkBitmapToCanvas(*bitmap, canvas, dest_rect_gfx, | 1314 DrawSkBitmapToCanvas(*bitmap, canvas, dest_rect_gfx, |
| 1305 current_print_settings_.printable_area.size.height); | 1315 current_print_settings_.printable_area.size.height); |
| 1306 // See comments in the header file. | 1316 // See comments in the header file. |
| 1307 last_printed_page_ = image; | 1317 last_printed_page_ = image; |
| 1308 #else // defined(OS_MACOSX) | 1318 #else // defined(OS_MACOSX) |
| 1309 if (draw_to_canvas) | 1319 if (draw_to_canvas) |
| 1310 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); | 1320 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); |
| 1311 #endif // defined(OS_MACOSX) | 1321 #endif // defined(OS_MACOSX) |
|
stuartmorgan
2011/04/12 18:14:04
FYI, it looks like you could/should just change th
_cary
2011/04/12 21:03:55
Done.
| |
| 1312 return true; | 1322 return true; |
| 1313 } | 1323 } |
| 1314 | 1324 |
| 1315 #if defined(OS_WIN) | 1325 #if defined(OS_WIN) |
| 1316 bool PluginInstance::DrawJPEGToPlatformDC( | 1326 bool PluginInstance::DrawJPEGToPlatformDC( |
| 1317 const SkBitmap& bitmap, | 1327 const SkBitmap& bitmap, |
| 1318 const gfx::Rect& printable_area, | 1328 const gfx::Rect& printable_area, |
| 1319 WebKit::WebCanvas* canvas) { | 1329 WebKit::WebCanvas* canvas) { |
| 1320 // Ideally we should add JPEG compression to the VectorPlatformDevice class | 1330 // Ideally we should add JPEG compression to the VectorPlatformDevice class |
| 1321 // However, Skia currently has no JPEG compression code and we cannot | 1331 // However, Skia currently has no JPEG compression code and we cannot |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1373 NULL, bitmap.getAddr32(0, 0), | 1383 NULL, bitmap.getAddr32(0, 0), |
| 1374 bitmap.rowBytes() * bitmap.height(), NULL)); | 1384 bitmap.rowBytes() * bitmap.height(), NULL)); |
| 1375 base::mac::ScopedCFTypeRef<CGImageRef> image( | 1385 base::mac::ScopedCFTypeRef<CGImageRef> image( |
| 1376 CGImageCreate( | 1386 CGImageCreate( |
| 1377 bitmap.width(), bitmap.height(), | 1387 bitmap.width(), bitmap.height(), |
| 1378 8, 32, bitmap.rowBytes(), | 1388 8, 32, bitmap.rowBytes(), |
| 1379 base::mac::GetSystemColorSpace(), | 1389 base::mac::GetSystemColorSpace(), |
| 1380 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | 1390 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, |
| 1381 data_provider, NULL, false, kCGRenderingIntentDefault)); | 1391 data_provider, NULL, false, kCGRenderingIntentDefault)); |
| 1382 | 1392 |
| 1393 #if defined(USE_SKIA) | |
| 1394 gfx::SkiaBitLocker bitLocker(canvas); | |
| 1395 CGContextRef cgContext = bitLocker.cgContext(); | |
|
stuartmorgan
2011/04/12 17:35:51
Is round-tripping through CG actually the best way
_cary
2011/04/12 21:03:55
Fixed, by using non-CG code paths where appropriat
| |
| 1396 #else | |
| 1397 CGContextRef cgContext = canvas; | |
| 1398 #endif | |
| 1383 // Flip the transform | 1399 // Flip the transform |
| 1384 CGContextSaveGState(canvas); | 1400 CGContextSaveGState(cgContext); |
| 1385 CGContextTranslateCTM(canvas, 0, canvas_height); | 1401 CGContextTranslateCTM(cgContext, 0, canvas_height); |
| 1386 CGContextScaleCTM(canvas, 1.0, -1.0); | 1402 CGContextScaleCTM(cgContext, 1.0, -1.0); |
| 1387 | 1403 |
| 1388 CGRect bounds; | 1404 CGRect bounds; |
| 1389 bounds.origin.x = dest_rect.x(); | 1405 bounds.origin.x = dest_rect.x(); |
| 1390 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); | 1406 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); |
| 1391 bounds.size.width = dest_rect.width(); | 1407 bounds.size.width = dest_rect.width(); |
| 1392 bounds.size.height = dest_rect.height(); | 1408 bounds.size.height = dest_rect.height(); |
| 1393 | 1409 |
| 1394 CGContextDrawImage(canvas, bounds, image); | 1410 CGContextDrawImage(cgContext, bounds, image); |
| 1395 CGContextRestoreGState(canvas); | 1411 CGContextRestoreGState(cgContext); |
| 1396 } | 1412 } |
| 1397 #endif // defined(OS_MACOSX) | 1413 #endif // defined(OS_MACOSX) |
| 1398 | 1414 |
| 1399 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { | 1415 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { |
| 1400 if (bound_graphics_.get() == NULL) | 1416 if (bound_graphics_.get() == NULL) |
| 1401 return NULL; | 1417 return NULL; |
| 1402 | 1418 |
| 1403 return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); | 1419 return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); |
| 1404 } | 1420 } |
| 1405 | 1421 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 return found->second; | 1481 return found->second; |
| 1466 } | 1482 } |
| 1467 | 1483 |
| 1468 bool PluginInstance::IsFullPagePlugin() const { | 1484 bool PluginInstance::IsFullPagePlugin() const { |
| 1469 WebFrame* frame = container()->element().document().frame(); | 1485 WebFrame* frame = container()->element().document().frame(); |
| 1470 return frame->view()->mainFrame()->document().isPluginDocument(); | 1486 return frame->view()->mainFrame()->document().isPluginDocument(); |
| 1471 } | 1487 } |
| 1472 | 1488 |
| 1473 } // namespace ppapi | 1489 } // namespace ppapi |
| 1474 } // namespace webkit | 1490 } // namespace webkit |
| OLD | NEW |