OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/c/pp_completion_callback.h" | 5 #include "ppapi/c/pp_completion_callback.h" |
6 #include "ppapi/c/pp_errors.h" | 6 #include "ppapi/c/pp_errors.h" |
7 #include "ppapi/c/ppb_graphics_2d.h" | 7 #include "ppapi/c/ppb_graphics_2d.h" |
8 #include "ppapi/thunk/common.h" | 8 #include "ppapi/thunk/common.h" |
9 #include "ppapi/thunk/enter.h" | 9 #include "ppapi/thunk/enter.h" |
10 #include "ppapi/thunk/ppb_graphics_2d_api.h" | 10 #include "ppapi/thunk/ppb_graphics_2d_api.h" |
11 #include "ppapi/thunk/resource_creation_api.h" | 11 #include "ppapi/thunk/resource_creation_api.h" |
12 #include "ppapi/thunk/thunk.h" | 12 #include "ppapi/thunk/thunk.h" |
13 | 13 |
14 namespace ppapi { | 14 namespace ppapi { |
15 namespace thunk { | 15 namespace thunk { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
| 19 typedef EnterResource<PPB_Graphics2D_API> EnterGraphics2D; |
| 20 |
19 PP_Resource Create(PP_Instance instance, | 21 PP_Resource Create(PP_Instance instance, |
20 const PP_Size* size, | 22 const PP_Size* size, |
21 PP_Bool is_always_opaque) { | 23 PP_Bool is_always_opaque) { |
22 EnterFunction<ResourceCreationAPI> enter(instance, true); | 24 EnterResourceCreation enter(instance); |
23 if (enter.failed()) | 25 if (enter.failed()) |
24 return 0; | 26 return 0; |
25 return enter.functions()->CreateGraphics2D(instance, *size, is_always_opaque); | 27 return enter.functions()->CreateGraphics2D(instance, *size, is_always_opaque); |
26 } | 28 } |
27 | 29 |
28 PP_Bool IsGraphics2D(PP_Resource resource) { | 30 PP_Bool IsGraphics2D(PP_Resource resource) { |
29 EnterResource<PPB_Graphics2D_API> enter(resource, false); | 31 EnterGraphics2D enter(resource, false); |
30 return enter.succeeded() ? PP_TRUE : PP_FALSE; | 32 return enter.succeeded() ? PP_TRUE : PP_FALSE; |
31 } | 33 } |
32 | 34 |
33 PP_Bool Describe(PP_Resource graphics_2d, | 35 PP_Bool Describe(PP_Resource graphics_2d, |
34 PP_Size* size, | 36 PP_Size* size, |
35 PP_Bool* is_always_opaque) { | 37 PP_Bool* is_always_opaque) { |
36 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true); | 38 EnterGraphics2D enter(graphics_2d, true); |
37 if (enter.failed()) { | 39 if (enter.failed()) { |
38 size->width = 0; | 40 size->width = 0; |
39 size->height = 0; | 41 size->height = 0; |
40 *is_always_opaque = PP_FALSE; | 42 *is_always_opaque = PP_FALSE; |
41 return PP_FALSE; | 43 return PP_FALSE; |
42 } | 44 } |
43 return enter.object()->Describe(size, is_always_opaque); | 45 return enter.object()->Describe(size, is_always_opaque); |
44 } | 46 } |
45 | 47 |
46 void PaintImageData(PP_Resource graphics_2d, | 48 void PaintImageData(PP_Resource graphics_2d, |
47 PP_Resource image_data, | 49 PP_Resource image_data, |
48 const PP_Point* top_left, | 50 const PP_Point* top_left, |
49 const PP_Rect* src_rect) { | 51 const PP_Rect* src_rect) { |
50 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true); | 52 EnterGraphics2D enter(graphics_2d, true); |
51 if (enter.failed()) | 53 if (enter.failed()) |
52 return; | 54 return; |
53 enter.object()->PaintImageData(image_data, top_left, src_rect); | 55 enter.object()->PaintImageData(image_data, top_left, src_rect); |
54 } | 56 } |
55 | 57 |
56 void Scroll(PP_Resource graphics_2d, | 58 void Scroll(PP_Resource graphics_2d, |
57 const PP_Rect* clip_rect, | 59 const PP_Rect* clip_rect, |
58 const PP_Point* amount) { | 60 const PP_Point* amount) { |
59 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true); | 61 EnterGraphics2D enter(graphics_2d, true); |
60 if (enter.failed()) | 62 if (enter.failed()) |
61 return; | 63 return; |
62 enter.object()->Scroll(clip_rect, amount); | 64 enter.object()->Scroll(clip_rect, amount); |
63 } | 65 } |
64 | 66 |
65 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) { | 67 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) { |
66 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true); | 68 EnterGraphics2D enter(graphics_2d, true); |
67 if (enter.failed()) | 69 if (enter.failed()) |
68 return; | 70 return; |
69 enter.object()->ReplaceContents(image_data); | 71 enter.object()->ReplaceContents(image_data); |
70 } | 72 } |
71 | 73 |
72 int32_t Flush(PP_Resource graphics_2d, | 74 int32_t Flush(PP_Resource graphics_2d, |
73 PP_CompletionCallback callback) { | 75 PP_CompletionCallback callback) { |
74 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true); | 76 EnterGraphics2D enter(graphics_2d, callback, true); |
75 if (enter.failed()) | 77 if (enter.failed()) |
76 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | 78 return enter.retval(); |
77 int32_t result = enter.object()->Flush(callback); | 79 return enter.SetResult(enter.object()->Flush(callback)); |
78 return MayForceCallback(callback, result); | |
79 } | 80 } |
80 | 81 |
81 const PPB_Graphics2D g_ppb_graphics_2d_thunk = { | 82 const PPB_Graphics2D g_ppb_graphics_2d_thunk = { |
82 &Create, | 83 &Create, |
83 &IsGraphics2D, | 84 &IsGraphics2D, |
84 &Describe, | 85 &Describe, |
85 &PaintImageData, | 86 &PaintImageData, |
86 &Scroll, | 87 &Scroll, |
87 &ReplaceContents, | 88 &ReplaceContents, |
88 &Flush | 89 &Flush |
89 }; | 90 }; |
90 | 91 |
91 } // namespace | 92 } // namespace |
92 | 93 |
93 const PPB_Graphics2D_1_0* GetPPB_Graphics2D_1_0_Thunk() { | 94 const PPB_Graphics2D_1_0* GetPPB_Graphics2D_1_0_Thunk() { |
94 return &g_ppb_graphics_2d_thunk; | 95 return &g_ppb_graphics_2d_thunk; |
95 } | 96 } |
96 | 97 |
97 } // namespace thunk | 98 } // namespace thunk |
98 } // namespace ppapi | 99 } // namespace ppapi |
OLD | NEW |