Commit 87e7e5f7 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Reduce parameter count for chrome_pdf::RenderPDFPageToBitmap().

Combine horizontal/vertical DPI into a gfx::Size. Combine output bitmap
width/height into a gfx::Size.

Change-Id: I603025b11ce8cc76ab8f890cb9104cdca25ac335
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2430764Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812045}
parent 6b449e14
...@@ -391,10 +391,8 @@ class PrintPreviewPdfGeneratedBrowserTest : public InProcessBrowserTest { ...@@ -391,10 +391,8 @@ class PrintPreviewPdfGeneratedBrowserTest : public InProcessBrowserTest {
settings.area.size().GetArea()); settings.area.size().GetArea());
ASSERT_TRUE(chrome_pdf::RenderPDFPageToBitmap( ASSERT_TRUE(chrome_pdf::RenderPDFPageToBitmap(
pdf_span, i, page_bitmap_data.data(), settings.area.size().width(), pdf_span, i, page_bitmap_data.data(), settings.area.size(),
settings.area.size().height(), settings.dpi.width(), settings.dpi, false, true, settings.autorotate, settings.use_color));
settings.dpi.height(), false, true, settings.autorotate,
settings.use_color));
FillPng(&page_bitmap_data, width_in_pixels, max_width_in_pixels, FillPng(&page_bitmap_data, width_in_pixels, max_width_in_pixels,
settings.area.size().height()); settings.area.size().height());
bitmap_data.insert(bitmap_data.end(), bitmap_data.insert(bitmap_data.end(),
......
...@@ -64,9 +64,8 @@ void PdfThumbnailer::GetThumbnail(printing::mojom::ThumbParamsPtr params, ...@@ -64,9 +64,8 @@ void PdfThumbnailer::GetThumbnail(printing::mojom::ThumbParamsPtr params,
// Convert PDF bytes into a bitmap thumbnail. // Convert PDF bytes into a bitmap thumbnail.
if (!chrome_pdf::RenderPDFPageToBitmap( if (!chrome_pdf::RenderPDFPageToBitmap(
pdf_buffer, 0, result.getPixels(), width_px, height_px, pdf_buffer, 0, result.getPixels(), params->size_px, params->dpi,
params->dpi.width(), params->dpi.height(), params->stretch, params->stretch, params->keep_aspect, kAutorotate, kUseColor)) {
params->keep_aspect, kAutorotate, kUseColor)) {
DLOG(ERROR) << "Failed to render PDF buffer as bitmap image"; DLOG(ERROR) << "Failed to render PDF buffer as bitmap image";
std::move(callback).Run(SkBitmap()); std::move(callback).Run(SkBitmap());
return; return;
......
...@@ -55,9 +55,9 @@ base::ReadOnlySharedMemoryRegion RenderPdfPagesToPwgRaster( ...@@ -55,9 +55,9 @@ base::ReadOnlySharedMemoryRegion RenderPdfPagesToPwgRaster(
page_number = total_page_count - 1 - page_number; page_number = total_page_count - 1 - page_number;
if (!chrome_pdf::RenderPDFPageToBitmap( if (!chrome_pdf::RenderPDFPageToBitmap(
pdf_data, page_number, image.pixel_data(), image.size().width(), pdf_data, page_number, image.pixel_data(), image.size(),
image.size().height(), settings.dpi.width(), settings.dpi.height(), settings.dpi, false, true, settings.autorotate,
false, true, settings.autorotate, settings.use_color)) { settings.use_color)) {
return invalid_pwg_region; return invalid_pwg_region;
} }
......
...@@ -370,9 +370,8 @@ class HeadlessWebContentsPDFTest : public HeadlessAsyncDevTooledBrowserTest { ...@@ -370,9 +370,8 @@ class HeadlessWebContentsPDFTest : public HeadlessAsyncDevTooledBrowserTest {
std::vector<uint8_t> page_bitmap_data(kColorChannels * std::vector<uint8_t> page_bitmap_data(kColorChannels *
settings.area.size().GetArea()); settings.area.size().GetArea());
EXPECT_TRUE(chrome_pdf::RenderPDFPageToBitmap( EXPECT_TRUE(chrome_pdf::RenderPDFPageToBitmap(
pdf_span, i, page_bitmap_data.data(), settings.area.size().width(), pdf_span, i, page_bitmap_data.data(), settings.area.size(),
settings.area.size().height(), settings.dpi.width(), settings.dpi, /*stretch_to_bounds=*/false,
settings.dpi.height(), /*stretch_to_bounds=*/false,
/*keep_aspect_ratio=*/true, settings.autorotate, settings.use_color)); /*keep_aspect_ratio=*/true, settings.autorotate, settings.use_color));
EXPECT_EQ(0x56, page_bitmap_data[0]); // B EXPECT_EQ(0x56, page_bitmap_data[0]); // B
EXPECT_EQ(0x34, page_bitmap_data[1]); // G EXPECT_EQ(0x34, page_bitmap_data[1]); // G
......
...@@ -62,7 +62,7 @@ bool RenderPDFPageToDC(base::span<const uint8_t> pdf_buffer, ...@@ -62,7 +62,7 @@ bool RenderPDFPageToDC(base::span<const uint8_t> pdf_buffer,
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true); ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
PDFEngineExports* engine_exports = PDFEngineExports::Get(); PDFEngineExports* engine_exports = PDFEngineExports::Get();
PDFEngineExports::RenderingSettings settings( PDFEngineExports::RenderingSettings settings(
dpi_x, dpi_y, gfx::Size(dpi_x, dpi_y),
gfx::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height), gfx::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height),
fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds,
autorotate, use_color); autorotate, use_color);
...@@ -117,10 +117,8 @@ base::Optional<gfx::SizeF> GetPDFPageSizeByIndex( ...@@ -117,10 +117,8 @@ base::Optional<gfx::SizeF> GetPDFPageSizeByIndex(
bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer, bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
int page_number, int page_number,
void* bitmap_buffer, void* bitmap_buffer,
int bitmap_width, const gfx::Size& bitmap_size,
int bitmap_height, const gfx::Size& dpi,
int dpi_x,
int dpi_y,
bool stretch_to_bounds, bool stretch_to_bounds,
bool keep_aspect_ratio, bool keep_aspect_ratio,
bool autorotate, bool autorotate,
...@@ -128,7 +126,7 @@ bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer, ...@@ -128,7 +126,7 @@ bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true); ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
PDFEngineExports* engine_exports = PDFEngineExports::Get(); PDFEngineExports* engine_exports = PDFEngineExports::Get();
PDFEngineExports::RenderingSettings settings( PDFEngineExports::RenderingSettings settings(
dpi_x, dpi_y, gfx::Rect(bitmap_width, bitmap_height), dpi, gfx::Rect(bitmap_size),
/*fit_to_bounds=*/true, stretch_to_bounds, keep_aspect_ratio, /*fit_to_bounds=*/true, stretch_to_bounds, keep_aspect_ratio,
/*center_in_bounds=*/true, autorotate, use_color); /*center_in_bounds=*/true, autorotate, use_color);
return engine_exports->RenderPDFPageToBitmap(pdf_buffer, page_number, return engine_exports->RenderPDFPageToBitmap(pdf_buffer, page_number,
......
...@@ -132,11 +132,10 @@ base::Optional<gfx::SizeF> GetPDFPageSizeByIndex( ...@@ -132,11 +132,10 @@ base::Optional<gfx::SizeF> GetPDFPageSizeByIndex(
// rendered. // rendered.
// |page_number| is the 0-based index of the page to be rendered. // |page_number| is the 0-based index of the page to be rendered.
// |bitmap_buffer| is the output buffer for bitmap. // |bitmap_buffer| is the output buffer for bitmap.
// |bitmap_width| is the width of the output bitmap. // |bitmap_size| is the size of the output bitmap.
// |bitmap_height| is the height of the output bitmap. // |dpi| is the 2D resolution.
// |dpi_x| and |dpi_y| is the resolution.
// |stretch_to_bounds| specifies whether the output should be stretched to fit // |stretch_to_bounds| specifies whether the output should be stretched to fit
// the supplied |bitmap_width| and |bitmap_height|. // the supplied |bitmap_size|.
// |keep_aspect_ratio| If any scaling is needed, this parameter specifies // |keep_aspect_ratio| If any scaling is needed, this parameter specifies
// whether the original aspect ratio of the page is preserved while scaling. // whether the original aspect ratio of the page is preserved while scaling.
// |autorotate| specifies whether the final image should be rotated to match // |autorotate| specifies whether the final image should be rotated to match
...@@ -146,10 +145,8 @@ base::Optional<gfx::SizeF> GetPDFPageSizeByIndex( ...@@ -146,10 +145,8 @@ base::Optional<gfx::SizeF> GetPDFPageSizeByIndex(
bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer, bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
int page_number, int page_number,
void* bitmap_buffer, void* bitmap_buffer,
int bitmap_width, const gfx::Size& bitmap_size,
int bitmap_height, const gfx::Size& dpi,
int dpi_x,
int dpi_y,
bool stretch_to_bounds, bool stretch_to_bounds,
bool keep_aspect_ratio, bool keep_aspect_ratio,
bool autorotate, bool autorotate,
......
...@@ -506,8 +506,7 @@ class PDFEngine { ...@@ -506,8 +506,7 @@ class PDFEngine {
class PDFEngineExports { class PDFEngineExports {
public: public:
struct RenderingSettings { struct RenderingSettings {
RenderingSettings(int dpi_x, RenderingSettings(const gfx::Size& dpi,
int dpi_y,
const gfx::Rect& bounds, const gfx::Rect& bounds,
bool fit_to_bounds, bool fit_to_bounds,
bool stretch_to_bounds, bool stretch_to_bounds,
...@@ -517,8 +516,7 @@ class PDFEngineExports { ...@@ -517,8 +516,7 @@ class PDFEngineExports {
bool use_color); bool use_color);
RenderingSettings(const RenderingSettings& that); RenderingSettings(const RenderingSettings& that);
int dpi_x; gfx::Size dpi;
int dpi_y;
gfx::Rect bounds; gfx::Rect bounds;
bool fit_to_bounds; bool fit_to_bounds;
bool stretch_to_bounds; bool stretch_to_bounds;
......
...@@ -37,7 +37,9 @@ int CalculatePosition(FPDF_PAGE page, ...@@ -37,7 +37,9 @@ int CalculatePosition(FPDF_PAGE page,
const PDFiumEngineExports::RenderingSettings& settings, const PDFiumEngineExports::RenderingSettings& settings,
gfx::Rect* dest) { gfx::Rect* dest) {
// settings.bounds is in terms of the max DPI. Convert page sizes to match. // settings.bounds is in terms of the max DPI. Convert page sizes to match.
int dpi = std::max(settings.dpi_x, settings.dpi_y); const int dpi_x = settings.dpi.width();
const int dpi_y = settings.dpi.height();
const int dpi = std::max(dpi_x, dpi_y);
int page_width = static_cast<int>( int page_width = static_cast<int>(
ConvertUnitDouble(FPDF_GetPageWidthF(page), kPointsPerInch, dpi)); ConvertUnitDouble(FPDF_GetPageWidthF(page), kPointsPerInch, dpi));
int page_height = static_cast<int>( int page_height = static_cast<int>(
...@@ -89,15 +91,15 @@ int CalculatePosition(FPDF_PAGE page, ...@@ -89,15 +91,15 @@ int CalculatePosition(FPDF_PAGE page,
} }
// Scale the bounds to device units if DPI is rectangular. // Scale the bounds to device units if DPI is rectangular.
if (settings.dpi_x != settings.dpi_y) { if (dpi_x != dpi_y) {
dest->set_width(dest->width() * settings.dpi_x / dpi); dest->set_width(dest->width() * dpi_x / dpi);
dest->set_height(dest->height() * settings.dpi_y / dpi); dest->set_height(dest->height() * dpi_y / dpi);
} }
if (settings.center_in_bounds) { if (settings.center_in_bounds) {
gfx::Vector2d offset( gfx::Vector2d offset(
(settings.bounds.width() * settings.dpi_x / dpi - dest->width()) / 2, (settings.bounds.width() * dpi_x / dpi - dest->width()) / 2,
(settings.bounds.height() * settings.dpi_y / dpi - dest->height()) / 2); (settings.bounds.height() * dpi_y / dpi - dest->height()) / 2);
dest->Offset(offset); dest->Offset(offset);
} }
return rotate; return rotate;
...@@ -183,8 +185,7 @@ base::Value RecursiveGetStructTree(FPDF_STRUCTELEMENT struct_elem) { ...@@ -183,8 +185,7 @@ base::Value RecursiveGetStructTree(FPDF_STRUCTELEMENT struct_elem) {
} // namespace } // namespace
PDFEngineExports::RenderingSettings::RenderingSettings(int dpi_x, PDFEngineExports::RenderingSettings::RenderingSettings(const gfx::Size& dpi,
int dpi_y,
const gfx::Rect& bounds, const gfx::Rect& bounds,
bool fit_to_bounds, bool fit_to_bounds,
bool stretch_to_bounds, bool stretch_to_bounds,
...@@ -192,8 +193,7 @@ PDFEngineExports::RenderingSettings::RenderingSettings(int dpi_x, ...@@ -192,8 +193,7 @@ PDFEngineExports::RenderingSettings::RenderingSettings(int dpi_x,
bool center_in_bounds, bool center_in_bounds,
bool autorotate, bool autorotate,
bool use_color) bool use_color)
: dpi_x(dpi_x), : dpi(dpi),
dpi_y(dpi_y),
bounds(bounds), bounds(bounds),
fit_to_bounds(fit_to_bounds), fit_to_bounds(fit_to_bounds),
stretch_to_bounds(stretch_to_bounds), stretch_to_bounds(stretch_to_bounds),
...@@ -239,10 +239,10 @@ bool PDFiumEngineExports::RenderPDFPageToDC( ...@@ -239,10 +239,10 @@ bool PDFiumEngineExports::RenderPDFPageToDC(
RenderingSettings new_settings = settings; RenderingSettings new_settings = settings;
// calculate the page size // calculate the page size
if (new_settings.dpi_x == -1) if (new_settings.dpi.width() == -1)
new_settings.dpi_x = GetDeviceCaps(dc, LOGPIXELSX); new_settings.dpi.set_width(GetDeviceCaps(dc, LOGPIXELSX));
if (new_settings.dpi_y == -1) if (new_settings.dpi.height() == -1)
new_settings.dpi_y = GetDeviceCaps(dc, LOGPIXELSY); new_settings.dpi.set_height(GetDeviceCaps(dc, LOGPIXELSY));
gfx::Rect dest; gfx::Rect dest;
int rotate = CalculatePosition(page.get(), new_settings, &dest); int rotate = CalculatePosition(page.get(), new_settings, &dest);
......
...@@ -69,7 +69,7 @@ void CheckPdfRendering(const std::vector<uint8_t>& pdf_data, ...@@ -69,7 +69,7 @@ void CheckPdfRendering(const std::vector<uint8_t>& pdf_data,
page_rect.height()); page_rect.height());
PDFEngineExports::RenderingSettings settings( PDFEngineExports::RenderingSettings settings(
printing::kDefaultPdfDpi, printing::kDefaultPdfDpi, page_rect, gfx::Size(printing::kDefaultPdfDpi, printing::kDefaultPdfDpi), page_rect,
/*fit_to_bounds=*/true, /*fit_to_bounds=*/true,
/*stretch_to_bounds=*/false, /*stretch_to_bounds=*/false,
/*keep_aspect_ratio=*/true, /*keep_aspect_ratio=*/true,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment