ash: Update app list layout:
[chromium-blink-merge.git] / ppapi / thunk / ppb_graphics_2d_thunk.cc
blob393b4c663d63bcde44c287a98be4cd89658ca7fe
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/pp_completion_callback.h"
6 #include "ppapi/c/pp_errors.h"
7 #include "ppapi/c/ppb_graphics_2d.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_graphics_2d_api.h"
10 #include "ppapi/thunk/resource_creation_api.h"
11 #include "ppapi/thunk/thunk.h"
13 namespace ppapi {
14 namespace thunk {
16 namespace {
18 typedef EnterResource<PPB_Graphics2D_API> EnterGraphics2D;
20 PP_Resource Create(PP_Instance instance,
21 const PP_Size* size,
22 PP_Bool is_always_opaque) {
23 EnterResourceCreation enter(instance);
24 if (enter.failed())
25 return 0;
26 return enter.functions()->CreateGraphics2D(instance, *size, is_always_opaque);
29 PP_Bool IsGraphics2D(PP_Resource resource) {
30 EnterGraphics2D enter(resource, false);
31 return enter.succeeded() ? PP_TRUE : PP_FALSE;
34 PP_Bool Describe(PP_Resource graphics_2d,
35 PP_Size* size,
36 PP_Bool* is_always_opaque) {
37 EnterGraphics2D enter(graphics_2d, true);
38 if (enter.failed()) {
39 size->width = 0;
40 size->height = 0;
41 *is_always_opaque = PP_FALSE;
42 return PP_FALSE;
44 return enter.object()->Describe(size, is_always_opaque);
47 void PaintImageData(PP_Resource graphics_2d,
48 PP_Resource image_data,
49 const PP_Point* top_left,
50 const PP_Rect* src_rect) {
51 EnterGraphics2D enter(graphics_2d, true);
52 if (enter.failed())
53 return;
54 enter.object()->PaintImageData(image_data, top_left, src_rect);
57 void Scroll(PP_Resource graphics_2d,
58 const PP_Rect* clip_rect,
59 const PP_Point* amount) {
60 EnterGraphics2D enter(graphics_2d, true);
61 if (enter.failed())
62 return;
63 enter.object()->Scroll(clip_rect, amount);
66 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
67 EnterGraphics2D enter(graphics_2d, true);
68 if (enter.failed())
69 return;
70 enter.object()->ReplaceContents(image_data);
73 int32_t Flush(PP_Resource graphics_2d,
74 PP_CompletionCallback callback) {
75 EnterGraphics2D enter(graphics_2d, callback, true);
76 if (enter.failed())
77 return enter.retval();
78 return enter.SetResult(enter.object()->Flush(callback));
81 const PPB_Graphics2D g_ppb_graphics_2d_thunk = {
82 &Create,
83 &IsGraphics2D,
84 &Describe,
85 &PaintImageData,
86 &Scroll,
87 &ReplaceContents,
88 &Flush
91 } // namespace
93 const PPB_Graphics2D_1_0* GetPPB_Graphics2D_1_0_Thunk() {
94 return &g_ppb_graphics_2d_thunk;
97 } // namespace thunk
98 } // namespace ppapi