| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/graphics_2d.h" | 10 #include "ppapi/cpp/graphics_2d.h" |
| 11 #include "ppapi/cpp/image_data.h" | 11 #include "ppapi/cpp/image_data.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 if (host_size_ == host_size) | 103 if (host_size_ == host_size) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 host_size_ = host_size; | 106 host_size_ = host_size; |
| 107 | 107 |
| 108 // Submit an update of desktop size to Javascript. | 108 // Submit an update of desktop size to Javascript. |
| 109 instance_->GetScriptableObject()->SetDesktopSize( | 109 instance_->GetScriptableObject()->SetDesktopSize( |
| 110 host_size.width(), host_size.height()); | 110 host_size.width(), host_size.height()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void PepperView::PaintFrame(media::VideoFrame* frame, const SkRegion& region) { | 113 void PepperView::PaintFrame(media::VideoFrame* frame, RectVector* rects) { |
| 114 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); | 114 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); |
| 115 | 115 |
| 116 SetHostSize(SkISize::Make(frame->width(), frame->height())); | 116 SetHostSize(SkISize::Make(frame->width(), frame->height())); |
| 117 | 117 |
| 118 if (!backing_store_.get() || backing_store_->is_null()) { | 118 if (!backing_store_.get() || backing_store_->is_null()) { |
| 119 LOG(ERROR) << "Backing store is not available."; | 119 LOG(ERROR) << "Backing store is not available."; |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 base::Time start_time = base::Time::Now(); | 123 base::Time start_time = base::Time::Now(); |
| 124 | 124 |
| 125 // Copy updated regions to the backing store and then paint the regions. | 125 // Copy updated regions to the backing store and then paint the regions. |
| 126 bool changes_made = false; | 126 bool changes_made = false; |
| 127 for (SkRegion::Iterator i(region); !i.done(); i.next()) | 127 for (size_t i = 0; i < rects->size(); ++i) |
| 128 changes_made |= PaintRect(frame, i.rect()); | 128 changes_made |= PaintRect(frame, (*rects)[i]); |
| 129 | 129 |
| 130 if (changes_made) | 130 if (changes_made) |
| 131 FlushGraphics(start_time); | 131 FlushGraphics(start_time); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool PepperView::PaintRect(media::VideoFrame* frame, const SkIRect& r) { | 134 bool PepperView::PaintRect(media::VideoFrame* frame, const SkIRect& r) { |
| 135 const uint8* frame_data = frame->data(media::VideoFrame::kRGBPlane); | 135 const uint8* frame_data = frame->data(media::VideoFrame::kRGBPlane); |
| 136 const int kFrameStride = frame->stride(media::VideoFrame::kRGBPlane); | 136 const int kFrameStride = frame->stride(media::VideoFrame::kRGBPlane); |
| 137 const int kBytesPerPixel = GetBytesPerPixel(media::VideoFrame::RGB32); | 137 const int kBytesPerPixel = GetBytesPerPixel(media::VideoFrame::RGB32); |
| 138 | 138 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 } | 306 } |
| 307 | 307 |
| 308 void PepperView::ReleaseFrame(media::VideoFrame* frame) { | 308 void PepperView::ReleaseFrame(media::VideoFrame* frame) { |
| 309 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); | 309 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); |
| 310 | 310 |
| 311 if (frame) | 311 if (frame) |
| 312 frame->Release(); | 312 frame->Release(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void PepperView::OnPartialFrameOutput(media::VideoFrame* frame, | 315 void PepperView::OnPartialFrameOutput(media::VideoFrame* frame, |
| 316 SkRegion* region, | 316 RectVector* rects, |
| 317 const base::Closure& done) { | 317 const base::Closure& done) { |
| 318 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); | 318 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); |
| 319 | 319 |
| 320 // TODO(ajwong): Clean up this API to be async so we don't need to use a | 320 // TODO(ajwong): Clean up this API to be async so we don't need to use a |
| 321 // member variable as a hack. | 321 // member variable as a hack. |
| 322 PaintFrame(frame, *region); | 322 PaintFrame(frame, rects); |
| 323 done.Run(); | 323 done.Run(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void PepperView::OnPaintDone(base::Time paint_start) { | 326 void PepperView::OnPaintDone(base::Time paint_start) { |
| 327 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); | 327 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); |
| 328 instance_->GetStats()->video_paint_ms()->Record( | 328 instance_->GetStats()->video_paint_ms()->Record( |
| 329 (base::Time::Now() - paint_start).InMilliseconds()); | 329 (base::Time::Now() - paint_start).InMilliseconds()); |
| 330 | 330 |
| 331 // If the last flush failed because there was already another one in progress | 331 // If the last flush failed because there was already another one in progress |
| 332 // then we perform the flush now. | 332 // then we perform the flush now. |
| 333 if (flush_blocked_) | 333 if (flush_blocked_) |
| 334 FlushGraphics(base::Time::Now()); | 334 FlushGraphics(base::Time::Now()); |
| 335 return; | 335 return; |
| 336 } | 336 } |
| 337 | 337 |
| 338 } // namespace remoting | 338 } // namespace remoting |
| OLD | NEW |