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

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

Issue 18233015: Abstract PPAPI's ImageData behind webrtc::DesktopFrame interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
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/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "ppapi/cpp/image_data.h"
14 #include "remoting/base/util.h" 13 #include "remoting/base/util.h"
15 #include "remoting/codec/video_decoder.h" 14 #include "remoting/codec/video_decoder.h"
16 #include "remoting/codec/video_decoder_verbatim.h" 15 #include "remoting/codec/video_decoder_verbatim.h"
17 #include "remoting/codec/video_decoder_vp8.h" 16 #include "remoting/codec/video_decoder_vp8.h"
18 #include "remoting/client/frame_consumer.h" 17 #include "remoting/client/frame_consumer.h"
18 #include "remoting/client/image_buffer.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::SingleThreadTaskRunner> main_task_runner, 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 // If the view size is empty or we have no output buffers ready, return. 117 // If the view size is empty or we have no output buffers ready, return.
118 if (buffers_.empty() || view_size_.isEmpty()) 118 if (buffers_.empty() || view_size_.isEmpty())
119 return; 119 return;
120 120
121 // If no Decoder is initialized, or the host dimensions are empty, return. 121 // If no Decoder is initialized, or the host dimensions are empty, return.
122 if (!decoder_.get() || source_size_.isEmpty()) 122 if (!decoder_.get() || source_size_.isEmpty())
123 return; 123 return;
124 124
125 // Draw the invalidated region to the buffer. 125 // Draw the invalidated region to the buffer.
126 pp::ImageData* buffer = buffers_.front(); 126 ImageBuffer* buffer = buffers_.front();
127 SkRegion output_region; 127 SkRegion output_region;
128 decoder_->RenderFrame(view_size_, clip_area_, 128 decoder_->RenderFrame(view_size_, clip_area_,
129 reinterpret_cast<uint8*>(buffer->data()), 129 buffer->data(),
130 buffer->stride(), 130 buffer->stride(),
131 &output_region); 131 &output_region);
132 132
133 // Notify the consumer that painting is done. 133 // Notify the consumer that painting is done.
134 if (!output_region.isEmpty()) { 134 if (!output_region.isEmpty()) {
135 buffers_.pop_front(); 135 buffers_.pop_front();
136 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region); 136 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region);
137 } 137 }
138 } 138 }
139 139
140 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) { 140 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) {
141 if (!decode_task_runner_->BelongsToCurrentThread()) { 141 if (!decode_task_runner_->BelongsToCurrentThread()) {
142 decode_task_runner_->PostTask( 142 decode_task_runner_->PostTask(
143 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers, 143 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers,
144 this, done)); 144 this, done));
145 return; 145 return;
146 } 146 }
147 147
148 while (!buffers_.empty()) { 148 while (!buffers_.empty()) {
149 consumer_->ReturnBuffer(buffers_.front()); 149 consumer_->ReturnBuffer(buffers_.front());
150 buffers_.pop_front(); 150 buffers_.pop_front();
151 } 151 }
152 152
153 if (!done.is_null()) 153 if (!done.is_null())
154 done.Run(); 154 done.Run();
155 } 155 }
156 156
157 void RectangleUpdateDecoder::DrawBuffer(pp::ImageData* buffer) { 157 void RectangleUpdateDecoder::DrawBuffer(ImageBuffer* buffer) {
158 if (!decode_task_runner_->BelongsToCurrentThread()) { 158 if (!decode_task_runner_->BelongsToCurrentThread()) {
159 decode_task_runner_->PostTask( 159 decode_task_runner_->PostTask(
160 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DrawBuffer, 160 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DrawBuffer,
161 this, buffer)); 161 this, buffer));
162 return; 162 return;
163 } 163 }
164 164
165 DCHECK(clip_area_.width() <= buffer->size().width() && 165 DCHECK(clip_area_.width() <= buffer->width() &&
166 clip_area_.height() <= buffer->size().height()); 166 clip_area_.height() <= buffer->height());
167 167
168 buffers_.push_back(buffer); 168 buffers_.push_back(buffer);
169 SchedulePaint(); 169 SchedulePaint();
170 } 170 }
171 171
172 void RectangleUpdateDecoder::InvalidateRegion(const SkRegion& region) { 172 void RectangleUpdateDecoder::InvalidateRegion(const SkRegion& region) {
173 if (!decode_task_runner_->BelongsToCurrentThread()) { 173 if (!decode_task_runner_->BelongsToCurrentThread()) {
174 decode_task_runner_->PostTask( 174 decode_task_runner_->PostTask(
175 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion, 175 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion,
176 this, region)); 176 this, region));
(...skipping 22 matching lines...) Expand all
199 decoder_->Invalidate(view_size, region); 199 decoder_->Invalidate(view_size, region);
200 } 200 }
201 201
202 if (view_size_ != view_size || 202 if (view_size_ != view_size ||
203 clip_area_ != clip_area) { 203 clip_area_ != clip_area) {
204 view_size_ = view_size; 204 view_size_ = view_size;
205 clip_area_ = clip_area; 205 clip_area_ = clip_area;
206 206
207 // Return buffers that are smaller than needed to the consumer for 207 // Return buffers that are smaller than needed to the consumer for
208 // reuse/reallocation. 208 // reuse/reallocation.
209 std::list<pp::ImageData*>::iterator i = buffers_.begin(); 209 std::list<ImageBuffer*>::iterator i = buffers_.begin();
210 while (i != buffers_.end()) { 210 while (i != buffers_.end()) {
211 pp::Size buffer_size = (*i)->size(); 211 if ((*i)->width() < clip_area_.width() ||
212 if (buffer_size.width() < clip_area_.width() || 212 (*i)->height() < clip_area_.height()) {
213 buffer_size.height() < clip_area_.height()) {
214 consumer_->ReturnBuffer(*i); 213 consumer_->ReturnBuffer(*i);
215 i = buffers_.erase(i); 214 i = buffers_.erase(i);
216 } else { 215 } else {
217 ++i; 216 ++i;
218 } 217 }
219 } 218 }
220 219
221 SchedulePaint(); 220 SchedulePaint();
222 } 221 }
223 } 222 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 288
290 done.Run(); 289 done.Run();
291 } 290 }
292 291
293 ChromotingStats* RectangleUpdateDecoder::GetStats() { 292 ChromotingStats* RectangleUpdateDecoder::GetStats() {
294 DCHECK(main_task_runner_->BelongsToCurrentThread()); 293 DCHECK(main_task_runner_->BelongsToCurrentThread());
295 return &stats_; 294 return &stats_;
296 } 295 }
297 296
298 } // namespace remoting 297 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698