Commit 8737b36a authored by Hui Yingst's avatar Hui Yingst Committed by Chromium LUCI CQ

Move 4 attributes from OutOfProcessInstance to PdfViewPluginBase.

In OutOfProcessInstance, the attributes `zoom_`, `device_scale_`,
`first_paint_` and `in_paint_` are used for drawing graphics, and they
will be used by PdfViewWebPlugin in the future. Therefore this CL moves
them into PdfViewPluginBase so that they can be shared between
PdfViewWebPlugin and OutOfProcessInstance, and adds accessors and
mutators for them.

Meanwhile, to avoid providing pointer access to `in_paint_`, this CL
moves the definition of OnPaint() into PdfViewPluginBase while keeping
the majority of its functionality wrapped in DoPaint(), which is
delegated to PdfViewPluginBase's derived classes.

Bug: 1140629
Change-Id: Ie2439d883836d5755ca4d86291ae9ccecc1b07a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601039Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839202}
parent 6be323c7
This diff is collapsed.
......@@ -159,9 +159,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
bool IsValidLink(const std::string& url) override;
std::unique_ptr<Graphics> CreatePaintGraphics(const gfx::Size& size) override;
bool BindPaintGraphics(Graphics& graphics) override;
void OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
void ScheduleTaskOnMainThread(
base::TimeDelta delay,
ResultCallback callback,
......@@ -187,6 +184,9 @@ class OutOfProcessInstance : public PdfViewPluginBase,
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) override;
void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) override;
void DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
private:
// Message handlers.
......@@ -378,8 +378,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
PINCH_END = 4
};
// Current zoom factor.
double zoom_ = 1.0;
// True if we request a new bitmap rendering.
bool needs_reraster_ = true;
// The scroll position for the last raster, before any transformations are
......@@ -387,17 +385,9 @@ class OutOfProcessInstance : public PdfViewPluginBase,
pp::FloatPoint scroll_offset_at_last_raster_;
// True if last bitmap was smaller than screen.
bool last_bitmap_smaller_ = false;
// Current device scale factor. Multiply by |device_scale_| to convert from
// viewport to screen coordinates. Divide by |device_scale_| to convert from
// screen to viewport coordinates.
float device_scale_ = 1.0f;
// True if the plugin is full-page.
bool full_ = false;
// True if we haven't painted the plugin viewport yet.
bool first_paint_ = true;
// Whether OnPaint() is in progress or not.
bool in_paint_ = false;
// Deferred invalidates while |in_paint_| is true.
std::vector<gfx::Rect> deferred_invalidates_;
......
......@@ -53,14 +53,14 @@ class PaintManager {
// Paints the given invalid area of the plugin to the given graphics
// device. Returns true if anything was painted.
//
// You are given the list of rects to paint in |paint_rects|. You can
// You are given the list of rects to paint in `paint_rects`. You can
// combine painting into less rectangles if it's more efficient. When a
// rect is painted, information about that paint should be inserted into
// |ready|. Otherwise if a paint needs more work, add the rect to
// |pending|. If |pending| is not empty, your OnPaint function will get
// `ready`. Otherwise if a paint needs more work, add the rect to
// `pending`. If `pending` is not empty, your OnPaint function will get
// called again. Once OnPaint is called and it returns no pending rects,
// all the previously ready rects will be flushed on screen. The exception
// is for ready rects that have |flush_now| set to true. These will be
// is for ready rects that have `flush_now` set to true. These will be
// flushed right away.
//
// Do not call Flush() on the graphics device, this will be done
......
......@@ -8,6 +8,7 @@
#include <string>
#include <utility>
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
......@@ -24,6 +25,13 @@ uint32_t PdfViewPluginBase::GetBackgroundColor() {
return background_color_;
}
void PdfViewPluginBase::OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) {
base::AutoReset<bool> auto_reset_in_paint(&in_paint_, true);
DoPaint(paint_rects, ready, pending);
}
void PdfViewPluginBase::InitializeEngine(
PDFiumFormFiller::ScriptOption script_option) {
engine_ = std::make_unique<PDFiumEngine>(this, script_option);
......
......@@ -32,6 +32,11 @@ class PdfViewPluginBase : public PDFEngine::Client,
// PDFEngine::Client:
uint32_t GetBackgroundColor() override;
// PaintManager::Client
void OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
protected:
PdfViewPluginBase();
~PdfViewPluginBase() override;
......@@ -65,6 +70,12 @@ class PdfViewPluginBase : public PDFEngine::Client,
virtual void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) = 0;
// Paints the given invalid area of the plugin to the given graphics device.
// PaintManager::Client::OnPaint() should be its only caller.
virtual void DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) = 0;
void SetBackgroundColor(uint32_t background_color) {
background_color_ = background_color;
}
......@@ -77,6 +88,17 @@ class PdfViewPluginBase : public PDFEngine::Client,
top_toolbar_height_in_viewport_coords_ = height;
}
double zoom() const { return zoom_; }
void set_zoom(double zoom) { zoom_ = zoom; }
float device_scale() const { return device_scale_; }
void set_device_scale(float device_scale) { device_scale_ = device_scale; }
bool first_paint() const { return first_paint_; }
void set_first_paint(bool first_paint) { first_paint_ = first_paint; }
bool in_paint() const { return in_paint_; }
private:
std::unique_ptr<PDFiumEngine> engine_;
PaintManager paint_manager_{this};
......@@ -87,6 +109,20 @@ class PdfViewPluginBase : public PDFEngine::Client,
// The blank space above the first page of the document reserved for the
// toolbar.
int top_toolbar_height_in_viewport_coords_ = 0;
// Current zoom factor.
double zoom_ = 1.0;
// Current device scale factor. Multiply by `device_scale_` to convert from
// viewport to screen coordinates. Divide by `device_scale_` to convert from
// screen to viewport coordinates.
float device_scale_ = 1.0f;
// True if we haven't painted the plugin viewport yet.
bool first_paint_ = true;
// Whether OnPaint() is in progress or not.
bool in_paint_ = false;
};
} // namespace chrome_pdf
......
......@@ -323,14 +323,6 @@ bool PdfViewWebPlugin::BindPaintGraphics(Graphics& graphics) {
return false;
}
// TODO(https://crbug.com/1099020): To be implemented as a Pepper-free version
// of `OutOfProcessInstance::OnPaint()`
void PdfViewWebPlugin::OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) {
NOTIMPLEMENTED_LOG_ONCE();
}
void PdfViewWebPlugin::ScheduleTaskOnMainThread(
base::TimeDelta delay,
ResultCallback callback,
......@@ -397,4 +389,12 @@ void PdfViewWebPlugin::DidOpenPreview(std::unique_ptr<UrlLoader> loader,
NOTIMPLEMENTED();
}
// TODO(https://crbug.com/1099020): To be implemented as a Pepper-free version
// of `OutOfProcessInstance::DoPaint()`
void PdfViewWebPlugin::DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) {
NOTIMPLEMENTED_LOG_ONCE();
}
} // namespace chrome_pdf
......@@ -105,9 +105,6 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
bool IsValidLink(const std::string& url) override;
std::unique_ptr<Graphics> CreatePaintGraphics(const gfx::Size& size) override;
bool BindPaintGraphics(Graphics& graphics) override;
void OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
void ScheduleTaskOnMainThread(
base::TimeDelta delay,
ResultCallback callback,
......@@ -130,6 +127,9 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) override;
void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) override;
void DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
private:
// Call `Destroy()` instead.
......
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