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

Side by Side Diff: remoting/client/plugin/pepper_view.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
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/plugin/pepper_view.h" 5 #include "remoting/client/plugin/pepper_view.h"
6 6
7 #include <functional> 7 #include <functional>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 bool PepperView::Initialize() { 90 bool PepperView::Initialize() {
91 DCHECK(!is_initialized_); 91 DCHECK(!is_initialized_);
92 92
93 is_initialized_ = true; 93 is_initialized_ = true;
94 InitiateDrawing(); 94 InitiateDrawing();
95 return true; 95 return true;
96 } 96 }
97 97
98 void PepperView::TearDown() { 98 void PepperView::TearDown() {
99 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); 99 DCHECK(context_->main_task_runner()->BelongsToCurrentThread());
100 DCHECK(is_initialized_); 100 DCHECK(is_initialized_);
101 101
102 is_initialized_ = false; 102 is_initialized_ = false;
103 103
104 // The producer should now return any pending buffers. At this point, however, 104 // The producer should now return any pending buffers. At this point, however,
105 // ReturnBuffer() tasks scheduled by the producer will not be delivered, 105 // ReturnBuffer() tasks scheduled by the producer will not be delivered,
106 // so we free all the buffers once the producer's queue is empty. 106 // so we free all the buffers once the producer's queue is empty.
107 base::WaitableEvent done_event(true, false); 107 base::WaitableEvent done_event(true, false);
108 producer_->RequestReturnBuffers( 108 producer_->RequestReturnBuffers(
109 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event))); 109 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event)));
110 done_event.Wait(); 110 done_event.Wait();
111 111
112 merge_buffer_ = NULL; 112 merge_buffer_ = NULL;
113 while (!buffers_.empty()) { 113 while (!buffers_.empty()) {
114 FreeBuffer(buffers_.front()); 114 FreeBuffer(buffers_.front());
115 } 115 }
116 } 116 }
117 117
118 void PepperView::SetConnectionState(protocol::ConnectionToHost::State state, 118 void PepperView::SetConnectionState(protocol::ConnectionToHost::State state,
119 protocol::ErrorCode error) { 119 protocol::ErrorCode error) {
120 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); 120 DCHECK(context_->main_task_runner()->BelongsToCurrentThread());
121 121
122 switch (state) { 122 switch (state) {
123 case protocol::ConnectionToHost::CONNECTING: 123 case protocol::ConnectionToHost::CONNECTING:
124 instance_->SetConnectionState( 124 instance_->SetConnectionState(
125 ChromotingInstance::STATE_CONNECTING, 125 ChromotingInstance::STATE_CONNECTING,
126 ConvertConnectionError(error)); 126 ConvertConnectionError(error));
127 break; 127 break;
128 128
129 case protocol::ConnectionToHost::CONNECTED: 129 case protocol::ConnectionToHost::CONNECTED:
130 instance_->SetConnectionState( 130 instance_->SetConnectionState(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (view_changed) { 181 if (view_changed) {
182 producer_->SetOutputSizeAndClip(view_size_, clip_area_); 182 producer_->SetOutputSizeAndClip(view_size_, clip_area_);
183 InitiateDrawing(); 183 InitiateDrawing();
184 } 184 }
185 } 185 }
186 186
187 void PepperView::ApplyBuffer(const SkISize& view_size, 187 void PepperView::ApplyBuffer(const SkISize& view_size,
188 const SkIRect& clip_area, 188 const SkIRect& clip_area,
189 pp::ImageData* buffer, 189 pp::ImageData* buffer,
190 const SkRegion& region) { 190 const SkRegion& region) {
191 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); 191 DCHECK(context_->main_task_runner()->BelongsToCurrentThread());
192 192
193 if (!frame_received_) { 193 if (!frame_received_) {
194 instance_->OnFirstFrameReceived(); 194 instance_->OnFirstFrameReceived();
195 frame_received_ = true; 195 frame_received_ = true;
196 } 196 }
197 // Currently we cannot use the data in the buffer is scale factor has changed 197 // Currently we cannot use the data in the buffer is scale factor has changed
198 // already. 198 // already.
199 // TODO(alexeypa): We could rescale and draw it (or even draw it without 199 // TODO(alexeypa): We could rescale and draw it (or even draw it without
200 // rescaling) to reduce the perceived lag while we are waiting for 200 // rescaling) to reduce the perceived lag while we are waiting for
201 // the properly scaled data. 201 // the properly scaled data.
202 if (view_size_ != view_size) { 202 if (view_size_ != view_size) {
203 FreeBuffer(buffer); 203 FreeBuffer(buffer);
204 InitiateDrawing(); 204 InitiateDrawing();
205 } else { 205 } else {
206 FlushBuffer(clip_area, buffer, region); 206 FlushBuffer(clip_area, buffer, region);
207 } 207 }
208 } 208 }
209 209
210 void PepperView::ReturnBuffer(pp::ImageData* buffer) { 210 void PepperView::ReturnBuffer(pp::ImageData* buffer) {
211 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); 211 DCHECK(context_->main_task_runner()->BelongsToCurrentThread());
212 212
213 // Free the buffer if there is nothing to paint. 213 // Free the buffer if there is nothing to paint.
214 if (!is_initialized_) { 214 if (!is_initialized_) {
215 FreeBuffer(buffer); 215 FreeBuffer(buffer);
216 return; 216 return;
217 } 217 }
218 218
219 // Reuse the buffer if it is large enough, otherwise drop it on the floor 219 // Reuse the buffer if it is large enough, otherwise drop it on the floor
220 // and allocate a new one. 220 // and allocate a new one.
221 if (buffer->size().width() >= clip_area_.width() && 221 if (buffer->size().width() >= clip_area_.width() &&
222 buffer->size().height() >= clip_area_.height()) { 222 buffer->size().height() >= clip_area_.height()) {
223 producer_->DrawBuffer(buffer); 223 producer_->DrawBuffer(buffer);
224 } else { 224 } else {
225 FreeBuffer(buffer); 225 FreeBuffer(buffer);
226 InitiateDrawing(); 226 InitiateDrawing();
227 } 227 }
228 } 228 }
229 229
230 void PepperView::SetSourceSize(const SkISize& source_size) { 230 void PepperView::SetSourceSize(const SkISize& source_size) {
231 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); 231 DCHECK(context_->main_task_runner()->BelongsToCurrentThread());
232 232
233 if (source_size_ == source_size) 233 if (source_size_ == source_size)
234 return; 234 return;
235 235
236 source_size_ = source_size; 236 source_size_ = source_size;
237 237
238 // Notify JavaScript of the change in source size. 238 // Notify JavaScript of the change in source size.
239 instance_->SetDesktopSize(source_size.width(), source_size.height()); 239 instance_->SetDesktopSize(source_size.width(), source_size.height());
240 } 240 }
241 241
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 int error = graphics2d_.Flush( 330 int error = graphics2d_.Flush(
331 PpCompletionCallback(base::Bind( 331 PpCompletionCallback(base::Bind(
332 &PepperView::OnFlushDone, AsWeakPtr(), start_time, buffer))); 332 &PepperView::OnFlushDone, AsWeakPtr(), start_time, buffer)));
333 CHECK(error == PP_OK_COMPLETIONPENDING); 333 CHECK(error == PP_OK_COMPLETIONPENDING);
334 flush_pending_ = true; 334 flush_pending_ = true;
335 } 335 }
336 336
337 void PepperView::OnFlushDone(base::Time paint_start, 337 void PepperView::OnFlushDone(base::Time paint_start,
338 pp::ImageData* buffer, 338 pp::ImageData* buffer,
339 int result) { 339 int result) {
340 DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); 340 DCHECK(context_->main_task_runner()->BelongsToCurrentThread());
341 DCHECK(flush_pending_); 341 DCHECK(flush_pending_);
342 342
343 instance_->GetStats()->video_paint_ms()->Record( 343 instance_->GetStats()->video_paint_ms()->Record(
344 (base::Time::Now() - paint_start).InMilliseconds()); 344 (base::Time::Now() - paint_start).InMilliseconds());
345 345
346 flush_pending_ = false; 346 flush_pending_ = false;
347 ReturnBuffer(buffer); 347 ReturnBuffer(buffer);
348 348
349 // If there is a buffer queued for rendering then render it now. 349 // If there is a buffer queued for rendering then render it now.
350 if (merge_buffer_ != NULL) { 350 if (merge_buffer_ != NULL) {
351 buffer = merge_buffer_; 351 buffer = merge_buffer_;
352 merge_buffer_ = NULL; 352 merge_buffer_ = NULL;
353 FlushBuffer(merge_clip_area_, buffer, merge_region_); 353 FlushBuffer(merge_clip_area_, buffer, merge_region_);
354 } 354 }
355 } 355 }
356 356
357 } // namespace remoting 357 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/pepper_network_manager.cc ('k') | remoting/client/plugin/pepper_xmpp_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698