OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/queue_message_swap_promise.h" |
| 6 #include "content/renderer/gpu/frame_swap_message_queue.h" |
| 7 #include "ipc/ipc_sync_message_filter.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 QueueMessageSwapPromise::QueueMessageSwapPromise( |
| 12 scoped_refptr<IPC::SyncMessageFilter> message_sender, |
| 13 scoped_refptr<content::FrameSwapMessageQueue> message_queue, |
| 14 int source_frame_number) |
| 15 : message_sender_(message_sender), |
| 16 message_queue_(message_queue), |
| 17 source_frame_number_(source_frame_number), |
| 18 #ifndef NDEBUG |
| 19 completed_(false) |
| 20 #endif |
| 21 { |
| 22 DCHECK(message_sender_.get()); |
| 23 DCHECK(message_queue_.get()); |
| 24 } |
| 25 |
| 26 QueueMessageSwapPromise::~QueueMessageSwapPromise() { |
| 27 // The promise should have either been kept or broken before it's deleted. |
| 28 DCHECK(completed_); |
| 29 } |
| 30 |
| 31 void QueueMessageSwapPromise::DidSwap(cc::CompositorFrameMetadata* metadata) { |
| 32 DCHECK(!completed_); |
| 33 message_queue_->AdvanceToFrame(source_frame_number_); |
| 34 // The OutputSurface will take care of the Drain+Send. |
| 35 PromiseCompleted(); |
| 36 } |
| 37 |
| 38 void QueueMessageSwapPromise::DidNotSwap(DidNotSwapReason reason) { |
| 39 DCHECK(!completed_); |
| 40 // This will also send messages explicitly queued with the WITH_NEXT_SWAP |
| 41 // policy. It makes sense to send them if reason == SWAP_FAILS, but they may |
| 42 // end up being sent prematurely if reason == COMMIT_FAILS. |
| 43 ScopedVector<IPC::Message> messages; |
| 44 message_queue_->AdvanceToFrame(source_frame_number_); |
| 45 scoped_ptr<content::FrameSwapMessageQueue::SendMessageScope> |
| 46 send_message_scope = message_queue_->AcquireSendMessageScope(); |
| 47 message_queue_->DrainMessages(&messages); |
| 48 for (ScopedVector<IPC::Message>::iterator i = messages.begin(); |
| 49 i != messages.end(); |
| 50 ++i) { |
| 51 message_sender_->Send(*i); |
| 52 } |
| 53 messages.weak_clear(); |
| 54 PromiseCompleted(); |
| 55 } |
| 56 |
| 57 void QueueMessageSwapPromise::PromiseCompleted() { |
| 58 #ifndef NDEBUG |
| 59 completed_ = true; |
| 60 #endif |
| 61 } |
| 62 |
| 63 } // namespace content |
OLD | NEW |