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_image_data.idl modified Tue Aug 20 08:13:36 2013.
6
7 #include <string.h>
8
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_image_data.h"
11 #include "ppapi/shared_impl/ppb_image_data_shared.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_image_data_api.h"
16
17 namespace ppapi {
18 namespace thunk {
19
20 namespace {
21
GetNativeImageDataFormat(void)22 PP_ImageDataFormat GetNativeImageDataFormat(void) {
23 VLOG(4) << "PPB_ImageData::GetNativeImageDataFormat()";
24 return PPB_ImageData_Shared::GetNativeImageDataFormat();
25 }
26
IsImageDataFormatSupported(PP_ImageDataFormat format)27 PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) {
28 VLOG(4) << "PPB_ImageData::IsImageDataFormatSupported()";
29 return PPB_ImageData_Shared::IsImageDataFormatSupported(format);
30 }
31
Create(PP_Instance instance,PP_ImageDataFormat format,const struct PP_Size * size,PP_Bool init_to_zero)32 PP_Resource Create(PP_Instance instance,
33 PP_ImageDataFormat format,
34 const struct PP_Size* size,
35 PP_Bool init_to_zero) {
36 VLOG(4) << "PPB_ImageData::Create()";
37 EnterResourceCreation enter(instance);
38 if (enter.failed())
39 return 0;
40 return enter.functions()->CreateImageData(instance,
41 format,
42 size,
43 init_to_zero);
44 }
45
IsImageData(PP_Resource image_data)46 PP_Bool IsImageData(PP_Resource image_data) {
47 VLOG(4) << "PPB_ImageData::IsImageData()";
48 EnterResource<PPB_ImageData_API> enter(image_data, false);
49 return PP_FromBool(enter.succeeded());
50 }
51
Describe(PP_Resource image_data,struct PP_ImageDataDesc * desc)52 PP_Bool Describe(PP_Resource image_data, struct PP_ImageDataDesc* desc) {
53 VLOG(4) << "PPB_ImageData::Describe()";
54 EnterResource<PPB_ImageData_API> enter(image_data, true);
55 if (enter.failed()) {
56 memset(desc, 0, sizeof(*desc));
57 return PP_FALSE;
58 }
59 return enter.object()->Describe(desc);
60 }
61
Map(PP_Resource image_data)62 void* Map(PP_Resource image_data) {
63 VLOG(4) << "PPB_ImageData::Map()";
64 EnterResource<PPB_ImageData_API> enter(image_data, true);
65 if (enter.failed())
66 return NULL;
67 return enter.object()->Map();
68 }
69
Unmap(PP_Resource image_data)70 void Unmap(PP_Resource image_data) {
71 VLOG(4) << "PPB_ImageData::Unmap()";
72 EnterResource<PPB_ImageData_API> enter(image_data, true);
73 if (enter.failed())
74 return;
75 enter.object()->Unmap();
76 }
77
78 const PPB_ImageData_1_0 g_ppb_imagedata_thunk_1_0 = {
79 &GetNativeImageDataFormat,
80 &IsImageDataFormatSupported,
81 &Create,
82 &IsImageData,
83 &Describe,
84 &Map,
85 &Unmap
86 };
87
88 } // namespace
89
GetPPB_ImageData_1_0_Thunk()90 PPAPI_THUNK_EXPORT const PPB_ImageData_1_0* GetPPB_ImageData_1_0_Thunk() {
91 return &g_ppb_imagedata_thunk_1_0;
92 }
93
94 } // namespace thunk
95 } // namespace ppapi
96