1 // Copyright (c) 2011 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 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_
6 #define WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/shared_memory.h"
12 #include "ppapi/thunk/ppb_buffer_api.h"
13 #include "ppapi/shared_impl/resource.h"
14 #include "webkit/plugins/webkit_plugins_export.h"
19 class WEBKIT_PLUGINS_EXPORT PPB_Buffer_Impl
:
20 public ::ppapi::Resource
,
21 public ::ppapi::thunk::PPB_Buffer_API
{
23 virtual ~PPB_Buffer_Impl();
25 static PP_Resource
Create(PP_Instance instance
, uint32_t size
);
26 static scoped_refptr
<PPB_Buffer_Impl
> CreateResource(PP_Instance instance
,
29 virtual PPB_Buffer_Impl
* AsPPB_Buffer_Impl();
31 base::SharedMemory
* shared_memory() const { return shared_memory_
.get(); }
32 uint32_t size() const { return size_
; }
34 // Resource overrides.
35 virtual ::ppapi::thunk::PPB_Buffer_API
* AsPPB_Buffer_API() OVERRIDE
;
37 // PPB_Buffer_API implementation.
38 virtual PP_Bool
Describe(uint32_t* size_in_bytes
) OVERRIDE
;
39 virtual PP_Bool
IsMapped() OVERRIDE
;
40 virtual void* Map() OVERRIDE
;
41 virtual void Unmap() OVERRIDE
;
44 virtual int32_t GetSharedMemory(int* handle
) OVERRIDE
;
47 explicit PPB_Buffer_Impl(PP_Instance instance
);
48 bool Init(uint32_t size
);
50 scoped_ptr
<base::SharedMemory
> shared_memory_
;
54 DISALLOW_COPY_AND_ASSIGN(PPB_Buffer_Impl
);
57 // Ensures that the given buffer is mapped, and returns it to its previous
58 // mapped state in the destructor.
59 class BufferAutoMapper
{
61 explicit BufferAutoMapper(::ppapi::thunk::PPB_Buffer_API
* api
);
64 // Will be NULL on failure to map.
65 void* data() { return data_
; }
66 uint32_t size() { return size_
; }
69 ::ppapi::thunk::PPB_Buffer_API
* api_
;
76 DISALLOW_COPY_AND_ASSIGN(BufferAutoMapper
);
82 #endif // WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_