Index: ppapi/cpp/graphics_2d.cc |
diff --git a/ppapi/cpp/graphics_2d.cc b/ppapi/cpp/graphics_2d.cc |
index f4cd6451babf5c73c4a271f09fd9edbc021eba94..3a766c83546ef224f9a437bcf156f497d3aba534 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 |