Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / client / frame_consumer_proxy.cc
blob21d03bfc663d3948e0cd40487a5077c9d2ff35db
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.
5 #include "remoting/client/frame_consumer_proxy.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
13 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
15 namespace remoting {
17 FrameConsumerProxy::FrameConsumerProxy(
18 const base::WeakPtr<FrameConsumer>& frame_consumer)
19 : frame_consumer_(frame_consumer),
20 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
21 pixel_format_ = frame_consumer_->GetPixelFormat();
24 static void DoApplyBuffer(base::WeakPtr<FrameConsumer> frame_consumer,
25 const webrtc::DesktopSize& view_size,
26 const webrtc::DesktopRect& clip_area,
27 webrtc::DesktopFrame* buffer,
28 const webrtc::DesktopRegion& region,
29 scoped_ptr<webrtc::DesktopRegion> shape) {
30 if (!frame_consumer)
31 return;
33 frame_consumer->ApplyBuffer(view_size, clip_area, buffer, region,
34 shape.get());
37 void FrameConsumerProxy::ApplyBuffer(const webrtc::DesktopSize& view_size,
38 const webrtc::DesktopRect& clip_area,
39 webrtc::DesktopFrame* buffer,
40 const webrtc::DesktopRegion& region,
41 const webrtc::DesktopRegion* shape) {
42 scoped_ptr<webrtc::DesktopRegion> shape_ptr;
43 if (shape)
44 shape_ptr = make_scoped_ptr(new webrtc::DesktopRegion(*shape));
45 task_runner_->PostTask(
46 FROM_HERE,
47 base::Bind(DoApplyBuffer, frame_consumer_, view_size, clip_area, buffer,
48 region, base::Passed(&shape_ptr)));
51 void FrameConsumerProxy::ReturnBuffer(webrtc::DesktopFrame* buffer) {
52 task_runner_->PostTask(FROM_HERE, base::Bind(&FrameConsumer::ReturnBuffer,
53 frame_consumer_, buffer));
56 void FrameConsumerProxy::SetSourceSize(
57 const webrtc::DesktopSize& source_size,
58 const webrtc::DesktopVector& source_dpi) {
59 task_runner_->PostTask(
60 FROM_HERE, base::Bind(&FrameConsumer::SetSourceSize, frame_consumer_,
61 source_size, source_dpi));
64 FrameConsumer::PixelFormat FrameConsumerProxy::GetPixelFormat() {
65 return pixel_format_;
68 FrameConsumerProxy::~FrameConsumerProxy() {
71 } // namespace remoting