| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/pepper_video_source_host.h" | 5 #include "content/renderer/pepper/pepper_video_source_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
| 9 #include "content/public/renderer/renderer_ppapi_host.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
| 10 #include "content/renderer/pepper/ppb_image_data_impl.h" | 10 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 void PepperVideoSourceHost::SendGetFrameReply() { | 113 void PepperVideoSourceHost::SendGetFrameReply() { |
| 114 DCHECK(get_frame_pending_); | 114 DCHECK(get_frame_pending_); |
| 115 get_frame_pending_ = false; | 115 get_frame_pending_ = false; |
| 116 | 116 |
| 117 DCHECK(last_frame_.get()); | 117 DCHECK(last_frame_.get()); |
| 118 const gfx::Size dst_size = last_frame_->natural_size(); | 118 const gfx::Size dst_size = last_frame_->natural_size(); |
| 119 | 119 |
| 120 // Note: We try to reuse the shared memory for the previous frame here. This | 120 // Note: We try to reuse the shared memory for the previous frame here. This |
| 121 // means that the previous frame may be overwritten and is no longer valid | 121 // means that the previous frame may be overwritten and is no longer valid |
| 122 // after calling this function again. | 122 // after calling this function again. |
| 123 IPC::PlatformFileForTransit image_handle; | 123 base::SharedMemoryHandle image_handle; |
| 124 uint32_t byte_count; | 124 uint32_t byte_count; |
| 125 if (shared_image_.get() && dst_size.width() == shared_image_->width() && | 125 if (shared_image_.get() && dst_size.width() == shared_image_->width() && |
| 126 dst_size.height() == shared_image_->height()) { | 126 dst_size.height() == shared_image_->height()) { |
| 127 // We have already allocated the correct size in shared memory. We need to | 127 // We have already allocated the correct size in shared memory. We need to |
| 128 // duplicate the handle for IPC however, which will close down the | 128 // duplicate the handle for IPC however, which will close down the |
| 129 // duplicated handle when it's done. | 129 // duplicated handle when it's done. |
| 130 int local_fd = 0; | 130 base::SharedMemoryHandle local_handle; |
| 131 if (shared_image_->GetSharedMemory(&local_fd, &byte_count) != PP_OK) { | 131 if (shared_image_->GetSharedMemory(&local_handle, &byte_count) != PP_OK) { |
| 132 SendGetFrameErrorReply(PP_ERROR_FAILED); | 132 SendGetFrameErrorReply(PP_ERROR_FAILED); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 ppapi::proxy::HostDispatcher* dispatcher = | 136 ppapi::proxy::HostDispatcher* dispatcher = |
| 137 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 137 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
| 138 if (!dispatcher) { | 138 if (!dispatcher) { |
| 139 SendGetFrameErrorReply(PP_ERROR_FAILED); | 139 SendGetFrameErrorReply(PP_ERROR_FAILED); |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 | 142 |
| 143 #if defined(OS_WIN) | 143 image_handle = dispatcher->ShareSharedMemoryHandleWithRemote(local_handle); |
| 144 image_handle = dispatcher->ShareHandleWithRemote( | |
| 145 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); | |
| 146 #elif defined(OS_POSIX) | |
| 147 image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); | |
| 148 #else | |
| 149 #error Not implemented. | |
| 150 #endif | |
| 151 } else { | 144 } else { |
| 152 // We need to allocate new shared memory. | 145 // We need to allocate new shared memory. |
| 153 shared_image_ = NULL; // Release any previous image. | 146 shared_image_ = NULL; // Release any previous image. |
| 154 | 147 |
| 155 ppapi::ScopedPPResource resource( | 148 ppapi::ScopedPPResource resource( |
| 156 ppapi::ScopedPPResource::PassRef(), | 149 ppapi::ScopedPPResource::PassRef(), |
| 157 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData( | 150 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData( |
| 158 pp_instance(), | 151 pp_instance(), |
| 159 ppapi::PPB_ImageData_Shared::SIMPLE, | 152 ppapi::PPB_ImageData_Shared::SIMPLE, |
| 160 PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 153 PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (source_handler_.get() && !stream_url_.empty()) | 281 if (source_handler_.get() && !stream_url_.empty()) |
| 289 source_handler_->Close(frame_receiver_.get()); | 282 source_handler_->Close(frame_receiver_.get()); |
| 290 | 283 |
| 291 source_handler_.reset(NULL); | 284 source_handler_.reset(NULL); |
| 292 stream_url_.clear(); | 285 stream_url_.clear(); |
| 293 | 286 |
| 294 shared_image_ = NULL; | 287 shared_image_ = NULL; |
| 295 } | 288 } |
| 296 | 289 |
| 297 } // namespace content | 290 } // namespace content |
| OLD | NEW |