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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 page_rect.origin.y = current_print_settings_.printable_area.point.y; | 1224 page_rect.origin.y = current_print_settings_.printable_area.point.y; |
1225 page_rect.size.width = current_print_settings_.printable_area.size.width; | 1225 page_rect.size.width = current_print_settings_.printable_area.size.width; |
1226 page_rect.size.height = current_print_settings_.printable_area.size.height; | 1226 page_rect.size.height = current_print_settings_.printable_area.size.height; |
1227 | 1227 |
1228 ret = metafile->RenderPage(1, canvas, page_rect, true, false, true, true); | 1228 ret = metafile->RenderPage(1, canvas, page_rect, true, false, true, true); |
1229 CGContextRestoreGState(canvas); | 1229 CGContextRestoreGState(canvas); |
1230 } | 1230 } |
1231 #elif defined(OS_WIN) | 1231 #elif defined(OS_WIN) |
1232 // On Windows, we now need to render the PDF to the DC that backs the | 1232 // On Windows, we now need to render the PDF to the DC that backs the |
1233 // supplied canvas. | 1233 // supplied canvas. |
1234 HDC dc = canvas->beginPlatformPaint(); | 1234 HDC dc = skia::BeginPlatformPaint(canvas); |
1235 gfx::Size size_in_pixels; | 1235 gfx::Size size_in_pixels; |
1236 size_in_pixels.set_width( | 1236 size_in_pixels.set_width( |
1237 printing::ConvertUnit(current_print_settings_.printable_area.size.width, | 1237 printing::ConvertUnit(current_print_settings_.printable_area.size.width, |
1238 static_cast<int>(printing::kPointsPerInch), | 1238 static_cast<int>(printing::kPointsPerInch), |
1239 current_print_settings_.dpi)); | 1239 current_print_settings_.dpi)); |
1240 size_in_pixels.set_height( | 1240 size_in_pixels.set_height( |
1241 printing::ConvertUnit(current_print_settings_.printable_area.size.height, | 1241 printing::ConvertUnit(current_print_settings_.printable_area.size.height, |
1242 static_cast<int>(printing::kPointsPerInch), | 1242 static_cast<int>(printing::kPointsPerInch), |
1243 current_print_settings_.dpi)); | 1243 current_print_settings_.dpi)); |
1244 // We need to render using the actual printer DPI (rendering to a smaller | 1244 // We need to render using the actual printer DPI (rendering to a smaller |
1245 // set of pixels leads to a blurry output). However, we need to counter the | 1245 // set of pixels leads to a blurry output). However, we need to counter the |
1246 // scaling up that will happen in the browser. | 1246 // scaling up that will happen in the browser. |
1247 XFORM xform = {0}; | 1247 XFORM xform = {0}; |
1248 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) / | 1248 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) / |
1249 static_cast<float>(current_print_settings_.dpi); | 1249 static_cast<float>(current_print_settings_.dpi); |
1250 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); | 1250 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); |
1251 | 1251 |
1252 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc, | 1252 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc, |
1253 current_print_settings_.dpi, current_print_settings_.dpi, | 1253 current_print_settings_.dpi, current_print_settings_.dpi, |
1254 0, 0, size_in_pixels.width(), | 1254 0, 0, size_in_pixels.width(), |
1255 size_in_pixels.height(), true, false, true, true); | 1255 size_in_pixels.height(), true, false, true, true); |
1256 canvas->endPlatformPaint(); | 1256 skia::EndPlatformPaint(canvas); |
1257 #endif // defined(OS_WIN) | 1257 #endif // defined(OS_WIN) |
1258 | 1258 |
1259 return ret; | 1259 return ret; |
1260 } | 1260 } |
1261 | 1261 |
1262 bool PluginInstance::PrintRasterOutput(PP_Resource print_output, | 1262 bool PluginInstance::PrintRasterOutput(PP_Resource print_output, |
1263 WebKit::WebCanvas* canvas) { | 1263 WebKit::WebCanvas* canvas) { |
1264 scoped_refptr<PPB_ImageData_Impl> image( | 1264 scoped_refptr<PPB_ImageData_Impl> image( |
1265 Resource::GetAs<PPB_ImageData_Impl>(print_output)); | 1265 Resource::GetAs<PPB_ImageData_Impl>(print_output)); |
1266 if (!image.get() || !image->is_mapped()) | 1266 if (!image.get() || !image->is_mapped()) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 reinterpret_cast<const unsigned char*>(pixels), | 1333 reinterpret_cast<const unsigned char*>(pixels), |
1334 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(), | 1334 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(), |
1335 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image); | 1335 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image); |
1336 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime", | 1336 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime", |
1337 base::TimeTicks::Now() - start_time); | 1337 base::TimeTicks::Now() - start_time); |
1338 if (!encoded) { | 1338 if (!encoded) { |
1339 NOTREACHED(); | 1339 NOTREACHED(); |
1340 return false; | 1340 return false; |
1341 } | 1341 } |
1342 | 1342 |
1343 HDC dc = canvas->beginPlatformPaint(); | 1343 HDC dc = skia::BeginPlatformPaint(canvas); |
1344 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG | 1344 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG |
1345 // to the EMF, the EnumEnhMetaFile call fails in the browser | 1345 // to the EMF, the EnumEnhMetaFile call fails in the browser |
1346 // process. The failure also happens if we output nothing here. | 1346 // process. The failure also happens if we output nothing here. |
1347 // We need to investigate the reason for this failure and fix it. | 1347 // We need to investigate the reason for this failure and fix it. |
1348 // In the meantime this temporary hack of drawing an empty | 1348 // In the meantime this temporary hack of drawing an empty |
1349 // rectangle in the DC gets us by. | 1349 // rectangle in the DC gets us by. |
1350 Rectangle(dc, 0, 0, 0, 0); | 1350 Rectangle(dc, 0, 0, 0, 0); |
1351 BITMAPINFOHEADER bmi = {0}; | 1351 BITMAPINFOHEADER bmi = {0}; |
1352 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi); | 1352 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi); |
1353 bmi.biCompression = BI_JPEG; | 1353 bmi.biCompression = BI_JPEG; |
1354 bmi.biSizeImage = compressed_image.size(); | 1354 bmi.biSizeImage = compressed_image.size(); |
1355 bmi.biHeight = -bmi.biHeight; | 1355 bmi.biHeight = -bmi.biHeight; |
1356 StretchDIBits(dc, printable_area.x(), printable_area.y(), | 1356 StretchDIBits(dc, printable_area.x(), printable_area.y(), |
1357 printable_area.width(), printable_area.height(), | 1357 printable_area.width(), printable_area.height(), |
1358 0, 0, bitmap.width(), bitmap.height(), | 1358 0, 0, bitmap.width(), bitmap.height(), |
1359 &compressed_image.front(), | 1359 &compressed_image.front(), |
1360 reinterpret_cast<const BITMAPINFO*>(&bmi), | 1360 reinterpret_cast<const BITMAPINFO*>(&bmi), |
1361 DIB_RGB_COLORS, SRCCOPY); | 1361 DIB_RGB_COLORS, SRCCOPY); |
1362 canvas->endPlatformPaint(); | 1362 skia::EndPlatformPaint(canvas); |
1363 return true; | 1363 return true; |
1364 } | 1364 } |
1365 #endif // OS_WIN | 1365 #endif // OS_WIN |
1366 | 1366 |
1367 #if defined(OS_MACOSX) | 1367 #if defined(OS_MACOSX) |
1368 void PluginInstance::DrawSkBitmapToCanvas( | 1368 void PluginInstance::DrawSkBitmapToCanvas( |
1369 const SkBitmap& bitmap, WebKit::WebCanvas* canvas, | 1369 const SkBitmap& bitmap, WebKit::WebCanvas* canvas, |
1370 const gfx::Rect& dest_rect, | 1370 const gfx::Rect& dest_rect, |
1371 int canvas_height) { | 1371 int canvas_height) { |
1372 SkAutoLockPixels lock(bitmap); | 1372 SkAutoLockPixels lock(bitmap); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 return found->second; | 1468 return found->second; |
1469 } | 1469 } |
1470 | 1470 |
1471 bool PluginInstance::IsFullPagePlugin() const { | 1471 bool PluginInstance::IsFullPagePlugin() const { |
1472 WebFrame* frame = container()->element().document().frame(); | 1472 WebFrame* frame = container()->element().document().frame(); |
1473 return frame->view()->mainFrame()->document().isPluginDocument(); | 1473 return frame->view()->mainFrame()->document().isPluginDocument(); |
1474 } | 1474 } |
1475 | 1475 |
1476 } // namespace ppapi | 1476 } // namespace ppapi |
1477 } // namespace webkit | 1477 } // namespace webkit |
OLD | NEW |