diff options
author | jhorwich@chromium.org <jhorwich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-09 15:39:22 +0000 |
---|---|---|
committer | jhorwich@chromium.org <jhorwich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-09 15:39:22 +0000 |
commit | f381e90d6f112bc395d7cf743cfa199737041541 (patch) | |
tree | 42507ef60f9021cee0f13971acdb54829434715c /ppapi | |
parent | e20b88d661f2468003a38cbdaebb0ea3ef63474d (diff) | |
download | chromium_src-f381e90d6f112bc395d7cf743cfa199737041541.zip chromium_src-f381e90d6f112bc395d7cf743cfa199737041541.tar.gz chromium_src-f381e90d6f112bc395d7cf743cfa199737041541.tar.bz2 |
Move HiDPI-related Pepper interfaces to stable
This adds the APIs provided in PPB_View_Dev_0_1 and PP_Graphics2D_Dev_0_1 to
the public Pepper APIs for PPB_View and PPB_Graphics2D.
Includes:
- Change to IDL and generated C headers/shim
- Change to PPAPI to export the 1_1 interfaces
- C++ glue
- Example PPAPI plugin for using HiDPI Pepper APIs
BUG=144071
TEST=Existing (prebuilt) PDF plugin using 1.0 interfaces still works
Review URL: https://codereview.chromium.org/12989006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/api/ppb_graphics_2d.idl | 39 | ||||
-rw-r--r-- | ppapi/api/ppb_view.idl | 36 | ||||
-rw-r--r-- | ppapi/c/ppb_graphics_2d.h | 57 | ||||
-rw-r--r-- | ppapi/c/ppb_view.h | 47 | ||||
-rw-r--r-- | ppapi/cpp/graphics_2d.cc | 104 | ||||
-rw-r--r-- | ppapi/cpp/graphics_2d.h | 28 | ||||
-rw-r--r-- | ppapi/cpp/view.cc | 71 | ||||
-rw-r--r-- | ppapi/cpp/view.h | 20 | ||||
-rw-r--r-- | ppapi/examples/scaling/scaling.cc | 232 | ||||
-rw-r--r-- | ppapi/examples/scaling/scaling.html | 44 | ||||
-rw-r--r-- | ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c | 90 | ||||
-rw-r--r-- | ppapi/ppapi_tests.gypi | 10 | ||||
-rw-r--r-- | ppapi/tests/test_graphics_2d.cc | 39 | ||||
-rw-r--r-- | ppapi/tests/test_graphics_2d.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/interfaces_ppb_public_stable.h | 2 | ||||
-rw-r--r-- | ppapi/thunk/ppb_graphics_2d_thunk.cc | 20 | ||||
-rw-r--r-- | ppapi/thunk/ppb_view_thunk.cc | 29 |
17 files changed, 809 insertions, 60 deletions
diff --git a/ppapi/api/ppb_graphics_2d.idl b/ppapi/api/ppb_graphics_2d.idl index 1dddc65..f9b420d 100644 --- a/ppapi/api/ppb_graphics_2d.idl +++ b/ppapi/api/ppb_graphics_2d.idl @@ -9,7 +9,8 @@ */ label Chrome { - M14 = 1.0 + M14 = 1.0, + M27 = 1.1 }; /** @@ -242,5 +243,41 @@ interface PPB_Graphics2D { int32_t Flush( [in] PP_Resource graphics_2d, [in] PP_CompletionCallback callback); + + /** + * SetScale() sets the scale factor that will be applied when painting the + * graphics context onto the output device. Typically, if rendering at device + * resolution is desired, the context would be created with the width and + * height scaled up by the view's GetDeviceScale and SetScale called with a + * scale of 1.0 / GetDeviceScale(). For example, if the view resource passed + * to DidChangeView has a rectangle of (w=200, h=100) and a device scale of + * 2.0, one would call Create with a size of (w=400, h=200) and then call + * SetScale with 0.5. One would then treat each pixel in the context as a + * single device pixel. + * + * @param[in] resource A <code>Graphics2D</code> context resource. + * @param[in] scale The scale to apply when painting. + * + * @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.1] + PP_Bool SetScale( + [in] PP_Resource resource, + [in] float_t scale); + + /*** + * GetScale() gets the scale factor that will be applied when painting the + * graphics context onto the output device. + * + * @param[in] resource A <code>Graphics2D</code> context resource. + * + * @return Returns the scale factor for the graphics context. If the resource + * is not a valid <code>Graphics2D</code> context, this will return 0.0. + */ + [version=1.1] + float_t GetScale( + [in] PP_Resource resource); + }; diff --git a/ppapi/api/ppb_view.idl b/ppapi/api/ppb_view.idl index cc61ed2..a01c5e8 100644 --- a/ppapi/api/ppb_view.idl +++ b/ppapi/api/ppb_view.idl @@ -11,7 +11,8 @@ [generate_thunk] label Chrome { - M18 = 1.0 + M18 = 1.0, + M28 = 1.1 }; /** @@ -159,5 +160,38 @@ interface PPB_View { */ PP_Bool GetClipRect([in] PP_Resource resource, [out] PP_Rect clip); + + /** + * GetDeviceScale returns the scale factor between device pixels and Density + * Independent Pixels (DIPs, also known as logical pixels or UI pixels on + * some platforms). This allows the developer to render their contents at + * device resolution, even as coordinates / sizes are given in DIPs through + * the API. + * + * Note that the coordinate system for Pepper APIs is DIPs. Also note that + * one DIP might not equal one CSS pixel - when page scale/zoom is in effect. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a + * <code>PPB_View</code> resource. + * + * @return A <code>float</code> value representing the number of device pixels + * per DIP. If the resource is invalid, the value will be 0.0. + */ + [version=1.1] + float_t GetDeviceScale([in] PP_Resource resource); + + /** + * GetCSSScale returns the scale factor between DIPs and CSS pixels. This + * allows proper scaling between DIPs - as sent via the Pepper API - and CSS + * pixel coordinates used for Web content. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a + * <code>PPB_View</code> resource. + * + * @return css_scale A <code>float</code> value representing the number of + * DIPs per CSS pixel. If the resource is invalid, the value will be 0.0. + */ + [version=1.1] + float_t GetCSSScale([in] PP_Resource resource); }; diff --git a/ppapi/c/ppb_graphics_2d.h b/ppapi/c/ppb_graphics_2d.h index 4c41e5a..fc15f14 100644 --- a/ppapi/c/ppb_graphics_2d.h +++ b/ppapi/c/ppb_graphics_2d.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From ppb_graphics_2d.idl modified Thu Mar 28 10:10:42 2013. */ +/* From ppb_graphics_2d.idl modified Sun Mar 31 14:34:56 2013. */ #ifndef PPAPI_C_PPB_GRAPHICS_2D_H_ #define PPAPI_C_PPB_GRAPHICS_2D_H_ @@ -19,7 +19,8 @@ #include "ppapi/c/pp_stdint.h" #define PPB_GRAPHICS_2D_INTERFACE_1_0 "PPB_Graphics2D;1.0" -#define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_1_0 +#define PPB_GRAPHICS_2D_INTERFACE_1_1 "PPB_Graphics2D;1.1" +#define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_1_1 /** * @file @@ -35,7 +36,7 @@ /** * <code>PPB_Graphics2D</code> defines the interface for a 2D graphics context. */ -struct PPB_Graphics2D_1_0 { +struct PPB_Graphics2D_1_1 { /** * Create() creates a 2D graphics context. The returned graphics context will * not be bound to the module instance on creation (call BindGraphics() on @@ -247,9 +248,57 @@ struct PPB_Graphics2D_1_0 { */ int32_t (*Flush)(PP_Resource graphics_2d, struct PP_CompletionCallback callback); + /** + * SetScale() sets the scale factor that will be applied when painting the + * graphics context onto the output device. Typically, if rendering at device + * resolution is desired, the context would be created with the width and + * height scaled up by the view's GetDeviceScale and SetScale called with a + * scale of 1.0 / GetDeviceScale(). For example, if the view resource passed + * to DidChangeView has a rectangle of (w=200, h=100) and a device scale of + * 2.0, one would call Create with a size of (w=400, h=200) and then call + * SetScale with 0.5. One would then treat each pixel in the context as a + * single device pixel. + * + * @param[in] resource A <code>Graphics2D</code> context resource. + * @param[in] scale The scale to apply when painting. + * + * @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 (*SetScale)(PP_Resource resource, float scale); + /*** + * GetScale() gets the scale factor that will be applied when painting the + * graphics context onto the output device. + * + * @param[in] resource A <code>Graphics2D</code> context resource. + * + * @return Returns the scale factor for the graphics context. If the resource + * is not a valid <code>Graphics2D</code> context, this will return 0.0. + */ + float (*GetScale)(PP_Resource resource); }; -typedef struct PPB_Graphics2D_1_0 PPB_Graphics2D; +typedef struct PPB_Graphics2D_1_1 PPB_Graphics2D; + +struct PPB_Graphics2D_1_0 { + 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_opqaue); + 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); +}; /** * @} */ diff --git a/ppapi/c/ppb_view.h b/ppapi/c/ppb_view.h index a2a92ac..8b82c78 100644 --- a/ppapi/c/ppb_view.h +++ b/ppapi/c/ppb_view.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From ppb_view.idl modified Fri Feb 17 09:09:15 2012. */ +/* From ppb_view.idl modified Fri Mar 29 11:55:32 2013. */ #ifndef PPAPI_C_PPB_VIEW_H_ #define PPAPI_C_PPB_VIEW_H_ @@ -17,7 +17,8 @@ #include "ppapi/c/pp_stdint.h" #define PPB_VIEW_INTERFACE_1_0 "PPB_View;1.0" -#define PPB_VIEW_INTERFACE PPB_VIEW_INTERFACE_1_0 +#define PPB_VIEW_INTERFACE_1_1 "PPB_View;1.1" +#define PPB_VIEW_INTERFACE PPB_VIEW_INTERFACE_1_1 /** * @file @@ -35,7 +36,7 @@ * You will receive new view information using * <code>PPP_Instance.DidChangeView</code>. */ -struct PPB_View_1_0 { +struct PPB_View_1_1 { /** * IsView() determines if the given resource is a valid * <code>PPB_View</code> resource. Note that <code>PPB_ViewChanged</code> @@ -167,9 +168,47 @@ struct PPB_View_1_0 { * clip rect was filled in, <code>PP_FALSE</code> if not. */ PP_Bool (*GetClipRect)(PP_Resource resource, struct PP_Rect* clip); + /** + * GetDeviceScale returns the scale factor between device pixels and Density + * Independent Pixels (DIPs, also known as logical pixels or UI pixels on + * some platforms). This allows the developer to render their contents at + * device resolution, even as coordinates / sizes are given in DIPs through + * the API. + * + * Note that the coordinate system for Pepper APIs is DIPs. Also note that + * one DIP might not equal one CSS pixel - when page scale/zoom is in effect. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a + * <code>PPB_View</code> resource. + * + * @return A <code>float</code> value representing the number of device pixels + * per DIP. If the resource is invalid, the value will be 0.0. + */ + float (*GetDeviceScale)(PP_Resource resource); + /** + * GetCSSScale returns the scale factor between DIPs and CSS pixels. This + * allows proper scaling between DIPs - as sent via the Pepper API - and CSS + * pixel coordinates used for Web content. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a + * <code>PPB_View</code> resource. + * + * @return css_scale A <code>float</code> value representing the number of + * DIPs per CSS pixel. If the resource is invalid, the value will be 0.0. + */ + float (*GetCSSScale)(PP_Resource resource); }; -typedef struct PPB_View_1_0 PPB_View; +typedef struct PPB_View_1_1 PPB_View; + +struct PPB_View_1_0 { + PP_Bool (*IsView)(PP_Resource resource); + PP_Bool (*GetRect)(PP_Resource resource, struct PP_Rect* rect); + PP_Bool (*IsFullscreen)(PP_Resource resource); + PP_Bool (*IsVisible)(PP_Resource resource); + PP_Bool (*IsPageVisible)(PP_Resource resource); + PP_Bool (*GetClipRect)(PP_Resource resource, struct PP_Rect* clip); +}; /** * @} */ diff --git a/ppapi/cpp/graphics_2d.cc b/ppapi/cpp/graphics_2d.cc index f4cd645..3a766c8 100644 --- a/ppapi/cpp/graphics_2d.cc +++ b/ppapi/cpp/graphics_2d.cc @@ -22,6 +22,10 @@ template <> const char* interface_name<PPB_Graphics2D_1_0>() { return PPB_GRAPHICS_2D_INTERFACE_1_0; } +template <> const char* interface_name<PPB_Graphics2D_1_1>() { + return PPB_GRAPHICS_2D_INTERFACE_1_1; +} + } // namespace Graphics2D::Graphics2D() : Resource() { @@ -36,12 +40,19 @@ Graphics2D::Graphics2D(const InstanceHandle& instance, const Size& size, bool is_always_opaque) : Resource() { - if (!has_interface<PPB_Graphics2D_1_0>()) + if (has_interface<PPB_Graphics2D_1_1>()) { + PassRefFromConstructor(get_interface<PPB_Graphics2D_1_1>()->Create( + instance.pp_instance(), + &size.pp_size(), + PP_FromBool(is_always_opaque))); + } else if (has_interface<PPB_Graphics2D_1_0>()) { + PassRefFromConstructor(get_interface<PPB_Graphics2D_1_0>()->Create( + instance.pp_instance(), + &size.pp_size(), + PP_FromBool(is_always_opaque))); + } else { return; - PassRefFromConstructor(get_interface<PPB_Graphics2D_1_0>()->Create( - instance.pp_instance(), - &size.pp_size(), - PP_FromBool(is_always_opaque))); + } if (!is_null()) { // Only save the size if allocation succeeded. size_ = size; @@ -59,38 +70,57 @@ Graphics2D& Graphics2D::operator=(const Graphics2D& other) { void Graphics2D::PaintImageData(const ImageData& image, const Point& top_left) { - if (!has_interface<PPB_Graphics2D_1_0>()) - return; - get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(), - image.pp_resource(), - &top_left.pp_point(), - NULL); + if (has_interface<PPB_Graphics2D_1_1>()) { + get_interface<PPB_Graphics2D_1_1>()->PaintImageData(pp_resource(), + image.pp_resource(), + &top_left.pp_point(), + NULL); + } else if (has_interface<PPB_Graphics2D_1_0>()) { + get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(), + image.pp_resource(), + &top_left.pp_point(), + NULL); + } } void Graphics2D::PaintImageData(const ImageData& image, const Point& top_left, const Rect& src_rect) { - if (!has_interface<PPB_Graphics2D_1_0>()) - return; - get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(), - image.pp_resource(), - &top_left.pp_point(), - &src_rect.pp_rect()); + if (has_interface<PPB_Graphics2D_1_1>()) { + get_interface<PPB_Graphics2D_1_1>()->PaintImageData(pp_resource(), + image.pp_resource(), + &top_left.pp_point(), + &src_rect.pp_rect()); + } else if (has_interface<PPB_Graphics2D_1_0>()) { + get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(), + image.pp_resource(), + &top_left.pp_point(), + &src_rect.pp_rect()); + } } void Graphics2D::Scroll(const Rect& clip, const Point& amount) { - if (!has_interface<PPB_Graphics2D_1_0>()) - return; - get_interface<PPB_Graphics2D_1_0>()->Scroll(pp_resource(), - &clip.pp_rect(), - &amount.pp_point()); + if (has_interface<PPB_Graphics2D_1_1>()) { + get_interface<PPB_Graphics2D_1_1>()->Scroll(pp_resource(), + &clip.pp_rect(), + &amount.pp_point()); + } else if (has_interface<PPB_Graphics2D_1_0>()) { + get_interface<PPB_Graphics2D_1_0>()->Scroll(pp_resource(), + &clip.pp_rect(), + &amount.pp_point()); + } } void Graphics2D::ReplaceContents(ImageData* image) { - if (!has_interface<PPB_Graphics2D_1_0>()) + if (has_interface<PPB_Graphics2D_1_1>()) { + get_interface<PPB_Graphics2D_1_1>()->ReplaceContents(pp_resource(), + image->pp_resource()); + } else if (has_interface<PPB_Graphics2D_1_0>()) { + get_interface<PPB_Graphics2D_1_0>()->ReplaceContents(pp_resource(), + image->pp_resource()); + } else { return; - get_interface<PPB_Graphics2D_1_0>()->ReplaceContents(pp_resource(), - image->pp_resource()); + } // On success, reset the image data. This is to help prevent people // from continuing to use the resource which will result in artifacts. @@ -98,10 +128,28 @@ void Graphics2D::ReplaceContents(ImageData* image) { } int32_t Graphics2D::Flush(const CompletionCallback& cc) { - if (!has_interface<PPB_Graphics2D_1_0>()) + if (has_interface<PPB_Graphics2D_1_1>()) { + return get_interface<PPB_Graphics2D_1_1>()->Flush( + pp_resource(), cc.pp_completion_callback()); + } else if (has_interface<PPB_Graphics2D_1_0>()) { + return get_interface<PPB_Graphics2D_1_0>()->Flush( + pp_resource(), cc.pp_completion_callback()); + } else { return cc.MayForce(PP_ERROR_NOINTERFACE); - return get_interface<PPB_Graphics2D_1_0>()->Flush( - pp_resource(), cc.pp_completion_callback()); + } +} + +bool Graphics2D::SetScale(float scale) { + if (!has_interface<PPB_Graphics2D_1_1>()) + return false; + return PP_ToBool(get_interface<PPB_Graphics2D_1_1>()->SetScale(pp_resource(), + scale)); +} + +float Graphics2D::GetScale() { + if (!has_interface<PPB_Graphics2D_1_1>()) + return 1.0f; + return get_interface<PPB_Graphics2D_1_1>()->GetScale(pp_resource()); } } // namespace pp diff --git a/ppapi/cpp/graphics_2d.h b/ppapi/cpp/graphics_2d.h index 427ea48..c6a2390 100644 --- a/ppapi/cpp/graphics_2d.h +++ b/ppapi/cpp/graphics_2d.h @@ -41,7 +41,7 @@ class Graphics2D : public Resource { /// associated. /// /// @param[in] size The size of the 2D graphics context in the browser, - /// measured in device pixels. + /// measured in pixels. See <code>SetScale()</code> for more information. /// /// @param[in] is_always_opaque Set the <code>is_always_opaque</code> flag /// to true if you know that you will be painting only opaque data to this @@ -74,7 +74,7 @@ class Graphics2D : public Resource { /// Getter function for returning size of the 2D graphics context. /// - /// @return The size of the 2D graphics context measured in device pixels. + /// @return The size of the 2D graphics context measured in pixels. const Size& size() const { return size_; } /// PaintImageData() enqueues a paint command of the given image into @@ -260,6 +260,30 @@ class Graphics2D : public Resource { // for it. int32_t Flush(const CompletionCallback& cc); + /// SetScale() sets the scale factor that will be applied when painting the + /// graphics context onto the output device. Typically, if rendering at device + /// resolution is desired, the context would be created with the width and + /// height scaled up by the view's GetDeviceScale and SetScale called with a + /// scale of 1.0 / GetDeviceScale(). For example, if the view resource passed + /// to DidChangeView has a rectangle of (w=200, h=100) and a device scale of + /// 2.0, one would call Create with a size of (w=400, h=200) and then call + /// SetScale with 0.5. One would then treat each pixel in the context as a + /// single device pixel. + /// + /// @param[in] scale The scale to apply when painting. + /// + /// @return Returns <code>true</code> on success or <code>false</code> + /// if the resource is invalid or the scale factor is 0 or less. + bool SetScale(float scale); + + /// GetScale() gets the scale factor that will be applied when painting the + /// graphics context onto the output device. + /// + /// @return Returns the scale factor for the graphics context. If the resource + /// is invalid, 0.0 will be returned. The default scale for a graphics context + /// is 1.0. + float GetScale(); + private: Size size_; }; diff --git a/ppapi/cpp/view.cc b/ppapi/cpp/view.cc index 68c6e311..ce34785 100644 --- a/ppapi/cpp/view.cc +++ b/ppapi/cpp/view.cc @@ -15,6 +15,10 @@ template <> const char* interface_name<PPB_View_1_0>() { return PPB_VIEW_INTERFACE_1_0; } +template <> const char* interface_name<PPB_View_1_1>() { + return PPB_VIEW_INTERFACE_1_1; +} + } // namespace View::View() : Resource() { @@ -24,40 +28,71 @@ View::View(PP_Resource view_resource) : Resource(view_resource) { } Rect View::GetRect() const { - if (!has_interface<PPB_View_1_0>()) - return Rect(); PP_Rect out; - if (PP_ToBool(get_interface<PPB_View_1_0>()->GetRect(pp_resource(), &out))) - return Rect(out); + if (has_interface<PPB_View_1_1>()) { + if (PP_ToBool(get_interface<PPB_View_1_1>()->GetRect(pp_resource(), &out))) + return Rect(out); + } else if (has_interface<PPB_View_1_0>()) { + if (PP_ToBool(get_interface<PPB_View_1_0>()->GetRect(pp_resource(), &out))) + return Rect(out); + } return Rect(); } bool View::IsFullscreen() const { - if (!has_interface<PPB_View_1_0>()) - return false; - return PP_ToBool(get_interface<PPB_View_1_0>()->IsFullscreen(pp_resource())); + if (has_interface<PPB_View_1_1>()) { + return PP_ToBool(get_interface<PPB_View_1_1>()->IsFullscreen( + pp_resource())); + } else if (has_interface<PPB_View_1_0>()) { + return PP_ToBool(get_interface<PPB_View_1_0>()->IsFullscreen( + pp_resource())); + } + return false; } bool View::IsVisible() const { - if (!has_interface<PPB_View_1_0>()) - return false; - return PP_ToBool(get_interface<PPB_View_1_0>()->IsVisible(pp_resource())); + if (has_interface<PPB_View_1_1>()) + return PP_ToBool(get_interface<PPB_View_1_1>()->IsVisible(pp_resource())); + else if (has_interface<PPB_View_1_0>()) + return PP_ToBool(get_interface<PPB_View_1_0>()->IsVisible(pp_resource())); + return false; } bool View::IsPageVisible() const { - if (!has_interface<PPB_View_1_0>()) - return true; - return PP_ToBool(get_interface<PPB_View_1_0>()->IsPageVisible(pp_resource())); + if (has_interface<PPB_View_1_1>()) { + return PP_ToBool(get_interface<PPB_View_1_1>()->IsPageVisible( + pp_resource())); + } else if (has_interface<PPB_View_1_0>()) { + return PP_ToBool(get_interface<PPB_View_1_0>()->IsPageVisible( + pp_resource())); + } + return true; } Rect View::GetClipRect() const { - if (!has_interface<PPB_View_1_0>()) - return Rect(); PP_Rect out; - if (PP_ToBool(get_interface<PPB_View_1_0>()->GetClipRect(pp_resource(), - &out))) - return Rect(out); + if (has_interface<PPB_View_1_1>()) { + if (PP_ToBool(get_interface<PPB_View_1_1>()->GetClipRect(pp_resource(), + &out))) + return Rect(out); + } else if (has_interface<PPB_View_1_0>()) { + if (PP_ToBool(get_interface<PPB_View_1_0>()->GetClipRect(pp_resource(), + &out))) + return Rect(out); + } return Rect(); } +float View::GetDeviceScale() const { + if (has_interface<PPB_View_1_1>()) + return get_interface<PPB_View_1_1>()->GetDeviceScale(pp_resource()); + return 1.0f; +} + +float View::GetCSSScale() const { + if (has_interface<PPB_View_1_1>()) + return get_interface<PPB_View_1_1>()->GetCSSScale(pp_resource()); + return 1.0f; +} + } // namespace pp diff --git a/ppapi/cpp/view.h b/ppapi/cpp/view.h index 4494edd..7ffd168 100644 --- a/ppapi/cpp/view.h +++ b/ppapi/cpp/view.h @@ -118,6 +118,26 @@ class View : public Resource { /// @return The rectangle representing the visible part of the module /// instance. If the resource is invalid, the empty rectangle is returned. Rect GetClipRect() const; + + /// GetDeviceScale returns the scale factor between device pixels and DIPs + /// (also known as logical pixels or UI pixels on some platforms). This allows + /// the developer to render their contents at device resolution, even as + /// coordinates / sizes are given in DIPs through the API. + /// + /// Note that the coordinate system for Pepper APIs is DIPs. Also note that + /// one DIP might not equal one CSS pixel - when page scale/zoom is in effect. + /// + /// @return A <code>float</code> value representing the number of device + /// pixels per DIP. + float GetDeviceScale() const; + + /// GetCSSScale returns the scale factor between DIPs and CSS pixels. This + /// allows proper scaling between DIPs - as sent via the Pepper API - and CSS + /// pixel coordinates used for Web content. + /// + /// @return A <code>float</code> value representing the number of DIPs per CSS + /// pixel. + float GetCSSScale() const; }; } // namespace pp diff --git a/ppapi/examples/scaling/scaling.cc b/ppapi/examples/scaling/scaling.cc new file mode 100644 index 0000000..01d9265 --- /dev/null +++ b/ppapi/examples/scaling/scaling.cc @@ -0,0 +1,232 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <sstream> + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/graphics_2d.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/input_event.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/cpp/var.h" +#include "ppapi/utility/completion_callback_factory.h" + +// When compiling natively on Windows, PostMessage can be #define-d to +// something else. +#ifdef PostMessage +#undef PostMessage +#endif + +// Example plugin to demonstrate usage of pp::View and pp::Graphics2D APIs for +// rendering 2D graphics at device resolution. See Paint() for more details. +class MyInstance : public pp::Instance { + public: + explicit MyInstance(PP_Instance instance) + : pp::Instance(instance), + width_(0), + height_(0), + pixel_width_(0), + pixel_height_(0), + device_scale_(1.0f), + css_scale_(1.0f), + using_device_pixels_(true) { + RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | + PP_INPUTEVENT_CLASS_KEYBOARD); + } + + virtual void DidChangeView(const pp::View& view) { + pp::Rect view_rect = view.GetRect(); + if (view_rect.width() == width_ && + view_rect.height() == height_ && + view.GetDeviceScale() == device_scale_ && + view.GetCSSScale() == css_scale_) + return; // We don't care about the position, only the size and scale. + + width_ = view_rect.width(); + height_ = view_rect.height(); + device_scale_ = view.GetDeviceScale(); + css_scale_ = view.GetCSSScale(); + + pixel_width_ = width_ * device_scale_; + pixel_height_ = height_ * device_scale_; + + SetupGraphics(); + } + + virtual bool HandleInputEvent(const pp::InputEvent& event) { + switch (event.GetType()) { + case PP_INPUTEVENT_TYPE_MOUSEDOWN: + HandleMouseDown(event); + return true; + default: + return false; + } + } + + virtual void HandleMessage(const pp::Var& message_data) { + if (message_data.is_string()) { + std::string str = message_data.AsString(); + if (str == "dip") { + if (using_device_pixels_) { + using_device_pixels_ = false; + SetupGraphics(); + } + } else if (str == "device") { + if (!using_device_pixels_) { + using_device_pixels_ = true; + SetupGraphics(); + } + } else if (str == "metrics") { + std::stringstream stream; + stream << "DIP (" << width_ << ", " << height_ << "), device pixels=(" + << pixel_width_ << ", " << pixel_height_ <<"), device_scale=" + << device_scale_ <<", css_scale=" << css_scale_; + PostMessage(stream.str()); + } + } + } + + private: + void HandleMouseDown(const pp::InputEvent& event) { + pp::MouseInputEvent mouse_event(event); + pp::Point position(mouse_event.GetPosition()); + pp::Point position_device(position.x() * device_scale_, + position.y() * device_scale_); + std::stringstream stream; + stream << "Mousedown at DIP (" << position.x() << ", " << position.y() + << "), device pixel (" << position_device.x() << ", " + << position_device.y() << ")"; + if (css_scale_ > 0.0f) { + pp::Point position_css(position.x() / css_scale_, + position.y() / css_scale_); + stream << ", CSS pixel (" << position_css.x() << ", " << position_css.y() + <<")"; + } else { + stream <<", unknown CSS pixel. css_scale_=" << css_scale_; + } + PostMessage(stream.str()); + } + + void SetupGraphics() { + if (using_device_pixels_) { + // The plugin will treat 1 pixel in the device context as 1 device pixel. + // This will set up a properly-sized pp::Graphics2D, and tell Pepper + // to apply the correct scale so the resulting concatenated scale leaves + // each pixel in the device context as one on the display device. + device_context_ = pp::Graphics2D(this, + pp::Size(pixel_width_, pixel_height_), + true); + if (device_scale_ > 0.0f) { + // If SetScale is promoted to pp::Graphics2D, the dc_dev constructor + // can be removed, and this will become the following line instead. + // device_context_.SetScale(1.0f / device_scale_); + device_context_.SetScale(1.0f / device_scale_); + } + } else { + // The plugin will treat 1 pixel in the device context as one DIP. + device_context_ = pp::Graphics2D(this, pp::Size(width_, height_), true); + } + BindGraphics(device_context_); + Paint(); + } + + void Paint() { + int width = using_device_pixels_ ? pixel_width_ : width_; + int height = using_device_pixels_ ? pixel_height_ : height_; + pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, + pp::Size(width, height), false); + if (image.is_null()) + return; + + // Painting here will demonstrate a few techniques: + // - painting a thin blue box and cross-hatch to show the finest resolution + // available. + // - painting a 25 DIP (logical pixel) green circle to show how objects of a + // fixed size in DIPs should be scaled if using a high-resolution + // pp::Graphics2D. + // - paiting a 50 CSS pixel red circle to show how objects of a fixed size + // in CSS pixels should be scaled if using a high-resolution + // pp::Graphics2D, as well as how to use the GetCSSScale value properly. + + // Painting in "DIP resolution" mode (|using_device_pixels_| false) will + // demonstrate how unscaled graphics would look, even on a high-DPI device. + // Painting in "device resolution" mode (|using_device_pixels_| true) will + // show how scaled graphics would look crisper on a high-DPI device, in + // comparison to using unscaled graphics. Both modes should look identical + // when displayed on a non-high-DPI device (window.devicePixelRatio == 1). + // Toggling between "DIP resolution" mode and "device resolution" mode + // should not change the sizes of the circles. + + // Changing the browser zoom level should cause the CSS circle to zoom, but + // not the DIP-sized circle. + + // All painting here does not use any anti-aliasing. + float circle_1_radius = 25; + if (using_device_pixels_) + circle_1_radius *= device_scale_; + + float circle_2_radius = 50 * css_scale_; + if (using_device_pixels_) + circle_2_radius *= device_scale_; + + for (int y = 0; y < height; ++y) { + char* row = static_cast<char*>(image.data()) + (y * image.stride()); + uint32_t* pixel = reinterpret_cast<uint32_t*>(row); + for (int x = 0; x < width; ++x) { + int dx = (width / 2) - x; + int dy = (height / 2) - y; + float dist_squared = (dx * dx) + (dy * dy); + if (x == 0 || y == 0 || x == width - 1 || y == width - 1 || x == y || + width - x - 1 == y) { + *pixel++ = 0xFF0000FF; + } else if (dist_squared < circle_1_radius * circle_1_radius) { + *pixel++ = 0xFF00FF00; + } else if (dist_squared < circle_2_radius * circle_2_radius) { + *pixel++ = 0xFFFF0000; + } else { + *pixel++ = 0xFF000000; + } + } + } + + device_context_.ReplaceContents(&image); + device_context_.Flush(pp::CompletionCallback(&OnFlush, this)); + } + + static void OnFlush(void* user_data, int32_t result) {} + + pp::Graphics2D device_context_; + int width_; + int height_; + int pixel_width_; + int pixel_height_; + float device_scale_; + float css_scale_; + bool using_device_pixels_; +}; + +// This object is the global object representing this plugin library as long as +// it is loaded. +class MyModule : public pp::Module { + public: + MyModule() : pp::Module() {} + virtual ~MyModule() {} + + // Override CreateInstance to create your customized Instance object. + virtual pp::Instance* CreateInstance(PP_Instance instance) { + return new MyInstance(instance); + } +}; + +namespace pp { + +// Factory function for your specialization of the Module object. +Module* CreateModule() { + return new MyModule(); +} + +} // namespace pp diff --git a/ppapi/examples/scaling/scaling.html b/ppapi/examples/scaling/scaling.html new file mode 100644 index 0000000..983cbd6 --- /dev/null +++ b/ppapi/examples/scaling/scaling.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2013 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <title>Pepper 2D Scaling Example</title> + <script> + + function HandleMessage(message_event) { + if (message_event.data) { + console.log(message_event.data); + } + } + + function AddListener() { + var plugin = document.getElementById("plugin"); + plugin.addEventListener("message", HandleMessage, false); + } + document.addEventListener("DOMContentLoaded", AddListener, false); + </script> +</head> + +<body> + <script> + function SendString(str) { + var plugin = document.getElementById("plugin"); + plugin.postMessage(str); + } + </script> + + <button onclick="SendString('dip')">DIP Res</button> + <button onclick="SendString('device')">Device Res</button> + <button onclick="SendString('metrics')">Metrics</button> + <hr> + <object id="plugin" type="application/x-ppapi-example-2d-scaling" width="200" height="200" border="2px"></object><br> +Blue lines are one pixel thin, at either DIP or device resolution.<br> +Green circle is 25 DIPs in radius.<br> +Red circle is 50 CSS pixels in radius.<br> +Mouse clicks in the plugin will generate a message in the JS console.<br> + <hr> +</body> diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 430156e..3ad8662 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -148,6 +148,7 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_FileSystem_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Fullscreen_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Gamepad_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Graphics2D_1_0; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Graphics2D_1_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Graphics3D_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_ImageData_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_InputEvent_1_0; @@ -170,6 +171,7 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VarArrayBuffer_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoReader_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoWriter_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_View_1_0; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_View_1_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_WebSocket_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPP_Graphics3D_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPP_InputEvent_0_1; @@ -692,6 +694,64 @@ int32_t Pnacl_M14_PPB_Graphics2D_Flush(PP_Resource graphics_2d, struct PP_Comple /* End wrapper methods for PPB_Graphics2D_1_0 */ +/* Begin wrapper methods for PPB_Graphics2D_1_1 */ + +static __attribute__((pnaclcall)) +PP_Resource Pnacl_M27_PPB_Graphics2D_Create(PP_Instance instance, const struct PP_Size* size, PP_Bool is_always_opaque) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + return iface->Create(instance, size, is_always_opaque); +} + +static __attribute__((pnaclcall)) +PP_Bool Pnacl_M27_PPB_Graphics2D_IsGraphics2D(PP_Resource resource) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + return iface->IsGraphics2D(resource); +} + +static __attribute__((pnaclcall)) +PP_Bool Pnacl_M27_PPB_Graphics2D_Describe(PP_Resource graphics_2d, struct PP_Size* size, PP_Bool* is_always_opqaue) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + return iface->Describe(graphics_2d, size, is_always_opqaue); +} + +static __attribute__((pnaclcall)) +void Pnacl_M27_PPB_Graphics2D_PaintImageData(PP_Resource graphics_2d, PP_Resource image_data, const struct PP_Point* top_left, const struct PP_Rect* src_rect) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + iface->PaintImageData(graphics_2d, image_data, top_left, src_rect); +} + +static __attribute__((pnaclcall)) +void Pnacl_M27_PPB_Graphics2D_Scroll(PP_Resource graphics_2d, const struct PP_Rect* clip_rect, const struct PP_Point* amount) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + iface->Scroll(graphics_2d, clip_rect, amount); +} + +static __attribute__((pnaclcall)) +void Pnacl_M27_PPB_Graphics2D_ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + iface->ReplaceContents(graphics_2d, image_data); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M27_PPB_Graphics2D_Flush(PP_Resource graphics_2d, struct PP_CompletionCallback callback) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + return iface->Flush(graphics_2d, callback); +} + +static __attribute__((pnaclcall)) +PP_Bool Pnacl_M27_PPB_Graphics2D_SetScale(PP_Resource resource, float scale) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + return iface->SetScale(resource, scale); +} + +static __attribute__((pnaclcall)) +float Pnacl_M27_PPB_Graphics2D_GetScale(PP_Resource resource) { + const struct PPB_Graphics2D_1_1 *iface = Pnacl_WrapperInfo_PPB_Graphics2D_1_1.real_iface; + return iface->GetScale(resource); +} + +/* End wrapper methods for PPB_Graphics2D_1_1 */ + /* Begin wrapper methods for PPB_Graphics3D_1_0 */ static __attribute__((pnaclcall)) @@ -1274,6 +1334,8 @@ void Pnacl_M28_PPB_VideoWriter_Close(PP_Resource writer) { /* Not generating wrapper methods for PPB_View_1_0 */ +/* Not generating wrapper methods for PPB_View_1_1 */ + /* Begin wrapper methods for PPB_WebSocket_1_0 */ static __attribute__((pnaclcall)) @@ -4137,6 +4199,18 @@ struct PPB_Graphics2D_1_0 Pnacl_Wrappers_PPB_Graphics2D_1_0 = { .Flush = (int32_t (*)(PP_Resource graphics_2d, struct PP_CompletionCallback callback))&Pnacl_M14_PPB_Graphics2D_Flush }; +struct PPB_Graphics2D_1_1 Pnacl_Wrappers_PPB_Graphics2D_1_1 = { + .Create = (PP_Resource (*)(PP_Instance instance, const struct PP_Size* size, PP_Bool is_always_opaque))&Pnacl_M27_PPB_Graphics2D_Create, + .IsGraphics2D = (PP_Bool (*)(PP_Resource resource))&Pnacl_M27_PPB_Graphics2D_IsGraphics2D, + .Describe = (PP_Bool (*)(PP_Resource graphics_2d, struct PP_Size* size, PP_Bool* is_always_opqaue))&Pnacl_M27_PPB_Graphics2D_Describe, + .PaintImageData = (void (*)(PP_Resource graphics_2d, PP_Resource image_data, const struct PP_Point* top_left, const struct PP_Rect* src_rect))&Pnacl_M27_PPB_Graphics2D_PaintImageData, + .Scroll = (void (*)(PP_Resource graphics_2d, const struct PP_Rect* clip_rect, const struct PP_Point* amount))&Pnacl_M27_PPB_Graphics2D_Scroll, + .ReplaceContents = (void (*)(PP_Resource graphics_2d, PP_Resource image_data))&Pnacl_M27_PPB_Graphics2D_ReplaceContents, + .Flush = (int32_t (*)(PP_Resource graphics_2d, struct PP_CompletionCallback callback))&Pnacl_M27_PPB_Graphics2D_Flush, + .SetScale = (PP_Bool (*)(PP_Resource resource, float scale))&Pnacl_M27_PPB_Graphics2D_SetScale, + .GetScale = (float (*)(PP_Resource resource))&Pnacl_M27_PPB_Graphics2D_GetScale +}; + struct PPB_Graphics3D_1_0 Pnacl_Wrappers_PPB_Graphics3D_1_0 = { .GetAttribMaxValue = (int32_t (*)(PP_Resource instance, int32_t attribute, int32_t* value))&Pnacl_M15_PPB_Graphics3D_GetAttribMaxValue, .Create = (PP_Resource (*)(PP_Instance instance, PP_Resource share_context, const int32_t attrib_list[]))&Pnacl_M15_PPB_Graphics3D_Create, @@ -4282,6 +4356,8 @@ struct PPB_VideoWriter_0_1 Pnacl_Wrappers_PPB_VideoWriter_0_1 = { /* Not generating wrapper interface for PPB_View_1_0 */ +/* Not generating wrapper interface for PPB_View_1_1 */ + struct PPB_WebSocket_1_0 Pnacl_Wrappers_PPB_WebSocket_1_0 = { .Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M18_PPB_WebSocket_Create, .IsWebSocket = (PP_Bool (*)(PP_Resource resource))&Pnacl_M18_PPB_WebSocket_IsWebSocket, @@ -5050,6 +5126,12 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Graphics2D_1_0 = { .real_iface = NULL }; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Graphics2D_1_1 = { + .iface_macro = PPB_GRAPHICS_2D_INTERFACE_1_1, + .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Graphics2D_1_1, + .real_iface = NULL +}; + static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Graphics3D_1_0 = { .iface_macro = PPB_GRAPHICS_3D_INTERFACE_1_0, .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Graphics3D_1_0, @@ -5182,6 +5264,12 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_View_1_0 = { .real_iface = NULL }; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_View_1_1 = { + .iface_macro = PPB_VIEW_INTERFACE_1_1, + .wrapped_iface = NULL /* Still need slot for real_iface */, + .real_iface = NULL +}; + static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_WebSocket_1_0 = { .iface_macro = PPB_WEBSOCKET_INTERFACE_1_0, .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_WebSocket_1_0, @@ -5868,6 +5956,7 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = { &Pnacl_WrapperInfo_PPB_Fullscreen_1_0, &Pnacl_WrapperInfo_PPB_Gamepad_1_0, &Pnacl_WrapperInfo_PPB_Graphics2D_1_0, + &Pnacl_WrapperInfo_PPB_Graphics2D_1_1, &Pnacl_WrapperInfo_PPB_Graphics3D_1_0, &Pnacl_WrapperInfo_PPB_ImageData_1_0, &Pnacl_WrapperInfo_PPB_InputEvent_1_0, @@ -5890,6 +5979,7 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = { &Pnacl_WrapperInfo_PPB_VideoReader_0_1, &Pnacl_WrapperInfo_PPB_VideoWriter_0_1, &Pnacl_WrapperInfo_PPB_View_1_0, + &Pnacl_WrapperInfo_PPB_View_1_1, &Pnacl_WrapperInfo_PPB_WebSocket_1_0, &Pnacl_WrapperInfo_PPB_AudioTrusted_0_6, &Pnacl_WrapperInfo_PPB_BrokerTrusted_0_2, diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index 197580d..78e878d 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -352,6 +352,16 @@ ], }, { + 'target_name': 'ppapi_example_scaling', + 'dependencies': [ + 'ppapi_example_skeleton', + 'ppapi.gyp:ppapi_cpp', + ], + 'sources': [ + 'examples/scaling/scaling.cc', + ], + }, + { 'target_name': 'ppapi_example_scroll', 'dependencies': [ 'ppapi_example_skeleton', diff --git a/ppapi/tests/test_graphics_2d.cc b/ppapi/tests/test_graphics_2d.cc index aea741d..14ed49a 100644 --- a/ppapi/tests/test_graphics_2d.cc +++ b/ppapi/tests/test_graphics_2d.cc @@ -59,6 +59,7 @@ void TestGraphics2D::RunTests(const std::string& filter) { RUN_TEST(Humongous, filter); RUN_TEST(InitToZero, filter); RUN_TEST(Describe, filter); + RUN_TEST(Scale, filter); RUN_TEST_FORCEASYNC_AND_NOT(Paint, filter); RUN_TEST_FORCEASYNC_AND_NOT(Scroll, filter); RUN_TEST_FORCEASYNC_AND_NOT(Replace, filter); @@ -369,6 +370,44 @@ std::string TestGraphics2D::TestDescribe() { PASS(); } +std::string TestGraphics2D::TestScale() { + // Tests GetScale/SetScale + const int w = 20, h = 16; + const float scale = 1.0f/2.0f; + pp::Graphics2D dc(instance_, pp::Size(w, h), false); + if (dc.is_null()) + return "Failure creating a boring device"; + if (dc.GetScale() != 1.0f) + return "GetScale returned unexpected value before SetScale"; + if (!dc.SetScale(scale)) + return "SetScale failed"; + if (dc.GetScale() != scale) + return "GetScale mismatch with prior SetScale"; + // Try setting a few invalid scale factors. Ensure that we catch these errors + // and don't change the actual scale + if (dc.SetScale(-1.0f)) + return "SetScale(-1f) did not fail"; + if (dc.SetScale(0.0f)) + return "SetScale(0.0f) did not fail"; + if (dc.GetScale() != scale) + return "SetScale with invalid parameter overwrote the scale"; + + // Verify that the context has the specified number of pixels, despite the + // non-identity scale + PP_Size size; + size.width = -1; + size.height = -1; + PP_Bool is_always_opaque = PP_FALSE; + if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, + &is_always_opaque)) + return "Describe failed"; + if (size.width != w || size.height != h || + is_always_opaque != PP_FromBool(false)) + return "Mismatch of data."; + + PASS(); +} + std::string TestGraphics2D::TestPaint() { const int w = 15, h = 17; pp::Graphics2D dc(instance_, pp::Size(w, h), false); diff --git a/ppapi/tests/test_graphics_2d.h b/ppapi/tests/test_graphics_2d.h index 4107504..b54a04b 100644 --- a/ppapi/tests/test_graphics_2d.h +++ b/ppapi/tests/test_graphics_2d.h @@ -96,6 +96,7 @@ class TestGraphics2D : public TestCase { std::string TestHumongous(); std::string TestInitToZero(); std::string TestDescribe(); + std::string TestScale(); std::string TestPaint(); std::string TestScroll(); std::string TestReplace(); diff --git a/ppapi/thunk/interfaces_ppb_public_stable.h b/ppapi/thunk/interfaces_ppb_public_stable.h index 588896f..832b9ce 100644 --- a/ppapi/thunk/interfaces_ppb_public_stable.h +++ b/ppapi/thunk/interfaces_ppb_public_stable.h @@ -58,6 +58,7 @@ PROXIED_IFACE(PPB_Instance, PPB_INSTANCE_INTERFACE_1_0, PPB_Instance_1_0) PROXIED_IFACE(NoAPIName, PPB_FILEIO_INTERFACE_1_0, PPB_FileIO_1_0) PROXIED_IFACE(NoAPIName, PPB_FILEIO_INTERFACE_1_1, PPB_FileIO_1_1) PROXIED_IFACE(NoAPIName, PPB_GRAPHICS_2D_INTERFACE_1_0, PPB_Graphics2D_1_0) +PROXIED_IFACE(NoAPIName, PPB_GRAPHICS_2D_INTERFACE_1_1, PPB_Graphics2D_1_1) PROXIED_IFACE(NoAPIName, PPB_INPUT_EVENT_INTERFACE_1_0, PPB_InputEvent_1_0) PROXIED_IFACE(NoAPIName, PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_0, PPB_KeyboardInputEvent_1_0) @@ -82,6 +83,7 @@ PROXIED_IFACE(NoAPIName, PPB_WEBSOCKET_INTERFACE_1_0, PPB_WebSocket_1_0) // Note: PPB_Var and PPB_VarArrayBuffer are special and registered manually. PROXIED_IFACE(NoAPIName, PPB_VIEW_INTERFACE_1_0, PPB_View_1_0) +PROXIED_IFACE(NoAPIName, PPB_VIEW_INTERFACE_1_1, PPB_View_1_1) // This has no corresponding _Proxy object since it does no IPC. PROXIED_IFACE(NoAPIName, PPB_AUDIO_CONFIG_INTERFACE_1_0, PPB_AudioConfig_1_0) diff --git a/ppapi/thunk/ppb_graphics_2d_thunk.cc b/ppapi/thunk/ppb_graphics_2d_thunk.cc index e6c0366..073129d 100644 --- a/ppapi/thunk/ppb_graphics_2d_thunk.cc +++ b/ppapi/thunk/ppb_graphics_2d_thunk.cc @@ -93,7 +93,7 @@ float GetScale(PP_Resource graphics_2d) { return enter.object()->GetScale(); } -const PPB_Graphics2D g_ppb_graphics_2d_thunk = { +const PPB_Graphics2D_1_0 g_ppb_graphics_2d_1_0_thunk = { &Create, &IsGraphics2D, &Describe, @@ -103,6 +103,18 @@ const PPB_Graphics2D g_ppb_graphics_2d_thunk = { &Flush }; +const PPB_Graphics2D_1_1 g_ppb_graphics_2d_1_1_thunk = { + &Create, + &IsGraphics2D, + &Describe, + &PaintImageData, + &Scroll, + &ReplaceContents, + &Flush, + &SetScale, + &GetScale +}; + const PPB_Graphics2D_Dev g_ppb_graphics_2d_dev_thunk = { &SetScale, &GetScale @@ -111,7 +123,11 @@ const PPB_Graphics2D_Dev g_ppb_graphics_2d_dev_thunk = { } // namespace const PPB_Graphics2D_1_0* GetPPB_Graphics2D_1_0_Thunk() { - return &g_ppb_graphics_2d_thunk; + return &g_ppb_graphics_2d_1_0_thunk; +} + +const PPB_Graphics2D_1_1* GetPPB_Graphics2D_1_1_Thunk() { + return &g_ppb_graphics_2d_1_1_thunk; } const PPB_Graphics2D_Dev_0_1* GetPPB_Graphics2D_Dev_0_1_Thunk() { diff --git a/ppapi/thunk/ppb_view_thunk.cc b/ppapi/thunk/ppb_view_thunk.cc index d0ff38a..04a3931 100644 --- a/ppapi/thunk/ppb_view_thunk.cc +++ b/ppapi/thunk/ppb_view_thunk.cc @@ -64,6 +64,20 @@ PP_Bool GetClipRect(PP_Resource resource, struct PP_Rect* clip) { return enter.object()->GetClipRect(clip); } +float GetDeviceScale(PP_Resource resource) { + EnterResource<PPB_View_API> enter(resource, true); + if (enter.failed()) + return 0.0f; + return enter.object()->GetDeviceScale(); +} + +float GetCSSScale(PP_Resource resource) { + EnterResource<PPB_View_API> enter(resource, true); + if (enter.failed()) + return 0.0f; + return enter.object()->GetCSSScale(); +} + const PPB_View_1_0 g_ppb_view_thunk_1_0 = { &IsView, &GetRect, @@ -73,11 +87,26 @@ const PPB_View_1_0 g_ppb_view_thunk_1_0 = { &GetClipRect }; +const PPB_View_1_1 g_ppb_view_thunk_1_1 = { + &IsView, + &GetRect, + &IsFullscreen, + &IsVisible, + &IsPageVisible, + &GetClipRect, + &GetDeviceScale, + &GetCSSScale +}; + } // namespace const PPB_View_1_0* GetPPB_View_1_0_Thunk() { return &g_ppb_view_thunk_1_0; } +const PPB_View_1_1* GetPPB_View_1_1_Thunk() { + return &g_ppb_view_thunk_1_1; +} + } // namespace thunk } // namespace ppapi |