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