| 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 "remoting/client/frame_consumer_proxy.h" | 5 #include "remoting/client/frame_consumer_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "ppapi/cpp/image_data.h" |
| 9 | 10 |
| 10 namespace remoting { | 11 namespace remoting { |
| 11 | 12 |
| 12 FrameConsumerProxy::FrameConsumerProxy( | 13 FrameConsumerProxy::FrameConsumerProxy( |
| 13 FrameConsumer* frame_consumer, | |
| 14 base::MessageLoopProxy* frame_consumer_message_loop) | 14 base::MessageLoopProxy* frame_consumer_message_loop) |
| 15 : frame_consumer_(frame_consumer), | 15 : frame_consumer_(NULL), |
| 16 frame_consumer_message_loop_(frame_consumer_message_loop) { | 16 frame_consumer_message_loop_(frame_consumer_message_loop) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 FrameConsumerProxy::~FrameConsumerProxy() { | 19 FrameConsumerProxy::~FrameConsumerProxy() { |
| 20 } | 20 } |
| 21 | 21 |
| 22 void FrameConsumerProxy::AllocateFrame( | 22 void FrameConsumerProxy::PaintBuffer(const SkISize& view_size, |
| 23 media::VideoFrame::Format format, | 23 const SkIRect& clip_area, |
| 24 const SkISize& size, | 24 pp::ImageData* buffer, |
| 25 scoped_refptr<media::VideoFrame>* frame_out, | 25 const SkRegion& region) { |
| 26 const base::Closure& done) { | |
| 27 if (!frame_consumer_message_loop_->BelongsToCurrentThread()) { | 26 if (!frame_consumer_message_loop_->BelongsToCurrentThread()) { |
| 28 frame_consumer_message_loop_->PostTask(FROM_HERE, base::Bind( | 27 frame_consumer_message_loop_->PostTask(FROM_HERE, base::Bind( |
| 29 &FrameConsumerProxy::AllocateFrame, this, format, size, frame_out, | 28 &FrameConsumerProxy::PaintBuffer, this, |
| 30 done)); | 29 view_size, clip_area, buffer, region)); |
| 31 return; | |
| 32 } | |
| 33 | |
| 34 if (frame_consumer_) { | |
| 35 frame_consumer_->AllocateFrame(format, size, frame_out, done); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void FrameConsumerProxy::ReleaseFrame(media::VideoFrame* frame) { | |
| 40 if (!frame_consumer_message_loop_->BelongsToCurrentThread()) { | |
| 41 frame_consumer_message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 42 &FrameConsumerProxy::ReleaseFrame, this, make_scoped_refptr(frame))); | |
| 43 return; | 30 return; |
| 44 } | 31 } |
| 45 | 32 |
| 46 if (frame_consumer_) | 33 if (frame_consumer_) |
| 47 frame_consumer_->ReleaseFrame(frame); | 34 frame_consumer_->PaintBuffer(view_size, clip_area, buffer, region); |
| 48 } | 35 } |
| 49 | 36 |
| 50 void FrameConsumerProxy::OnPartialFrameOutput(media::VideoFrame* frame, | 37 void FrameConsumerProxy::ReturnBuffer(pp::ImageData* buffer) { |
| 51 SkRegion* region, | |
| 52 const base::Closure& done) { | |
| 53 if (!frame_consumer_message_loop_->BelongsToCurrentThread()) { | 38 if (!frame_consumer_message_loop_->BelongsToCurrentThread()) { |
| 54 frame_consumer_message_loop_->PostTask(FROM_HERE, base::Bind( | 39 frame_consumer_message_loop_->PostTask(FROM_HERE, base::Bind( |
| 55 &FrameConsumerProxy::OnPartialFrameOutput, this, | 40 &FrameConsumerProxy::ReturnBuffer, this, buffer)); |
| 56 make_scoped_refptr(frame), region, done)); | |
| 57 return; | 41 return; |
| 58 } | 42 } |
| 59 | 43 |
| 60 if (frame_consumer_) | 44 if (frame_consumer_) |
| 61 frame_consumer_->OnPartialFrameOutput(frame, region, done); | 45 frame_consumer_->ReturnBuffer(buffer); |
| 46 } |
| 47 |
| 48 void FrameConsumerProxy::SetScreenSize(const SkISize& screen_size) { |
| 49 if (!frame_consumer_message_loop_->BelongsToCurrentThread()) { |
| 50 frame_consumer_message_loop_->PostTask(FROM_HERE, base::Bind( |
| 51 &FrameConsumerProxy::SetScreenSize, this, screen_size)); |
| 52 return; |
| 53 } |
| 54 |
| 55 if (frame_consumer_) |
| 56 frame_consumer_->SetScreenSize(screen_size); |
| 57 } |
| 58 |
| 59 void FrameConsumerProxy::Attach(FrameConsumer* frame_consumer) { |
| 60 DCHECK(frame_consumer_message_loop_->BelongsToCurrentThread()); |
| 61 DCHECK(frame_consumer_ == NULL); |
| 62 frame_consumer_ = frame_consumer; |
| 62 } | 63 } |
| 63 | 64 |
| 64 void FrameConsumerProxy::Detach() { | 65 void FrameConsumerProxy::Detach() { |
| 65 DCHECK(frame_consumer_message_loop_->BelongsToCurrentThread()); | 66 DCHECK(frame_consumer_message_loop_->BelongsToCurrentThread()); |
| 66 frame_consumer_ = NULL; | 67 frame_consumer_ = NULL; |
| 67 } | 68 } |
| 68 | 69 |
| 69 } // namespace remoting | 70 } // namespace remoting |
| OLD | NEW |