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