diff options
author | solb@chromium.org <solb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 02:46:50 +0000 |
---|---|---|
committer | solb@chromium.org <solb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 02:46:50 +0000 |
commit | fbc08aa288ecf9ffba63e229a3017dfddda5a28f (patch) | |
tree | 29630834ba0d81f24e5c888238d8b3822d1b74b3 /remoting | |
parent | c84c6afb54cfbc9c7ad21a455c195870005be760 (diff) | |
download | chromium_src-fbc08aa288ecf9ffba63e229a3017dfddda5a28f.zip chromium_src-fbc08aa288ecf9ffba63e229a3017dfddda5a28f.tar.gz chromium_src-fbc08aa288ecf9ffba63e229a3017dfddda5a28f.tar.bz2 |
Abstract PPAPI's ImageData behind webrtc::DesktopFrame interface
This abstracts away RectangleUpdateDecoder's direct use of the the former class. It will ease the development of non--Web app client implementations.
BUG=255309
TBR=brettw (third_party/webrtc dependency)
Review URL: https://chromiumcodereview.appspot.com/18233015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210113 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/DEPS | 1 | ||||
-rw-r--r-- | remoting/client/frame_consumer.h | 10 | ||||
-rw-r--r-- | remoting/client/frame_consumer_proxy.cc | 6 | ||||
-rw-r--r-- | remoting/client/frame_consumer_proxy.h | 4 | ||||
-rw-r--r-- | remoting/client/frame_producer.h | 8 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_view.cc | 58 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_view.h | 22 | ||||
-rw-r--r-- | remoting/client/rectangle_update_decoder.cc | 15 | ||||
-rw-r--r-- | remoting/client/rectangle_update_decoder.h | 8 | ||||
-rw-r--r-- | remoting/remoting.gyp | 17 |
10 files changed, 91 insertions, 58 deletions
diff --git a/remoting/client/DEPS b/remoting/client/DEPS index 235d972..4b52eec 100644 --- a/remoting/client/DEPS +++ b/remoting/client/DEPS @@ -2,6 +2,7 @@ include_rules = [ "+ppapi", "+jingle/glue", "+net", + "+third_party/webrtc", "+remoting/codec", "+remoting/protocol", diff --git a/remoting/client/frame_consumer.h b/remoting/client/frame_consumer.h index a315054..81a6013 100644 --- a/remoting/client/frame_consumer.h +++ b/remoting/client/frame_consumer.h @@ -9,9 +9,9 @@ #include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkSize.h" -namespace pp { -class ImageData; -} // namespace pp +namespace webrtc { +class DesktopFrame; +} // namespace webrtc namespace remoting { @@ -27,13 +27,13 @@ class FrameConsumer { // the frame. virtual void ApplyBuffer(const SkISize& view_size, const SkIRect& clip_area, - pp::ImageData* buffer, + webrtc::DesktopFrame* buffer, const SkRegion& region) = 0; // Accepts a buffer that couldn't be used for drawing for any reason (shutdown // is in progress, the view area has changed, etc.). The accepted buffer can // be freed or reused for another drawing operation. - virtual void ReturnBuffer(pp::ImageData* buffer) = 0; + virtual void ReturnBuffer(webrtc::DesktopFrame* buffer) = 0; // Set the dimension of the entire host screen. virtual void SetSourceSize(const SkISize& source_size, diff --git a/remoting/client/frame_consumer_proxy.cc b/remoting/client/frame_consumer_proxy.cc index 6f56c22..070130c 100644 --- a/remoting/client/frame_consumer_proxy.cc +++ b/remoting/client/frame_consumer_proxy.cc @@ -7,7 +7,7 @@ #include "base/bind.h" #include "base/location.h" #include "base/single_thread_task_runner.h" -#include "ppapi/cpp/image_data.h" +#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" namespace remoting { @@ -18,7 +18,7 @@ FrameConsumerProxy::FrameConsumerProxy( void FrameConsumerProxy::ApplyBuffer(const SkISize& view_size, const SkIRect& clip_area, - pp::ImageData* buffer, + webrtc::DesktopFrame* buffer, const SkRegion& region) { if (!task_runner_->BelongsToCurrentThread()) { task_runner_->PostTask(FROM_HERE, base::Bind( @@ -31,7 +31,7 @@ void FrameConsumerProxy::ApplyBuffer(const SkISize& view_size, frame_consumer_->ApplyBuffer(view_size, clip_area, buffer, region); } -void FrameConsumerProxy::ReturnBuffer(pp::ImageData* buffer) { +void FrameConsumerProxy::ReturnBuffer(webrtc::DesktopFrame* buffer) { if (!task_runner_->BelongsToCurrentThread()) { task_runner_->PostTask(FROM_HERE, base::Bind( &FrameConsumerProxy::ReturnBuffer, this, buffer)); diff --git a/remoting/client/frame_consumer_proxy.h b/remoting/client/frame_consumer_proxy.h index 58bbd7d..e39d156 100644 --- a/remoting/client/frame_consumer_proxy.h +++ b/remoting/client/frame_consumer_proxy.h @@ -31,9 +31,9 @@ class FrameConsumerProxy // FrameConsumer implementation. virtual void ApplyBuffer(const SkISize& view_size, const SkIRect& clip_area, - pp::ImageData* buffer, + webrtc::DesktopFrame* buffer, const SkRegion& region) OVERRIDE; - virtual void ReturnBuffer(pp::ImageData* buffer) OVERRIDE; + virtual void ReturnBuffer(webrtc::DesktopFrame* buffer) OVERRIDE; virtual void SetSourceSize(const SkISize& source_size, const SkIPoint& dpi) OVERRIDE; diff --git a/remoting/client/frame_producer.h b/remoting/client/frame_producer.h index 3506e8f..14bf283 100644 --- a/remoting/client/frame_producer.h +++ b/remoting/client/frame_producer.h @@ -10,9 +10,9 @@ #include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkSize.h" -namespace pp { -class ImageData; -} // namespace pp +namespace webrtc { +class DesktopFrame; +} // namespace webrtc namespace remoting { @@ -26,7 +26,7 @@ class FrameProducer { // be returned via the FrameConsumer::ReturnBuffer() call. // // The passed buffer must be large enough to hold the whole clipping area. - virtual void DrawBuffer(pp::ImageData* buffer) = 0; + virtual void DrawBuffer(webrtc::DesktopFrame* buffer) = 0; // Requests repainting of the specified |region| of the frame as soon as // possible. |region| is specified in output coordinates relative to diff --git a/remoting/client/plugin/pepper_view.cc b/remoting/client/plugin/pepper_view.cc index 8af4fa3..ba58341 100644 --- a/remoting/client/plugin/pepper_view.cc +++ b/remoting/client/plugin/pepper_view.cc @@ -23,9 +23,37 @@ #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 { + +// DesktopFrame that wraps a supplied pp::ImageData +class PepperDesktopFrame : public webrtc::DesktopFrame { + public: + // Wraps the supplied ImageData. + explicit PepperDesktopFrame(const pp::ImageData& buffer); + + // Access to underlying pepper representation. + const pp::ImageData& buffer() const { + return 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) {} + +} // namespace + namespace remoting { namespace { @@ -139,7 +167,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 +188,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,28 +216,30 @@ 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()) { + pp::ImageData buffer_data(instance_, + PP_IMAGEDATAFORMAT_BGRA_PREMUL, + pp::Size(clip_area_.width(), + clip_area_.height()), + false); + if (buffer_data.is_null()) { LOG(WARNING) << "Not enough memory for frame buffers."; - delete buffer; return NULL; } + webrtc::DesktopFrame* buffer = new PepperDesktopFrame(buffer_data); buffers_.push_back(buffer); 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 +247,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 +255,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 +287,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)->buffer(), pp::Point(clip_area.left(), clip_area.top()), pp::Rect(rect.left(), rect.top(), rect.width(), rect.height())); } @@ -286,7 +316,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_); diff --git a/remoting/client/plugin/pepper_view.h b/remoting/client/plugin/pepper_view.h index 4d1138e..7f405d4 100644 --- a/remoting/client/plugin/pepper_view.h +++ b/remoting/client/plugin/pepper_view.h @@ -20,6 +20,10 @@ namespace base { class Time; } // namespace base +namespace webrtc { +class DesktopFrame; +} // namespace webrtc + namespace remoting { class ChromotingInstance; @@ -39,9 +43,9 @@ class PepperView : public FrameConsumer, // FrameConsumer implementation. virtual void ApplyBuffer(const SkISize& view_size, const SkIRect& clip_area, - pp::ImageData* buffer, + webrtc::DesktopFrame* buffer, const SkRegion& region) OVERRIDE; - virtual void ReturnBuffer(pp::ImageData* buffer) OVERRIDE; + virtual void ReturnBuffer(webrtc::DesktopFrame* buffer) OVERRIDE; virtual void SetSourceSize(const SkISize& source_size, const SkIPoint& dpi) OVERRIDE; @@ -63,10 +67,10 @@ class PepperView : public FrameConsumer, private: // Allocates a new frame buffer to supply to the FrameProducer to render into. // Returns NULL if the maximum number of buffers has already been allocated. - pp::ImageData* AllocateBuffer(); + webrtc::DesktopFrame* AllocateBuffer(); // Frees a frame buffer previously allocated by AllocateBuffer. - void FreeBuffer(pp::ImageData* buffer); + void FreeBuffer(webrtc::DesktopFrame* buffer); // Allocates buffers and passes them to the FrameProducer to render into until // the maximum number of buffers are in-flight. @@ -77,12 +81,14 @@ class PepperView : public FrameConsumer, // FrameProducer is supplied the missed parts of |region|. The FrameProducer // will be supplied a new buffer when FlushBuffer() completes. void FlushBuffer(const SkIRect& clip_area, - pp::ImageData* buffer, + webrtc::DesktopFrame* buffer, const SkRegion& region); // Handles completion of FlushBuffer(), triggering a new buffer to be // returned to FrameProducer for rendering. - void OnFlushDone(base::Time paint_start, pp::ImageData* buffer, int result); + void OnFlushDone(base::Time paint_start, + webrtc::DesktopFrame* buffer, + int result); // Reference to the creating plugin instance. Needed for interacting with // pepper. Marking explicitly as const since it must be initialized at @@ -97,10 +103,10 @@ class PepperView : public FrameConsumer, FrameProducer* producer_; // List of allocated image buffers. - std::list<pp::ImageData*> buffers_; + std::list<webrtc::DesktopFrame*> buffers_; // Queued buffer to paint, with clip area and dirty region in device pixels. - pp::ImageData* merge_buffer_; + webrtc::DesktopFrame* merge_buffer_; SkIRect merge_clip_area_; SkRegion merge_region_; diff --git a/remoting/client/rectangle_update_decoder.cc b/remoting/client/rectangle_update_decoder.cc index 6c2f61b..3e93446 100644 --- a/remoting/client/rectangle_update_decoder.cc +++ b/remoting/client/rectangle_update_decoder.cc @@ -10,13 +10,13 @@ #include "base/location.h" #include "base/logging.h" #include "base/single_thread_task_runner.h" -#include "ppapi/cpp/image_data.h" #include "remoting/base/util.h" #include "remoting/codec/video_decoder.h" #include "remoting/codec/video_decoder_verbatim.h" #include "remoting/codec/video_decoder_vp8.h" #include "remoting/client/frame_consumer.h" #include "remoting/protocol/session_config.h" +#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" using base::Passed; using remoting::protocol::ChannelConfig; @@ -123,10 +123,10 @@ void RectangleUpdateDecoder::DoPaint() { return; // Draw the invalidated region to the buffer. - pp::ImageData* buffer = buffers_.front(); + webrtc::DesktopFrame* buffer = buffers_.front(); SkRegion output_region; decoder_->RenderFrame(view_size_, clip_area_, - reinterpret_cast<uint8*>(buffer->data()), + buffer->data(), buffer->stride(), &output_region); @@ -154,7 +154,7 @@ void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) { done.Run(); } -void RectangleUpdateDecoder::DrawBuffer(pp::ImageData* buffer) { +void RectangleUpdateDecoder::DrawBuffer(webrtc::DesktopFrame* buffer) { if (!decode_task_runner_->BelongsToCurrentThread()) { decode_task_runner_->PostTask( FROM_HERE, base::Bind(&RectangleUpdateDecoder::DrawBuffer, @@ -206,11 +206,10 @@ void RectangleUpdateDecoder::SetOutputSizeAndClip(const SkISize& view_size, // Return buffers that are smaller than needed to the consumer for // reuse/reallocation. - std::list<pp::ImageData*>::iterator i = buffers_.begin(); + std::list<webrtc::DesktopFrame*>::iterator i = buffers_.begin(); while (i != buffers_.end()) { - pp::Size buffer_size = (*i)->size(); - if (buffer_size.width() < clip_area_.width() || - buffer_size.height() < clip_area_.height()) { + if ((*i)->size().width() < clip_area_.width() || + (*i)->size().height() < clip_area_.height()) { consumer_->ReturnBuffer(*i); i = buffers_.erase(i); } else { diff --git a/remoting/client/rectangle_update_decoder.h b/remoting/client/rectangle_update_decoder.h index fe71909..457c724 100644 --- a/remoting/client/rectangle_update_decoder.h +++ b/remoting/client/rectangle_update_decoder.h @@ -20,10 +20,6 @@ namespace base { class SingleThreadTaskRunner; } // namespace base -namespace pp { -class ImageData; -} // namespace pp - namespace remoting { class ChromotingStats; @@ -55,7 +51,7 @@ class RectangleUpdateDecoder // FrameProducer implementation. These methods may be called before we are // Initialize()d, or we know the source screen size. - virtual void DrawBuffer(pp::ImageData* buffer) OVERRIDE; + virtual void DrawBuffer(webrtc::DesktopFrame* buffer) OVERRIDE; virtual void InvalidateRegion(const SkRegion& region) OVERRIDE; virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; virtual void SetOutputSizeAndClip(const SkISize& view_size, @@ -106,7 +102,7 @@ class RectangleUpdateDecoder SkIRect clip_area_; // The drawing buffers supplied by the frame consumer. - std::list<pp::ImageData*> buffers_; + std::list<webrtc::DesktopFrame*> buffers_; // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). bool paint_scheduled_; diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index bd87756..eb87228 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -2388,6 +2388,7 @@ 'remoting_base', 'remoting_jingle_glue', 'remoting_protocol', + '../third_party/webrtc/modules/modules.gyp:desktop_capture', ], 'sources': [ 'client/audio_decode_scheduler.cc', @@ -2735,19 +2736,19 @@ # valgrind and test errors. # # Javascript unittests are disabled on Windows because they add a - # dependency on 'common_constants' which (only on Windows) requires - # additional dependencies: + # dependency on 'common_constants' which (only on Windows) requires + # additional dependencies: # '../content/content.gyp:content_common', # 'installer_util', - # These targets are defined in .gypi files that would need to be - # included here: + # These targets are defined in .gypi files that would need to be + # included here: # '../chrome/chrome_common.gypi', # '../chrome/chrome_installer.gypi', # '../chrome/chrome_installer_util.gypi', - # But we can't do that because ninja will complain about multiple - # target definitions. - # TODO(garykac): Move installer_util into a proper .gyp file so that - # it can be included in multiple .gyp files. + # But we can't do that because ninja will complain about multiple + # target definitions. + # TODO(garykac): Move installer_util into a proper .gyp file so that + # it can be included in multiple .gyp files. 'includes': [ '../chrome/js_unittest_rules.gypi', ], |