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 #ifndef CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
| 6 #define CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/auto_reset.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/synchronization/lock.h" |
| 16 #include "content/common/content_export.h" |
| 17 |
| 18 namespace IPC { |
| 19 class Message; |
| 20 }; |
| 21 |
| 22 namespace content { |
| 23 |
| 24 // Queue used to keep track of which IPC::Messages should be sent along with a |
| 25 // particular compositor frame swap. |
| 26 class CONTENT_EXPORT FrameSwapMessageQueue |
| 27 : public base::RefCountedThreadSafe<FrameSwapMessageQueue> { |
| 28 public: |
| 29 class CONTENT_EXPORT SendMessageScope { |
| 30 public: |
| 31 virtual ~SendMessageScope() {} |
| 32 }; |
| 33 |
| 34 FrameSwapMessageQueue(); |
| 35 |
| 36 // Queues message to be returned on the next call to DrainMessages. |
| 37 // |
| 38 // |msg| - message to queue. The method takes ownership of |msg|. |
| 39 void QueueMessage(scoped_ptr<IPC::Message> msg); |
| 40 |
| 41 // Queues message to be returned on the first call to DrainMessages ocurring |
| 42 // after a DidSwapFrame call with the coresponding source_frame_number. Takes |
| 43 // ownership of |msg|. |
| 44 // |
| 45 // |source_frame_number| frame number to queue |msg| for. |
| 46 // |msg| - message to queue. The method takes ownership of |msg|. |
| 47 // |is_first| - output parameter. Set to true if this was the first message |
| 48 // enqueued for the given source_frame_number. |
| 49 void QueueMessageForFrame(int source_frame_number, |
| 50 scoped_ptr<IPC::Message> msg, |
| 51 bool* is_first); |
| 52 |
| 53 // Returns true if there are no messages in the queue. |
| 54 bool Empty() const; |
| 55 |
| 56 // Makes the next call do DrainMessages return messages scheduled for any |
| 57 // source frame numbers less than or equal to |source_frame_number|. |
| 58 void AdvanceToFrame(int source_frame_number); |
| 59 |
| 60 // A SendMessageScope object must be held by the caller when this method is |
| 61 // called. |
| 62 // |
| 63 // |messages| vector to store messages. it's not cleared, only appended to. |
| 64 // The method will append messages queued for frame numbers lower |
| 65 // or equal to |source_frame_number| |
| 66 void DrainMessages(ScopedVector<IPC::Message>* messages); |
| 67 |
| 68 // SendMessageScope is used to make sure that messages sent from different |
| 69 // threads (impl/main) are scheduled in the right order on the IO threads. |
| 70 // |
| 71 // Returns an object that must be kept in scope till an IPC message containing |
| 72 // |messages| is sent. |
| 73 scoped_ptr<SendMessageScope> AcquireSendMessageScope(); |
| 74 |
| 75 static void TransferMessages(ScopedVector<IPC::Message>& source, |
| 76 std::vector<IPC::Message>* dest); |
| 77 |
| 78 private: |
| 79 friend class base::RefCountedThreadSafe<FrameSwapMessageQueue>; |
| 80 typedef std::map<int, std::vector<IPC::Message*> > FrameQueueMap; |
| 81 |
| 82 ~FrameSwapMessageQueue(); |
| 83 |
| 84 mutable base::Lock lock_; |
| 85 int highest_swapped_source_frame_number_; |
| 86 FrameQueueMap queued_messages_; |
| 87 ScopedVector<IPC::Message> next_drain_messages_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue); |
| 90 }; |
| 91 |
| 92 } // namespace content |
| 93 |
| 94 #endif // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
OLD | NEW |