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