Skip to content

Commit

Permalink
Added SetLayerTransform to PPAPI.
Browse files Browse the repository at this point in the history
SetLayerTransform() sets a transformation factor that will be applied for the current
layer displayed on the output device.
This function has no effect until you call Flush().
@param[in] scale The scale to be applied.
@param[in] origin The origin of the scale.
@param[in] translate The translation to be applied.

@return Returns true on success or false if the resource is invalid or the scale factor is 0 or less.

BUG=605379
NOPRESUBMIT=true

Reason:
** Presubmit ERRORS **
TODOs found in stable public PPAPI files:
ppapi/cpp/graphics_2d.h

Review URL: https://codereview.chromium.org/1881603002

Cr-Commit-Position: refs/heads/master@{#388851}
  • Loading branch information
alessandroa authored and Commit bot committed Apr 21, 2016
1 parent f4b5752 commit d55efd0
Show file tree
Hide file tree
Showing 19 changed files with 286 additions and 16 deletions.
33 changes: 32 additions & 1 deletion content/renderer/pepper/pepper_graphics_2d_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ConvertImageData(PPB_ImageData_Impl* src_image,
} // namespace

struct PepperGraphics2DHost::QueuedOperation {
enum Type { PAINT, SCROLL, REPLACE, };
enum Type { PAINT, SCROLL, REPLACE, TRANSFORM };

QueuedOperation(Type t)
: type(t), paint_x(0), paint_y(0), scroll_dx(0), scroll_dy(0) {}
Expand All @@ -148,6 +148,10 @@ struct PepperGraphics2DHost::QueuedOperation {

// Valid when type == REPLACE.
scoped_refptr<PPB_ImageData_Impl> replace_image;

// Valid when type == TRANSFORM
float scale;
gfx::PointF translation;
};

// static
Expand Down Expand Up @@ -223,6 +227,8 @@ int32_t PepperGraphics2DHost::OnResourceMessageReceived(
OnHostMsgFlush)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetScale,
OnHostMsgSetScale)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetLayerTransform,
OnHostMsgSetLayerTransform)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReadImageData,
OnHostMsgReadImageData)
PPAPI_END_MESSAGE_MAP()
Expand Down Expand Up @@ -524,6 +530,21 @@ int32_t PepperGraphics2DHost::OnHostMsgSetScale(
return PP_ERROR_BADARGUMENT;
}

int32_t PepperGraphics2DHost::OnHostMsgSetLayerTransform(
ppapi::host::HostMessageContext* context,
float scale,
const PP_FloatPoint& translation) {
if (scale < 0.0f)
return PP_ERROR_BADARGUMENT;

QueuedOperation operation(QueuedOperation::TRANSFORM);
operation.scale = scale;
operation.translation = gfx::PointF(translation.x, translation.y);
queued_operations_.push_back(operation);
return PP_OK;
}


