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

Side by Side Diff: content/renderer/gpu/frame_swap_message_queue.cc

Issue 240163005: Deliver IPC messages together with SwapCompositorFrame (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback + add more testing Created 6 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 | Annotate | Revision Log
OLDNEW
(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/gpu/frame_swap_message_queue.h"
6
7 #include <limits>
8
9 #include "base/logging.h"
10 #include "base/stl_util.h"
11 #include "ipc/ipc_message.h"
12
13 using std::vector;
14
15 namespace content {
16
17 namespace {
18
19 class SendMessageScopeImpl : public FrameSwapMessageQueue::SendMessageScope {
20 public:
21 SendMessageScopeImpl(base::Lock* lock) : auto_lock_(*lock) {}
22 virtual ~SendMessageScopeImpl() OVERRIDE {}
23
24 private:
25 base::AutoLock auto_lock_;
26 };
27
28 } // namespace
29
30 FrameSwapMessageQueue::FrameSwapMessageQueue()
31 : highest_swapped_source_frame_number_(std::numeric_limits<
32 typeof(highest_swapped_source_frame_number_)>::min()) {
33 }
34
35 FrameSwapMessageQueue::~FrameSwapMessageQueue() {
36 for (FrameQueueMap::iterator i = queued_messages_.begin();
37 i != queued_messages_.end();
38 i++) {
39 STLDeleteElements(&i->second);
40 }
41 }
42
43 bool FrameSwapMessageQueue::Empty() const {
44 base::AutoLock lock(lock_);
45 return queued_messages_.empty() && next_drain_messages_.empty();
46 }
47
48 void FrameSwapMessageQueue::QueueMessage(scoped_ptr<IPC::Message> msg) {
49 base::AutoLock lock(lock_);
50 next_drain_messages_.push_back(msg.release());
51 }
52
53 void FrameSwapMessageQueue::QueueMessageForFrame(int source_frame_number,
54 scoped_ptr<IPC::Message> msg,
55 bool* is_first) {
56 base::AutoLock lock(lock_);
57 DCHECK(source_frame_number >= highest_swapped_source_frame_number_);
58
59 if (is_first)
60 *is_first = (queued_messages_.count(source_frame_number) == 0);
61
62 queued_messages_[source_frame_number].push_back(msg.release());
63 }
64
65 void FrameSwapMessageQueue::AdvanceToFrame(int source_frame_number) {
66 base::AutoLock lock(lock_);
67
68 if (highest_swapped_source_frame_number_ > source_frame_number)
69 return;
70 highest_swapped_source_frame_number_ = source_frame_number;
71
72 FrameQueueMap::iterator end =
73 queued_messages_.upper_bound(source_frame_number);
74 for (FrameQueueMap::iterator i = queued_messages_.begin(); i != end; i++) {
75 DCHECK(i->first <= source_frame_number);
76 next_drain_messages_.insert(
77 next_drain_messages_.end(), i->second.begin(), i->second.end());
78 i->second.clear();
79 }
80 queued_messages_.erase(queued_messages_.begin(), end);
81 }
82
83 void FrameSwapMessageQueue::DrainMessages(
84 ScopedVector<IPC::Message>* messages) {
85 lock_.AssertAcquired();
86 messages->swap(next_drain_messages_);
87 next_drain_messages_.clear();
88 }
89
90 scoped_ptr<FrameSwapMessageQueue::SendMessageScope>
91 FrameSwapMessageQueue::AcquireSendMessageScope() {
92 return make_scoped_ptr(new SendMessageScopeImpl(&lock_))
93 .PassAs<SendMessageScope>();
94 }
95
96 // static
97 void FrameSwapMessageQueue::TransferMessages(ScopedVector<IPC::Message>& source,
98 vector<IPC::Message>* dest) {
99 for (vector<IPC::Message*>::iterator i = source.begin(); i != source.end();
100 ++i) {
101 IPC::Message* m(*i);
102 dest->push_back(*m);
103 delete m;
104 }
105 source.weak_clear();
106 }
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698