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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 7019013: Removal of dependencies on PlatformDevice classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add ScopedPlatformPaint class. Created 9 years, 7 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 "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 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 page_rect.origin.y = current_print_settings_.printable_area.point.y; 1316 page_rect.origin.y = current_print_settings_.printable_area.point.y;
1317 page_rect.size.width = current_print_settings_.printable_area.size.width; 1317 page_rect.size.width = current_print_settings_.printable_area.size.width;
1318 page_rect.size.height = current_print_settings_.printable_area.size.height; 1318 page_rect.size.height = current_print_settings_.printable_area.size.height;
1319 1319
1320 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true); 1320 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true);
1321 CGContextRestoreGState(canvas); 1321 CGContextRestoreGState(canvas);
1322 } 1322 }
1323 #elif defined(OS_WIN) 1323 #elif defined(OS_WIN)
1324 // On Windows, we now need to render the PDF to the DC that backs the 1324 // On Windows, we now need to render the PDF to the DC that backs the
1325 // supplied canvas. 1325 // supplied canvas.
1326 HDC dc = skia::BeginPlatformPaint(canvas); 1326 skia::ScopedPlatformPaint scoped_platform_paint(canvas);
1327 HDC dc = scoped_platform_paint.GetPlatformSurface();
1327 gfx::Size size_in_pixels; 1328 gfx::Size size_in_pixels;
1328 size_in_pixels.set_width( 1329 size_in_pixels.set_width(
1329 printing::ConvertUnit(current_print_settings_.printable_area.size.width, 1330 printing::ConvertUnit(current_print_settings_.printable_area.size.width,
1330 static_cast<int>(printing::kPointsPerInch), 1331 static_cast<int>(printing::kPointsPerInch),
1331 current_print_settings_.dpi)); 1332 current_print_settings_.dpi));
1332 size_in_pixels.set_height( 1333 size_in_pixels.set_height(
1333 printing::ConvertUnit(current_print_settings_.printable_area.size.height, 1334 printing::ConvertUnit(current_print_settings_.printable_area.size.height,
1334 static_cast<int>(printing::kPointsPerInch), 1335 static_cast<int>(printing::kPointsPerInch),
1335 current_print_settings_.dpi)); 1336 current_print_settings_.dpi));
1336 // We need to render using the actual printer DPI (rendering to a smaller 1337 // We need to render using the actual printer DPI (rendering to a smaller
1337 // set of pixels leads to a blurry output). However, we need to counter the 1338 // set of pixels leads to a blurry output). However, we need to counter the
1338 // scaling up that will happen in the browser. 1339 // scaling up that will happen in the browser.
1339 XFORM xform = {0}; 1340 XFORM xform = {0};
1340 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) / 1341 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) /
1341 static_cast<float>(current_print_settings_.dpi); 1342 static_cast<float>(current_print_settings_.dpi);
1342 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); 1343 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
1343 1344
1344 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc, 1345 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc,
1345 current_print_settings_.dpi, current_print_settings_.dpi, 1346 current_print_settings_.dpi, current_print_settings_.dpi,
1346 0, 0, size_in_pixels.width(), 1347 0, 0, size_in_pixels.width(),
1347 size_in_pixels.height(), true, false, true, true); 1348 size_in_pixels.height(), true, false, true, true);
1348 skia::EndPlatformPaint(canvas);
1349 #endif // defined(OS_WIN) 1349 #endif // defined(OS_WIN)
1350 1350
1351 return ret; 1351 return ret;
1352 } 1352 }
1353 1353
1354 bool PluginInstance::PrintRasterOutput(PP_Resource print_output, 1354 bool PluginInstance::PrintRasterOutput(PP_Resource print_output,
1355 WebKit::WebCanvas* canvas) { 1355 WebKit::WebCanvas* canvas) {
1356 scoped_refptr<PPB_ImageData_Impl> image( 1356 scoped_refptr<PPB_ImageData_Impl> image(
1357 Resource::GetAs<PPB_ImageData_Impl>(print_output)); 1357 Resource::GetAs<PPB_ImageData_Impl>(print_output));
1358 if (!image.get() || !image->is_mapped()) 1358 if (!image.get() || !image->is_mapped())
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 reinterpret_cast<const unsigned char*>(pixels), 1425 reinterpret_cast<const unsigned char*>(pixels),
1426 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(), 1426 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(),
1427 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image); 1427 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image);
1428 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime", 1428 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime",
1429 base::TimeTicks::Now() - start_time); 1429 base::TimeTicks::Now() - start_time);
1430 if (!encoded) { 1430 if (!encoded) {
1431 NOTREACHED(); 1431 NOTREACHED();
1432 return false; 1432 return false;
1433 } 1433 }
1434 1434
1435 HDC dc = skia::BeginPlatformPaint(canvas); 1435 skia::ScopedPlatformPaint scoped_platform_paint(canvas);
1436 HDC dc = scoped_platform_paint.GetPlatformSurface();
1436 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG 1437 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG
1437 // to the EMF, the EnumEnhMetaFile call fails in the browser 1438 // to the EMF, the EnumEnhMetaFile call fails in the browser
1438 // process. The failure also happens if we output nothing here. 1439 // process. The failure also happens if we output nothing here.
1439 // We need to investigate the reason for this failure and fix it. 1440 // We need to investigate the reason for this failure and fix it.
1440 // In the meantime this temporary hack of drawing an empty 1441 // In the meantime this temporary hack of drawing an empty
1441 // rectangle in the DC gets us by. 1442 // rectangle in the DC gets us by.
1442 Rectangle(dc, 0, 0, 0, 0); 1443 Rectangle(dc, 0, 0, 0, 0);
1443 BITMAPINFOHEADER bmi = {0}; 1444 BITMAPINFOHEADER bmi = {0};
1444 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi); 1445 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi);
1445 bmi.biCompression = BI_JPEG; 1446 bmi.biCompression = BI_JPEG;
1446 bmi.biSizeImage = compressed_image.size(); 1447 bmi.biSizeImage = compressed_image.size();
1447 bmi.biHeight = -bmi.biHeight; 1448 bmi.biHeight = -bmi.biHeight;
1448 StretchDIBits(dc, printable_area.x(), printable_area.y(), 1449 StretchDIBits(dc, printable_area.x(), printable_area.y(),
1449 printable_area.width(), printable_area.height(), 1450 printable_area.width(), printable_area.height(),
1450 0, 0, bitmap.width(), bitmap.height(), 1451 0, 0, bitmap.width(), bitmap.height(),
1451 &compressed_image.front(), 1452 &compressed_image.front(),
1452 reinterpret_cast<const BITMAPINFO*>(&bmi), 1453 reinterpret_cast<const BITMAPINFO*>(&bmi),
1453 DIB_RGB_COLORS, SRCCOPY); 1454 DIB_RGB_COLORS, SRCCOPY);
1454 skia::EndPlatformPaint(canvas);
1455 return true; 1455 return true;
1456 } 1456 }
1457 #endif // OS_WIN 1457 #endif // OS_WIN
1458 1458
1459 #if defined(OS_MACOSX) 1459 #if defined(OS_MACOSX)
1460 void PluginInstance::DrawSkBitmapToCanvas( 1460 void PluginInstance::DrawSkBitmapToCanvas(
1461 const SkBitmap& bitmap, WebKit::WebCanvas* canvas, 1461 const SkBitmap& bitmap, WebKit::WebCanvas* canvas,
1462 const gfx::Rect& dest_rect, 1462 const gfx::Rect& dest_rect,
1463 int canvas_height) { 1463 int canvas_height) {
1464 SkAutoLockPixels lock(bitmap); 1464 SkAutoLockPixels lock(bitmap);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 return found->second; 1560 return found->second;
1561 } 1561 }
1562 1562
1563 bool PluginInstance::IsFullPagePlugin() const { 1563 bool PluginInstance::IsFullPagePlugin() const {
1564 WebFrame* frame = container()->element().document().frame(); 1564 WebFrame* frame = container()->element().document().frame();
1565 return frame->view()->mainFrame()->document().isPluginDocument(); 1565 return frame->view()->mainFrame()->document().isPluginDocument();
1566 } 1566 }
1567 1567
1568 } // namespace ppapi 1568 } // namespace ppapi
1569 } // namespace webkit 1569 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698