1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ppapi/cpp/dev/graphics_2d_dev.h" 6 7 #include "ppapi/cpp/module_impl.h" 8 #include "ppapi/cpp/point.h" 9 10 namespace pp { 11 12 namespace { 13 14 template <> const char* interface_name<PPB_Graphics2D_Dev_0_1>() { 15 return PPB_GRAPHICS2D_DEV_INTERFACE_0_1; 16 } 17 18 template <> const char* interface_name<PPB_Graphics2D_Dev_0_2>() { 19 return PPB_GRAPHICS2D_DEV_INTERFACE_0_2; 20 } 21 22 } // namespace 23 24 // static 25 bool Graphics2D_Dev::SupportsScale() { 26 return has_interface<PPB_Graphics2D_Dev_0_1>() || 27 has_interface<PPB_Graphics2D_Dev_0_2>(); 28 } 29 30 bool Graphics2D_Dev::SetScale(float scale) { 31 if (has_interface<PPB_Graphics2D_Dev_0_2>()) { 32 return PP_ToBool(get_interface<PPB_Graphics2D_Dev_0_2>()->SetScale( 33 pp_resource(), scale)); 34 } 35 if (has_interface<PPB_Graphics2D_Dev_0_1>()) { 36 return PP_ToBool(get_interface<PPB_Graphics2D_Dev_0_1>()->SetScale( 37 pp_resource(), scale)); 38 } 39 return false; 40 } 41 42 float Graphics2D_Dev::GetScale() { 43 if (has_interface<PPB_Graphics2D_Dev_0_2>()) 44 return get_interface<PPB_Graphics2D_Dev_0_2>()->GetScale(pp_resource()); 45 if (has_interface<PPB_Graphics2D_Dev_0_1>()) 46 return get_interface<PPB_Graphics2D_Dev_0_1>()->GetScale(pp_resource()); 47 return 1.0f; 48 } 49 50 void Graphics2D_Dev::SetOffset(const pp::Point& offset) { 51 if (!has_interface<PPB_Graphics2D_Dev_0_2>()) 52 return; 53 get_interface<PPB_Graphics2D_Dev_0_2>()->SetOffset(pp_resource(), 54 &offset.pp_point()); 55 } 56 57 void Graphics2D_Dev::SetResizeMode(PP_Graphics2D_Dev_ResizeMode resize_mode) { 58 if (!has_interface<PPB_Graphics2D_Dev_0_2>()) 59 return; 60 get_interface<PPB_Graphics2D_Dev_0_2>()->SetResizeMode(pp_resource(), 61 resize_mode); 62 } 63 64 } // namespace pp 65