diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 05:03:45 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 05:03:45 +0000 |
commit | 0e6444691424c2d052a94e092c9c5f9b8ef71523 (patch) | |
tree | 6cb1232ded66a838c93872d993ef1434493af6b8 /webkit | |
parent | 180ec26634a3970219fd5a6599c2b87851f231c7 (diff) | |
download | chromium_src-0e6444691424c2d052a94e092c9c5f9b8ef71523.zip chromium_src-0e6444691424c2d052a94e092c9c5f9b8ef71523.tar.gz chromium_src-0e6444691424c2d052a94e092c9c5f9b8ef71523.tar.bz2 |
Remove support for bitmap printing in pepper
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10096001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 143 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 13 |
2 files changed, 1 insertions, 155 deletions
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index ffb0c17..2947360 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -1118,9 +1118,6 @@ bool PluginInstance::GetPreferredPrintOutputFormat( if (supported_formats & PP_PRINTOUTPUTFORMAT_PDF) { *format = PP_PRINTOUTPUTFORMAT_PDF; return true; - } else if (supported_formats & PP_PRINTOUTPUTFORMAT_RASTER) { - *format = PP_PRINTOUTPUTFORMAT_RASTER; - return true; } return false; } @@ -1207,8 +1204,6 @@ bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) ret = PrintPDFOutput(print_output, canvas); - else if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER) - ret = PrintRasterOutput(print_output, canvas); // Now we need to release the print output resource. PluginModule::GetCore()->ReleaseResource(print_output); @@ -1509,144 +1504,6 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, return ret; } -bool PluginInstance::PrintRasterOutput(PP_Resource print_output, - WebKit::WebCanvas* canvas) { - EnterResourceNoLock<PPB_ImageData_API> enter(print_output, true); - if (enter.failed()) - return false; - PPB_ImageData_Impl* image = - static_cast<PPB_ImageData_Impl*>(enter.object()); - - if (!image->Map()) - return false; - - const SkBitmap* bitmap = image->GetMappedBitmap(); - if (!bitmap) - return false; - - // Draw the printed image into the supplied canvas. - SkIRect src_rect; - src_rect.set(0, 0, bitmap->width(), bitmap->height()); - SkRect dest_rect; - dest_rect.set( - SkIntToScalar(current_print_settings_.printable_area.point.x), - SkIntToScalar(current_print_settings_.printable_area.point.y), - SkIntToScalar(current_print_settings_.printable_area.point.x + - current_print_settings_.printable_area.size.width), - SkIntToScalar(current_print_settings_.printable_area.point.y + - current_print_settings_.printable_area.size.height)); - bool draw_to_canvas = true; - gfx::Rect dest_rect_gfx; - dest_rect_gfx.set_x(current_print_settings_.printable_area.point.x); - dest_rect_gfx.set_y(current_print_settings_.printable_area.point.y); - dest_rect_gfx.set_width(current_print_settings_.printable_area.size.width); - dest_rect_gfx.set_height(current_print_settings_.printable_area.size.height); - -#if defined(OS_WIN) - // Since this is a raster output, the size of the bitmap can be - // huge (especially at high printer DPIs). On Windows, this can - // result in a HUGE EMF (on Mac and Linux the output goes to PDF - // which appears to Flate compress the bitmap). So, if this bitmap - // is larger than 20 MB, we save the bitmap as a JPEG into the EMF - // DC. Note: We chose JPEG over PNG because JPEG compression seems - // way faster (about 4 times faster). - static const int kCompressionThreshold = 20 * 1024 * 1024; - if (bitmap->getSize() > kCompressionThreshold) { - DrawJPEGToPlatformDC(*bitmap, dest_rect_gfx, canvas); - draw_to_canvas = false; - } -#endif // defined(OS_WIN) -#if defined(OS_MACOSX) && !defined(USE_SKIA) - draw_to_canvas = false; - DrawSkBitmapToCanvas(*bitmap, canvas, dest_rect_gfx, - current_print_settings_.printable_area.size.height); - // See comments in the header file. - last_printed_page_ = image; -#else // defined(OS_MACOSX) && !defined(USE_SKIA) - if (draw_to_canvas) - canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); -#endif // defined(OS_MACOSX) && !defined(USE_SKIA) - return true; -} - -#if defined(OS_WIN) -bool PluginInstance::DrawJPEGToPlatformDC( - const SkBitmap& bitmap, - const gfx::Rect& printable_area, - WebKit::WebCanvas* canvas) { - // Ideally we should add JPEG compression to the VectorPlatformDevice class - // However, Skia currently has no JPEG compression code and we cannot - // depend on gfx/jpeg_codec.h in Skia. So we do the compression here. - SkAutoLockPixels lock(bitmap); - DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); - const uint32_t* pixels = - static_cast<const uint32_t*>(bitmap.getPixels()); - std::vector<unsigned char> compressed_image; - base::TimeTicks start_time = base::TimeTicks::Now(); - bool encoded = gfx::JPEGCodec::Encode( - reinterpret_cast<const unsigned char*>(pixels), - gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(), - static_cast<int>(bitmap.rowBytes()), 100, &compressed_image); - UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime", - base::TimeTicks::Now() - start_time); - if (!encoded) { - NOTREACHED(); - return false; - } - - skia::ScopedPlatformPaint scoped_platform_paint(canvas); - HDC dc = scoped_platform_paint.GetPlatformSurface(); - DrawEmptyRectangle(dc); - BITMAPINFOHEADER bmi = {0}; - gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi); - bmi.biCompression = BI_JPEG; - bmi.biSizeImage = compressed_image.size(); - bmi.biHeight = -bmi.biHeight; - StretchDIBits(dc, printable_area.x(), printable_area.y(), - printable_area.width(), printable_area.height(), - 0, 0, bitmap.width(), bitmap.height(), - &compressed_image.front(), - reinterpret_cast<const BITMAPINFO*>(&bmi), - DIB_RGB_COLORS, SRCCOPY); - return true; -} -#endif // OS_WIN - -#if defined(OS_MACOSX) && !defined(USE_SKIA) -void PluginInstance::DrawSkBitmapToCanvas( - const SkBitmap& bitmap, WebKit::WebCanvas* canvas, - const gfx::Rect& dest_rect, - int canvas_height) { - SkAutoLockPixels lock(bitmap); - DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); - base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( - CGDataProviderCreateWithData( - NULL, bitmap.getAddr32(0, 0), - bitmap.rowBytes() * bitmap.height(), NULL)); - base::mac::ScopedCFTypeRef<CGImageRef> image( - CGImageCreate( - bitmap.width(), bitmap.height(), - 8, 32, bitmap.rowBytes(), - base::mac::GetSystemColorSpace(), - kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, - data_provider, NULL, false, kCGRenderingIntentDefault)); - - // Flip the transform - CGContextSaveGState(canvas); - CGContextTranslateCTM(canvas, 0, canvas_height); - CGContextScaleCTM(canvas, 1.0, -1.0); - - CGRect bounds; - bounds.origin.x = dest_rect.x(); - bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); - bounds.size.width = dest_rect.width(); - bounds.size.height = dest_rect.height(); - - CGContextDrawImage(canvas, bounds, image); - CGContextRestoreGState(canvas); -} -#endif // defined(OS_MACOSX) && !defined(USE_SKIA) - PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const { if (bound_graphics_.get() == NULL) return NULL; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index dc430e71..932143b 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -430,20 +430,9 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // Queries the plugin for supported print formats and sets |format| to the // best format to use. Returns false if the plugin does not support any - // print format that we can handle (we can handle raster and PDF). + // print format that we can handle (we can handle only PDF). bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat_Dev* format); bool PrintPDFOutput(PP_Resource print_output, WebKit::WebCanvas* canvas); - bool PrintRasterOutput(PP_Resource print_output, WebKit::WebCanvas* canvas); -#if defined(OS_WIN) - bool DrawJPEGToPlatformDC(const SkBitmap& bitmap, - const gfx::Rect& printable_area, - WebKit::WebCanvas* canvas); -#elif defined(OS_MACOSX) && !defined(USE_SKIA) - // Draws the given kARGB_8888_Config bitmap to the specified canvas starting - // at the specified destination rect. - void DrawSkBitmapToCanvas(const SkBitmap& bitmap, WebKit::WebCanvas* canvas, - const gfx::Rect& dest_rect, int canvas_height); -#endif // OS_MACOSX // Get the bound graphics context as a concrete 2D graphics context or returns // null if the context is not 2D. |