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 "cc/base/swap_promise.h" |
| 17 #include "content/common/content_export.h" |
| 18 #include "content/renderer/message_delivery_policy.h" |
| 19 |
| 20 namespace IPC { |
| 21 class Message; |
| 22 }; |
| 23 |
| 24 namespace content { |
| 25 |
| 26 class FrameSwapMessageSubQueue; |
| 27 |
| 28 // Queue used to keep track of which IPC::Messages should be sent along with a |
| 29 // particular compositor frame swap. |
| 30 class CONTENT_EXPORT FrameSwapMessageQueue |
| 31 : public base::RefCountedThreadSafe<FrameSwapMessageQueue> { |
| 32 public: |
| 33 class CONTENT_EXPORT SendMessageScope { |
| 34 public: |
| 35 virtual ~SendMessageScope() {} |
| 36 }; |
| 37 |
| 38 FrameSwapMessageQueue(); |
| 39 |
| 40 // Queues message to be returned on a matching DrainMessages call. |
| 41 // |
| 42 // |policy| determines how messages are matched with DrainMessages calls. |
| 43 // |source_frame_number| frame number to queue |msg| for. |
| 44 // |msg| - message to queue. The method takes ownership of |msg|. |
| 45 // |is_first| - output parameter. Set to true if this was the first message |
| 46 // enqueued for the given source_frame_number. |
| 47 void QueueMessageForFrame(MessageDeliveryPolicy policy, |
| 48 int source_frame_number, |
| 49 scoped_ptr<IPC::Message> msg, |
| 50 bool* is_first); |
| 51 |
| 52 // Returns true if there are no messages in the queue. |
| 53 bool Empty() const; |
| 54 |
| 55 void DidSwap(int source_frame_number); |
| 56 void DidNotSwap(int source_frame_number, |
| 57 cc::SwapPromise::DidNotSwapReason reason, |
| 58 ScopedVector<IPC::Message>* messages); |
| 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 |
| 81 FrameSwapMessageSubQueue* GetSubQueue(MessageDeliveryPolicy policy); |
| 82 |
| 83 ~FrameSwapMessageQueue(); |
| 84 |
| 85 mutable base::Lock lock_; |
| 86 scoped_ptr<FrameSwapMessageSubQueue> visual_state_queue_; |
| 87 scoped_ptr<FrameSwapMessageSubQueue> swap_queue_; |
| 88 ScopedVector<IPC::Message> next_drain_messages_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue); |
| 91 }; |
| 92 |
| 93 } // namespace content |
| 94 |
| 95 #endif // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
OLD | NEW |