Commit 7722c8db authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Modernize chrome_pdf::PaintManager.

- Initialize variables in the header; make some const.
- Use = delete.
- Remove unused Initialize().
- Use more specific DCHECKs.

Change-Id: I1a9e2a35882193d7aae216ba09803bb3f8d620ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2154230
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760208}
parent 66e3178a
...@@ -29,24 +29,13 @@ PaintManager::PaintManager(pp::Instance* instance, ...@@ -29,24 +29,13 @@ PaintManager::PaintManager(pp::Instance* instance,
bool is_always_opaque) bool is_always_opaque)
: instance_(instance), : instance_(instance),
client_(client), client_(client),
is_always_opaque_(is_always_opaque), is_always_opaque_(is_always_opaque) {
callback_factory_(nullptr), DCHECK(instance_);
manual_callback_pending_(false), DCHECK(client_);
flush_pending_(false),
flush_requested_(false),
has_pending_resize_(false),
graphics_need_to_be_bound_(false),
pending_device_scale_(1.0),
device_scale_(1.0),
in_paint_(false),
first_paint_(true),
view_size_changed_waiting_for_paint_(false) {
// Set the callback object outside of the initializer list to avoid a // Set the callback object outside of the initializer list to avoid a
// compiler warning about using "this" in an initializer list. // compiler warning about using "this" in an initializer list.
callback_factory_.Initialize(this); callback_factory_.Initialize(this);
// You can not use a NULL client pointer.
DCHECK(client);
} }
PaintManager::~PaintManager() = default; PaintManager::~PaintManager() = default;
...@@ -86,19 +75,11 @@ pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size, ...@@ -86,19 +75,11 @@ pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size,
return result; return result;
} }
void PaintManager::Initialize(pp::Instance* instance,
Client* client,
bool is_always_opaque) {
DCHECK(!instance_ && !client_); // Can't initialize twice.
instance_ = instance;
client_ = client;
is_always_opaque_ = is_always_opaque;
}
void PaintManager::SetSize(const pp::Size& new_size, float device_scale) { void PaintManager::SetSize(const pp::Size& new_size, float device_scale) {
if (GetEffectiveSize() == new_size && if (GetEffectiveSize() == new_size &&
GetEffectiveDeviceScale() == device_scale) GetEffectiveDeviceScale() == device_scale) {
return; return;
}
has_pending_resize_ = true; has_pending_resize_ = true;
pending_size_ = new_size; pending_size_ = new_size;
...@@ -306,12 +287,12 @@ void PaintManager::Flush() { ...@@ -306,12 +287,12 @@ void PaintManager::Flush() {
// use one device, swap it with another, then swap it back, we won't know // use one device, swap it with another, then swap it back, we won't know
// that we've already scheduled a Flush on the first device. It's best to not // that we've already scheduled a Flush on the first device. It's best to not
// re-use devices in this way. // re-use devices in this way.
DCHECK(result != PP_ERROR_INPROGRESS); DCHECK_NE(PP_ERROR_INPROGRESS, result);
if (result == PP_OK_COMPLETIONPENDING) { if (result == PP_OK_COMPLETIONPENDING) {
flush_pending_ = true; flush_pending_ = true;
} else { } else {
DCHECK(result == PP_OK); // Catch all other errors in debug mode. DCHECK_EQ(PP_OK, result); // Catch all other errors in debug mode.
} }
} }
......
...@@ -50,6 +50,7 @@ class PaintManager { ...@@ -50,6 +50,7 @@ class PaintManager {
pp::ImageData image_data; pp::ImageData image_data;
bool flush_now; bool flush_now;
}; };
class Client { class Client {
public: public:
// Paints the given invalid area of the plugin to the given graphics // Paints the given invalid area of the plugin to the given graphics
...@@ -104,7 +105,8 @@ class PaintManager { ...@@ -104,7 +105,8 @@ class PaintManager {
// You will need to call SetSize before this class will do anything. Normally // You will need to call SetSize before this class will do anything. Normally
// you do this from the ViewChanged method of your plugin instance. // you do this from the ViewChanged method of your plugin instance.
PaintManager(pp::Instance* instance, Client* client, bool is_always_opaque); PaintManager(pp::Instance* instance, Client* client, bool is_always_opaque);
PaintManager(const PaintManager&) = delete;
PaintManager& operator=(const PaintManager&) = delete;
~PaintManager(); ~PaintManager();
// Returns the size of the graphics context to allocate for a given plugin // Returns the size of the graphics context to allocate for a given plugin
...@@ -114,12 +116,6 @@ class PaintManager { ...@@ -114,12 +116,6 @@ class PaintManager {
static pp::Size GetNewContextSize(const pp::Size& current_context_size, static pp::Size GetNewContextSize(const pp::Size& current_context_size,
const pp::Size& plugin_size); const pp::Size& plugin_size);
// You must call this function before using if you use the 0-arg constructor.
// See the constructor for what these arguments mean.
void Initialize(pp::Instance* instance,
Client* client,
bool is_always_opaque);
// Sets the size of the plugin. If the size is the same as the previous call, // Sets the size of the plugin. If the size is the same as the previous call,
// this will be a NOP. If the size has changed, a new device will be // this will be a NOP. If the size has changed, a new device will be
// allocated to the given size and a paint to that device will be scheduled. // allocated to the given size and a paint to that device will be scheduled.
...@@ -160,10 +156,6 @@ class PaintManager { ...@@ -160,10 +156,6 @@ class PaintManager {
void ClearTransform(); void ClearTransform();
private: private:
// Disallow copy and assign (these are unimplemented).
PaintManager(const PaintManager&);
PaintManager& operator=(const PaintManager&);
// Makes sure there is a callback that will trigger a paint at a later time. // Makes sure there is a callback that will trigger a paint at a later time.
// This will be either a Flush callback telling us we're allowed to generate // This will be either a Flush callback telling us we're allowed to generate
// more data, or, if there's no flush callback pending, a manual call back // more data, or, if there's no flush callback pending, a manual call back
...@@ -183,12 +175,12 @@ class PaintManager { ...@@ -183,12 +175,12 @@ class PaintManager {
// pending. // pending.
void OnManualCallbackComplete(int32_t); void OnManualCallbackComplete(int32_t);
pp::Instance* instance_; pp::Instance* const instance_;
// Non-owning pointer. See the constructor. // Non-owning pointer. See the constructor.
Client* client_; Client* const client_;
bool is_always_opaque_; const bool is_always_opaque_;
pp::CompletionCallbackFactory<PaintManager> callback_factory_; pp::CompletionCallbackFactory<PaintManager> callback_factory_;
...@@ -199,28 +191,28 @@ class PaintManager { ...@@ -199,28 +191,28 @@ class PaintManager {
PaintAggregator aggregator_; PaintAggregator aggregator_;
// See comment for EnsureCallbackPending for more on how these work. // See comment for EnsureCallbackPending for more on how these work.
bool manual_callback_pending_; bool manual_callback_pending_ = false;
bool flush_pending_; bool flush_pending_ = false;
bool flush_requested_; bool flush_requested_ = false;
// When we get a resize, we don't bind right away (see SetSize). The // When we get a resize, we don't bind right away (see SetSize). The
// has_pending_resize_ tells us that we need to do a resize for the next // has_pending_resize_ tells us that we need to do a resize for the next
// paint operation. When true, the new size is in pending_size_. // paint operation. When true, the new size is in pending_size_.
bool has_pending_resize_; bool has_pending_resize_ = false;
bool graphics_need_to_be_bound_; bool graphics_need_to_be_bound_ = false;
pp::Size pending_size_; pp::Size pending_size_;
pp::Size plugin_size_; pp::Size plugin_size_;
float pending_device_scale_; float pending_device_scale_ = 1.0f;
float device_scale_; float device_scale_ = 1.0f;
// True iff we're in the middle of a paint. // True iff we're in the middle of a paint.
bool in_paint_; bool in_paint_ = false;
// True if we haven't painted the plugin viewport yet. // True if we haven't painted the plugin viewport yet.
bool first_paint_; bool first_paint_ = true;
// True when the view size just changed and we're waiting for a paint. // True when the view size just changed and we're waiting for a paint.
bool view_size_changed_waiting_for_paint_; bool view_size_changed_waiting_for_paint_ = false;
}; };
#endif // PDF_PAINT_MANAGER_H_ #endif // PDF_PAINT_MANAGER_H_
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