0

Convert PaintReadyRect to a class

Switches PaintReadyRect from a struct to a class, since this type can
enforce invariants like most members being immutable.

Bug: 1099020
Change-Id: I79ed7dcb60273c3db0d5223a64fd5e7cdeb0e633
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2311069
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790634}
This commit is contained in:
K. Moon
2020-07-22 00:39:54 +00:00
committed by Commit Bot
parent dac916ed9c
commit 70565f67e7
5 changed files with 25 additions and 14 deletions

@ -43,7 +43,7 @@ class TextInput_Dev;
namespace chrome_pdf {
struct PaintReadyRect;
class PaintReadyRect;
class OutOfProcessInstance : public pp::Instance,
public pp::Find_Private,

@ -221,8 +221,8 @@ void PaintAggregator::ScrollRect(const gfx::Rect& clip_rect,
InvalidateRectInternal(leftover_rect, false);
for (auto& update_rect : update_.ready_rects) {
if (update_.scroll_rect.Contains(update_rect.rect))
update_rect.rect = ScrollPaintRect(update_rect.rect, amount);
if (update_.scroll_rect.Contains(update_rect.rect()))
update_rect.set_rect(ScrollPaintRect(update_rect.rect(), amount));
}
if (update_.synthesized_scroll_damage_rect_) {
@ -249,7 +249,7 @@ void PaintAggregator::InvalidateRectInternal(const gfx::Rect& rect_old,
gfx::Rect rect = rect_old;
// Check if any rects that are ready to be painted overlap.
for (size_t i = 0; i < update_.ready_rects.size(); ++i) {
const gfx::Rect& existing_rect = update_.ready_rects[i].rect;
const gfx::Rect& existing_rect = update_.ready_rects[i].rect();
if (rect.Intersects(existing_rect)) {
// Re-invalidate in case the union intersects other paint rects.
rect.Union(existing_rect);

@ -249,7 +249,7 @@ void PaintManager::DoPaint() {
// previous image, but if we flush, it'll revert to using the blank image.
// We make an exception for the first paint since we want to show the
// default background color instead of the pepper default of black.
if (ready_rect.flush_now &&
if (ready_rect.flush_now() &&
(!view_size_changed_waiting_for_paint_ || first_paint_)) {
ready_now.push_back(ready_rect);
} else {
@ -267,8 +267,8 @@ void PaintManager::DoPaint() {
}
for (const auto& ready_rect : ready_now) {
graphics_.PaintImageData(ready_rect.image_data, pp::Point(),
PPRectFromRect(ready_rect.rect));
graphics_.PaintImageData(ready_rect.image_data(), pp::Point(),
PPRectFromRect(ready_rect.rect()));
}
Flush();

@ -13,13 +13,15 @@ namespace chrome_pdf {
PaintReadyRect::PaintReadyRect(const pp::Rect& rect,
const pp::ImageData& image_data,
bool flush_now)
: rect(RectFromPPRect(rect)),
image_data(image_data),
flush_now(flush_now) {}
: rect_(RectFromPPRect(rect)),
image_data_(image_data),
flush_now_(flush_now) {}
PaintReadyRect::PaintReadyRect(const PaintReadyRect& other) = default;
PaintReadyRect& PaintReadyRect::operator=(const PaintReadyRect& other) =
default;
PaintReadyRect::~PaintReadyRect() = default;
} // namespace chrome_pdf

@ -17,19 +17,28 @@ namespace chrome_pdf {
// Stores information about a rectangle that has finished painting. The
// `PaintManager` will paint it only when everything else on the screen is also
// ready.
struct PaintReadyRect {
class PaintReadyRect {
public:
PaintReadyRect(const pp::Rect& rect,
const pp::ImageData& image_data,
bool flush_now = false);
PaintReadyRect(const PaintReadyRect& other);
PaintReadyRect& operator=(const PaintReadyRect& other);
~PaintReadyRect();
gfx::Rect rect;
pp::ImageData image_data;
const gfx::Rect& rect() const { return rect_; }
void set_rect(const gfx::Rect& rect) { rect_ = rect; }
const pp::ImageData& image_data() const { return image_data_; }
// Whether to flush to screen immediately; otherwise, when the rest of the
// plugin viewport is ready.
bool flush_now;
bool flush_now() const { return flush_now_; }
private:
gfx::Rect rect_;
pp::ImageData image_data_;
bool flush_now_;
};
} // namespace chrome_pdf