Chromium Code Reviews| Index: remoting/client/plugin/pepper_view.cc |
| diff --git a/remoting/client/plugin/pepper_view.cc b/remoting/client/plugin/pepper_view.cc |
| index 8af4fa3f9393bbec5bb3d703a14b5dd239791c6c..0953a23ca60b6c5511791c9f92301b34768ccfd0 100644 |
| --- a/remoting/client/plugin/pepper_view.cc |
| +++ b/remoting/client/plugin/pepper_view.cc |
| @@ -23,9 +23,39 @@ |
| #include "remoting/client/frame_producer.h" |
| #include "remoting/client/plugin/chromoting_instance.h" |
| #include "remoting/client/plugin/pepper_util.h" |
| +#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| using base::Passed; |
| +namespace { |
| + |
| +// ImageBuffer that uses PPAPI to allocate space for a raw image. |
| +class PepperDesktopFrame : public webrtc::DesktopFrame { |
| + public: |
| + // Wraps the supplied ImageData. |
| + explicit PepperDesktopFrame(const pp::ImageData& buffer); |
| + |
| + // Access to underlying pepper representation. |
| + inline const pp::ImageData& get_buffer(); |
|
Lambros
2013/07/03 22:39:46
nit: Add another const after get_buffer().
|
| + |
| + private: |
| + pp::ImageData buffer_; |
| +}; |
| + |
| +PepperDesktopFrame::PepperDesktopFrame(const pp::ImageData& buffer) |
| + : DesktopFrame(webrtc::DesktopSize(buffer.size().width(), |
| + buffer.size().height()), |
| + buffer.stride(), |
| + reinterpret_cast<uint8_t*>(buffer.data()), |
| + NULL), |
| + buffer_(buffer) {} |
| + |
| +const pp::ImageData& PepperDesktopFrame::get_buffer() { |
| + return buffer_; |
| +} |
| + |
| +} // namespace |
| + |
| namespace remoting { |
| namespace { |
| @@ -139,7 +169,7 @@ void PepperView::SetView(const pp::View& view) { |
| void PepperView::ApplyBuffer(const SkISize& view_size, |
| const SkIRect& clip_area, |
| - pp::ImageData* buffer, |
| + webrtc::DesktopFrame* buffer, |
| const SkRegion& region) { |
| DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); |
| @@ -160,7 +190,7 @@ void PepperView::ApplyBuffer(const SkISize& view_size, |
| } |
| } |
| -void PepperView::ReturnBuffer(pp::ImageData* buffer) { |
| +void PepperView::ReturnBuffer(webrtc::DesktopFrame* buffer) { |
| DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); |
| // Reuse the buffer if it is large enough, otherwise drop it on the floor |
| @@ -188,18 +218,21 @@ void PepperView::SetSourceSize(const SkISize& source_size, |
| instance_->SetDesktopSize(source_size, source_dpi); |
| } |
| -pp::ImageData* PepperView::AllocateBuffer() { |
| +webrtc::DesktopFrame* PepperView::AllocateBuffer() { |
| if (buffers_.size() >= kMaxPendingBuffersCount) |
| return NULL; |
| - pp::Size pp_size = pp::Size(clip_area_.width(), clip_area_.height()); |
| - if (pp_size.IsEmpty()) |
| + if (clip_area_.width()==0 || clip_area_.height()==0) |
| return NULL; |
| // Create an image buffer of the required size, but don't zero it. |
| - pp::ImageData* buffer = new pp::ImageData( |
| - instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp_size, false); |
| - if (buffer->is_null()) { |
| + webrtc::DesktopFrame* buffer = new PepperDesktopFrame( |
| + pp::ImageData(instance_, |
| + PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| + pp::Size(clip_area_.width(), |
| + clip_area_.height()), |
| + false)); |
| + if (static_cast<PepperDesktopFrame*>(buffer)->get_buffer().is_null()) { |
| LOG(WARNING) << "Not enough memory for frame buffers."; |
| delete buffer; |
| return NULL; |
| @@ -209,7 +242,7 @@ pp::ImageData* PepperView::AllocateBuffer() { |
| return buffer; |
| } |
| -void PepperView::FreeBuffer(pp::ImageData* buffer) { |
| +void PepperView::FreeBuffer(webrtc::DesktopFrame* buffer) { |
| DCHECK(std::find(buffers_.begin(), buffers_.end(), buffer) != buffers_.end()); |
| buffers_.remove(buffer); |
| @@ -217,7 +250,7 @@ void PepperView::FreeBuffer(pp::ImageData* buffer) { |
| } |
| void PepperView::InitiateDrawing() { |
| - pp::ImageData* buffer = AllocateBuffer(); |
| + webrtc::DesktopFrame* buffer = AllocateBuffer(); |
| while (buffer) { |
| producer_->DrawBuffer(buffer); |
| buffer = AllocateBuffer(); |
| @@ -225,7 +258,7 @@ void PepperView::InitiateDrawing() { |
| } |
| void PepperView::FlushBuffer(const SkIRect& clip_area, |
| - pp::ImageData* buffer, |
| + webrtc::DesktopFrame* buffer, |
| const SkRegion& region) { |
| // Defer drawing if the flush is already in progress. |
| if (flush_pending_) { |
| @@ -257,7 +290,7 @@ void PepperView::FlushBuffer(const SkIRect& clip_area, |
| // Pepper Graphics 2D has a strange and badly documented API that the |
| // point here is the offset from the source rect. Why? |
| graphics2d_.PaintImageData( |
| - *buffer, |
| + static_cast<PepperDesktopFrame*>(buffer)->get_buffer(), |
| pp::Point(clip_area.left(), clip_area.top()), |
| pp::Rect(rect.left(), rect.top(), rect.width(), rect.height())); |
| } |
| @@ -286,7 +319,7 @@ void PepperView::FlushBuffer(const SkIRect& clip_area, |
| } |
| void PepperView::OnFlushDone(base::Time paint_start, |
| - pp::ImageData* buffer, |
| + webrtc::DesktopFrame* buffer, |
| int result) { |
| DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); |
| DCHECK(flush_pending_); |