ppb_graphics_2d_thunk.cc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // From ppb_graphics_2d.idl modified Fri Apr 15 15:37:20 2016.
  5. #include <stdint.h>
  6. #include <string.h>
  7. #include "base/logging.h"
  8. #include "ppapi/c/pp_completion_callback.h"
  9. #include "ppapi/c/pp_errors.h"
  10. #include "ppapi/c/ppb_graphics_2d.h"
  11. #include "ppapi/shared_impl/tracked_callback.h"
  12. #include "ppapi/thunk/enter.h"
  13. #include "ppapi/thunk/ppapi_thunk_export.h"
  14. #include "ppapi/thunk/ppb_graphics_2d_api.h"
  15. namespace ppapi {
  16. namespace thunk {
  17. namespace {
  18. PP_Resource Create(PP_Instance instance,
  19. const struct PP_Size* size,
  20. PP_Bool is_always_opaque) {
  21. VLOG(4) << "PPB_Graphics2D::Create()";
  22. EnterResourceCreation enter(instance);
  23. if (enter.failed())
  24. return 0;
  25. return enter.functions()->CreateGraphics2D(instance, size, is_always_opaque);
  26. }
  27. PP_Bool IsGraphics2D(PP_Resource resource) {
  28. VLOG(4) << "PPB_Graphics2D::IsGraphics2D()";
  29. EnterResource<PPB_Graphics2D_API> enter(resource, false);
  30. return PP_FromBool(enter.succeeded());
  31. }
  32. PP_Bool Describe(PP_Resource graphics_2d,
  33. struct PP_Size* size,
  34. PP_Bool* is_always_opaque) {
  35. VLOG(4) << "PPB_Graphics2D::Describe()";
  36. EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
  37. if (enter.failed()) {
  38. memset(size, 0, sizeof(*size));
  39. memset(is_always_opaque, 0, sizeof(*is_always_opaque));
  40. return PP_FALSE;
  41. }
  42. return enter.object()->Describe(size, is_always_opaque);
  43. }
  44. void PaintImageData(PP_Resource graphics_2d,
  45. PP_Resource image_data,
  46. const struct PP_Point* top_left,
  47. const struct PP_Rect* src_rect) {
  48. VLOG(4) << "PPB_Graphics2D::PaintImageData()";
  49. EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
  50. if (enter.failed())
  51. return;
  52. enter.object()->PaintImageData(image_data, top_left, src_rect);
  53. }
  54. void Scroll(PP_Resource graphics_2d,
  55. const struct PP_Rect* clip_rect,
  56. const struct PP_Point* amount) {
  57. VLOG(4) << "PPB_Graphics2D::Scroll()";
  58. EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
  59. if (enter.failed())
  60. return;
  61. enter.object()->Scroll(clip_rect, amount);
  62. }
  63. void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
  64. VLOG(4) << "PPB_Graphics2D::ReplaceContents()";
  65. EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
  66. if (enter.failed())
  67. return;
  68. enter.object()->ReplaceContents(image_data);
  69. }
  70. int32_t Flush(PP_Resource graphics_2d, struct PP_CompletionCallback callback) {
  71. VLOG(4) << "PPB_Graphics2D::Flush()";
  72. EnterResource<PPB_Graphics2D_API> enter(graphics_2d, callback, true);
  73. if (enter.failed())
  74. return enter.retval();
  75. return enter.SetResult(enter.object()->Flush(enter.callback()));
  76. }
  77. PP_Bool SetScale(PP_Resource resource, float scale) {
  78. VLOG(4) << "PPB_Graphics2D::SetScale()";
  79. EnterResource<PPB_Graphics2D_API> enter(resource, true);
  80. if (enter.failed())
  81. return PP_FALSE;
  82. return enter.object()->SetScale(scale);
  83. }
  84. float GetScale(PP_Resource resource) {
  85. VLOG(4) << "PPB_Graphics2D::GetScale()";
  86. EnterResource<PPB_Graphics2D_API> enter(resource, true);
  87. if (enter.failed())
  88. return 0.0f;
  89. return enter.object()->GetScale();
  90. }
  91. PP_Bool SetLayerTransform(PP_Resource resource,
  92. float scale,
  93. const struct PP_Point* origin,
  94. const struct PP_Point* translate) {
  95. VLOG(4) << "PPB_Graphics2D::SetLayerTransform()";
  96. EnterResource<PPB_Graphics2D_API> enter(resource, true);
  97. if (enter.failed())
  98. return PP_FALSE;
  99. return enter.object()->SetLayerTransform(scale, origin, translate);
  100. }
  101. const PPB_Graphics2D_1_0 g_ppb_graphics2d_thunk_1_0 = {
  102. &Create, &IsGraphics2D, &Describe, &PaintImageData,
  103. &Scroll, &ReplaceContents, &Flush};
  104. const PPB_Graphics2D_1_1 g_ppb_graphics2d_thunk_1_1 = {
  105. &Create, &IsGraphics2D, &Describe, &PaintImageData, &Scroll,
  106. &ReplaceContents, &Flush, &SetScale, &GetScale};
  107. const PPB_Graphics2D_1_2 g_ppb_graphics2d_thunk_1_2 = {
  108. &Create, &IsGraphics2D, &Describe, &PaintImageData,
  109. &Scroll, &ReplaceContents, &Flush, &SetScale,
  110. &GetScale, &SetLayerTransform};
  111. } // namespace
  112. PPAPI_THUNK_EXPORT const PPB_Graphics2D_1_0* GetPPB_Graphics2D_1_0_Thunk() {
  113. return &g_ppb_graphics2d_thunk_1_0;
  114. }
  115. PPAPI_THUNK_EXPORT const PPB_Graphics2D_1_1* GetPPB_Graphics2D_1_1_Thunk() {
  116. return &g_ppb_graphics2d_thunk_1_1;
  117. }
  118. PPAPI_THUNK_EXPORT const PPB_Graphics2D_1_2* GetPPB_Graphics2D_1_2_Thunk() {
  119. return &g_ppb_graphics2d_thunk_1_2;
  120. }
  121. } // namespace thunk
  122. } // namespace ppapi