| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/renderer/pepper/ppb_buffer_impl.h" | 5 #include "content/renderer/pepper/ppb_buffer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/renderer/pepper/common.h" | 11 #include "content/renderer/pepper/common.h" |
| 12 #include "content/renderer/pepper/plugin_delegate.h" | |
| 13 #include "content/renderer/pepper/resource_helper.h" | 12 #include "content/renderer/pepper/resource_helper.h" |
| 14 #include "content/renderer/render_thread_impl.h" | 13 #include "content/renderer/render_thread_impl.h" |
| 15 #include "ppapi/c/dev/ppb_buffer_dev.h" | 14 #include "ppapi/c/dev/ppb_buffer_dev.h" |
| 15 #include "ppapi/c/pp_errors.h" |
| 16 #include "ppapi/c/pp_instance.h" | 16 #include "ppapi/c/pp_instance.h" |
| 17 #include "ppapi/c/pp_resource.h" | 17 #include "ppapi/c/pp_resource.h" |
| 18 | 18 |
| 19 using ::ppapi::thunk::PPB_Buffer_API; | 19 using ::ppapi::thunk::PPB_Buffer_API; |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 PPB_Buffer_Impl::PPB_Buffer_Impl(PP_Instance instance) | 23 PPB_Buffer_Impl::PPB_Buffer_Impl(PP_Instance instance) |
| 24 : Resource(::ppapi::OBJECT_IS_IMPL, instance), | 24 : Resource(::ppapi::OBJECT_IS_IMPL, instance), |
| 25 size_(0), | 25 size_(0), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 49 | 49 |
| 50 PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { | 50 PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { |
| 51 return this; | 51 return this; |
| 52 } | 52 } |
| 53 | 53 |
| 54 PPB_Buffer_API* PPB_Buffer_Impl::AsPPB_Buffer_API() { | 54 PPB_Buffer_API* PPB_Buffer_Impl::AsPPB_Buffer_API() { |
| 55 return this; | 55 return this; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool PPB_Buffer_Impl::Init(uint32_t size) { | 58 bool PPB_Buffer_Impl::Init(uint32_t size) { |
| 59 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 59 if (size == 0) |
| 60 if (size == 0 || !plugin_delegate) | |
| 61 return false; | 60 return false; |
| 62 size_ = size; | 61 size_ = size; |
| 63 shared_memory_.reset( | 62 shared_memory_.reset( |
| 64 RenderThread::Get()->HostAllocateSharedMemoryBuffer(size).release()); | 63 RenderThread::Get()->HostAllocateSharedMemoryBuffer(size).release()); |
| 65 return shared_memory_.get() != NULL; | 64 return shared_memory_.get() != NULL; |
| 66 } | 65 } |
| 67 | 66 |
| 68 PP_Bool PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) { | 67 PP_Bool PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) { |
| 69 *size_in_bytes = size_; | 68 *size_in_bytes = size_; |
| 70 return PP_TRUE; | 69 return PP_TRUE; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 data_ = api->Map(); | 103 data_ = api->Map(); |
| 105 api->Describe(&size_); | 104 api->Describe(&size_); |
| 106 } | 105 } |
| 107 | 106 |
| 108 BufferAutoMapper::~BufferAutoMapper() { | 107 BufferAutoMapper::~BufferAutoMapper() { |
| 109 if (needs_unmap_) | 108 if (needs_unmap_) |
| 110 api_->Unmap(); | 109 api_->Unmap(); |
| 111 } | 110 } |
| 112 | 111 |
| 113 } // namespace content | 112 } // namespace content |
| OLD | NEW |