Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ppapi / thunk / ppb_graphics_2d_thunk.cc
blob073129d05382aec76a63d6bc3db0bc12b6061008
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.
5 #include "ppapi/c/dev/ppb_graphics_2d_dev.h"
6 #include "ppapi/c/pp_completion_callback.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_graphics_2d.h"
9 #include "ppapi/shared_impl/tracked_callback.h"
10 #include "ppapi/thunk/enter.h"
11 #include "ppapi/thunk/ppb_graphics_2d_api.h"
12 #include "ppapi/thunk/resource_creation_api.h"
13 #include "ppapi/thunk/thunk.h"
15 namespace ppapi {
16 namespace thunk {
18 namespace {
20 typedef EnterResource<PPB_Graphics2D_API> EnterGraphics2D;
22 PP_Resource Create(PP_Instance instance,
23 const PP_Size* size,
24 PP_Bool is_always_opaque) {
25 EnterResourceCreation enter(instance);
26 if (enter.failed())
27 return 0;
28 return enter.functions()->CreateGraphics2D(instance, *size, is_always_opaque);
31 PP_Bool IsGraphics2D(PP_Resource resource) {
32 EnterGraphics2D enter(resource, false);
33 return enter.succeeded() ? PP_TRUE : PP_FALSE;
36 PP_Bool Describe(PP_Resource graphics_2d,
37 PP_Size* size,
38 PP_Bool* is_always_opaque) {
39 EnterGraphics2D enter(graphics_2d, true);
40 if (enter.failed()) {
41 size->width = 0;
42 size->height = 0;
43 *is_always_opaque = PP_FALSE;
44 return PP_FALSE;
46 return enter.object()->Describe(size, is_always_opaque);
49 void PaintImageData(PP_Resource graphics_2d,
50 PP_Resource image_data,
51 const PP_Point* top_left,
52 const PP_Rect* src_rect) {
53 EnterGraphics2D enter(graphics_2d, true);
54 if (enter.failed())
55 return;
56 enter.object()->PaintImageData(image_data, top_left, src_rect);
59 void Scroll(PP_Resource graphics_2d,
60 const PP_Rect* clip_rect,
61 const PP_Point* amount) {
62 EnterGraphics2D enter(graphics_2d, true);
63 if (enter.failed())
64 return;
65 enter.object()->Scroll(clip_rect, amount);
68 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
69 EnterGraphics2D enter(graphics_2d, true);
70 if (enter.failed())
71 return;
72 enter.object()->ReplaceContents(image_data);
75 int32_t Flush(PP_Resource graphics_2d, PP_CompletionCallback callback) {
76 EnterGraphics2D enter(graphics_2d, callback, true);
77 if (enter.failed())
78 return enter.retval();
79 return enter.SetResult(enter.object()->Flush(enter.callback(), NULL));
82 PP_Bool SetScale(PP_Resource graphics_2d, float scale) {
83 EnterGraphics2D enter(graphics_2d, true);
84 if (enter.failed())
85 return PP_FALSE;
86 return PP_FromBool(enter.object()->SetScale(scale));
89 float GetScale(PP_Resource graphics_2d) {
90 EnterGraphics2D enter(graphics_2d, true);
91 if (enter.failed())
92 return 0.0f;
93 return enter.object()->GetScale();
96 const PPB_Graphics2D_1_0 g_ppb_graphics_2d_1_0_thunk = {
97 &Create,
98 &IsGraphics2D,
99 &Describe,
100 &PaintImageData,
101 &Scroll,
102 &ReplaceContents,
103 &Flush
106 const PPB_Graphics2D_1_1 g_ppb_graphics_2d_1_1_thunk = {
107 &Create,
108 &IsGraphics2D,
109 &Describe,
110 &PaintImageData,
111 &Scroll,
112 &ReplaceContents,
113 &Flush,
114 &SetScale,
115 &GetScale
118 const PPB_Graphics2D_Dev g_ppb_graphics_2d_dev_thunk = {
119 &SetScale,
120 &GetScale
123 } // namespace
125 const PPB_Graphics2D_1_0* GetPPB_Graphics2D_1_0_Thunk() {
126 return &g_ppb_graphics_2d_1_0_thunk;
129 const PPB_Graphics2D_1_1* GetPPB_Graphics2D_1_1_Thunk() {
130 return &g_ppb_graphics_2d_1_1_thunk;
133 const PPB_Graphics2D_Dev_0_1* GetPPB_Graphics2D_Dev_0_1_Thunk() {
134 return &g_ppb_graphics_2d_dev_thunk;
137 } // namespace thunk
138 } // namespace ppapi