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

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

Issue 23440046: Remove dependency on Skia from chromoting client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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') | remoting/codec/codec_test.cc » ('j') | 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/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 13 matching lines...) Expand all
24 24
25 namespace remoting { 25 namespace remoting {
26 26
27 RectangleUpdateDecoder::RectangleUpdateDecoder( 27 RectangleUpdateDecoder::RectangleUpdateDecoder(
28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
29 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, 29 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner,
30 scoped_refptr<FrameConsumerProxy> consumer) 30 scoped_refptr<FrameConsumerProxy> consumer)
31 : main_task_runner_(main_task_runner), 31 : main_task_runner_(main_task_runner),
32 decode_task_runner_(decode_task_runner), 32 decode_task_runner_(decode_task_runner),
33 consumer_(consumer), 33 consumer_(consumer),
34 source_size_(SkISize::Make(0, 0)),
35 source_dpi_(SkIPoint::Make(0, 0)),
36 view_size_(SkISize::Make(0, 0)),
37 clip_area_(SkIRect::MakeEmpty()),
38 paint_scheduled_(false), 34 paint_scheduled_(false),
39 latest_sequence_number_(0) { 35 latest_sequence_number_(0) {
40 } 36 }
41 37
42 RectangleUpdateDecoder::~RectangleUpdateDecoder() { 38 RectangleUpdateDecoder::~RectangleUpdateDecoder() {
43 } 39 }
44 40
45 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) { 41 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) {
46 // Initialize decoder based on the selected codec. 42 // Initialize decoder based on the selected codec.
47 ChannelConfig::Codec codec = config.video_config().codec; 43 ChannelConfig::Codec codec = config.video_config().codec;
(...skipping 11 matching lines...) Expand all
59 DCHECK(decode_task_runner_->BelongsToCurrentThread()); 55 DCHECK(decode_task_runner_->BelongsToCurrentThread());
60 56
61 base::ScopedClosureRunner done_runner(done); 57 base::ScopedClosureRunner done_runner(done);
62 58
63 bool decoder_needs_reset = false; 59 bool decoder_needs_reset = false;
64 bool notify_size_or_dpi_change = false; 60 bool notify_size_or_dpi_change = false;
65 61
66 // If the packet includes screen size or DPI information, store them. 62 // If the packet includes screen size or DPI information, store them.
67 if (packet->format().has_screen_width() && 63 if (packet->format().has_screen_width() &&
68 packet->format().has_screen_height()) { 64 packet->format().has_screen_height()) {
69 SkISize source_size = SkISize::Make(packet->format().screen_width(), 65 webrtc::DesktopSize source_size(packet->format().screen_width(),
70 packet->format().screen_height()); 66 packet->format().screen_height());
71 if (source_size_ != source_size) { 67 if (!source_size_.equals(source_size)) {
72 source_size_ = source_size; 68 source_size_ = source_size;
73 decoder_needs_reset = true; 69 decoder_needs_reset = true;
74 notify_size_or_dpi_change = true; 70 notify_size_or_dpi_change = true;
75 } 71 }
76 } 72 }
77 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { 73 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) {
78 SkIPoint source_dpi(SkIPoint::Make(packet->format().x_dpi(), 74 webrtc::DesktopVector source_dpi(packet->format().x_dpi(),
79 packet->format().y_dpi())); 75 packet->format().y_dpi());
80 if (source_dpi != source_dpi_) { 76 if (!source_dpi.equals(source_dpi_)) {
81 source_dpi_ = source_dpi; 77 source_dpi_ = source_dpi;
82 notify_size_or_dpi_change = true; 78 notify_size_or_dpi_change = true;
83 } 79 }
84 } 80 }
85 81
86 // If we've never seen a screen size, ignore the packet. 82 // If we've never seen a screen size, ignore the packet.
87 if (source_size_.isZero()) 83 if (source_size_.is_empty())
88 return; 84 return;
89 85
90 if (decoder_needs_reset) 86 if (decoder_needs_reset)
91 decoder_->Initialize(source_size_); 87 decoder_->Initialize(source_size_);
92 if (notify_size_or_dpi_change) 88 if (notify_size_or_dpi_change)
93 consumer_->SetSourceSize(source_size_, source_dpi_); 89 consumer_->SetSourceSize(source_size_, source_dpi_);
94 90
95 if (decoder_->DecodePacket(*packet.get())) { 91 if (decoder_->DecodePacket(*packet.get())) {
96 SchedulePaint(); 92 SchedulePaint();
97 } else { 93 } else {
98 LOG(ERROR) << "DecodePacket() failed."; 94 LOG(ERROR) << "DecodePacket() failed.";
99 } 95 }
100 } 96 }
101 97
102 void RectangleUpdateDecoder::SchedulePaint() { 98 void RectangleUpdateDecoder::SchedulePaint() {
103 if (paint_scheduled_) 99 if (paint_scheduled_)
104 return; 100 return;
105 paint_scheduled_ = true; 101 paint_scheduled_ = true;
106 decode_task_runner_->PostTask( 102 decode_task_runner_->PostTask(
107 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DoPaint, this)); 103 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DoPaint, this));
108 } 104 }
109 105
110 void RectangleUpdateDecoder::DoPaint() { 106 void RectangleUpdateDecoder::DoPaint() {
111 DCHECK(paint_scheduled_); 107 DCHECK(paint_scheduled_);
112 paint_scheduled_ = false; 108 paint_scheduled_ = false;
113 109
114 // 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.
115 if (buffers_.empty() || view_size_.isEmpty()) 111 if (buffers_.empty() || view_size_.is_empty())
116 return; 112 return;
117 113
118 // If no Decoder is initialized, or the host dimensions are empty, return. 114 // If no Decoder is initialized, or the host dimensions are empty, return.
119 if (!decoder_.get() || source_size_.isEmpty()) 115 if (!decoder_.get() || source_size_.is_empty())
120 return; 116 return;
121 117
122 // Draw the invalidated region to the buffer. 118 // Draw the invalidated region to the buffer.
123 webrtc::DesktopFrame* buffer = buffers_.front(); 119 webrtc::DesktopFrame* buffer = buffers_.front();
124 SkRegion output_region; 120 webrtc::DesktopRegion output_region;
125 decoder_->RenderFrame(view_size_, clip_area_, 121 decoder_->RenderFrame(view_size_, clip_area_,
126 buffer->data(), 122 buffer->data(),
127 buffer->stride(), 123 buffer->stride(),
128 &output_region); 124 &output_region);
129 125
130 // Notify the consumer that painting is done. 126 // Notify the consumer that painting is done.
131 if (!output_region.isEmpty()) { 127 if (!output_region.is_empty()) {
132 buffers_.pop_front(); 128 buffers_.pop_front();
133 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region); 129 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region);
134 } 130 }
135 } 131 }
136 132
137 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) { 133 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) {
138 if (!decode_task_runner_->BelongsToCurrentThread()) { 134 if (!decode_task_runner_->BelongsToCurrentThread()) {
139 decode_task_runner_->PostTask( 135 decode_task_runner_->PostTask(
140 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers, 136 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers,
141 this, done)); 137 this, done));
(...skipping 17 matching lines...) Expand all
159 return; 155 return;
160 } 156 }
161 157
162 DCHECK(clip_area_.width() <= buffer->size().width() && 158 DCHECK(clip_area_.width() <= buffer->size().width() &&
163 clip_area_.height() <= buffer->size().height()); 159 clip_area_.height() <= buffer->size().height());
164 160
165 buffers_.push_back(buffer); 161 buffers_.push_back(buffer);
166 SchedulePaint(); 162 SchedulePaint();
167 } 163 }
168 164
169 void RectangleUpdateDecoder::InvalidateRegion(const SkRegion& region) { 165 void RectangleUpdateDecoder::InvalidateRegion(
166 const webrtc::DesktopRegion& region) {
170 if (!decode_task_runner_->BelongsToCurrentThread()) { 167 if (!decode_task_runner_->BelongsToCurrentThread()) {
171 decode_task_runner_->PostTask( 168 decode_task_runner_->PostTask(
172 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion, 169 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion,
173 this, region)); 170 this, region));
174 return; 171 return;
175 } 172 }
176 173
177 if (decoder_.get()) { 174 if (decoder_.get()) {
178 decoder_->Invalidate(view_size_, region); 175 decoder_->Invalidate(view_size_, region);
179 SchedulePaint(); 176 SchedulePaint();
180 } 177 }
181 } 178 }
182 179
183 void RectangleUpdateDecoder::SetOutputSizeAndClip(const SkISize& view_size, 180 void RectangleUpdateDecoder::SetOutputSizeAndClip(
184 const SkIRect& clip_area) { 181 const webrtc::DesktopSize& view_size,
182 const webrtc::DesktopRect& clip_area) {
185 if (!decode_task_runner_->BelongsToCurrentThread()) { 183 if (!decode_task_runner_->BelongsToCurrentThread()) {
186 decode_task_runner_->PostTask( 184 decode_task_runner_->PostTask(
187 FROM_HERE, base::Bind(&RectangleUpdateDecoder::SetOutputSizeAndClip, 185 FROM_HERE, base::Bind(&RectangleUpdateDecoder::SetOutputSizeAndClip,
188 this, view_size, clip_area)); 186 this, view_size, clip_area));
189 return; 187 return;
190 } 188 }
191 189
192 // The whole frame needs to be repainted if the scaling factor has changed. 190 // The whole frame needs to be repainted if the scaling factor has changed.
193 if (view_size_ != view_size && decoder_.get()) { 191 if (!view_size_.equals(view_size) && decoder_.get()) {
194 SkRegion region; 192 webrtc::DesktopRegion region;
195 region.op(SkIRect::MakeSize(view_size), SkRegion::kUnion_Op); 193 region.AddRect(webrtc::DesktopRect::MakeSize(view_size));
196 decoder_->Invalidate(view_size, region); 194 decoder_->Invalidate(view_size, region);
197 } 195 }
198 196
199 if (view_size_ != view_size || 197 if (!view_size_.equals(view_size) ||
200 clip_area_ != clip_area) { 198 !clip_area_.equals(clip_area)) {
201 view_size_ = view_size; 199 view_size_ = view_size;
202 clip_area_ = clip_area; 200 clip_area_ = clip_area;
203 201
204 // Return buffers that are smaller than needed to the consumer for 202 // Return buffers that are smaller than needed to the consumer for
205 // reuse/reallocation. 203 // reuse/reallocation.
206 std::list<webrtc::DesktopFrame*>::iterator i = buffers_.begin(); 204 std::list<webrtc::DesktopFrame*>::iterator i = buffers_.begin();
207 while (i != buffers_.end()) { 205 while (i != buffers_.end()) {
208 if ((*i)->size().width() < clip_area_.width() || 206 if ((*i)->size().width() < clip_area_.width() ||
209 (*i)->size().height() < clip_area_.height()) { 207 (*i)->size().height() < clip_area_.height()) {
210 consumer_->ReturnBuffer(*i); 208 consumer_->ReturnBuffer(*i);
211 i = buffers_.erase(i); 209 i = buffers_.erase(i);
212 } else { 210 } else {
213 ++i; 211 ++i;
214 } 212 }
215 } 213 }
216 214
217 SchedulePaint(); 215 SchedulePaint();
218 } 216 }
219 } 217 }
220 218
221 const SkRegion* RectangleUpdateDecoder::GetBufferShape() { 219 const webrtc::DesktopRegion* RectangleUpdateDecoder::GetBufferShape() {
222 return decoder_->GetImageShape(); 220 return decoder_->GetImageShape();
223 } 221 }
224 222
225 void RectangleUpdateDecoder::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, 223 void RectangleUpdateDecoder::ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
226 const base::Closure& done) { 224 const base::Closure& done) {
227 DCHECK(main_task_runner_->BelongsToCurrentThread()); 225 DCHECK(main_task_runner_->BelongsToCurrentThread());
228 226
229 // If the video packet is empty then drop it. Empty packets are used to 227 // If the video packet is empty then drop it. Empty packets are used to
230 // maintain activity on the network. 228 // maintain activity on the network.
231 if (!packet->has_data() || packet->data().size() == 0) { 229 if (!packet->has_data() || packet->data().size() == 0) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 275
278 done.Run(); 276 done.Run();
279 } 277 }
280 278
281 ChromotingStats* RectangleUpdateDecoder::GetStats() { 279 ChromotingStats* RectangleUpdateDecoder::GetStats() {
282 DCHECK(main_task_runner_->BelongsToCurrentThread()); 280 DCHECK(main_task_runner_->BelongsToCurrentThread());
283 return &stats_; 281 return &stats_;
284 } 282 }
285 283
286 } // namespace remoting 284 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/rectangle_update_decoder.h ('k') | remoting/codec/codec_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698