Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: remoting/client/rectangle_update_decoder.cc

Issue 10454018: MessageLoopProxy cleanups in remoting client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/client/rectangle_update_decoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/rectangle_update_decoder.h" 5 #include "remoting/client/rectangle_update_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "ppapi/cpp/image_data.h" 13 #include "ppapi/cpp/image_data.h"
14 #include "remoting/base/decoder.h" 14 #include "remoting/base/decoder.h"
15 #include "remoting/base/decoder_row_based.h" 15 #include "remoting/base/decoder_row_based.h"
16 #include "remoting/base/decoder_vp8.h" 16 #include "remoting/base/decoder_vp8.h"
17 #include "remoting/base/util.h" 17 #include "remoting/base/util.h"
18 #include "remoting/client/frame_consumer.h" 18 #include "remoting/client/frame_consumer.h"
19 #include "remoting/protocol/session_config.h" 19 #include "remoting/protocol/session_config.h"
20 20
21 using base::Passed; 21 using base::Passed;
22 using remoting::protocol::ChannelConfig; 22 using remoting::protocol::ChannelConfig;
23 using remoting::protocol::SessionConfig; 23 using remoting::protocol::SessionConfig;
24 24
25 namespace remoting { 25 namespace remoting {
26 26
27 RectangleUpdateDecoder::RectangleUpdateDecoder( 27 RectangleUpdateDecoder::RectangleUpdateDecoder(
28 scoped_refptr<base::MessageLoopProxy> message_loop, 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
29 scoped_refptr<FrameConsumerProxy> consumer) 29 scoped_refptr<FrameConsumerProxy> consumer)
30 : message_loop_(message_loop), 30 : task_runner_(task_runner),
31 consumer_(consumer), 31 consumer_(consumer),
32 source_size_(SkISize::Make(0, 0)), 32 source_size_(SkISize::Make(0, 0)),
33 view_size_(SkISize::Make(0, 0)), 33 view_size_(SkISize::Make(0, 0)),
34 clip_area_(SkIRect::MakeEmpty()), 34 clip_area_(SkIRect::MakeEmpty()),
35 paint_scheduled_(false) { 35 paint_scheduled_(false) {
36 } 36 }
37 37
38 RectangleUpdateDecoder::~RectangleUpdateDecoder() { 38 RectangleUpdateDecoder::~RectangleUpdateDecoder() {
39 } 39 }
40 40
41 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) { 41 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) {
42 // Initialize decoder based on the selected codec. 42 // Initialize decoder based on the selected codec.
43 ChannelConfig::Codec codec = config.video_config().codec; 43 ChannelConfig::Codec codec = config.video_config().codec;
44 if (codec == ChannelConfig::CODEC_VERBATIM) { 44 if (codec == ChannelConfig::CODEC_VERBATIM) {
45 decoder_.reset(DecoderRowBased::CreateVerbatimDecoder()); 45 decoder_.reset(DecoderRowBased::CreateVerbatimDecoder());
46 } else if (codec == ChannelConfig::CODEC_ZIP) { 46 } else if (codec == ChannelConfig::CODEC_ZIP) {
47 decoder_.reset(DecoderRowBased::CreateZlibDecoder()); 47 decoder_.reset(DecoderRowBased::CreateZlibDecoder());
48 } else if (codec == ChannelConfig::CODEC_VP8) { 48 } else if (codec == ChannelConfig::CODEC_VP8) {
49 decoder_.reset(new DecoderVp8()); 49 decoder_.reset(new DecoderVp8());
50 } else { 50 } else {
51 NOTREACHED() << "Invalid Encoding found: " << codec; 51 NOTREACHED() << "Invalid Encoding found: " << codec;
52 } 52 }
53 } 53 }
54 54
55 void RectangleUpdateDecoder::DecodePacket(scoped_ptr<VideoPacket> packet, 55 void RectangleUpdateDecoder::DecodePacket(scoped_ptr<VideoPacket> packet,
56 const base::Closure& done) { 56 const base::Closure& done) {
57 if (!message_loop_->BelongsToCurrentThread()) { 57 if (!task_runner_->BelongsToCurrentThread()) {
58 message_loop_->PostTask( 58 task_runner_->PostTask(
59 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DecodePacket, 59 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DecodePacket,
60 this, base::Passed(&packet), done)); 60 this, base::Passed(&packet), done));
61 return; 61 return;
62 } 62 }
63 63
64 base::ScopedClosureRunner done_runner(done); 64 base::ScopedClosureRunner done_runner(done);
65 bool decoder_needs_reset = false; 65 bool decoder_needs_reset = false;
66 66
67 // If the packet includes a screen size, store it. 67 // If the packet includes a screen size, store it.
68 if (packet->format().has_screen_width() && 68 if (packet->format().has_screen_width() &&
(...skipping 23 matching lines...) Expand all
92 } 92 }
93 93
94 if (decoder_->DecodePacket(packet.get()) == Decoder::DECODE_DONE) 94 if (decoder_->DecodePacket(packet.get()) == Decoder::DECODE_DONE)
95 SchedulePaint(); 95 SchedulePaint();
96 } 96 }
97 97
98 void RectangleUpdateDecoder::SchedulePaint() { 98 void RectangleUpdateDecoder::SchedulePaint() {
99 if (paint_scheduled_) 99 if (paint_scheduled_)
100 return; 100 return;
101 paint_scheduled_ = true; 101 paint_scheduled_ = true;
102 message_loop_->PostTask( 102 task_runner_->PostTask(
103 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DoPaint, this)); 103 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DoPaint, this));
104 } 104 }
105 105
106 void RectangleUpdateDecoder::DoPaint() { 106 void RectangleUpdateDecoder::DoPaint() {
107 DCHECK(paint_scheduled_); 107 DCHECK(paint_scheduled_);
108 paint_scheduled_ = false; 108 paint_scheduled_ = false;
109 109
110 // If the view size is empty or we have no output buffers ready, return. 110 // If the view size is empty or we have no output buffers ready, return.
111 if (buffers_.empty() || view_size_.isEmpty()) 111 if (buffers_.empty() || view_size_.isEmpty())
112 return; 112 return;
(...skipping 11 matching lines...) Expand all
124 &output_region); 124 &output_region);
125 125
126 // Notify the consumer that painting is done. 126 // Notify the consumer that painting is done.
127 if (!output_region.isEmpty()) { 127 if (!output_region.isEmpty()) {
128 buffers_.pop_front(); 128 buffers_.pop_front();
129 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region); 129 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region);
130 } 130 }
131 } 131 }
132 132
133 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) { 133 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) {
134 if (!message_loop_->BelongsToCurrentThread()) { 134 if (!task_runner_->BelongsToCurrentThread()) {
135 message_loop_->PostTask( 135 task_runner_->PostTask(
136 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers, 136 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers,
137 this, done)); 137 this, done));
138 return; 138 return;
139 } 139 }
140 140
141 while (!buffers_.empty()) { 141 while (!buffers_.empty()) {
142 consumer_->ReturnBuffer(buffers_.front()); 142 consumer_->ReturnBuffer(buffers_.front());
143 buffers_.pop_front(); 143 buffers_.pop_front();
144 } 144 }
145 145
146 if (!done.is_null()) 146 if (!done.is_null())
147 done.Run(); 147 done.Run();
148 } 148 }
149 149
150 void RectangleUpdateDecoder::DrawBuffer(pp::ImageData* buffer) { 150 void RectangleUpdateDecoder::DrawBuffer(pp::ImageData* buffer) {
151 if (!message_loop_->BelongsToCurrentThread()) { 151 if (!task_runner_->BelongsToCurrentThread()) {
152 message_loop_->PostTask( 152 task_runner_->PostTask(
153 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DrawBuffer, 153 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DrawBuffer,
154 this, buffer)); 154 this, buffer));
155 return; 155 return;
156 } 156 }
157 157
158 DCHECK(clip_area_.width() <= buffer->size().width() && 158 DCHECK(clip_area_.width() <= buffer->size().width() &&
159 clip_area_.height() <= buffer->size().height()); 159 clip_area_.height() <= buffer->size().height());
160 160
161 buffers_.push_back(buffer); 161 buffers_.push_back(buffer);
162 SchedulePaint(); 162 SchedulePaint();
163 } 163 }
164 164
165 void RectangleUpdateDecoder::InvalidateRegion(const SkRegion& region) { 165 void RectangleUpdateDecoder::InvalidateRegion(const SkRegion& region) {
166 if (!message_loop_->BelongsToCurrentThread()) { 166 if (!task_runner_->BelongsToCurrentThread()) {
167 message_loop_->PostTask( 167 task_runner_->PostTask(
168 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion, 168 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion,
169 this, region)); 169 this, region));
170 return; 170 return;
171 } 171 }
172 172
173 if (decoder_.get()) { 173 if (decoder_.get()) {
174 decoder_->Invalidate(view_size_, region); 174 decoder_->Invalidate(view_size_, region);
175 SchedulePaint(); 175 SchedulePaint();
176 } 176 }
177 } 177 }
178 178
179 void RectangleUpdateDecoder::SetOutputSizeAndClip(const SkISize& view_size, 179 void RectangleUpdateDecoder::SetOutputSizeAndClip(const SkISize& view_size,
180 const SkIRect& clip_area) { 180 const SkIRect& clip_area) {
181 if (!message_loop_->BelongsToCurrentThread()) { 181 if (!task_runner_->BelongsToCurrentThread()) {
182 message_loop_->PostTask( 182 task_runner_->PostTask(
183 FROM_HERE, base::Bind(&RectangleUpdateDecoder::SetOutputSizeAndClip, 183 FROM_HERE, base::Bind(&RectangleUpdateDecoder::SetOutputSizeAndClip,
184 this, view_size, clip_area)); 184 this, view_size, clip_area));
185 return; 185 return;
186 } 186 }
187 187
188 // The whole frame needs to be repainted if the scaling factor has changed. 188 // The whole frame needs to be repainted if the scaling factor has changed.
189 if (view_size_ != view_size && decoder_.get()) { 189 if (view_size_ != view_size && decoder_.get()) {
190 SkRegion region; 190 SkRegion region;
191 region.op(SkIRect::MakeSize(view_size), SkRegion::kUnion_Op); 191 region.op(SkIRect::MakeSize(view_size), SkRegion::kUnion_Op);
192 decoder_->Invalidate(view_size, region); 192 decoder_->Invalidate(view_size, region);
(...skipping 16 matching lines...) Expand all
209 } else { 209 } else {
210 ++i; 210 ++i;
211 } 211 }
212 } 212 }
213 213
214 SchedulePaint(); 214 SchedulePaint();
215 } 215 }
216 } 216 }
217 217
218 } // namespace remoting 218 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/rectangle_update_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698