Chromium Code Reviews| 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_video_renderer_2d.h" | 5 #include "remoting/client/plugin/pepper_video_renderer_2d.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
| 16 #include "ppapi/cpp/completion_callback.h" | 16 #include "ppapi/cpp/completion_callback.h" |
| 17 #include "ppapi/cpp/image_data.h" | 17 #include "ppapi/cpp/image_data.h" |
| 18 #include "ppapi/cpp/instance.h" | 18 #include "ppapi/cpp/instance.h" |
| 19 #include "ppapi/cpp/point.h" | 19 #include "ppapi/cpp/point.h" |
| 20 #include "ppapi/cpp/rect.h" | 20 #include "ppapi/cpp/rect.h" |
| 21 #include "ppapi/cpp/size.h" | 21 #include "ppapi/cpp/size.h" |
| 22 #include "remoting/base/util.h" | 22 #include "remoting/base/util.h" |
| 23 #include "remoting/client/client_context.h" | 23 #include "remoting/client/client_context.h" |
| 24 #include "remoting/client/software_video_renderer.h" | |
| 25 #include "remoting/proto/video.pb.h" | 24 #include "remoting/proto/video.pb.h" |
| 26 #include "remoting/protocol/performance_tracker.h" | 25 #include "remoting/protocol/performance_tracker.h" |
| 27 #include "third_party/libyuv/include/libyuv/scale_argb.h" | 26 #include "third_party/libyuv/include/libyuv/scale_argb.h" |
| 28 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 27 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 29 | 28 |
| 30 namespace remoting { | 29 namespace remoting { |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 // DesktopFrame that wraps a supplied pp::ImageData | 33 // DesktopFrame that wraps a supplied pp::ImageData |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 48 return buffer_; | 47 return buffer_; |
| 49 } | 48 } |
| 50 | 49 |
| 51 private: | 50 private: |
| 52 pp::ImageData buffer_; | 51 pp::ImageData buffer_; |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 } // namespace | 54 } // namespace |
| 56 | 55 |
| 57 PepperVideoRenderer2D::PepperVideoRenderer2D() | 56 PepperVideoRenderer2D::PepperVideoRenderer2D() |
| 58 : callback_factory_(this), | 57 : software_video_renderer_(this), |
| 58 callback_factory_(this), | |
| 59 weak_factory_(this) {} | 59 weak_factory_(this) {} |
| 60 | 60 |
| 61 PepperVideoRenderer2D::~PepperVideoRenderer2D() {} | 61 PepperVideoRenderer2D::~PepperVideoRenderer2D() {} |
| 62 | 62 |
| 63 bool PepperVideoRenderer2D::Initialize( | 63 void PepperVideoRenderer2D::SetPepperContext( |
| 64 pp::Instance* instance, | 64 pp::Instance* instance, |
| 65 const ClientContext& context, | 65 EventHandler* event_handler) { |
| 66 EventHandler* event_handler, | |
| 67 protocol::PerformanceTracker* perf_tracker) { | |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | 66 DCHECK(thread_checker_.CalledOnValidThread()); |
| 69 DCHECK(!instance_); | 67 DCHECK(!instance_); |
| 70 DCHECK(!event_handler_); | 68 DCHECK(!event_handler_); |
| 71 DCHECK(instance); | 69 DCHECK(instance); |
| 72 DCHECK(event_handler); | 70 DCHECK(event_handler); |
| 73 | 71 |
| 74 instance_ = instance; | 72 instance_ = instance; |
| 75 event_handler_ = event_handler; | 73 event_handler_ = event_handler; |
| 76 software_video_renderer_.reset(new SoftwareVideoRenderer( | |
| 77 context.decode_task_runner(), this, perf_tracker)); | |
| 78 | |
| 79 return true; | |
| 80 } | 74 } |
| 81 | 75 |
| 82 void PepperVideoRenderer2D::OnViewChanged(const pp::View& view) { | 76 void PepperVideoRenderer2D::OnViewChanged(const pp::View& view) { |
| 83 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 84 | 78 |
| 85 pp::Rect pp_size = view.GetRect(); | 79 pp::Rect pp_size = view.GetRect(); |
| 86 view_size_ = webrtc::DesktopSize(pp_size.width(), pp_size.height()); | 80 view_size_ = webrtc::DesktopSize(pp_size.width(), pp_size.height()); |
| 87 | 81 |
| 88 // Update scale if graphics2d has been initialized. | 82 // Update scale if graphics2d has been initialized. |
| 89 if (!graphics2d_.is_null() && source_size_.width() > 0) { | 83 if (!graphics2d_.is_null() && source_size_.width() > 0) { |
| 90 graphics2d_.SetScale(static_cast<float>(view_size_.width()) / | 84 graphics2d_.SetScale(static_cast<float>(view_size_.width()) / |
| 91 source_size_.width()); | 85 source_size_.width()); |
| 92 | 86 |
| 93 // Bind graphics2d_ again after changing the scale to work around | 87 // Bind graphics2d_ again after changing the scale to work around |
| 94 // crbug.com/521745 . | 88 // crbug.com/521745 . |
| 95 instance_->BindGraphics(graphics2d_); | 89 instance_->BindGraphics(graphics2d_); |
| 96 bool result = instance_->BindGraphics(graphics2d_); | 90 bool result = instance_->BindGraphics(graphics2d_); |
| 97 DCHECK(result) << "Couldn't bind the device context."; | 91 DCHECK(result) << "Couldn't bind the device context."; |
| 98 } | 92 } |
| 99 } | 93 } |
| 100 | 94 |
| 101 void PepperVideoRenderer2D::EnableDebugDirtyRegion(bool enable) { | 95 void PepperVideoRenderer2D::EnableDebugDirtyRegion(bool enable) { |
| 102 debug_dirty_region_ = enable; | 96 debug_dirty_region_ = enable; |
| 103 } | 97 } |
| 104 | 98 |
| 99 bool PepperVideoRenderer2D::Initialize( | |
| 100 const ClientContext& client_context, | |
| 101 protocol::PerformanceTracker* perf_tracker) { | |
| 102 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 103 | |
| 104 software_video_renderer_.Initialize(client_context, perf_tracker); | |
|
Sergey Ulanov
2016/06/29 23:02:12
return the result.
Yuwei
2016/06/29 23:38:02
Done.
| |
| 105 | |
| 106 return true; | |
| 107 } | |
| 108 | |
| 105 void PepperVideoRenderer2D::OnSessionConfig( | 109 void PepperVideoRenderer2D::OnSessionConfig( |
| 106 const protocol::SessionConfig& config) { | 110 const protocol::SessionConfig& config) { |
| 107 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
| 108 | 112 |
| 109 software_video_renderer_->OnSessionConfig(config); | 113 software_video_renderer_.OnSessionConfig(config); |
| 110 } | 114 } |
| 111 | 115 |
| 112 protocol::VideoStub* PepperVideoRenderer2D::GetVideoStub() { | 116 protocol::VideoStub* PepperVideoRenderer2D::GetVideoStub() { |
| 113 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
| 114 | 118 |
| 115 return software_video_renderer_->GetVideoStub(); | 119 return software_video_renderer_.GetVideoStub(); |
| 116 } | 120 } |
| 117 | 121 |
| 118 protocol::FrameConsumer* PepperVideoRenderer2D::GetFrameConsumer() { | 122 protocol::FrameConsumer* PepperVideoRenderer2D::GetFrameConsumer() { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 123 DCHECK(thread_checker_.CalledOnValidThread()); |
| 120 | 124 |
| 121 return software_video_renderer_->GetFrameConsumer(); | 125 return software_video_renderer_.GetFrameConsumer(); |
| 122 } | 126 } |
| 123 | 127 |
| 124 std::unique_ptr<webrtc::DesktopFrame> PepperVideoRenderer2D::AllocateFrame( | 128 std::unique_ptr<webrtc::DesktopFrame> PepperVideoRenderer2D::AllocateFrame( |
| 125 const webrtc::DesktopSize& size) { | 129 const webrtc::DesktopSize& size) { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 130 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 | 131 |
| 128 pp::ImageData buffer_data(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 132 pp::ImageData buffer_data(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 129 pp::Size(size.width(), size.height()), false); | 133 pp::Size(size.width(), size.height()), false); |
| 130 return base::WrapUnique(new PepperDesktopFrame(buffer_data)); | 134 return base::WrapUnique(new PepperDesktopFrame(buffer_data)); |
| 131 } | 135 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 flush_pending_ = false; | 212 flush_pending_ = false; |
| 209 | 213 |
| 210 // Call all callbacks for the frames we've just flushed. | 214 // Call all callbacks for the frames we've just flushed. |
| 211 flushing_frames_done_callbacks_.clear(); | 215 flushing_frames_done_callbacks_.clear(); |
| 212 | 216 |
| 213 // Flush again if necessary. | 217 // Flush again if necessary. |
| 214 Flush(); | 218 Flush(); |
| 215 } | 219 } |
| 216 | 220 |
| 217 } // namespace remoting | 221 } // namespace remoting |
| OLD | NEW |