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/plugin/pepper_view.h" | 5 #include "remoting/client/plugin/pepper_view.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 if (view_changed) { | 158 if (view_changed) { |
159 producer_->SetOutputSizeAndClip(view_size_, clip_area_); | 159 producer_->SetOutputSizeAndClip(view_size_, clip_area_); |
160 Initialize(producer_); | 160 Initialize(producer_); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 void PepperView::ApplyBuffer(const webrtc::DesktopSize& view_size, | 164 void PepperView::ApplyBuffer(const webrtc::DesktopSize& view_size, |
165 const webrtc::DesktopRect& clip_area, | 165 const webrtc::DesktopRect& clip_area, |
166 webrtc::DesktopFrame* buffer, | 166 webrtc::DesktopFrame* buffer, |
167 const webrtc::DesktopRegion& region) { | 167 const webrtc::DesktopRegion& region, |
| 168 const webrtc::DesktopRegion& shape) { |
168 DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); | 169 DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); |
169 | 170 |
170 if (!frame_received_) { | 171 if (!frame_received_) { |
171 instance_->OnFirstFrameReceived(); | 172 instance_->OnFirstFrameReceived(); |
172 frame_received_ = true; | 173 frame_received_ = true; |
173 } | 174 } |
174 // We cannot use the data in the buffer if its dimensions don't match the | 175 // We cannot use the data in the buffer if its dimensions don't match the |
175 // current view size. | 176 // current view size. |
176 // TODO(alexeypa): We could rescale and draw it (or even draw it without | 177 // TODO(alexeypa): We could rescale and draw it (or even draw it without |
177 // rescaling) to reduce the perceived lag while we are waiting for | 178 // rescaling) to reduce the perceived lag while we are waiting for |
178 // the properly scaled data. | 179 // the properly scaled data. |
179 if (!view_size_.equals(view_size)) { | 180 if (!view_size_.equals(view_size)) { |
180 FreeBuffer(buffer); | 181 FreeBuffer(buffer); |
181 Initialize(producer_); | 182 Initialize(producer_); |
182 } else { | 183 } else { |
183 FlushBuffer(clip_area, buffer, region); | 184 FlushBuffer(clip_area, buffer, region); |
| 185 instance_->SetDesktopShape(shape); |
184 } | 186 } |
185 } | 187 } |
186 | 188 |
187 void PepperView::ReturnBuffer(webrtc::DesktopFrame* buffer) { | 189 void PepperView::ReturnBuffer(webrtc::DesktopFrame* buffer) { |
188 DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); | 190 DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); |
189 | 191 |
190 // Reuse the buffer if it is large enough, otherwise drop it on the floor | 192 // Reuse the buffer if it is large enough, otherwise drop it on the floor |
191 // and allocate a new one. | 193 // and allocate a new one. |
192 if (buffer->size().width() >= clip_area_.width() && | 194 if (buffer->size().width() >= clip_area_.width() && |
193 buffer->size().height() >= clip_area_.height()) { | 195 buffer->size().height() >= clip_area_.height()) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 298 } |
297 | 299 |
298 // Flush the updated areas to the screen. | 300 // Flush the updated areas to the screen. |
299 pp::CompletionCallback callback = | 301 pp::CompletionCallback callback = |
300 callback_factory_.NewCallback(&PepperView::OnFlushDone, | 302 callback_factory_.NewCallback(&PepperView::OnFlushDone, |
301 start_time, | 303 start_time, |
302 buffer); | 304 buffer); |
303 int error = graphics2d_.Flush(callback); | 305 int error = graphics2d_.Flush(callback); |
304 CHECK(error == PP_OK_COMPLETIONPENDING); | 306 CHECK(error == PP_OK_COMPLETIONPENDING); |
305 flush_pending_ = true; | 307 flush_pending_ = true; |
306 | |
307 // If the buffer we just rendered has a shape then pass that to JavaScript. | |
308 const webrtc::DesktopRegion* buffer_shape = producer_->GetBufferShape(); | |
309 if (buffer_shape) | |
310 instance_->SetDesktopShape(*buffer_shape); | |
311 } | 308 } |
312 | 309 |
313 void PepperView::OnFlushDone(int result, | 310 void PepperView::OnFlushDone(int result, |
314 const base::Time& paint_start, | 311 const base::Time& paint_start, |
315 webrtc::DesktopFrame* buffer) { | 312 webrtc::DesktopFrame* buffer) { |
316 DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); | 313 DCHECK(context_->main_task_runner()->BelongsToCurrentThread()); |
317 DCHECK(flush_pending_); | 314 DCHECK(flush_pending_); |
318 | 315 |
319 instance_->GetStats()->video_paint_ms()->Record( | 316 instance_->GetStats()->video_paint_ms()->Record( |
320 (base::Time::Now() - paint_start).InMilliseconds()); | 317 (base::Time::Now() - paint_start).InMilliseconds()); |
321 | 318 |
322 flush_pending_ = false; | 319 flush_pending_ = false; |
323 ReturnBuffer(buffer); | 320 ReturnBuffer(buffer); |
324 | 321 |
325 // If there is a buffer queued for rendering then render it now. | 322 // If there is a buffer queued for rendering then render it now. |
326 if (merge_buffer_ != NULL) { | 323 if (merge_buffer_ != NULL) { |
327 buffer = merge_buffer_; | 324 buffer = merge_buffer_; |
328 merge_buffer_ = NULL; | 325 merge_buffer_ = NULL; |
329 FlushBuffer(merge_clip_area_, buffer, merge_region_); | 326 FlushBuffer(merge_clip_area_, buffer, merge_region_); |
330 } | 327 } |
331 } | 328 } |
332 | 329 |
333 } // namespace remoting | 330 } // namespace remoting |
OLD | NEW |