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

Unified Diff: content/renderer/gpu/frame_swap_message_queue.h

Issue 240163005: Deliver IPC messages together with SwapCompositorFrame (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/gpu/frame_swap_message_queue.h
diff --git a/content/renderer/gpu/frame_swap_message_queue.h b/content/renderer/gpu/frame_swap_message_queue.h
new file mode 100644
index 0000000000000000000000000000000000000000..e3726ec4be764e2b5ab87785c83a6e23cca01a55
--- /dev/null
+++ b/content/renderer/gpu/frame_swap_message_queue.h
@@ -0,0 +1,75 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_
+#define CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_
+
+#include <map>
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/lock.h"
+#include "content/common/content_export.h"
+
+namespace IPC {
+class Message;
+};
+
+namespace content {
+
+// Queue used to keep track of which IPC::Messages should be sent along with a
+// particular compositor frame swap.
+class CONTENT_EXPORT FrameSwapMessageQueue
+ : public base::RefCountedThreadSafe<FrameSwapMessageQueue> {
+ public:
+ typedef scoped_ptr<base::AutoLock> SendMessageScope;
+ FrameSwapMessageQueue();
+
+ // Queues message to be sent on next drain.
+ //
+ // |msg| - message to queue. The method takes ownership of |msg|.
+ void QueueMessage(IPC::Message* msg);
+
+ // Queues message to take place on next drain coresponding to the given
+ // source_frame_number. Takes ownership of |msg|.
+ //
+ // |source_frame_number| frame number to queue |msg| for.
+ // |msg| - message to queue. The method takes ownership of |msg|.
+ // Returns false if the given source frame number had already been drained at
+ // least once.
+ bool TryQueueMessage(int source_frame_number, IPC::Message* msg);
+
+ // SendMessageScope must exist till after the messages are sent. The
+ // SendMessageScope is used to make sure that messages sent directly from the
+ // main thread can't overtake the message containing |messages|.
+ //
+ // |source_frame_number| frame number to get messages for
+ // |messages| vector to store messages. it's not cleared, only appended to.
+ // The method will append messages queued for frame numbers lower
+ // or equal to |source_frame_number|
+ // Returns an object that must be kept in scope till an IPC message containing
+ // |messages| is sent.
+ SendMessageScope DrainMessages(int source_frame_number,
+ std::vector<IPC::Message>* messages);
+
+ private:
+ friend class base::RefCountedThreadSafe<FrameSwapMessageQueue>;
+ typedef std::map<int, std::vector<IPC::Message*> > FrameQueueMap;
+
+ static void TransferMessages(std::vector<IPC::Message*>& source,
+ std::vector<IPC::Message>* dest);
+
+ ~FrameSwapMessageQueue();
+
+ base::Lock lock_;
+ int highest_swapped_source_frame_number_;
+ FrameQueueMap queued_messages_;
+
+ DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_

Powered by Google App Engine
This is Rietveld 408576698