| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "remoting/base/decoder_zlib.h" | 8 #include "remoting/base/decoder_zlib.h" |
| 9 #include "remoting/client/plugin/chromoting_plugin.h" | 9 #include "remoting/client/plugin/chromoting_instance.h" |
| 10 #include "remoting/client/plugin/pepper_util.h" | 10 #include "remoting/client/plugin/pepper_util.h" |
| 11 #include "third_party/ppapi/cpp/device_context_2d.h" | 11 #include "third_party/ppapi/cpp/device_context_2d.h" |
| 12 #include "third_party/ppapi/cpp/image_data.h" | 12 #include "third_party/ppapi/cpp/image_data.h" |
| 13 #include "third_party/ppapi/cpp/point.h" | 13 #include "third_party/ppapi/cpp/point.h" |
| 14 #include "third_party/ppapi/cpp/size.h" | 14 #include "third_party/ppapi/cpp/size.h" |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 | 17 |
| 18 PepperView::PepperView(ChromotingPlugin* plugin) | 18 PepperView::PepperView(ChromotingInstance* instance) |
| 19 : plugin_(plugin), | 19 : instance_(instance), |
| 20 backing_store_width_(0), | 20 backing_store_width_(0), |
| 21 backing_store_height_(0), | 21 backing_store_height_(0), |
| 22 viewport_x_(0), | 22 viewport_x_(0), |
| 23 viewport_y_(0), | 23 viewport_y_(0), |
| 24 viewport_width_(0), | 24 viewport_width_(0), |
| 25 viewport_height_(0), | 25 viewport_height_(0), |
| 26 is_static_fill_(false), | 26 is_static_fill_(false), |
| 27 static_fill_color_(0) { | 27 static_fill_color_(0) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 PepperView::~PepperView() { | 30 PepperView::~PepperView() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 bool PepperView::Initialize() { | 33 bool PepperView::Initialize() { |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void PepperView::TearDown() { | 37 void PepperView::TearDown() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 void PepperView::Paint() { | 40 void PepperView::Paint() { |
| 41 if (!plugin_->CurrentlyOnPluginThread()) { | 41 if (!instance_->CurrentlyOnPluginThread()) { |
| 42 RunTaskOnPluginThread(NewRunnableMethod(this, &PepperView::Paint)); | 42 RunTaskOnPluginThread(NewRunnableMethod(this, &PepperView::Paint)); |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // TODO(ajwong): We're assuming the native format is BGRA_PREMUL below. This | 46 // TODO(ajwong): We're assuming the native format is BGRA_PREMUL below. This |
| 47 // is wrong. | 47 // is wrong. |
| 48 pp::ImageData image(pp::ImageData::GetNativeImageDataFormat(), | 48 pp::ImageData image(pp::ImageData::GetNativeImageDataFormat(), |
| 49 pp::Size(viewport_width_, viewport_height_), | 49 pp::Size(viewport_width_, viewport_height_), |
| 50 false); | 50 false); |
| 51 if (image.is_null()) { | 51 if (image.is_null()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 77 // | 77 // |
| 78 // TODO(ajwong): This is an ugly control flow. fix. | 78 // TODO(ajwong): This is an ugly control flow. fix. |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 device_context_.ReplaceContents(&image); | 81 device_context_.ReplaceContents(&image); |
| 82 device_context_.Flush(TaskToCompletionCallback( | 82 device_context_.Flush(TaskToCompletionCallback( |
| 83 NewRunnableMethod(this, &PepperView::OnPaintDone))); | 83 NewRunnableMethod(this, &PepperView::OnPaintDone))); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void PepperView::SetSolidFill(uint32 color) { | 86 void PepperView::SetSolidFill(uint32 color) { |
| 87 if (!plugin_->CurrentlyOnPluginThread()) { | 87 if (!instance_->CurrentlyOnPluginThread()) { |
| 88 RunTaskOnPluginThread( | 88 RunTaskOnPluginThread( |
| 89 NewRunnableMethod(this, &PepperView::SetSolidFill, color)); | 89 NewRunnableMethod(this, &PepperView::SetSolidFill, color)); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 | 92 |
| 93 is_static_fill_ = true; | 93 is_static_fill_ = true; |
| 94 static_fill_color_ = color; | 94 static_fill_color_ = color; |
| 95 } | 95 } |
| 96 | 96 |
| 97 void PepperView::UnsetSolidFill() { | 97 void PepperView::UnsetSolidFill() { |
| 98 if (!plugin_->CurrentlyOnPluginThread()) { | 98 if (!instance_->CurrentlyOnPluginThread()) { |
| 99 RunTaskOnPluginThread( | 99 RunTaskOnPluginThread( |
| 100 NewRunnableMethod(this, &PepperView::UnsetSolidFill)); | 100 NewRunnableMethod(this, &PepperView::UnsetSolidFill)); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 | 103 |
| 104 is_static_fill_ = false; | 104 is_static_fill_ = false; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void PepperView::SetViewport(int x, int y, int width, int height) { | 107 void PepperView::SetViewport(int x, int y, int width, int height) { |
| 108 if (!plugin_->CurrentlyOnPluginThread()) { | 108 if (!instance_->CurrentlyOnPluginThread()) { |
| 109 RunTaskOnPluginThread(NewRunnableMethod(this, &PepperView::SetViewport, | 109 RunTaskOnPluginThread(NewRunnableMethod(this, &PepperView::SetViewport, |
| 110 x, y, width, height)); | 110 x, y, width, height)); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // TODO(ajwong): Should we ignore x & y updates? What do those even mean? | 114 // TODO(ajwong): Should we ignore x & y updates? What do those even mean? |
| 115 | 115 |
| 116 // TODO(ajwong): What does viewport x, y mean to a plugin anyways? | 116 // TODO(ajwong): What does viewport x, y mean to a plugin anyways? |
| 117 viewport_x_ = x; | 117 viewport_x_ = x; |
| 118 viewport_y_ = y; | 118 viewport_y_ = y; |
| 119 viewport_width_ = width; | 119 viewport_width_ = width; |
| 120 viewport_height_ = height; | 120 viewport_height_ = height; |
| 121 | 121 |
| 122 device_context_ = | 122 device_context_ = |
| 123 pp::DeviceContext2D(pp::Size(viewport_width_, viewport_height_), false); | 123 pp::DeviceContext2D(pp::Size(viewport_width_, viewport_height_), false); |
| 124 if (!plugin_->BindGraphicsDeviceContext(device_context_)) { | 124 if (!instance_->BindGraphicsDeviceContext(device_context_)) { |
| 125 LOG(ERROR) << "Couldn't bind the device context."; | 125 LOG(ERROR) << "Couldn't bind the device context."; |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void PepperView::SetHostScreenSize(int width, int height) { | 130 void PepperView::SetHostScreenSize(int width, int height) { |
| 131 if (!plugin_->CurrentlyOnPluginThread()) { | 131 if (!instance_->CurrentlyOnPluginThread()) { |
| 132 RunTaskOnPluginThread(NewRunnableMethod(this, | 132 RunTaskOnPluginThread(NewRunnableMethod(this, |
| 133 &PepperView::SetHostScreenSize, | 133 &PepperView::SetHostScreenSize, |
| 134 width, height)); | 134 width, height)); |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 backing_store_width_ = width; | 138 backing_store_width_ = width; |
| 139 backing_store_height_ = height; | 139 backing_store_height_ = height; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PepperView::HandleBeginUpdateStream(HostMessage* msg) { | 142 void PepperView::HandleBeginUpdateStream(HostMessage* msg) { |
| 143 if (!plugin_->CurrentlyOnPluginThread()) { | 143 if (!instance_->CurrentlyOnPluginThread()) { |
| 144 RunTaskOnPluginThread( | 144 RunTaskOnPluginThread( |
| 145 NewRunnableMethod(this, &PepperView::HandleBeginUpdateStream, | 145 NewRunnableMethod(this, &PepperView::HandleBeginUpdateStream, |
| 146 msg)); | 146 msg)); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 | 149 |
| 150 scoped_ptr<HostMessage> deleter(msg); | 150 scoped_ptr<HostMessage> deleter(msg); |
| 151 | 151 |
| 152 // TODO(hclam): Use the information from the message to create the decoder. | 152 // TODO(hclam): Use the information from the message to create the decoder. |
| 153 // We lazily construct the decoder. | 153 // We lazily construct the decoder. |
| 154 if (!decoder_.get()) { | 154 if (!decoder_.get()) { |
| 155 decoder_.reset(new DecoderZlib()); | 155 decoder_.reset(new DecoderZlib()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 if (!frame_) { | 158 if (!frame_) { |
| 159 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, | 159 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, |
| 160 backing_store_width_, | 160 backing_store_width_, |
| 161 backing_store_height_, | 161 backing_store_height_, |
| 162 base::TimeDelta(), base::TimeDelta(), | 162 base::TimeDelta(), base::TimeDelta(), |
| 163 &frame_); | 163 &frame_); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Tell the decoder to do start decoding. | 166 // Tell the decoder to do start decoding. |
| 167 decoder_->BeginDecode(frame_, &update_rects_, | 167 decoder_->BeginDecode(frame_, &update_rects_, |
| 168 NewRunnableMethod(this, &PepperView::OnPartialDecodeDone), | 168 NewRunnableMethod(this, &PepperView::OnPartialDecodeDone), |
| 169 NewRunnableMethod(this, &PepperView::OnDecodeDone)); | 169 NewRunnableMethod(this, &PepperView::OnDecodeDone)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void PepperView::HandleUpdateStreamPacket(HostMessage* msg) { | 172 void PepperView::HandleUpdateStreamPacket(HostMessage* msg) { |
| 173 if (!plugin_->CurrentlyOnPluginThread()) { | 173 if (!instance_->CurrentlyOnPluginThread()) { |
| 174 RunTaskOnPluginThread( | 174 RunTaskOnPluginThread( |
| 175 NewRunnableMethod(this, &PepperView::HandleUpdateStreamPacket, | 175 NewRunnableMethod(this, &PepperView::HandleUpdateStreamPacket, |
| 176 msg)); | 176 msg)); |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 decoder_->PartialDecode(msg); | 180 decoder_->PartialDecode(msg); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void PepperView::HandleEndUpdateStream(HostMessage* msg) { | 183 void PepperView::HandleEndUpdateStream(HostMessage* msg) { |
| 184 if (!plugin_->CurrentlyOnPluginThread()) { | 184 if (!instance_->CurrentlyOnPluginThread()) { |
| 185 RunTaskOnPluginThread( | 185 RunTaskOnPluginThread( |
| 186 NewRunnableMethod(this, &PepperView::HandleEndUpdateStream, | 186 NewRunnableMethod(this, &PepperView::HandleEndUpdateStream, |
| 187 msg)); | 187 msg)); |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 | 190 |
| 191 scoped_ptr<HostMessage> deleter(msg); | 191 scoped_ptr<HostMessage> deleter(msg); |
| 192 decoder_->EndDecode(); | 192 decoder_->EndDecode(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void PepperView::OnPaintDone() { | 195 void PepperView::OnPaintDone() { |
| 196 // TODO(ajwong):Probably should set some variable to allow repaints to | 196 // TODO(ajwong):Probably should set some variable to allow repaints to |
| 197 // actually paint. | 197 // actually paint. |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void PepperView::OnPartialDecodeDone() { | 201 void PepperView::OnPartialDecodeDone() { |
| 202 all_update_rects_.insert(all_update_rects_.begin() + | 202 all_update_rects_.insert(all_update_rects_.begin() + |
| 203 all_update_rects_.size(), | 203 all_update_rects_.size(), |
| 204 update_rects_.begin(), update_rects_.end()); | 204 update_rects_.begin(), update_rects_.end()); |
| 205 Paint(); | 205 Paint(); |
| 206 // TODO(ajwong): Need to block here to be synchronous. | 206 // TODO(ajwong): Need to block here to be synchronous. |
| 207 } | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 void PepperView::OnDecodeDone() { | 210 void PepperView::OnDecodeDone() { |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace remoting | 213 } // namespace remoting |
| OLD | NEW |