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 #include "ppapi/c/dev/ppb_buffer_dev.h" 6 #include "ppapi/thunk/thunk.h" 7 #include "ppapi/thunk/enter.h" 8 #include "ppapi/thunk/ppb_buffer_api.h" 9 #include "ppapi/thunk/resource_creation_api.h" 10 11 namespace ppapi { 12 namespace thunk { 13 14 namespace { 15 16 PP_Resource Create(PP_Instance instance, uint32_t size) { 17 EnterResourceCreation enter(instance); 18 if (enter.failed()) 19 return 0; 20 return enter.functions()->CreateBuffer(instance, size); 21 } 22 23 PP_Bool IsBuffer(PP_Resource resource) { 24 EnterResource<PPB_Buffer_API> enter(resource, false); 25 return PP_FromBool(enter.succeeded()); 26 } 27 28 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { 29 EnterResource<PPB_Buffer_API> enter(resource, true); 30 if (enter.failed()) { 31 *size_in_bytes = 0; 32 return PP_FALSE; 33 } 34 return enter.object()->Describe(size_in_bytes); 35 } 36 37 void* Map(PP_Resource resource) { 38 EnterResource<PPB_Buffer_API> enter(resource, true); 39 if (enter.failed()) 40 return NULL; 41 return enter.object()->Map(); 42 } 43 44 void Unmap(PP_Resource resource) { 45 EnterResource<PPB_Buffer_API> enter(resource, true); 46 if (enter.succeeded()) 47 enter.object()->Unmap(); 48 } 49 50 const PPB_Buffer_Dev g_ppb_buffer_thunk = { 51 &Create, 52 &IsBuffer, 53 &Describe, 54 &Map, 55 &Unmap, 56 }; 57 58 } // namespace 59 60 const PPB_Buffer_Dev_0_4* GetPPB_Buffer_Dev_0_4_Thunk() { 61 return &g_ppb_buffer_thunk; 62 } 63 64 } // namespace thunk 65 } // namespace ppapi 66