| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_ |
| 6 #define WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| 11 #include "ppapi/thunk/ppb_buffer_api.h" | 11 #include "ppapi/thunk/ppb_buffer_api.h" |
| 12 #include "ppapi/thunk/ppb_buffer_trusted_api.h" |
| 12 #include "webkit/plugins/ppapi/resource.h" | 13 #include "webkit/plugins/ppapi/resource.h" |
| 13 | 14 |
| 14 struct PPB_Buffer_Dev; | 15 struct PPB_Buffer_Dev; |
| 15 | 16 |
| 16 namespace webkit { | 17 namespace webkit { |
| 17 namespace ppapi { | 18 namespace ppapi { |
| 18 | 19 |
| 19 class PluginInstance; | 20 class PluginInstance; |
| 20 | 21 |
| 21 class PPB_Buffer_Impl : public Resource, | 22 class PPB_Buffer_Impl : public Resource, |
| 22 public ::ppapi::thunk::PPB_Buffer_API { | 23 public ::ppapi::thunk::PPB_Buffer_API, |
| 24 public ::ppapi::thunk::PPB_BufferTrusted_API { |
| 23 public: | 25 public: |
| 24 virtual ~PPB_Buffer_Impl(); | 26 virtual ~PPB_Buffer_Impl(); |
| 25 | 27 |
| 26 static PP_Resource Create(PP_Instance instance, uint32_t size); | 28 static PP_Resource Create(PP_Instance instance, uint32_t size); |
| 27 | 29 |
| 28 virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl(); | 30 virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl(); |
| 29 | 31 |
| 30 base::SharedMemory* shared_memory() const { return shared_memory_.get(); } | 32 base::SharedMemory* shared_memory() const { return shared_memory_.get(); } |
| 31 uint32_t size() const { return size_; } | 33 uint32_t size() const { return size_; } |
| 32 | 34 |
| 33 // ResourceObjectBase overries. | 35 // ResourceObjectBase overrides. |
| 34 virtual ::ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; | 36 virtual ::ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; |
| 37 virtual ::ppapi::thunk::PPB_BufferTrusted_API* AsPPB_BufferTrusted_API(); |
| 35 | 38 |
| 36 // PPB_Buffer_API implementation. | 39 // PPB_Buffer_API implementation. |
| 37 virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; | 40 virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; |
| 38 virtual PP_Bool IsMapped() OVERRIDE; | 41 virtual PP_Bool IsMapped() OVERRIDE; |
| 39 virtual void* Map() OVERRIDE; | 42 virtual void* Map() OVERRIDE; |
| 40 virtual void Unmap() OVERRIDE; | 43 virtual void Unmap() OVERRIDE; |
| 41 | 44 |
| 45 // PPB_BufferTrusted_API implementation. |
| 46 virtual int32_t GetSharedMemory(int* handle) OVERRIDE; |
| 47 |
| 42 private: | 48 private: |
| 43 explicit PPB_Buffer_Impl(PluginInstance* instance); | 49 explicit PPB_Buffer_Impl(PluginInstance* instance); |
| 44 bool Init(uint32_t size); | 50 bool Init(uint32_t size); |
| 45 | 51 |
| 46 scoped_ptr<base::SharedMemory> shared_memory_; | 52 scoped_ptr<base::SharedMemory> shared_memory_; |
| 47 uint32_t size_; | 53 uint32_t size_; |
| 48 | 54 |
| 49 DISALLOW_COPY_AND_ASSIGN(PPB_Buffer_Impl); | 55 DISALLOW_COPY_AND_ASSIGN(PPB_Buffer_Impl); |
| 50 }; | 56 }; |
| 51 | 57 |
| 52 // Ensures that the given buffer is mapped, and retursn it to its previous | 58 // Ensures that the given buffer is mapped, and returns it to its previous |
| 53 // mapped state in the destructor. | 59 // mapped state in the destructor. |
| 54 class BufferAutoMapper { | 60 class BufferAutoMapper { |
| 55 public: | 61 public: |
| 56 BufferAutoMapper(::ppapi::thunk::PPB_Buffer_API* api); | 62 BufferAutoMapper(::ppapi::thunk::PPB_Buffer_API* api); |
| 57 ~BufferAutoMapper(); | 63 ~BufferAutoMapper(); |
| 58 | 64 |
| 59 // Will be NULL on failure to map. | 65 // Will be NULL on failure to map. |
| 60 void* data() { return data_; } | 66 void* data() { return data_; } |
| 61 uint32_t size() { return size_; } | 67 uint32_t size() { return size_; } |
| 62 | 68 |
| 63 private: | 69 private: |
| 64 ::ppapi::thunk::PPB_Buffer_API* api_; | 70 ::ppapi::thunk::PPB_Buffer_API* api_; |
| 65 | 71 |
| 66 bool needs_unmap_; | 72 bool needs_unmap_; |
| 67 | 73 |
| 68 void* data_; | 74 void* data_; |
| 69 uint32_t size_; | 75 uint32_t size_; |
| 70 | 76 |
| 71 DISALLOW_COPY_AND_ASSIGN(BufferAutoMapper); | 77 DISALLOW_COPY_AND_ASSIGN(BufferAutoMapper); |
| 72 }; | 78 }; |
| 73 | 79 |
| 74 } // namespace ppapi | 80 } // namespace ppapi |
| 75 } // namespace webkit | 81 } // namespace webkit |
| 76 | 82 |
| 77 #endif // WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_ | 83 #endif // WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_ |
| OLD | NEW |