| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/client/plugin/pepper_view_proxy.h" | |
| 6 | |
| 7 #include "base/message_loop.h" | |
| 8 #include "remoting/client/client_context.h" | |
| 9 #include "remoting/client/plugin/chromoting_instance.h" | |
| 10 | |
| 11 namespace remoting { | |
| 12 | |
| 13 PepperViewProxy::PepperViewProxy(ChromotingInstance* instance, PepperView* view, | |
| 14 base::MessageLoopProxy* plugin_message_loop) | |
| 15 : instance_(instance), | |
| 16 view_(view), | |
| 17 plugin_message_loop_(plugin_message_loop) { | |
| 18 } | |
| 19 | |
| 20 PepperViewProxy::~PepperViewProxy() { | |
| 21 } | |
| 22 | |
| 23 bool PepperViewProxy::Initialize() { | |
| 24 // This method needs a return value so we can't post a task and process on | |
| 25 // another thread so just return true since PepperView doesn't do anything | |
| 26 // either. | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 30 void PepperViewProxy::TearDown() { | |
| 31 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 32 plugin_message_loop_->PostTask( | |
| 33 FROM_HERE, base::Bind(&PepperViewProxy::TearDown, this)); | |
| 34 return; | |
| 35 } | |
| 36 | |
| 37 if (view_) | |
| 38 view_->TearDown(); | |
| 39 } | |
| 40 | |
| 41 void PepperViewProxy::Paint() { | |
| 42 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 43 plugin_message_loop_->PostTask( | |
| 44 FROM_HERE, base::Bind(&PepperViewProxy::Paint, this)); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 if (view_) | |
| 49 view_->Paint(); | |
| 50 } | |
| 51 | |
| 52 void PepperViewProxy::SetSolidFill(uint32 color) { | |
| 53 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 54 plugin_message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 55 &PepperViewProxy::SetSolidFill, this, color)); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 if (view_) | |
| 60 view_->SetSolidFill(color); | |
| 61 } | |
| 62 | |
| 63 void PepperViewProxy::UnsetSolidFill() { | |
| 64 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 65 plugin_message_loop_->PostTask( | |
| 66 FROM_HERE, base::Bind(&PepperViewProxy::UnsetSolidFill, this)); | |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 if (view_) | |
| 71 view_->UnsetSolidFill(); | |
| 72 } | |
| 73 | |
| 74 void PepperViewProxy::SetConnectionState( | |
| 75 protocol::ConnectionToHost::State state, | |
| 76 protocol::ConnectionToHost::Error error) { | |
| 77 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 78 plugin_message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 79 &PepperViewProxy::SetConnectionState, this, state, error)); | |
| 80 return; | |
| 81 } | |
| 82 | |
| 83 if (view_) | |
| 84 view_->SetConnectionState(state, error); | |
| 85 } | |
| 86 | |
| 87 double PepperViewProxy::GetHorizontalScaleRatio() const { | |
| 88 // This method returns a value, so must run synchronously, so must be | |
| 89 // called only on the pepper thread. | |
| 90 DCHECK(plugin_message_loop_->BelongsToCurrentThread()); | |
| 91 | |
| 92 if (view_) | |
| 93 return view_->GetHorizontalScaleRatio(); | |
| 94 return 1.0; | |
| 95 } | |
| 96 | |
| 97 double PepperViewProxy::GetVerticalScaleRatio() const { | |
| 98 // This method returns a value, so must run synchronously, so must be | |
| 99 // called only on the pepper thread. | |
| 100 DCHECK(plugin_message_loop_->BelongsToCurrentThread()); | |
| 101 | |
| 102 if (view_) | |
| 103 return view_->GetVerticalScaleRatio(); | |
| 104 return 1.0; | |
| 105 } | |
| 106 | |
| 107 void PepperViewProxy::AllocateFrame( | |
| 108 media::VideoFrame::Format format, | |
| 109 const SkISize& size, | |
| 110 scoped_refptr<media::VideoFrame>* frame_out, | |
| 111 const base::Closure& done) { | |
| 112 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 113 plugin_message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 114 &PepperViewProxy::AllocateFrame, this, format, size, frame_out, done)); | |
| 115 return; | |
| 116 } | |
| 117 | |
| 118 if (view_) { | |
| 119 view_->AllocateFrame(format, size, frame_out, done); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 void PepperViewProxy::ReleaseFrame(media::VideoFrame* frame) { | |
| 124 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 125 plugin_message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 126 &PepperViewProxy::ReleaseFrame, this, make_scoped_refptr(frame))); | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 if (view_) | |
| 131 view_->ReleaseFrame(frame); | |
| 132 } | |
| 133 | |
| 134 void PepperViewProxy::OnPartialFrameOutput(media::VideoFrame* frame, | |
| 135 RectVector* rects, | |
| 136 const base::Closure& done) { | |
| 137 if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) { | |
| 138 plugin_message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 139 &PepperViewProxy::OnPartialFrameOutput, this, | |
| 140 make_scoped_refptr(frame), rects, done)); | |
| 141 return; | |
| 142 } | |
| 143 | |
| 144 if (view_) | |
| 145 view_->OnPartialFrameOutput(frame, rects, done); | |
| 146 } | |
| 147 | |
| 148 void PepperViewProxy::Detach() { | |
| 149 DCHECK(plugin_message_loop_->BelongsToCurrentThread()); | |
| 150 instance_ = NULL; | |
| 151 view_ = NULL; | |
| 152 } | |
| 153 | |
| 154 } // namespace remoting | |
| OLD | NEW |