Commit 22d9cbed authored by Hui Yingst's avatar Hui Yingst Committed by Chromium LUCI CQ

Migrate Invalidate(), InvalidateAfterPaintDone() to PdfViewPluginBase.

This CL migrates `deferred_invalidates_` to PdfViewPluginBase so that
Invalidate() and InvalidateAfterPaintDone() can be migrated as well,
which will allow these two methods to be shared by both
OutOfProcessInstance and PdfViewWebPlugin.

This CL also removed PdfViewPluginBase::in_paint() since all uses of
`in_paint_` are within the same class.

Bug: 1140629
Change-Id: I819687e402b3a0687b597194e2210c9282772c22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2639169
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846398}
parent ff2d1e99
...@@ -1235,7 +1235,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::Rect>& paint_rects, ...@@ -1235,7 +1235,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::Rect>& paint_rects,
engine()->PostPaint(); engine()->PostPaint();
if (!deferred_invalidates_.empty()) { if (!deferred_invalidates().empty()) {
ScheduleTaskOnMainThread( ScheduleTaskOnMainThread(
base::TimeDelta(), base::TimeDelta(),
base::BindOnce(&OutOfProcessInstance::InvalidateAfterPaintDone, base::BindOnce(&OutOfProcessInstance::InvalidateAfterPaintDone,
...@@ -1305,16 +1305,6 @@ void OutOfProcessInstance::ProposeDocumentLayout(const DocumentLayout& layout) { ...@@ -1305,16 +1305,6 @@ void OutOfProcessInstance::ProposeDocumentLayout(const DocumentLayout& layout) {
LoadAccessibility(); LoadAccessibility();
} }
void OutOfProcessInstance::Invalidate(const gfx::Rect& rect) {
if (in_paint()) {
deferred_invalidates_.push_back(rect);
return;
}
gfx::Rect offset_rect = rect + available_area().OffsetFromOrigin();
paint_manager().InvalidateRect(offset_rect);
}
void OutOfProcessInstance::DidScroll(const gfx::Vector2d& offset) { void OutOfProcessInstance::DidScroll(const gfx::Vector2d& offset) {
if (!image_data_.is_null()) if (!image_data_.is_null())
paint_manager().ScrollRect(available_area(), offset); paint_manager().ScrollRect(available_area(), offset);
...@@ -2549,14 +2539,6 @@ void OutOfProcessInstance::OnPrint(int32_t /*unused_but_required*/) { ...@@ -2549,14 +2539,6 @@ void OutOfProcessInstance::OnPrint(int32_t /*unused_but_required*/) {
pp::PDF::Print(this); pp::PDF::Print(this);
} }
void OutOfProcessInstance::InvalidateAfterPaintDone(
int32_t /*unused_but_required*/) {
DCHECK(!in_paint());
for (const gfx::Rect& rect : deferred_invalidates_)
Invalidate(rect);
deferred_invalidates_.clear();
}
void OutOfProcessInstance::PrintSettings::Clear() { void OutOfProcessInstance::PrintSettings::Clear() {
is_printing = false; is_printing = false;
print_pages_called = false; print_pages_called = false;
......
...@@ -105,7 +105,6 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -105,7 +105,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// PdfViewPluginBase: // PdfViewPluginBase:
void ProposeDocumentLayout(const DocumentLayout& layout) override; void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const gfx::Rect& rect) override;
void DidScroll(const gfx::Vector2d& offset) override; void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override; void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override; void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
...@@ -331,9 +330,6 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -331,9 +330,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// Callback to print without re-entrancy issues. // Callback to print without re-entrancy issues.
void OnPrint(int32_t /*unused_but_required*/); void OnPrint(int32_t /*unused_but_required*/);
// Callback to do invalidation after painting finishes.
void InvalidateAfterPaintDone(int32_t /*unused_but_required*/);
// Helper for HandleInputEvent(). Returns whether engine() handled the event // Helper for HandleInputEvent(). Returns whether engine() handled the event
// or not. // or not.
bool SendInputEventToEngine(const pp::InputEvent& event); bool SendInputEventToEngine(const pp::InputEvent& event);
...@@ -368,9 +364,6 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -368,9 +364,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// True if the plugin is full-page. // True if the plugin is full-page.
bool full_ = false; bool full_ = false;
// Deferred invalidates while |in_paint_| is true.
std::vector<gfx::Rect> deferred_invalidates_;
struct PrintSettings { struct PrintSettings {
PrintSettings() { Clear(); } PrintSettings() { Clear(); }
......
...@@ -27,6 +27,16 @@ PdfViewPluginBase::PdfViewPluginBase() = default; ...@@ -27,6 +27,16 @@ PdfViewPluginBase::PdfViewPluginBase() = default;
PdfViewPluginBase::~PdfViewPluginBase() = default; PdfViewPluginBase::~PdfViewPluginBase() = default;
void PdfViewPluginBase::Invalidate(const gfx::Rect& rect) {
if (in_paint_) {
deferred_invalidates_.push_back(rect);
return;
}
gfx::Rect offset_rect = rect + available_area_.OffsetFromOrigin();
paint_manager_.InvalidateRect(offset_rect);
}
uint32_t PdfViewPluginBase::GetBackgroundColor() { uint32_t PdfViewPluginBase::GetBackgroundColor() {
return background_color_; return background_color_;
} }
...@@ -62,6 +72,14 @@ void PdfViewPluginBase::LoadUrl(const std::string& url, bool is_print_preview) { ...@@ -62,6 +72,14 @@ void PdfViewPluginBase::LoadUrl(const std::string& url, bool is_print_preview) {
GetWeakPtr(), std::move(loader))); GetWeakPtr(), std::move(loader)));
} }
void PdfViewPluginBase::InvalidateAfterPaintDone(
int32_t /*unused_but_required*/) {
DCHECK(!in_paint_);
for (const gfx::Rect& rect : deferred_invalidates_)
Invalidate(rect);
deferred_invalidates_.clear();
}
void PdfViewPluginBase::RecalculateAreas(double old_zoom, void PdfViewPluginBase::RecalculateAreas(double old_zoom,
float old_device_scale) { float old_device_scale) {
if (zoom_ != old_zoom || device_scale_ != old_device_scale) if (zoom_ != old_zoom || device_scale_ != old_device_scale)
...@@ -90,7 +108,7 @@ void PdfViewPluginBase::RecalculateAreas(double old_zoom, ...@@ -90,7 +108,7 @@ void PdfViewPluginBase::RecalculateAreas(double old_zoom,
if (document_size_.IsEmpty()) if (document_size_.IsEmpty())
return; return;
paint_manager().InvalidateRect(gfx::Rect(plugin_size_)); paint_manager_.InvalidateRect(gfx::Rect(plugin_size_));
} }
void PdfViewPluginBase::CalculateBackgroundParts() { void PdfViewPluginBase::CalculateBackgroundParts() {
......
...@@ -5,15 +5,15 @@ ...@@ -5,15 +5,15 @@
#ifndef PDF_PDF_VIEW_PLUGIN_BASE_H_ #ifndef PDF_PDF_VIEW_PLUGIN_BASE_H_
#define PDF_PDF_VIEW_PLUGIN_BASE_H_ #define PDF_PDF_VIEW_PLUGIN_BASE_H_
#include "pdf/pdf_engine.h"
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector>
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "pdf/paint_manager.h" #include "pdf/paint_manager.h"
#include "pdf/pdf_engine.h"
#include "pdf/pdfium/pdfium_form_filler.h" #include "pdf/pdfium/pdfium_form_filler.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -31,6 +31,7 @@ class PdfViewPluginBase : public PDFEngine::Client, ...@@ -31,6 +31,7 @@ class PdfViewPluginBase : public PDFEngine::Client,
PdfViewPluginBase& operator=(const PdfViewPluginBase& other) = delete; PdfViewPluginBase& operator=(const PdfViewPluginBase& other) = delete;
// PDFEngine::Client: // PDFEngine::Client:
void Invalidate(const gfx::Rect& rect) override;
uint32_t GetBackgroundColor() override; uint32_t GetBackgroundColor() override;
// PaintManager::Client // PaintManager::Client
...@@ -85,6 +86,9 @@ class PdfViewPluginBase : public PDFEngine::Client, ...@@ -85,6 +86,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
std::vector<PaintReadyRect>* ready, std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) = 0; std::vector<gfx::Rect>* pending) = 0;
// Callback to do invalidation after painting finishes.
void InvalidateAfterPaintDone(int32_t /*unused_but_required*/);
// Updates the available area and the background parts, notifies the PDF // Updates the available area and the background parts, notifies the PDF
// engine, and updates the accessibility information. // engine, and updates the accessibility information.
virtual void OnGeometryChanged(double old_zoom, float old_device_scale) = 0; virtual void OnGeometryChanged(double old_zoom, float old_device_scale) = 0;
...@@ -106,6 +110,10 @@ class PdfViewPluginBase : public PDFEngine::Client, ...@@ -106,6 +110,10 @@ class PdfViewPluginBase : public PDFEngine::Client,
return background_parts_; return background_parts_;
} }
const std::vector<gfx::Rect>& deferred_invalidates() const {
return deferred_invalidates_;
}
const gfx::Rect& available_area() const { return available_area_; } const gfx::Rect& available_area() const { return available_area_; }
const gfx::Size& document_size() const { return document_size_; } const gfx::Size& document_size() const { return document_size_; }
...@@ -143,14 +151,15 @@ class PdfViewPluginBase : public PDFEngine::Client, ...@@ -143,14 +151,15 @@ class PdfViewPluginBase : public PDFEngine::Client,
bool first_paint() const { return first_paint_; } bool first_paint() const { return first_paint_; }
void set_first_paint(bool first_paint) { first_paint_ = first_paint; } void set_first_paint(bool first_paint) { first_paint_ = first_paint; }
bool in_paint() const { return in_paint_; }
private: private:
std::unique_ptr<PDFiumEngine> engine_; std::unique_ptr<PDFiumEngine> engine_;
PaintManager paint_manager_{this}; PaintManager paint_manager_{this};
std::vector<BackgroundPart> background_parts_; std::vector<BackgroundPart> background_parts_;
// Deferred invalidates while |in_paint_| is true.
std::vector<gfx::Rect> deferred_invalidates_;
// Remaining area, in pixels, to render the pdf in after accounting for // Remaining area, in pixels, to render the pdf in after accounting for
// horizontal centering. // horizontal centering.
gfx::Rect available_area_; gfx::Rect available_area_;
......
...@@ -181,8 +181,6 @@ void PdfViewWebPlugin::DidFailLoading(const blink::WebURLError& error) {} ...@@ -181,8 +181,6 @@ void PdfViewWebPlugin::DidFailLoading(const blink::WebURLError& error) {}
void PdfViewWebPlugin::ProposeDocumentLayout(const DocumentLayout& layout) {} void PdfViewWebPlugin::ProposeDocumentLayout(const DocumentLayout& layout) {}
void PdfViewWebPlugin::Invalidate(const gfx::Rect& rect) {}
void PdfViewWebPlugin::DidScroll(const gfx::Vector2d& offset) {} void PdfViewWebPlugin::DidScroll(const gfx::Vector2d& offset) {}
void PdfViewWebPlugin::ScrollToX(int x_in_screen_coords) {} void PdfViewWebPlugin::ScrollToX(int x_in_screen_coords) {}
......
...@@ -49,7 +49,6 @@ class PdfViewWebPlugin final : public PdfViewPluginBase, ...@@ -49,7 +49,6 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// PdfViewPluginBase: // PdfViewPluginBase:
void ProposeDocumentLayout(const DocumentLayout& layout) override; void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const gfx::Rect& rect) override;
void DidScroll(const gfx::Vector2d& offset) override; void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override; void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override; void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
......
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