Commit 6487f722 authored by pkasting@chromium.org's avatar pkasting@chromium.org

Fixes for re-enabling more MSVC level 4 warnings: pdf/ edition

This contains fixes for the following sorts of issues:
* Signedness mismatch

This relies on https://codereview.chromium.org/376003003 to make FPDF_FillRect()
take a 32-bit value for the color in order to make the changes here as simple
and clean as possible.

This also contains a few other cleanups to make code simpler or more consistent.

BUG=81439
TEST=none

Review URL: https://codereview.chromium.org/372273005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282146 0039d316-1c4b-4281-b951-d872f2087c98
parent 25063816
...@@ -77,7 +77,7 @@ vars = { ...@@ -77,7 +77,7 @@ vars = {
# Three lines of non-changing comments so that # Three lines of non-changing comments so that
# the commit queue can handle CLs rolling PDFIum # the commit queue can handle CLs rolling PDFIum
# and whatever else without interference from each other. # and whatever else without interference from each other.
"pdfium_revision": "cb46ea1bca55b448a7a54db2086c6f736f05c35f", "pdfium_revision": "532a6a7ece21ca4ea253a196bb5c61a1861d12a0",
# Three lines of non-changing comments so that # Three lines of non-changing comments so that
# the commit queue can handle CLs rolling openmax_dl # the commit queue can handle CLs rolling openmax_dl
# and whatever else without interference from each other. # and whatever else without interference from each other.
......
...@@ -768,11 +768,7 @@ void Instance::OnPaint(const std::vector<pp::Rect>& paint_rects, ...@@ -768,11 +768,7 @@ void Instance::OnPaint(const std::vector<pp::Rect>& paint_rects,
if (first_paint_) { if (first_paint_) {
first_paint_ = false; first_paint_ = false;
pp::Rect rect = pp::Rect(pp::Point(), plugin_size_); pp::Rect rect = pp::Rect(pp::Point(), plugin_size_);
unsigned int color = kBackgroundColorA << 24 | FillRect(rect, kBackgroundColor);
kBackgroundColorR << 16 |
kBackgroundColorG << 8 |
kBackgroundColorB;
FillRect(rect, color);
ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); ready->push_back(PaintManager::ReadyRect(rect, image_data_, true));
*pending = paint_rects; *pending = paint_rects;
return; return;
...@@ -1024,12 +1020,10 @@ void Instance::CalculateBackgroundParts() { ...@@ -1024,12 +1020,10 @@ void Instance::CalculateBackgroundParts() {
// Add the left, right, and bottom rectangles. Note: we assume only // Add the left, right, and bottom rectangles. Note: we assume only
// horizontal centering. // horizontal centering.
BackgroundPart part; BackgroundPart part = {
part.color = kBackgroundColorA << 24 | pp::Rect(0, 0, left_width, bottom),
kBackgroundColorR << 16 | kBackgroundColor
kBackgroundColorG << 8 | };
kBackgroundColorB;
part.location = pp::Rect(0, 0, left_width, bottom);
if (!part.location.IsEmpty()) if (!part.location.IsEmpty())
background_parts_.push_back(part); background_parts_.push_back(part);
part.location = pp::Rect(right_start, 0, right_width, bottom); part.location = pp::Rect(right_start, 0, right_width, bottom);
...@@ -1066,17 +1060,17 @@ int Instance::GetDocumentPixelHeight() const { ...@@ -1066,17 +1060,17 @@ int Instance::GetDocumentPixelHeight() const {
device_scale_)); device_scale_));
} }
void Instance::FillRect(const pp::Rect& rect, unsigned int color) { void Instance::FillRect(const pp::Rect& rect, uint32 color) {
DCHECK(!image_data_.is_null() || rect.IsEmpty()); DCHECK(!image_data_.is_null() || rect.IsEmpty());
unsigned int* buffer_start = static_cast<unsigned int*>(image_data_.data()); uint32* buffer_start = static_cast<uint32*>(image_data_.data());
int stride = image_data_.stride(); int stride = image_data_.stride();
unsigned int* ptr = buffer_start + rect.y() * stride / 4 + rect.x(); uint32* ptr = buffer_start + rect.y() * stride / 4 + rect.x();
int height = rect.height(); int height = rect.height();
int width = rect.width(); int width = rect.width();
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) for (int x = 0; x < width; ++x)
*(ptr + x) = color; *(ptr + x) = color;
ptr += stride /4; ptr += stride / 4;
} }
} }
......
...@@ -228,7 +228,7 @@ class Instance : public pp::InstancePrivate, ...@@ -228,7 +228,7 @@ class Instance : public pp::InstancePrivate,
int GetDocumentPixelHeight() const; int GetDocumentPixelHeight() const;
// Draws a rectangle with the specified dimensions and color in our buffer. // Draws a rectangle with the specified dimensions and color in our buffer.
void FillRect(const pp::Rect& rect, unsigned int color); void FillRect(const pp::Rect& rect, uint32 color);
std::vector<pp::ImageData> GetThumbnailResources(); std::vector<pp::ImageData> GetThumbnailResources();
std::vector<pp::ImageData> GetProgressBarResources(pp::ImageData* background); std::vector<pp::ImageData> GetProgressBarResources(pp::ImageData* background);
...@@ -410,7 +410,7 @@ class Instance : public pp::InstancePrivate, ...@@ -410,7 +410,7 @@ class Instance : public pp::InstancePrivate,
struct BackgroundPart { struct BackgroundPart {
pp::Rect location; pp::Rect location;
unsigned int color; uint32 color;
}; };
std::vector<BackgroundPart> background_parts_; std::vector<BackgroundPart> background_parts_;
......
...@@ -629,11 +629,7 @@ void OutOfProcessInstance::OnPaint( ...@@ -629,11 +629,7 @@ void OutOfProcessInstance::OnPaint(
if (first_paint_) { if (first_paint_) {
first_paint_ = false; first_paint_ = false;
pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); pp::Rect rect = pp::Rect(pp::Point(), image_data_.size());
unsigned int color = kBackgroundColorA << 24 | FillRect(rect, kBackgroundColor);
kBackgroundColorR << 16 |
kBackgroundColorG << 8 |
kBackgroundColorB;
FillRect(rect, color);
ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); ready->push_back(PaintManager::ReadyRect(rect, image_data_, true));
} }
...@@ -724,12 +720,10 @@ void OutOfProcessInstance::CalculateBackgroundParts() { ...@@ -724,12 +720,10 @@ void OutOfProcessInstance::CalculateBackgroundParts() {
// Add the left, right, and bottom rectangles. Note: we assume only // Add the left, right, and bottom rectangles. Note: we assume only
// horizontal centering. // horizontal centering.
BackgroundPart part; BackgroundPart part = {
part.color = kBackgroundColorA << 24 | pp::Rect(0, 0, left_width, bottom),
kBackgroundColorR << 16 | kBackgroundColor
kBackgroundColorG << 8 | };
kBackgroundColorB;
part.location = pp::Rect(0, 0, left_width, bottom);
if (!part.location.IsEmpty()) if (!part.location.IsEmpty())
background_parts_.push_back(part); background_parts_.push_back(part);
part.location = pp::Rect(right_start, 0, right_width, bottom); part.location = pp::Rect(right_start, 0, right_width, bottom);
...@@ -750,11 +744,11 @@ int OutOfProcessInstance::GetDocumentPixelHeight() const { ...@@ -750,11 +744,11 @@ int OutOfProcessInstance::GetDocumentPixelHeight() const {
ceil(document_size_.height() * zoom_ * device_scale_)); ceil(document_size_.height() * zoom_ * device_scale_));
} }
void OutOfProcessInstance::FillRect(const pp::Rect& rect, unsigned int color) { void OutOfProcessInstance::FillRect(const pp::Rect& rect, uint32 color) {
DCHECK(!image_data_.is_null() || rect.IsEmpty()); DCHECK(!image_data_.is_null() || rect.IsEmpty());
unsigned int* buffer_start = static_cast<unsigned int*>(image_data_.data()); uint32* buffer_start = static_cast<uint32*>(image_data_.data());
int stride = image_data_.stride(); int stride = image_data_.stride();
unsigned int* ptr = buffer_start + rect.y() * stride / 4 + rect.x(); uint32* ptr = buffer_start + rect.y() * stride / 4 + rect.x();
int height = rect.height(); int height = rect.height();
int width = rect.width(); int width = rect.width();
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
......
...@@ -159,7 +159,7 @@ class OutOfProcessInstance : public pp::Instance, ...@@ -159,7 +159,7 @@ class OutOfProcessInstance : public pp::Instance,
int GetDocumentPixelHeight() const; int GetDocumentPixelHeight() const;
// Draws a rectangle with the specified dimensions and color in our buffer. // Draws a rectangle with the specified dimensions and color in our buffer.
void FillRect(const pp::Rect& rect, unsigned int color); void FillRect(const pp::Rect& rect, uint32 color);
void LoadUrl(const std::string& url); void LoadUrl(const std::string& url);
void LoadPreviewUrl(const std::string& url); void LoadPreviewUrl(const std::string& url);
...@@ -240,7 +240,7 @@ class OutOfProcessInstance : public pp::Instance, ...@@ -240,7 +240,7 @@ class OutOfProcessInstance : public pp::Instance,
struct BackgroundPart { struct BackgroundPart {
pp::Rect location; pp::Rect location;
unsigned int color; uint32 color;
}; };
std::vector<BackgroundPart> background_parts_; std::vector<BackgroundPart> background_parts_;
......
...@@ -29,10 +29,7 @@ namespace pp { ...@@ -29,10 +29,7 @@ namespace pp {
class InputEvent; class InputEvent;
} }
#define kBackgroundColorR 204 const uint32 kBackgroundColor = 0xFFCCCCCC;
#define kBackgroundColorG 204
#define kBackgroundColorB 204
#define kBackgroundColorA 255
namespace chrome_pdf { namespace chrome_pdf {
......
...@@ -55,10 +55,7 @@ namespace chrome_pdf { ...@@ -55,10 +55,7 @@ namespace chrome_pdf {
#define kHighlightColorG 193 #define kHighlightColorG 193
#define kHighlightColorB 218 #define kHighlightColorB 218
#define kPendingPageColorR 238 const uint32 kPendingPageColor = 0xFFEEEEEE;
#define kPendingPageColorG 238
#define kPendingPageColorB 238
#define kPendingPageColorA 255
#define kFormHighlightColor 0xFFE4DD #define kFormHighlightColor 0xFFE4DD
#define kFormHighlightAlpha 100 #define kFormHighlightAlpha 100
...@@ -1058,7 +1055,7 @@ pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF( ...@@ -1058,7 +1055,7 @@ pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF(
// Clear the bitmap // Clear the bitmap
FPDFBitmap_FillRect(bitmap, 0, 0, bitmap_size.width(), FPDFBitmap_FillRect(bitmap, 0, 0, bitmap_size.width(),
bitmap_size.height(), 255, 255, 255, 255); bitmap_size.height(), 0xFFFFFFFF);
pp::Rect page_rect = pages_to_print[i].rect(); pp::Rect page_rect = pages_to_print[i].rect();
FPDF_RenderPageBitmap(bitmap, pages_to_print[i].GetPrintPage(), FPDF_RenderPageBitmap(bitmap, pages_to_print[i].GetPrintPage(),
...@@ -1931,18 +1928,15 @@ void PDFiumEngine::PaintThumbnail(pp::ImageData* image_data, int index) { ...@@ -1931,18 +1928,15 @@ void PDFiumEngine::PaintThumbnail(pp::ImageData* image_data, int index) {
FPDFBitmap_BGRx, image_data->data(), image_data->stride()); FPDFBitmap_BGRx, image_data->data(), image_data->stride());
if (pages_[index]->available()) { if (pages_[index]->available()) {
FPDFBitmap_FillRect( FPDFBitmap_FillRect(bitmap, 0, 0, image_data->size().width(),
bitmap, 0, 0, image_data->size().width(), image_data->size().height(), image_data->size().height(), 0xFFFFFFFF);
255, 255, 255, 255);
FPDF_RenderPageBitmap( FPDF_RenderPageBitmap(
bitmap, pages_[index]->GetPage(), 0, 0, image_data->size().width(), bitmap, pages_[index]->GetPage(), 0, 0, image_data->size().width(),
image_data->size().height(), 0, GetRenderingFlags()); image_data->size().height(), 0, GetRenderingFlags());
} else { } else {
FPDFBitmap_FillRect( FPDFBitmap_FillRect(bitmap, 0, 0, image_data->size().width(),
bitmap, 0, 0, image_data->size().width(), image_data->size().height(), image_data->size().height(), kPendingPageColor);
kPendingPageColorR, kPendingPageColorG, kPendingPageColorB,
kPendingPageColorA);
} }
FPDFBitmap_Destroy(bitmap); FPDFBitmap_Destroy(bitmap);
...@@ -2346,9 +2340,8 @@ bool PDFiumEngine::ContinuePaint(int progressive_index, ...@@ -2346,9 +2340,8 @@ bool PDFiumEngine::ContinuePaint(int progressive_index,
int start_x, start_y, size_x, size_y; int start_x, start_y, size_x, size_y;
GetPDFiumRect( GetPDFiumRect(
page_index, dirty, &start_x, &start_y, &size_x, &size_y); page_index, dirty, &start_x, &start_y, &size_x, &size_y);
FPDFBitmap_FillRect( FPDFBitmap_FillRect(progressive_paints_[progressive_index].bitmap, start_x,
progressive_paints_[progressive_index].bitmap, start_x, start_y, size_x, start_y, size_x, size_y, 0xFFFFFFFF);
size_y, 255, 255, 255, 255);
rv = FPDF_RenderPageBitmap_Start( rv = FPDF_RenderPageBitmap_Start(
progressive_paints_[progressive_index].bitmap, progressive_paints_[progressive_index].bitmap,
pages_[page_index]->GetPage(), start_x, start_y, size_x, size_y, pages_[page_index]->GetPage(), start_x, start_y, size_x, size_y,
...@@ -2408,11 +2401,9 @@ void PDFiumEngine::FillPageSides(int progressive_index) { ...@@ -2408,11 +2401,9 @@ void PDFiumEngine::FillPageSides(int progressive_index) {
kPageShadowBottom + kPageSeparatorThickness); kPageShadowBottom + kPageSeparatorThickness);
left = GetScreenRect(left).Intersect(dirty_in_screen); left = GetScreenRect(left).Intersect(dirty_in_screen);
FPDFBitmap_FillRect( FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(),
bitmap, left.x() - dirty_in_screen.x(), left.y() - dirty_in_screen.y(), left.width(),
left.y() - dirty_in_screen.y(), left.width(), left.height(), left.height(), kBackgroundColor);
kBackgroundColorR, kBackgroundColorG, kBackgroundColorB,
kBackgroundColorA);
} }
if (page_rect.right() < document_size_.width()) { if (page_rect.right() < document_size_.width()) {
...@@ -2424,11 +2415,9 @@ void PDFiumEngine::FillPageSides(int progressive_index) { ...@@ -2424,11 +2415,9 @@ void PDFiumEngine::FillPageSides(int progressive_index) {
kPageShadowBottom + kPageSeparatorThickness); kPageShadowBottom + kPageSeparatorThickness);
right = GetScreenRect(right).Intersect(dirty_in_screen); right = GetScreenRect(right).Intersect(dirty_in_screen);
FPDFBitmap_FillRect( FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(),
bitmap, right.x() - dirty_in_screen.x(), right.y() - dirty_in_screen.y(), right.width(),
right.y() - dirty_in_screen.y(), right.width(), right.height(), right.height(), kBackgroundColor);
kBackgroundColorR, kBackgroundColorG, kBackgroundColorB,
kBackgroundColorA);
} }
// Paint separator. // Paint separator.
...@@ -2438,11 +2427,9 @@ void PDFiumEngine::FillPageSides(int progressive_index) { ...@@ -2438,11 +2427,9 @@ void PDFiumEngine::FillPageSides(int progressive_index) {
kPageSeparatorThickness); kPageSeparatorThickness);
bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); bottom = GetScreenRect(bottom).Intersect(dirty_in_screen);
FPDFBitmap_FillRect( FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(),
bitmap, bottom.x() - dirty_in_screen.x(), bottom.y() - dirty_in_screen.y(), bottom.width(),
bottom.y() - dirty_in_screen.y(), bottom.width(), bottom.height(), bottom.height(), kBackgroundColor);
kBackgroundColorR, kBackgroundColorG, kBackgroundColorB,
kBackgroundColorA);
} }
void PDFiumEngine::PaintPageShadow(int progressive_index, void PDFiumEngine::PaintPageShadow(int progressive_index,
...@@ -2515,8 +2502,7 @@ void PDFiumEngine::PaintUnavailablePage(int page_index, ...@@ -2515,8 +2502,7 @@ void PDFiumEngine::PaintUnavailablePage(int page_index,
GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y); GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y);
FPDF_BITMAP bitmap = CreateBitmap(dirty, image_data); FPDF_BITMAP bitmap = CreateBitmap(dirty, image_data);
FPDFBitmap_FillRect(bitmap, start_x, start_y, size_x, size_y, FPDFBitmap_FillRect(bitmap, start_x, start_y, size_x, size_y,
kPendingPageColorR, kPendingPageColorG, kPendingPageColorB, kPendingPageColor);
kPendingPageColorA);
pp::Rect loading_text_in_screen( pp::Rect loading_text_in_screen(
pages_[page_index]->rect().width() / 2, pages_[page_index]->rect().width() / 2,
...@@ -2817,10 +2803,6 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc, ...@@ -2817,10 +2803,6 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc,
// Page drop shadow parameters. // Page drop shadow parameters.
const double factor = 0.5; const double factor = 0.5;
const uint32 background = (kBackgroundColorA << 24) |
(kBackgroundColorR << 16) |
(kBackgroundColorG << 8) |
kBackgroundColorB;
uint32 depth = std::max( uint32 depth = std::max(
std::max(page_rect.x() - shadow_rect.x(), std::max(page_rect.x() - shadow_rect.x(),
page_rect.y() - shadow_rect.y()), page_rect.y() - shadow_rect.y()),
...@@ -2830,7 +2812,7 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc, ...@@ -2830,7 +2812,7 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc,
// We need to check depth only to verify our copy of shadow matrix is correct. // We need to check depth only to verify our copy of shadow matrix is correct.
if (!page_shadow_.get() || page_shadow_->depth() != depth) if (!page_shadow_.get() || page_shadow_->depth() != depth)
page_shadow_.reset(new ShadowMatrix(depth, factor, background)); page_shadow_.reset(new ShadowMatrix(depth, factor, kBackgroundColor));
DCHECK(!image_data->is_null()); DCHECK(!image_data->is_null());
DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_);
...@@ -3314,8 +3296,7 @@ bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer, ...@@ -3314,8 +3296,7 @@ bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer,
FPDF_BITMAP bitmap = FPDFBitmap_Create(dest.width(), dest.height(), FPDF_BITMAP bitmap = FPDFBitmap_Create(dest.width(), dest.height(),
FPDFBitmap_BGRx); FPDFBitmap_BGRx);
// Clear the bitmap // Clear the bitmap
FPDFBitmap_FillRect(bitmap, 0, 0, dest.width(), dest.height(), 255, 255, FPDFBitmap_FillRect(bitmap, 0, 0, dest.width(), dest.height(), 0xFFFFFFFF);
255, 255);
FPDF_RenderPageBitmap( FPDF_RenderPageBitmap(
bitmap, page, 0, 0, dest.width(), dest.height(), rotate, bitmap, page, 0, 0, dest.width(), dest.height(), rotate,
FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH);
...@@ -3368,7 +3349,7 @@ bool PDFiumEngineExports::RenderPDFPageToBitmap( ...@@ -3368,7 +3349,7 @@ bool PDFiumEngineExports::RenderPDFPageToBitmap(
settings.bounds.width() * 4); settings.bounds.width() * 4);
// Clear the bitmap // Clear the bitmap
FPDFBitmap_FillRect(bitmap, 0, 0, settings.bounds.width(), FPDFBitmap_FillRect(bitmap, 0, 0, settings.bounds.width(),
settings.bounds.height(), 255, 255, 255, 255); settings.bounds.height(), 0xFFFFFFFF);
// Shift top-left corner of bounds to (0, 0) if it's not there. // Shift top-left corner of bounds to (0, 0) if it's not there.
dest.set_point(dest.point() - settings.bounds.point()); dest.set_point(dest.point() - settings.bounds.point());
FPDF_RenderPageBitmap( FPDF_RenderPageBitmap(
......
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