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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 #include "printing/metafile.h" | 71 #include "printing/metafile.h" |
72 #include "printing/metafile_skia_wrapper.h" | 72 #include "printing/metafile_skia_wrapper.h" |
73 #endif | 73 #endif |
74 | 74 |
75 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
76 #include "skia/ext/vector_platform_device_emf_win.h" | 76 #include "skia/ext/vector_platform_device_emf_win.h" |
77 #include "ui/gfx/codec/jpeg_codec.h" | 77 #include "ui/gfx/codec/jpeg_codec.h" |
78 #include "ui/gfx/gdi_util.h" | 78 #include "ui/gfx/gdi_util.h" |
79 #endif | 79 #endif |
80 | 80 |
| 81 #if defined(OS_MACOSX) && defined(USE_SKIA) |
| 82 #include "skia/ext/skia_utils_mac.h" |
| 83 #endif |
| 84 |
81 using WebKit::WebBindings; | 85 using WebKit::WebBindings; |
82 using WebKit::WebCanvas; | 86 using WebKit::WebCanvas; |
83 using WebKit::WebCursorInfo; | 87 using WebKit::WebCursorInfo; |
84 using WebKit::WebDocument; | 88 using WebKit::WebDocument; |
85 using WebKit::WebFrame; | 89 using WebKit::WebFrame; |
86 using WebKit::WebInputEvent; | 90 using WebKit::WebInputEvent; |
87 using WebKit::WebPluginContainer; | 91 using WebKit::WebPluginContainer; |
88 using WebKit::WebString; | 92 using WebKit::WebString; |
89 using WebKit::WebURLRequest; | 93 using WebKit::WebURLRequest; |
90 using WebKit::WebView; | 94 using WebKit::WebView; |
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 printing::Metafile* metafile = | 1243 printing::Metafile* metafile = |
1240 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); | 1244 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); |
1241 DCHECK(metafile != NULL); | 1245 DCHECK(metafile != NULL); |
1242 if (metafile) | 1246 if (metafile) |
1243 ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size()); | 1247 ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size()); |
1244 #elif defined(OS_MACOSX) | 1248 #elif defined(OS_MACOSX) |
1245 printing::NativeMetafile metafile; | 1249 printing::NativeMetafile metafile; |
1246 // Create a PDF metafile and render from there into the passed in context. | 1250 // Create a PDF metafile and render from there into the passed in context. |
1247 if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) { | 1251 if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) { |
1248 // Flip the transform. | 1252 // Flip the transform. |
1249 CGContextSaveGState(canvas); | 1253 #if defined(USE_SKIA) |
1250 CGContextTranslateCTM(canvas, 0, | 1254 gfx::SkiaBitLocker bit_locker(canvas); |
| 1255 CGContextRef cgContext = bit_locker.cgContext(); |
| 1256 #else |
| 1257 CGContextRef cgContext = canvas; |
| 1258 #endif |
| 1259 CGContextSaveGState(cgContext); |
| 1260 CGContextTranslateCTM(cgContext, 0, |
1251 current_print_settings_.printable_area.size.height); | 1261 current_print_settings_.printable_area.size.height); |
1252 CGContextScaleCTM(canvas, 1.0, -1.0); | 1262 CGContextScaleCTM(cgContext, 1.0, -1.0); |
1253 CGRect page_rect; | 1263 CGRect page_rect; |
1254 page_rect.origin.x = current_print_settings_.printable_area.point.x; | 1264 page_rect.origin.x = current_print_settings_.printable_area.point.x; |
1255 page_rect.origin.y = current_print_settings_.printable_area.point.y; | 1265 page_rect.origin.y = current_print_settings_.printable_area.point.y; |
1256 page_rect.size.width = current_print_settings_.printable_area.size.width; | 1266 page_rect.size.width = current_print_settings_.printable_area.size.width; |
1257 page_rect.size.height = current_print_settings_.printable_area.size.height; | 1267 page_rect.size.height = current_print_settings_.printable_area.size.height; |
1258 | 1268 |
1259 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true); | 1269 ret = metafile.RenderPage(1, cgContext, page_rect, true, false, true, true); |
1260 CGContextRestoreGState(canvas); | 1270 CGContextRestoreGState(cgContext); |
1261 } | 1271 } |
1262 #elif defined(OS_WIN) | 1272 #elif defined(OS_WIN) |
1263 // On Windows, we now need to render the PDF to the DC that backs the | 1273 // On Windows, we now need to render the PDF to the DC that backs the |
1264 // supplied canvas. | 1274 // supplied canvas. |
1265 HDC dc = skia::BeginPlatformPaint(canvas); | 1275 HDC dc = skia::BeginPlatformPaint(canvas); |
1266 gfx::Size size_in_pixels; | 1276 gfx::Size size_in_pixels; |
1267 size_in_pixels.set_width( | 1277 size_in_pixels.set_width( |
1268 printing::ConvertUnit(current_print_settings_.printable_area.size.width, | 1278 printing::ConvertUnit(current_print_settings_.printable_area.size.width, |
1269 static_cast<int>(printing::kPointsPerInch), | 1279 static_cast<int>(printing::kPointsPerInch), |
1270 current_print_settings_.dpi)); | 1280 current_print_settings_.dpi)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 // which appears to Flate compress the bitmap). So, if this bitmap | 1336 // which appears to Flate compress the bitmap). So, if this bitmap |
1327 // is larger than 20 MB, we save the bitmap as a JPEG into the EMF | 1337 // is larger than 20 MB, we save the bitmap as a JPEG into the EMF |
1328 // DC. Note: We chose JPEG over PNG because JPEG compression seems | 1338 // DC. Note: We chose JPEG over PNG because JPEG compression seems |
1329 // way faster (about 4 times faster). | 1339 // way faster (about 4 times faster). |
1330 static const int kCompressionThreshold = 20 * 1024 * 1024; | 1340 static const int kCompressionThreshold = 20 * 1024 * 1024; |
1331 if (bitmap->getSize() > kCompressionThreshold) { | 1341 if (bitmap->getSize() > kCompressionThreshold) { |
1332 DrawJPEGToPlatformDC(*bitmap, dest_rect_gfx, canvas); | 1342 DrawJPEGToPlatformDC(*bitmap, dest_rect_gfx, canvas); |
1333 draw_to_canvas = false; | 1343 draw_to_canvas = false; |
1334 } | 1344 } |
1335 #endif // defined(OS_WIN) | 1345 #endif // defined(OS_WIN) |
1336 #if defined(OS_MACOSX) | 1346 #if defined(OS_MACOSX) && !defined(USE_SKIA) |
1337 draw_to_canvas = false; | 1347 draw_to_canvas = false; |
1338 DrawSkBitmapToCanvas(*bitmap, canvas, dest_rect_gfx, | 1348 DrawSkBitmapToCanvas(*bitmap, canvas, dest_rect_gfx, |
1339 current_print_settings_.printable_area.size.height); | 1349 current_print_settings_.printable_area.size.height); |
1340 // See comments in the header file. | 1350 // See comments in the header file. |
1341 last_printed_page_ = image; | 1351 last_printed_page_ = image; |
1342 #else // defined(OS_MACOSX) | 1352 #else // defined(OS_MACOSX) && !defined(USE_SKIA) |
1343 if (draw_to_canvas) | 1353 if (draw_to_canvas) |
1344 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); | 1354 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); |
1345 #endif // defined(OS_MACOSX) | 1355 #endif // defined(OS_MACOSX) && !defined(USE_SKIA) |
1346 return true; | 1356 return true; |
1347 } | 1357 } |
1348 | 1358 |
1349 #if defined(OS_WIN) | 1359 #if defined(OS_WIN) |
1350 bool PluginInstance::DrawJPEGToPlatformDC( | 1360 bool PluginInstance::DrawJPEGToPlatformDC( |
1351 const SkBitmap& bitmap, | 1361 const SkBitmap& bitmap, |
1352 const gfx::Rect& printable_area, | 1362 const gfx::Rect& printable_area, |
1353 WebKit::WebCanvas* canvas) { | 1363 WebKit::WebCanvas* canvas) { |
1354 // Ideally we should add JPEG compression to the VectorPlatformDevice class | 1364 // Ideally we should add JPEG compression to the VectorPlatformDevice class |
1355 // However, Skia currently has no JPEG compression code and we cannot | 1365 // However, Skia currently has no JPEG compression code and we cannot |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 printable_area.width(), printable_area.height(), | 1398 printable_area.width(), printable_area.height(), |
1389 0, 0, bitmap.width(), bitmap.height(), | 1399 0, 0, bitmap.width(), bitmap.height(), |
1390 &compressed_image.front(), | 1400 &compressed_image.front(), |
1391 reinterpret_cast<const BITMAPINFO*>(&bmi), | 1401 reinterpret_cast<const BITMAPINFO*>(&bmi), |
1392 DIB_RGB_COLORS, SRCCOPY); | 1402 DIB_RGB_COLORS, SRCCOPY); |
1393 skia::EndPlatformPaint(canvas); | 1403 skia::EndPlatformPaint(canvas); |
1394 return true; | 1404 return true; |
1395 } | 1405 } |
1396 #endif // OS_WIN | 1406 #endif // OS_WIN |
1397 | 1407 |
1398 #if defined(OS_MACOSX) | 1408 #if defined(OS_MACOSX) && !defined(USE_SKIA) |
1399 void PluginInstance::DrawSkBitmapToCanvas( | 1409 void PluginInstance::DrawSkBitmapToCanvas( |
1400 const SkBitmap& bitmap, WebKit::WebCanvas* canvas, | 1410 const SkBitmap& bitmap, WebKit::WebCanvas* canvas, |
1401 const gfx::Rect& dest_rect, | 1411 const gfx::Rect& dest_rect, |
1402 int canvas_height) { | 1412 int canvas_height) { |
1403 SkAutoLockPixels lock(bitmap); | 1413 SkAutoLockPixels lock(bitmap); |
1404 DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 1414 DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
1405 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( | 1415 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( |
1406 CGDataProviderCreateWithData( | 1416 CGDataProviderCreateWithData( |
1407 NULL, bitmap.getAddr32(0, 0), | 1417 NULL, bitmap.getAddr32(0, 0), |
1408 bitmap.rowBytes() * bitmap.height(), NULL)); | 1418 bitmap.rowBytes() * bitmap.height(), NULL)); |
(...skipping 12 matching lines...) Expand all Loading... |
1421 | 1431 |
1422 CGRect bounds; | 1432 CGRect bounds; |
1423 bounds.origin.x = dest_rect.x(); | 1433 bounds.origin.x = dest_rect.x(); |
1424 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); | 1434 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); |
1425 bounds.size.width = dest_rect.width(); | 1435 bounds.size.width = dest_rect.width(); |
1426 bounds.size.height = dest_rect.height(); | 1436 bounds.size.height = dest_rect.height(); |
1427 | 1437 |
1428 CGContextDrawImage(canvas, bounds, image); | 1438 CGContextDrawImage(canvas, bounds, image); |
1429 CGContextRestoreGState(canvas); | 1439 CGContextRestoreGState(canvas); |
1430 } | 1440 } |
1431 #endif // defined(OS_MACOSX) | 1441 #endif // defined(OS_MACOSX) && !defined(USE_SKIA) |
1432 | 1442 |
1433 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { | 1443 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { |
1434 if (bound_graphics_.get() == NULL) | 1444 if (bound_graphics_.get() == NULL) |
1435 return NULL; | 1445 return NULL; |
1436 | 1446 |
1437 return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); | 1447 return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); |
1438 } | 1448 } |
1439 | 1449 |
1440 PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { | 1450 PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { |
1441 if (bound_graphics_.get() == NULL) | 1451 if (bound_graphics_.get() == NULL) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 return found->second; | 1509 return found->second; |
1500 } | 1510 } |
1501 | 1511 |
1502 bool PluginInstance::IsFullPagePlugin() const { | 1512 bool PluginInstance::IsFullPagePlugin() const { |
1503 WebFrame* frame = container()->element().document().frame(); | 1513 WebFrame* frame = container()->element().document().frame(); |
1504 return frame->view()->mainFrame()->document().isPluginDocument(); | 1514 return frame->view()->mainFrame()->document().isPluginDocument(); |
1505 } | 1515 } |
1506 | 1516 |
1507 } // namespace ppapi | 1517 } // namespace ppapi |
1508 } // namespace webkit | 1518 } // namespace webkit |
OLD | NEW |