Android WebView: build debug/release based on variant.
[chromium-blink-merge.git] / ppapi / thunk / ppb_graphics_2d_thunk.cc
blob9eefee2d303b511ac4ec7a2c34880f33a28b7a9b
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 // From ppb_graphics_2d.idl modified Fri Apr 26 08:49:08 2013.
7 #include <string.h>
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/ppb_graphics_2d_api.h"
15 #include "ppapi/thunk/ppb_instance_api.h"
16 #include "ppapi/thunk/resource_creation_api.h"
17 #include "ppapi/thunk/thunk.h"
19 namespace ppapi {
20 namespace thunk {
22 namespace {
24 PP_Resource Create(PP_Instance instance,
25 const struct PP_Size* size,
26 PP_Bool is_always_opaque) {
27 VLOG(4) << "PPB_Graphics2D::Create()";
28 EnterResourceCreation enter(instance);
29 if (enter.failed())
30 return 0;
31 return enter.functions()->CreateGraphics2D(instance, size, is_always_opaque);
34 PP_Bool IsGraphics2D(PP_Resource resource) {
35 VLOG(4) << "PPB_Graphics2D::IsGraphics2D()";
36 EnterResource<PPB_Graphics2D_API> enter(resource, false);
37 return PP_FromBool(enter.succeeded());
40 PP_Bool Describe(PP_Resource graphics_2d,
41 struct PP_Size* size,
42 PP_Bool* is_always_opaque) {
43 VLOG(4) << "PPB_Graphics2D::Describe()";
44 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
45 if (enter.failed()) {
46 memset(size, 0, sizeof(*size));
47 memset(is_always_opaque, 0, sizeof(*is_always_opaque));
48 return PP_FALSE;
50 return enter.object()->Describe(size, is_always_opaque);
53 void PaintImageData(PP_Resource graphics_2d,
54 PP_Resource image_data,
55 const struct PP_Point* top_left,
56 const struct PP_Rect* src_rect) {
57 VLOG(4) << "PPB_Graphics2D::PaintImageData()";
58 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
59 if (enter.failed())
60 return;
61 enter.object()->PaintImageData(image_data, top_left, src_rect);
64 void Scroll(PP_Resource graphics_2d,
65 const struct PP_Rect* clip_rect,
66 const struct PP_Point* amount) {
67 VLOG(4) << "PPB_Graphics2D::Scroll()";
68 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
69 if (enter.failed())
70 return;
71 enter.object()->Scroll(clip_rect, amount);
74 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
75 VLOG(4) << "PPB_Graphics2D::ReplaceContents()";
76 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
77 if (enter.failed())
78 return;
79 enter.object()->ReplaceContents(image_data);
82 int32_t Flush(PP_Resource graphics_2d, struct PP_CompletionCallback callback) {
83 VLOG(4) << "PPB_Graphics2D::Flush()";
84 EnterResource<PPB_Graphics2D_API> enter(graphics_2d, callback, true);
85 if (enter.failed())
86 return enter.retval();
87 return enter.SetResult(enter.object()->Flush(enter.callback()));
90 PP_Bool SetScale(PP_Resource resource, float scale) {
91 VLOG(4) << "PPB_Graphics2D::SetScale()";
92 EnterResource<PPB_Graphics2D_API> enter(resource, true);
93 if (enter.failed())
94 return PP_FALSE;
95 return enter.object()->SetScale(scale);
98 float GetScale(PP_Resource resource) {
99 VLOG(4) << "PPB_Graphics2D::GetScale()";
100 EnterResource<PPB_Graphics2D_API> enter(resource, true);
101 if (enter.failed())
102 return 0.0f;
103 return enter.object()->GetScale();
106 const PPB_Graphics2D_1_0 g_ppb_graphics2d_thunk_1_0 = {
107 &Create,
108 &IsGraphics2D,
109 &Describe,
110 &PaintImageData,
111 &Scroll,
112 &ReplaceContents,
113 &Flush
116 const PPB_Graphics2D_1_1 g_ppb_graphics2d_thunk_1_1 = {
117 &Create,
118 &IsGraphics2D,
119 &Describe,
120 &PaintImageData,
121 &Scroll,
122 &ReplaceContents,
123 &Flush,
124 &SetScale,
125 &GetScale
128 } // namespace
130 const PPB_Graphics2D_1_0* GetPPB_Graphics2D_1_0_Thunk() {
131 return &g_ppb_graphics2d_thunk_1_0;
134 const PPB_Graphics2D_1_1* GetPPB_Graphics2D_1_1_Thunk() {
135 return &g_ppb_graphics2d_thunk_1_1;
138 } // namespace thunk
139 } // namespace ppapi