OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/jni/jni_frame_consumer.h" | 5 #include "remoting/client/jni/jni_frame_consumer.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "remoting/client/frame_producer.h" | 10 #include "remoting/client/frame_producer.h" |
11 #include "remoting/client/jni/chromoting_jni_runtime.h" | 11 #include "remoting/client/jni/chromoting_jni_runtime.h" |
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 13 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Allocates its buffer within a Java direct byte buffer, where it can be | 17 // Allocates its buffer within a Java direct byte buffer, where it can be |
17 // accessed by both native and managed code. | 18 // accessed by both native and managed code. |
18 class DirectDesktopFrame : public webrtc::BasicDesktopFrame { | 19 class DirectDesktopFrame : public webrtc::BasicDesktopFrame { |
19 public: | 20 public: |
20 DirectDesktopFrame(int width, int height); | 21 DirectDesktopFrame(int width, int height); |
21 | 22 |
22 virtual ~DirectDesktopFrame(); | 23 virtual ~DirectDesktopFrame(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 base::WaitableEvent done_event(true, false); | 56 base::WaitableEvent done_event(true, false); |
56 frame_producer_->RequestReturnBuffers( | 57 frame_producer_->RequestReturnBuffers( |
57 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event))); | 58 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event))); |
58 done_event.Wait(); | 59 done_event.Wait(); |
59 } | 60 } |
60 | 61 |
61 void JniFrameConsumer::set_frame_producer(FrameProducer* producer) { | 62 void JniFrameConsumer::set_frame_producer(FrameProducer* producer) { |
62 frame_producer_ = producer; | 63 frame_producer_ = producer; |
63 } | 64 } |
64 | 65 |
65 void JniFrameConsumer::ApplyBuffer(const SkISize& view_size, | 66 void JniFrameConsumer::ApplyBuffer(const webrtc::DesktopSize& view_size, |
66 const SkIRect& clip_area, | 67 const webrtc::DesktopRect& clip_area, |
67 webrtc::DesktopFrame* buffer, | 68 webrtc::DesktopFrame* buffer, |
68 const SkRegion& region) { | 69 const webrtc::DesktopRegion& region) { |
69 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); | 70 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); |
70 | 71 |
71 scoped_ptr<webrtc::DesktopFrame> buffer_scoped(buffer); | 72 scoped_ptr<webrtc::DesktopFrame> buffer_scoped(buffer); |
72 jni_runtime_->RedrawCanvas(); | 73 jni_runtime_->RedrawCanvas(); |
73 | 74 |
74 if (view_size.width() > view_size_.width() || | 75 if (view_size.width() > view_size_.width() || |
75 view_size.height() > view_size_.height()) { | 76 view_size.height() > view_size_.height()) { |
76 LOG(INFO) << "Existing buffer is too small"; | 77 LOG(INFO) << "Existing buffer is too small"; |
77 view_size_ = view_size; | 78 view_size_ = view_size; |
78 | 79 |
79 // Manually destroy the old buffer before allocating a new one to prevent | 80 // Manually destroy the old buffer before allocating a new one to prevent |
80 // our memory footprint from temporarily ballooning. | 81 // our memory footprint from temporarily ballooning. |
81 buffer_scoped.reset(); | 82 buffer_scoped.reset(); |
82 AllocateBuffer(); | 83 AllocateBuffer(); |
83 } | 84 } |
84 | 85 |
85 // Supply |frame_producer_| with a buffer to render the next frame into. | 86 // Supply |frame_producer_| with a buffer to render the next frame into. |
86 if (!in_dtor_) | 87 if (!in_dtor_) |
87 frame_producer_->DrawBuffer(buffer_scoped.release()); | 88 frame_producer_->DrawBuffer(buffer_scoped.release()); |
88 } | 89 } |
89 | 90 |
90 void JniFrameConsumer::ReturnBuffer(webrtc::DesktopFrame* buffer) { | 91 void JniFrameConsumer::ReturnBuffer(webrtc::DesktopFrame* buffer) { |
91 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); | 92 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); |
92 LOG(INFO) << "Returning image buffer"; | 93 LOG(INFO) << "Returning image buffer"; |
93 delete buffer; | 94 delete buffer; |
94 } | 95 } |
95 | 96 |
96 void JniFrameConsumer::SetSourceSize(const SkISize& source_size, | 97 void JniFrameConsumer::SetSourceSize(const webrtc::DesktopSize& source_size, |
97 const SkIPoint& dpi) { | 98 const webrtc::DesktopVector& dpi) { |
98 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); | 99 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); |
99 | 100 |
100 // We currently render the desktop 1:1 and perform pan/zoom scaling | 101 // We currently render the desktop 1:1 and perform pan/zoom scaling |
101 // and cropping on the managed canvas. | 102 // and cropping on the managed canvas. |
102 view_size_ = source_size; | 103 view_size_ = source_size; |
103 clip_area_ = SkIRect::MakeSize(view_size_); | 104 clip_area_ = webrtc::DesktopRect::MakeSize(view_size_); |
104 frame_producer_->SetOutputSizeAndClip(view_size_, clip_area_); | 105 frame_producer_->SetOutputSizeAndClip(view_size_, clip_area_); |
105 | 106 |
106 // Unless being destructed, allocate buffer and start drawing frames onto it. | 107 // Unless being destructed, allocate buffer and start drawing frames onto it. |
107 frame_producer_->RequestReturnBuffers(base::Bind( | 108 frame_producer_->RequestReturnBuffers(base::Bind( |
108 &JniFrameConsumer::AllocateBuffer, base::Unretained(this))); | 109 &JniFrameConsumer::AllocateBuffer, base::Unretained(this))); |
109 } | 110 } |
110 | 111 |
111 void JniFrameConsumer::AllocateBuffer() { | 112 void JniFrameConsumer::AllocateBuffer() { |
112 // Only do anything if we're not being destructed. | 113 // Only do anything if we're not being destructed. |
113 if (!in_dtor_) { | 114 if (!in_dtor_) { |
114 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { | 115 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
115 jni_runtime_->display_task_runner()->PostTask(FROM_HERE, | 116 jni_runtime_->display_task_runner()->PostTask(FROM_HERE, |
116 base::Bind(&JniFrameConsumer::AllocateBuffer, | 117 base::Bind(&JniFrameConsumer::AllocateBuffer, |
117 base::Unretained(this))); | 118 base::Unretained(this))); |
118 return; | 119 return; |
119 } | 120 } |
120 | 121 |
121 DirectDesktopFrame* buffer = new DirectDesktopFrame(view_size_.width(), | 122 DirectDesktopFrame* buffer = new DirectDesktopFrame(view_size_.width(), |
122 view_size_.height()); | 123 view_size_.height()); |
123 | 124 |
124 // Update Java's reference to the buffer and record of its dimensions. | 125 // Update Java's reference to the buffer and record of its dimensions. |
125 jni_runtime_->UpdateImageBuffer(view_size_.width(), | 126 jni_runtime_->UpdateImageBuffer(view_size_.width(), |
126 view_size_.height(), | 127 view_size_.height(), |
127 buffer->buffer()); | 128 buffer->buffer()); |
128 | 129 |
129 frame_producer_->DrawBuffer(buffer); | 130 frame_producer_->DrawBuffer(buffer); |
130 } | 131 } |
131 } | 132 } |
132 | 133 |
133 } // namespace remoting | 134 } // namespace remoting |
OLD | NEW |