Home | History | Annotate | Download | only in client
      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
      3 // found in the LICENSE file.
      4 
      5 #include "remoting/client/frame_consumer_proxy.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/location.h"
      9 #include "base/single_thread_task_runner.h"
     10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
     11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
     12 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
     13 
     14 namespace remoting {
     15 
     16 FrameConsumerProxy::FrameConsumerProxy(
     17     scoped_refptr<base::SingleThreadTaskRunner> task_runner,
     18     const base::WeakPtr<FrameConsumer>& frame_consumer)
     19     : frame_consumer_(frame_consumer),
     20       task_runner_(task_runner) {
     21   pixel_format_ = frame_consumer_->GetPixelFormat();
     22 }
     23 
     24 void FrameConsumerProxy::ApplyBuffer(const webrtc::DesktopSize& view_size,
     25                                      const webrtc::DesktopRect& clip_area,
     26                                      webrtc::DesktopFrame* buffer,
     27                                      const webrtc::DesktopRegion& region) {
     28   if (!task_runner_->BelongsToCurrentThread()) {
     29     task_runner_->PostTask(FROM_HERE, base::Bind(
     30         &FrameConsumerProxy::ApplyBuffer, this,
     31         view_size, clip_area, buffer, region));
     32     return;
     33   }
     34 
     35   if (frame_consumer_.get())
     36     frame_consumer_->ApplyBuffer(view_size, clip_area, buffer, region);
     37 }
     38 
     39 void FrameConsumerProxy::ReturnBuffer(webrtc::DesktopFrame* buffer) {
     40   if (!task_runner_->BelongsToCurrentThread()) {
     41     task_runner_->PostTask(FROM_HERE, base::Bind(
     42         &FrameConsumerProxy::ReturnBuffer, this, buffer));
     43     return;
     44   }
     45 
     46   if (frame_consumer_.get())
     47     frame_consumer_->ReturnBuffer(buffer);
     48 }
     49 
     50 void FrameConsumerProxy::SetSourceSize(
     51     const webrtc::DesktopSize& source_size,
     52     const webrtc::DesktopVector& source_dpi) {
     53   if (!task_runner_->BelongsToCurrentThread()) {
     54     task_runner_->PostTask(FROM_HERE, base::Bind(
     55         &FrameConsumerProxy::SetSourceSize, this, source_size, source_dpi));
     56     return;
     57   }
     58 
     59   if (frame_consumer_.get())
     60     frame_consumer_->SetSourceSize(source_size, source_dpi);
     61 }
     62 
     63 FrameConsumer::PixelFormat FrameConsumerProxy::GetPixelFormat() {
     64   return pixel_format_;
     65 }
     66 
     67 FrameConsumerProxy::~FrameConsumerProxy() {
     68 }
     69 
     70 }  // namespace remoting
     71