0

Create pp::Graphics2D in PaintManager::Client

Instead of directly creating and binding pp::Graphics2D in PaintManager,
delegate these operations to PaintManager::Client. This provides several
benefits:

1. Allows the PaintManager::Client to return a different pp::Graphics2D
   implementation in the future. This will be useful especially once we
   replace pp::Graphics2D with a Pepper-free API.
2. Eliminates the need for PaintManager to interact with pp::Instance.

Bug: 1099020
Change-Id: I46ce18cfb3ced088afdf6581fc335aa56b8be195
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303989
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789565}
This commit is contained in:
K. Moon
2020-07-17 18:53:01 +00:00
committed by Commit Bot
parent 0d45310526
commit bc5c2c8b71
4 changed files with 29 additions and 18 deletions

@ -40,6 +40,7 @@
#include "ppapi/cpp/dev/memory_dev.h"
#include "ppapi/cpp/dev/text_input_dev.h"
#include "ppapi/cpp/dev/url_util_dev.h"
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/module.h"
@ -47,6 +48,7 @@
#include "ppapi/cpp/private/pdf.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/size.h"
#include "ppapi/cpp/url_request_info.h"
#include "ppapi/cpp/var_array.h"
#include "ppapi/cpp/var_array_buffer.h"
@ -446,7 +448,7 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
: pp::Instance(instance),
pp::Find_Private(this),
pp::Printing_Dev(this),
paint_manager_(this, this) {
paint_manager_(this) {
callback_factory_.Initialize(this);
pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
AddPerInstanceObject(kPPPPdfInterface, this);
@ -948,6 +950,14 @@ void OutOfProcessInstance::StopFind() {
SetTickmarks(tickmarks_);
}
pp::Graphics2D OutOfProcessInstance::CreatePaintGraphics(const pp::Size& size) {
return pp::Graphics2D(this, size, /*is_always_opaque=*/true);
}
bool OutOfProcessInstance::BindPaintGraphics(pp::Graphics2D& graphics) {
return BindGraphics(graphics);
}
void OutOfProcessInstance::OnPaint(const std::vector<pp::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<pp::Rect>* pending) {

@ -30,6 +30,8 @@
#include "third_party/skia/include/core/SkBitmap.h"
namespace pp {
class Graphics2D;
class Size;
class TextInput_Dev;
}
@ -60,6 +62,8 @@ class OutOfProcessInstance : public pp::Instance,
void StopFind() override;
// pp::PaintManager::Client implementation.
pp::Graphics2D CreatePaintGraphics(const pp::Size& size) override;
bool BindPaintGraphics(pp::Graphics2D& graphics) override;
void OnPaint(const std::vector<pp::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<pp::Rect>* pending) override;

@ -13,14 +13,11 @@
#include "base/check_op.h"
#include "pdf/paint_ready_rect.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
namespace chrome_pdf {
PaintManager::PaintManager(pp::Instance* instance, Client* client)
: instance_(instance), client_(client) {
DCHECK(instance_);
PaintManager::PaintManager(Client* client) : client_(client) {
DCHECK(client_);
// Set the callback object outside of the initializer list to avoid a
@ -184,8 +181,7 @@ void PaintManager::DoPaint() {
// we only resize by a small amount.
pp::Size new_size = GetNewContextSize(graphics_.size(), pending_size_);
if (graphics_.size() != new_size) {
graphics_ =
pp::Graphics2D(instance_, new_size, /*is_always_opaque=*/true);
graphics_ = client_->CreatePaintGraphics(new_size);
graphics_need_to_be_bound_ = true;
// Since we're binding a new one, all of the callbacks have been canceled.
@ -258,7 +254,7 @@ void PaintManager::DoPaint() {
first_paint_ = false;
if (graphics_need_to_be_bound_) {
instance_->BindGraphics(graphics_);
client_->BindPaintGraphics(graphics_);
graphics_need_to_be_bound_ = false;
}
}

@ -14,9 +14,9 @@
#include "ppapi/utility/completion_callback_factory.h"
namespace pp {
class Instance;
class Point;
class Rect;
class Size;
} // namespace pp
namespace chrome_pdf {
@ -32,6 +32,14 @@ class PaintManager {
public:
class Client {
public:
// Creates a new, unbound `pp::Graphics2D` for the paint manager, with the
// given |size| and always-opaque rendering.
virtual pp::Graphics2D CreatePaintGraphics(const pp::Size& size) = 0;
// Binds a `pp::Graphics2D` created by `CreatePaintGraphics()`, returning
// `true` if binding was successful.
virtual bool BindPaintGraphics(pp::Graphics2D& graphics) = 0;
// Paints the given invalid area of the plugin to the given graphics
// device. Returns true if anything was painted.
//
@ -56,20 +64,15 @@ class PaintManager {
protected:
// You shouldn't be doing deleting through this interface.
virtual ~Client() {}
~Client() = default;
};
// The instance is the plugin instance using this paint manager to do its
// painting. Painting will automatically go to this instance and you don't
// have to manually bind any device context (this is all handled by the
// paint manager).
//
// The Client is a non-owning pointer and must remain valid (normally the
// object implementing the Client interface will own the paint manager).
//
// You will need to call SetSize before this class will do anything. Normally
// you do this from the ViewChanged method of your plugin instance.
PaintManager(pp::Instance* instance, Client* client);
explicit PaintManager(Client* client);
PaintManager(const PaintManager&) = delete;
PaintManager& operator=(const PaintManager&) = delete;
~PaintManager();
@ -140,8 +143,6 @@ class PaintManager {
// pending.
void OnManualCallbackComplete(int32_t);
pp::Instance* const instance_;
// Non-owning pointer. See the constructor.
Client* const client_;