Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / gpu / queue_message_swap_promise.cc
blobff524418b7f5c87ceda6af49b3951afc4f27b578
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.
5 #include "content/renderer/gpu/queue_message_swap_promise.h"
7 #include "content/renderer/gpu/frame_swap_message_queue.h"
8 #include "ipc/ipc_sync_message_filter.h"
10 namespace content {
12 QueueMessageSwapPromise::QueueMessageSwapPromise(
13 scoped_refptr<IPC::SyncMessageFilter> message_sender,
14 scoped_refptr<content::FrameSwapMessageQueue> message_queue,
15 int source_frame_number)
16 : message_sender_(message_sender),
17 message_queue_(message_queue),
18 source_frame_number_(source_frame_number)
19 #if DCHECK_IS_ON()
21 completed_(false)
22 #endif
24 DCHECK(message_sender_.get());
25 DCHECK(message_queue_.get());
28 QueueMessageSwapPromise::~QueueMessageSwapPromise() {
29 // The promise should have either been kept or broken before it's deleted.
30 #if DCHECK_IS_ON()
31 DCHECK(completed_);
32 #endif
35 void QueueMessageSwapPromise::DidActivate() {
36 #if DCHECK_IS_ON()
37 DCHECK(!completed_);
38 #endif
39 message_queue_->DidActivate(source_frame_number_);
40 // The OutputSurface will take care of the Drain+Send.
43 void QueueMessageSwapPromise::DidSwap(cc::CompositorFrameMetadata* metadata) {
44 #if DCHECK_IS_ON()
45 DCHECK(!completed_);
46 #endif
47 message_queue_->DidSwap(source_frame_number_);
48 // The OutputSurface will take care of the Drain+Send.
49 PromiseCompleted();
52 void QueueMessageSwapPromise::DidNotSwap(DidNotSwapReason reason) {
53 #if DCHECK_IS_ON()
54 DCHECK(!completed_);
55 #endif
56 ScopedVector<IPC::Message> messages;
57 message_queue_->DidNotSwap(source_frame_number_, reason, &messages);
58 for (ScopedVector<IPC::Message>::iterator i = messages.begin();
59 i != messages.end();
60 ++i) {
61 message_sender_->Send(*i);
63 messages.weak_clear();
64 PromiseCompleted();
67 void QueueMessageSwapPromise::PromiseCompleted() {
68 #if DCHECK_IS_ON()
69 completed_ = true;
70 #endif
73 int64 QueueMessageSwapPromise::TraceId() const {
74 return 0;
77 } // namespace content