| 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" | |
| 9 #include "remoting/client/plugin/chromoting_instance.h" | 8 #include "remoting/client/plugin/chromoting_instance.h" |
| 10 #include "remoting/client/plugin/pepper_util.h" | 9 #include "remoting/client/plugin/pepper_util.h" |
| 11 #include "third_party/ppapi/cpp/device_context_2d.h" | 10 #include "third_party/ppapi/cpp/device_context_2d.h" |
| 12 #include "third_party/ppapi/cpp/image_data.h" | 11 #include "third_party/ppapi/cpp/image_data.h" |
| 13 #include "third_party/ppapi/cpp/point.h" | 12 #include "third_party/ppapi/cpp/point.h" |
| 14 #include "third_party/ppapi/cpp/size.h" | 13 #include "third_party/ppapi/cpp/size.h" |
| 15 | 14 |
| 16 namespace remoting { | 15 namespace remoting { |
| 17 | 16 |
| 18 PepperView::PepperView(ChromotingInstance* instance) | 17 PepperView::PepperView(ChromotingInstance* instance) |
| 19 : instance_(instance), | 18 : instance_(instance), |
| 20 backing_store_width_(0), | |
| 21 backing_store_height_(0), | |
| 22 viewport_x_(0), | 19 viewport_x_(0), |
| 23 viewport_y_(0), | 20 viewport_y_(0), |
| 24 viewport_width_(0), | 21 viewport_width_(0), |
| 25 viewport_height_(0), | 22 viewport_height_(0), |
| 26 is_static_fill_(false), | 23 is_static_fill_(false), |
| 27 static_fill_color_(0) { | 24 static_fill_color_(0) { |
| 28 } | 25 } |
| 29 | 26 |
| 30 PepperView::~PepperView() { | 27 PepperView::~PepperView() { |
| 31 } | 28 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 56 | 53 |
| 57 if (is_static_fill_) { | 54 if (is_static_fill_) { |
| 58 for (int y = 0; y < image.size().height(); y++) { | 55 for (int y = 0; y < image.size().height(); y++) { |
| 59 for (int x = 0; x < image.size().width(); x++) { | 56 for (int x = 0; x < image.size().width(); x++) { |
| 60 *image.GetAddr32(pp::Point(x, y)) = static_fill_color_; | 57 *image.GetAddr32(pp::Point(x, y)) = static_fill_color_; |
| 61 } | 58 } |
| 62 } | 59 } |
| 63 } else if (frame_) { | 60 } else if (frame_) { |
| 64 uint32_t* frame_data = | 61 uint32_t* frame_data = |
| 65 reinterpret_cast<uint32_t*>(frame_->data(media::VideoFrame::kRGBPlane)); | 62 reinterpret_cast<uint32_t*>(frame_->data(media::VideoFrame::kRGBPlane)); |
| 66 int max_height = std::min(backing_store_height_, image.size().height()); | 63 int max_height = std::min(frame_height_, image.size().height()); |
| 67 int max_width = std::min(backing_store_width_, image.size().width()); | 64 int max_width = std::min(frame_width_, image.size().width()); |
| 68 for (int y = 0; y < max_height; y++) { | 65 for (int y = 0; y < max_height; y++) { |
| 69 for (int x = 0; x < max_width; x++) { | 66 for (int x = 0; x < max_width; x++) { |
| 70 // Force alpha to be set to 255. | 67 // Force alpha to be set to 255. |
| 71 *image.GetAddr32(pp::Point(x, y)) = | 68 *image.GetAddr32(pp::Point(x, y)) = |
| 72 frame_data[y*backing_store_width_ + x] | 0xFF000000; | 69 frame_data[y*frame_width_ + x] | 0xFF000000; |
| 73 } | 70 } |
| 74 } | 71 } |
| 75 } else { | 72 } else { |
| 76 // Nothing to paint. escape! | 73 // Nothing to paint. escape! |
| 77 // | 74 // |
| 78 // TODO(ajwong): This is an ugly control flow. fix. | 75 // TODO(ajwong): This is an ugly control flow. fix. |
| 79 return; | 76 return; |
| 80 } | 77 } |
| 81 device_context_.ReplaceContents(&image); | 78 device_context_.ReplaceContents(&image); |
| 82 device_context_.Flush(TaskToCompletionCallback( | 79 device_context_.Flush(TaskToCompletionCallback( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 125 } |
| 129 | 126 |
| 130 void PepperView::SetHostScreenSize(int width, int height) { | 127 void PepperView::SetHostScreenSize(int width, int height) { |
| 131 if (!instance_->CurrentlyOnPluginThread()) { | 128 if (!instance_->CurrentlyOnPluginThread()) { |
| 132 RunTaskOnPluginThread(NewRunnableMethod(this, | 129 RunTaskOnPluginThread(NewRunnableMethod(this, |
| 133 &PepperView::SetHostScreenSize, | 130 &PepperView::SetHostScreenSize, |
| 134 width, height)); | 131 width, height)); |
| 135 return; | 132 return; |
| 136 } | 133 } |
| 137 | 134 |
| 138 backing_store_width_ = width; | 135 frame_width_ = width; |
| 139 backing_store_height_ = height; | 136 frame_height_ = height; |
| 137 |
| 138 // Reset |frame_| - it will be recreated by the next update stream. |
| 139 frame_ = NULL; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PepperView::HandleBeginUpdateStream(HostMessage* msg) { | 142 void PepperView::HandleBeginUpdateStream(HostMessage* msg) { |
| 143 if (!instance_->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 // Make sure the |frame_| is initialized. |
| 153 // We lazily construct the decoder. | |
| 154 if (!decoder_.get()) { | |
| 155 decoder_.reset(new DecoderZlib()); | |
| 156 } | |
| 157 | |
| 158 if (!frame_) { | 153 if (!frame_) { |
| 159 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, | 154 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, |
| 160 backing_store_width_, | 155 frame_width_, frame_height_, |
| 161 backing_store_height_, | |
| 162 base::TimeDelta(), base::TimeDelta(), | 156 base::TimeDelta(), base::TimeDelta(), |
| 163 &frame_); | 157 &frame_); |
| 158 CHECK(frame_); |
| 164 } | 159 } |
| 165 | |
| 166 // Tell the decoder to do start decoding. | |
| 167 decoder_->BeginDecode(frame_, &update_rects_, | |
| 168 NewRunnableMethod(this, &PepperView::OnPartialDecodeDone), | |
| 169 NewRunnableMethod(this, &PepperView::OnDecodeDone)); | |
| 170 } | 160 } |
| 171 | 161 |
| 172 void PepperView::HandleUpdateStreamPacket(HostMessage* msg) { | 162 void PepperView::HandleUpdateStreamPacket(HostMessage* msg) { |
| 173 if (!instance_->CurrentlyOnPluginThread()) { | 163 if (!instance_->CurrentlyOnPluginThread()) { |
| 174 RunTaskOnPluginThread( | 164 RunTaskOnPluginThread( |
| 175 NewRunnableMethod(this, &PepperView::HandleUpdateStreamPacket, | 165 NewRunnableMethod(this, &PepperView::HandleUpdateStreamPacket, |
| 176 msg)); | 166 msg)); |
| 177 return; | 167 return; |
| 178 } | 168 } |
| 179 | 169 |
| 180 decoder_->PartialDecode(msg); | 170 // Lazily initialize the decoder. |
| 171 SetupDecoder(msg->update_stream_packet().begin_rect().encoding()); |
| 172 if (!decoder_->IsStarted()) { |
| 173 BeginDecoding(NewRunnableMethod(this, &PepperView::OnPartialDecodeDone), |
| 174 NewRunnableMethod(this, &PepperView::OnDecodeDone)); |
| 175 } |
| 176 |
| 177 Decode(msg); |
| 181 } | 178 } |
| 182 | 179 |
| 183 void PepperView::HandleEndUpdateStream(HostMessage* msg) { | 180 void PepperView::HandleEndUpdateStream(HostMessage* msg) { |
| 184 if (!instance_->CurrentlyOnPluginThread()) { | 181 if (!instance_->CurrentlyOnPluginThread()) { |
| 185 RunTaskOnPluginThread( | 182 RunTaskOnPluginThread( |
| 186 NewRunnableMethod(this, &PepperView::HandleEndUpdateStream, | 183 NewRunnableMethod(this, &PepperView::HandleEndUpdateStream, |
| 187 msg)); | 184 msg)); |
| 188 return; | 185 return; |
| 189 } | 186 } |
| 190 | 187 |
| 191 scoped_ptr<HostMessage> deleter(msg); | 188 scoped_ptr<HostMessage> deleter(msg); |
| 192 decoder_->EndDecode(); | 189 EndDecoding(); |
| 193 } | 190 } |
| 194 | 191 |
| 195 void PepperView::OnPaintDone() { | 192 void PepperView::OnPaintDone() { |
| 196 // TODO(ajwong):Probably should set some variable to allow repaints to | 193 // TODO(ajwong):Probably should set some variable to allow repaints to |
| 197 // actually paint. | 194 // actually paint. |
| 198 return; | 195 return; |
| 199 } | 196 } |
| 200 | 197 |
| 201 void PepperView::OnPartialDecodeDone() { | 198 void PepperView::OnPartialDecodeDone() { |
| 202 all_update_rects_.insert(all_update_rects_.begin() + | 199 all_update_rects_.insert(all_update_rects_.begin() + |
| 203 all_update_rects_.size(), | 200 all_update_rects_.size(), |
| 204 update_rects_.begin(), update_rects_.end()); | 201 update_rects_.begin(), update_rects_.end()); |
| 205 Paint(); | 202 Paint(); |
| 206 // TODO(ajwong): Need to block here to be synchronous. | 203 // TODO(ajwong): Need to block here to be synchronous. |
| 207 } | 204 } |
| 208 | 205 |
| 209 | 206 |
| 210 void PepperView::OnDecodeDone() { | 207 void PepperView::OnDecodeDone() { |
| 211 } | 208 } |
| 212 | 209 |
| 213 } // namespace remoting | 210 } // namespace remoting |
| OLD | NEW |