int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
ppapi::host::HostMessageContext* context,
PP_Resource image,
Expand Down Expand Up @@ -590,10 +611,15 @@ int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) {
bool done_replace_contents = false;
bool no_update_visible = true;
bool is_plugin_visible = true;

for (size_t i = 0; i < queued_operations_.size(); i++) {
QueuedOperation& operation = queued_operations_[i];
gfx::Rect op_rect;
switch (operation.type) {
case QueuedOperation::TRANSFORM:
ExecuteTransform(operation.scale, operation.translation);
no_update_visible = false;
break;
case QueuedOperation::PAINT:
ExecutePaintImageData(operation.paint_image.get(),
operation.paint_x,
Expand Down Expand Up @@ -679,6 +705,11 @@ int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) {
return PP_OK_COMPLETIONPENDING;
}

void PepperGraphics2DHost::ExecuteTransform(const float& scale,
const gfx::PointF& translate) {
bound_instance_->SetGraphics2DTransform(scale, translate);
}

void PepperGraphics2DHost::ExecutePaintImageData(PPB_ImageData_Impl* image,
int x,
int y,
Expand Down
6 changes: 6 additions & 0 deletions content/renderer/pepper/pepper_graphics_2d_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ppapi/host/resource_host.h"
#include "third_party/WebKit/public/platform/WebCanvas.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h"

namespace cc {
Expand Down Expand Up @@ -86,6 +87,7 @@ class CONTENT_EXPORT PepperGraphics2DHost

void SetScale(float scale);
float GetScale() const;
void SetLayerTransform(float scale, const PP_Point& transform);
bool IsAlwaysOpaque() const;
PPB_ImageData_Impl* ImageData();
gfx::Size Size() const;
Expand Down Expand Up @@ -116,6 +118,9 @@ class CONTENT_EXPORT PepperGraphics2DHost
int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgSetScale(ppapi::host::HostMessageContext* context,
float scale);
int32_t OnHostMsgSetLayerTransform(ppapi::host::HostMessageContext* context,
float Scale,
const PP_FloatPoint& Transform);
int32_t OnHostMsgReadImageData(ppapi::host::HostMessageContext* context,
PP_Resource image,
const PP_Point& top_left);
Expand All @@ -129,6 +134,7 @@ class CONTENT_EXPORT PepperGraphics2DHost
// rect argument will be filled by each function with the area affected by
// the update that requires invalidation. If there were no pixels changed,
// this rect can be untouched.
void ExecuteTransform(const float& scale, const gfx::PointF& translate);
void ExecutePaintImageData(PPB_ImageData_Impl* image,
int x,
int y,
Expand Down
32 changes: 28 additions & 4 deletions content/renderer/pepper/pepper_plugin_instance_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ PepperPluginInstanceImpl::PepperPluginInstanceImpl(
module_(module),
instance_interface_(instance_interface),
pp_instance_(0),
graphics2d_translation_(0, 0),
graphics2d_scale_(1.f),
container_(container),
layer_bound_to_fullscreen_(false),
layer_is_hardware_(false),
Expand Down Expand Up @@ -1544,6 +1546,15 @@ bool PepperPluginInstanceImpl::LoadTextInputInterface() {
return !!plugin_textinput_interface_;
}

void PepperPluginInstanceImpl::SetGraphics2DTransform(
const float& scale,
const gfx::PointF& translation) {
graphics2d_scale_ = scale;
graphics2d_translation_ = translation;

UpdateLayerTransform();
}

void PepperPluginInstanceImpl::UpdateLayerTransform() {
if (!bound_graphics_2d_platform_ || !texture_layer_) {
// Currently the transform is only applied for Graphics2D.
Expand All @@ -1563,11 +1574,24 @@ void PepperPluginInstanceImpl::UpdateLayerTransform() {
gfx::Size plugin_size_in_dip(view_data_.rect.size.width,
view_data_.rect.size.height);

// Adding the SetLayerTransform from Graphics2D to the UV.
// If graphics2d_scale_ is 1.f and graphics2d_translation_ is 0 then UV will
// be top_left (0,0) and lower_right (plugin_size_in_dip.width() /
// graphics_2d_size_in_dip.width(), plugin_size_in_dip.height() /
// graphics_2d_size_in_dip.height())
gfx::PointF top_left =
gfx::PointF(-graphics2d_translation_.x() / graphics2d_scale_,
-graphics2d_translation_.y() / graphics2d_scale_);
gfx::PointF lower_right =
gfx::PointF((1 / graphics2d_scale_) * plugin_size_in_dip.width() -
graphics2d_translation_.x() / graphics2d_scale_,
(1 / graphics2d_scale_) * plugin_size_in_dip.height() -
graphics2d_translation_.y() / graphics2d_scale_);
texture_layer_->SetUV(
gfx::PointF(0.0f, 0.0f),
gfx::PointF(
plugin_size_in_dip.width() / graphics_2d_size_in_dip.width(),
plugin_size_in_dip.height() / graphics_2d_size_in_dip.height()));
gfx::PointF(top_left.x() / graphics_2d_size_in_dip.width(),
top_left.y() / graphics_2d_size_in_dip.height()),
gfx::PointF(lower_right.x() / graphics_2d_size_in_dip.width(),
lower_right.y() / graphics_2d_size_in_dip.height()));
}

bool PepperPluginInstanceImpl::PluginHasFocus() const {
Expand Down
7 changes: 7 additions & 0 deletions content/renderer/pepper/pepper_plugin_instance_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ class CONTENT_EXPORT PepperPluginInstanceImpl

ContentDecryptorDelegate* GetContentDecryptorDelegate();

void SetGraphics2DTransform(const float& scale,
const gfx::PointF& translation);

// PluginInstance implementation
RenderView* GetRenderView() override;
blink::WebPluginContainer* GetContainer() override;
Expand Down Expand Up @@ -711,6 +714,10 @@ class CONTENT_EXPORT PepperPluginInstanceImpl

PP_Instance pp_instance_;

// These are the scale and the translation that will be applied to the layer.
gfx::PointF graphics2d_translation_;
float graphics2d_scale_;

// NULL until we have been initialized.
blink::WebPluginContainer* container_;
scoped_refptr<cc::Layer> compositor_layer_;
Expand Down
24 changes: 23 additions & 1 deletion ppapi/api/ppb_graphics_2d.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

label Chrome {
M14 = 1.0,
M27 = 1.1
M27 = 1.1,
M52 = 1.2
};

/**
Expand Down Expand Up @@ -282,5 +283,26 @@ interface PPB_Graphics2D {
float_t GetScale(
[in] PP_Resource resource);

/**
* SetLayerTransform() sets a transformation factor that will be applied for
* the current graphics context displayed on the output device. If both
* SetScale and SetLayerTransform will be used, they are going to get combined
* for the final result.
*
* This function has no effect until you call Flush().
*
* @param[in] scale The scale to be applied.
* @param[in] origin The origin of the scale.
* @param[in] translate The translation to be applied.
*
* @return Returns <code>PP_TRUE</code> on success or <code>PP_FALSE</code>
* if the resource is invalid or the scale factor is 0 or less.
*/
[version=1.2]
PP_Bool SetLayerTransform(
[in] PP_Resource resource,
[in] float_t scale,
[in] PP_Point origin,
[in] PP_Point translate);
};

4 changes: 2 additions & 2 deletions ppapi/c/pp_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* found in the LICENSE file.
*/

/* From pp_macros.idl modified Fri Jun 13 10:40:42 2014. */
/* From pp_macros.idl modified Mon Feb 1 13:37:12 2016. */

#ifndef PPAPI_C_PP_MACROS_H_
#define PPAPI_C_PP_MACROS_H_


#define PPAPI_RELEASE 48
#define PPAPI_RELEASE 52

/**
* @file
Expand Down
50 changes: 46 additions & 4 deletions ppapi/c/ppb_graphics_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* found in the LICENSE file.
*/

/* From ppb_graphics_2d.idl modified Fri Apr 26 08:49:08 2013. */
/* From ppb_graphics_2d.idl modified Wed Apr 20 13:37:06 2016. */

#ifndef PPAPI_C_PPB_GRAPHICS_2D_H_
#define PPAPI_C_PPB_GRAPHICS_2D_H_
Expand All @@ -20,7 +20,8 @@

#define PPB_GRAPHICS_2D_INTERFACE_1_0 "PPB_Graphics2D;1.0"
#define PPB_GRAPHICS_2D_INTERFACE_1_1 "PPB_Graphics2D;1.1"
#define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_1_1
#define PPB_GRAPHICS_2D_INTERFACE_1_2 "PPB_Graphics2D;1.2"
#define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_1_2

/**
* @file
Expand All @@ -36,7 +37,7 @@
/**
* <code>PPB_Graphics2D</code> defines the interface for a 2D graphics context.
*/
struct PPB_Graphics2D_1_1 {
struct PPB_Graphics2D_1_2 {
/**
* Create() creates a 2D graphics context. The returned graphics context will
* not be bound to the module instance on creation (call BindGraphics() on
Expand Down Expand Up @@ -276,9 +277,28 @@ struct PPB_Graphics2D_1_1 {
* is not a valid <code>Graphics2D</code> context, this will return 0.0.
*/
float (*GetScale)(PP_Resource resource);
/**
* SetLayerTransform() sets a transformation factor that will be applied for
* the current graphics context displayed on the output device. If both
* SetScale and SetLayerTransform will be used, they are going to get combined
* for the final result.
*
* This function has no effect until you call Flush().
*
* @param[in] scale The scale to be applied.
* @param[in] origin The origin of the scale.
* @param[in] translate The translation to be applied.
*
* @return Returns <code>PP_TRUE</code> on success or <code>PP_FALSE</code>
* if the resource is invalid or the scale factor is 0 or less.
*/
PP_Bool (*SetLayerTransform)(PP_Resource resource,
float scale,
const struct PP_Point* origin,
const struct PP_Point* translate);
};

typedef struct PPB_Graphics2D_1_1 PPB_Graphics2D;
typedef struct PPB_Graphics2D_1_2 PPB_Graphics2D;

struct PPB_Graphics2D_1_0 {
PP_Resource (*Create)(PP_Instance instance,
Expand All @@ -299,6 +319,28 @@ struct PPB_Graphics2D_1_0 {
int32_t (*Flush)(PP_Resource graphics_2d,
struct PP_CompletionCallback callback);
};

struct PPB_Graphics2D_1_1 {
PP_Resource (*Create)(PP_Instance instance,
const struct PP_Size* size,
PP_Bool is_always_opaque);
PP_Bool (*IsGraphics2D)(PP_Resource resource);
PP_Bool (*Describe)(PP_Resource graphics_2d,
struct PP_Size* size,
PP_Bool* is_always_opaque);
void (*PaintImageData)(PP_Resource graphics_2d,
PP_Resource image_data,
const struct PP_Point* top_left,
const struct PP_Rect* src_rect);
void (*Scroll)(PP_Resource graphics_2d,
const struct PP_Rect* clip_rect,
const struct PP_Point* amount);
void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data);
int32_t (*Flush)(PP_Resource graphics_2d,
struct PP_CompletionCallback callback);
PP_Bool (*SetScale)(PP_Resource resource, float scale);
float (*GetScale)(PP_Resource resource);
};
/**
* @}
*/
Expand Down
15 changes: 15 additions & 0 deletions ppapi/cpp/graphics_2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ template <> const char* interface_name<PPB_Graphics2D_1_1>() {
return PPB_GRAPHICS_2D_INTERFACE_1_1;
}

template <> const char* interface_name<PPB_Graphics2D_1_2>() {
return PPB_GRAPHICS_2D_INTERFACE_1_2;
}


} // namespace

Graphics2D::Graphics2D() : Resource() {
Expand Down Expand Up @@ -152,4 +157,14 @@ float Graphics2D::GetScale() {
return get_interface<PPB_Graphics2D_1_1>()->GetScale(pp_resource());
}

bool Graphics2D::SetLayerTransform(float scale,
const Point& origin,
const Point& translate) {
if (!has_interface<PPB_Graphics2D_1_2>())
return false;
return PP_ToBool(get_interface<PPB_Graphics2D_1_2>()->SetLayerTransform(
pp_resource(), scale, &origin.pp_point(), &translate.pp_point()));
}


} // namespace pp
3 changes: 3 additions & 0 deletions ppapi/cpp/graphics_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ class Graphics2D : public Resource {
/// is 1.0.
float GetScale();

bool SetLayerTransform(float scale,
const Point& origin,
const Point& translate);
private:
Size size_;
};
Expand Down
Loading

0 comments on commit d55efd0

Please sign in to comment.