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

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

Issue 6783023: Eliminate skia::PlatformCanvas - Step 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 skia::VectorPlatformDevice& device = 1234 HDC dc = skia::BeginPlatformPaint(canvas);
1235 static_cast<skia::VectorPlatformDevice&>(
1236 canvas->getTopPlatformDevice());
1237 HDC dc = device.getBitmapDC();
1238 gfx::Size size_in_pixels; 1235 gfx::Size size_in_pixels;
1239 size_in_pixels.set_width( 1236 size_in_pixels.set_width(
1240 printing::ConvertUnit(current_print_settings_.printable_area.size.width, 1237 printing::ConvertUnit(current_print_settings_.printable_area.size.width,
1241 static_cast<int>(printing::kPointsPerInch), 1238 static_cast<int>(printing::kPointsPerInch),
1242 current_print_settings_.dpi)); 1239 current_print_settings_.dpi));
1243 size_in_pixels.set_height( 1240 size_in_pixels.set_height(
1244 printing::ConvertUnit(current_print_settings_.printable_area.size.height, 1241 printing::ConvertUnit(current_print_settings_.printable_area.size.height,
1245 static_cast<int>(printing::kPointsPerInch), 1242 static_cast<int>(printing::kPointsPerInch),
1246 current_print_settings_.dpi)); 1243 current_print_settings_.dpi));
1247 // 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
1248 // 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
1249 // scaling up that will happen in the browser. 1246 // scaling up that will happen in the browser.
1250 XFORM xform = {0}; 1247 XFORM xform = {0};
1251 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) / 1248 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) /
1252 static_cast<float>(current_print_settings_.dpi); 1249 static_cast<float>(current_print_settings_.dpi);
1253 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); 1250 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
1254 1251
1255 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc, 1252 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc,
1256 current_print_settings_.dpi, current_print_settings_.dpi, 1253 current_print_settings_.dpi, current_print_settings_.dpi,
1257 0, 0, size_in_pixels.width(), 1254 0, 0, size_in_pixels.width(),
1258 size_in_pixels.height(), true, false, true, true); 1255 size_in_pixels.height(), true, false, true, true);
1256 skia::EndPlatformPaint(canvas);
1259 #endif // defined(OS_WIN) 1257 #endif // defined(OS_WIN)
1260 1258
1261 return ret; 1259 return ret;
1262 } 1260 }
1263 1261
1264 bool PluginInstance::PrintRasterOutput(PP_Resource print_output, 1262 bool PluginInstance::PrintRasterOutput(PP_Resource print_output,
1265 WebKit::WebCanvas* canvas) { 1263 WebKit::WebCanvas* canvas) {
1266 scoped_refptr<PPB_ImageData_Impl> image( 1264 scoped_refptr<PPB_ImageData_Impl> image(
1267 Resource::GetAs<PPB_ImageData_Impl>(print_output)); 1265 Resource::GetAs<PPB_ImageData_Impl>(print_output));
1268 if (!image.get() || !image->is_mapped()) 1266 if (!image.get() || !image->is_mapped())
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); 1313 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect);
1316 #endif // defined(OS_MACOSX) 1314 #endif // defined(OS_MACOSX)
1317 return true; 1315 return true;
1318 } 1316 }
1319 1317
1320 #if defined(OS_WIN) 1318 #if defined(OS_WIN)
1321 bool PluginInstance::DrawJPEGToPlatformDC( 1319 bool PluginInstance::DrawJPEGToPlatformDC(
1322 const SkBitmap& bitmap, 1320 const SkBitmap& bitmap,
1323 const gfx::Rect& printable_area, 1321 const gfx::Rect& printable_area,
1324 WebKit::WebCanvas* canvas) { 1322 WebKit::WebCanvas* canvas) {
1325 skia::VectorPlatformDevice& device =
1326 static_cast<skia::VectorPlatformDevice&>(
1327 canvas->getTopPlatformDevice());
1328 HDC dc = device.getBitmapDC();
1329 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG
1330 // to the EMF, the EnumEnhMetaFile call fails in the browser
1331 // process. The failure also happens if we output nothing here.
1332 // We need to investigate the reason for this failure and fix it.
1333 // In the meantime this temporary hack of drawing an empty
1334 // rectangle in the DC gets us by.
1335 Rectangle(dc, 0, 0, 0, 0);
1336
1337 // Ideally we should add JPEG compression to the VectorPlatformDevice class 1323 // Ideally we should add JPEG compression to the VectorPlatformDevice class
1338 // However, Skia currently has no JPEG compression code and we cannot 1324 // However, Skia currently has no JPEG compression code and we cannot
1339 // depend on gfx/jpeg_codec.h in Skia. So we do the compression here. 1325 // depend on gfx/jpeg_codec.h in Skia. So we do the compression here.
1340 SkAutoLockPixels lock(bitmap); 1326 SkAutoLockPixels lock(bitmap);
1341 DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); 1327 DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
1342 const uint32_t* pixels = 1328 const uint32_t* pixels =
1343 static_cast<const uint32_t*>(bitmap.getPixels()); 1329 static_cast<const uint32_t*>(bitmap.getPixels());
1344 std::vector<unsigned char> compressed_image; 1330 std::vector<unsigned char> compressed_image;
1345 base::TimeTicks start_time = base::TimeTicks::Now(); 1331 base::TimeTicks start_time = base::TimeTicks::Now();
1346 bool encoded = gfx::JPEGCodec::Encode( 1332 bool encoded = gfx::JPEGCodec::Encode(
1347 reinterpret_cast<const unsigned char*>(pixels), 1333 reinterpret_cast<const unsigned char*>(pixels),
1348 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(), 1334 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(),
1349 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image); 1335 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image);
1350 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime", 1336 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime",
1351 base::TimeTicks::Now() - start_time); 1337 base::TimeTicks::Now() - start_time);
1352 if (!encoded) { 1338 if (!encoded) {
1353 NOTREACHED(); 1339 NOTREACHED();
1354 return false; 1340 return false;
1355 } 1341 }
1342
1356 BITMAPINFOHEADER bmi = {0}; 1343 BITMAPINFOHEADER bmi = {0};
1357 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi); 1344 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi);
1358 bmi.biCompression = BI_JPEG; 1345 bmi.biCompression = BI_JPEG;
1359 bmi.biSizeImage = compressed_image.size(); 1346 bmi.biSizeImage = compressed_image.size();
1360 bmi.biHeight = -bmi.biHeight; 1347 bmi.biHeight = -bmi.biHeight;
1348 HDC dc = skia::BeginPlatformPaint(canvas);
1349 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG
1350 // to the EMF, the EnumEnhMetaFile call fails in the browser
1351 // process. The failure also happens if we output nothing here.
1352 // We need to investigate the reason for this failure and fix it.
1353 // In the meantime this temporary hack of drawing an empty
1354 // rectangle in the DC gets us by.
1355 Rectangle(dc, 0, 0, 0, 0);
1361 StretchDIBits(dc, printable_area.x(), printable_area.y(), 1356 StretchDIBits(dc, printable_area.x(), printable_area.y(),
1362 printable_area.width(), printable_area.height(), 1357 printable_area.width(), printable_area.height(),
1363 0, 0, bitmap.width(), bitmap.height(), 1358 0, 0, bitmap.width(), bitmap.height(),
1364 &compressed_image.front(), 1359 &compressed_image.front(),
1365 reinterpret_cast<const BITMAPINFO*>(&bmi), 1360 reinterpret_cast<const BITMAPINFO*>(&bmi),
1366 DIB_RGB_COLORS, SRCCOPY); 1361 DIB_RGB_COLORS, SRCCOPY);
1362 skia::EndPlatformPaint(canvas);
1367 return true; 1363 return true;
1368 } 1364 }
1369 #endif // OS_WIN 1365 #endif // OS_WIN
1370 1366
1371 #if defined(OS_MACOSX) 1367 #if defined(OS_MACOSX)
1372 void PluginInstance::DrawSkBitmapToCanvas( 1368 void PluginInstance::DrawSkBitmapToCanvas(
1373 const SkBitmap& bitmap, WebKit::WebCanvas* canvas, 1369 const SkBitmap& bitmap, WebKit::WebCanvas* canvas,
1374 const gfx::Rect& dest_rect, 1370 const gfx::Rect& dest_rect,
1375 int canvas_height) { 1371 int canvas_height) {
1376 SkAutoLockPixels lock(bitmap); 1372 SkAutoLockPixels lock(bitmap);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 return found->second; 1468 return found->second;
1473 } 1469 }
1474 1470
1475 bool PluginInstance::IsFullPagePlugin() const { 1471 bool PluginInstance::IsFullPagePlugin() const {
1476 WebFrame* frame = container()->element().document().frame(); 1472 WebFrame* frame = container()->element().document().frame();
1477 return frame->view()->mainFrame()->document().isPluginDocument(); 1473 return frame->view()->mainFrame()->document().isPluginDocument();
1478 } 1474 }
1479 1475
1480 } // namespace ppapi 1476 } // namespace ppapi
1481 } // namespace webkit 1477 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698