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

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

Powered by Google App Engine
This is Rietveld 408576698