OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ | 5 #ifndef CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
6 #define CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ | 6 #define CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "cc/output/swap_promise.h" | 17 #include "cc/output/swap_promise.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/renderer/message_delivery_policy.h" | 19 #include "content/renderer/message_delivery_policy.h" |
20 | 20 |
21 namespace IPC { | 21 namespace IPC { |
22 class Message; | 22 class Message; |
23 }; | 23 }; |
24 | 24 |
(...skipping 15 matching lines...) Expand all Loading... |
40 | 40 |
41 // Queues message to be returned on a matching DrainMessages call. | 41 // Queues message to be returned on a matching DrainMessages call. |
42 // | 42 // |
43 // |policy| determines how messages are matched with DrainMessages calls. | 43 // |policy| determines how messages are matched with DrainMessages calls. |
44 // |source_frame_number| frame number to queue |msg| for. | 44 // |source_frame_number| frame number to queue |msg| for. |
45 // |msg| - message to queue. The method takes ownership of |msg|. | 45 // |msg| - message to queue. The method takes ownership of |msg|. |
46 // |is_first| - output parameter. Set to true if this was the first message | 46 // |is_first| - output parameter. Set to true if this was the first message |
47 // enqueued for the given source_frame_number. | 47 // enqueued for the given source_frame_number. |
48 void QueueMessageForFrame(MessageDeliveryPolicy policy, | 48 void QueueMessageForFrame(MessageDeliveryPolicy policy, |
49 int source_frame_number, | 49 int source_frame_number, |
50 scoped_ptr<IPC::Message> msg, | 50 std::unique_ptr<IPC::Message> msg, |
51 bool* is_first); | 51 bool* is_first); |
52 | 52 |
53 // Returns true if there are no messages in the queue. | 53 // Returns true if there are no messages in the queue. |
54 bool Empty() const; | 54 bool Empty() const; |
55 | 55 |
56 // Should be called when a successful activation occurs. The messages for | 56 // Should be called when a successful activation occurs. The messages for |
57 // that activation can be obtained by calling DrainMessages. | 57 // that activation can be obtained by calling DrainMessages. |
58 // | 58 // |
59 // |source_frame_number| frame number for which the activate occurred. | 59 // |source_frame_number| frame number for which the activate occurred. |
60 void DidActivate(int source_frame_number); | 60 void DidActivate(int source_frame_number); |
61 | 61 |
62 // Should be called when a successful swap occurs. The messages for that | 62 // Should be called when a successful swap occurs. The messages for that |
63 // swap can be obtained by calling DrainMessages. | 63 // swap can be obtained by calling DrainMessages. |
64 // | 64 // |
65 // |source_frame_number| frame number for which the swap occurred. | 65 // |source_frame_number| frame number for which the swap occurred. |
66 void DidSwap(int source_frame_number); | 66 void DidSwap(int source_frame_number); |
67 | 67 |
68 // Should be called when we know a swap will not occur. | 68 // Should be called when we know a swap will not occur. |
69 // | 69 // |
70 // |source_frame_number| frame number for which the swap will not occur. | 70 // |source_frame_number| frame number for which the swap will not occur. |
71 // |reason| reason for the which the swap will not occur. | 71 // |reason| reason for the which the swap will not occur. |
72 // |messages| depending on |reason| it may make sense to deliver certain | 72 // |messages| depending on |reason| it may make sense to deliver certain |
73 // messages asynchronously. This vector will contain those | 73 // messages asynchronously. This vector will contain those |
74 // messages. | 74 // messages. |
75 void DidNotSwap(int source_frame_number, | 75 void DidNotSwap(int source_frame_number, |
76 cc::SwapPromise::DidNotSwapReason reason, | 76 cc::SwapPromise::DidNotSwapReason reason, |
77 std::vector<scoped_ptr<IPC::Message>>* messages); | 77 std::vector<std::unique_ptr<IPC::Message>>* messages); |
78 | 78 |
79 // A SendMessageScope object must be held by the caller when this method is | 79 // A SendMessageScope object must be held by the caller when this method is |
80 // called. | 80 // called. |
81 // | 81 // |
82 // |messages| vector to store messages, it's not cleared, only appended to. | 82 // |messages| vector to store messages, it's not cleared, only appended to. |
83 // The method will append messages queued for frame numbers lower | 83 // The method will append messages queued for frame numbers lower |
84 // or equal to |source_frame_number| | 84 // or equal to |source_frame_number| |
85 void DrainMessages(std::vector<scoped_ptr<IPC::Message>>* messages); | 85 void DrainMessages(std::vector<std::unique_ptr<IPC::Message>>* messages); |
86 | 86 |
87 // SendMessageScope is used to make sure that messages sent from different | 87 // SendMessageScope is used to make sure that messages sent from different |
88 // threads (impl/main) are scheduled in the right order on the IO threads. | 88 // threads (impl/main) are scheduled in the right order on the IO threads. |
89 // | 89 // |
90 // Returns an object that must be kept in scope till an IPC message containing | 90 // Returns an object that must be kept in scope till an IPC message containing |
91 // |messages| is sent. | 91 // |messages| is sent. |
92 scoped_ptr<SendMessageScope> AcquireSendMessageScope(); | 92 std::unique_ptr<SendMessageScope> AcquireSendMessageScope(); |
93 | 93 |
94 static void TransferMessages(std::vector<scoped_ptr<IPC::Message>>* source, | 94 static void TransferMessages( |
95 std::vector<IPC::Message>* dest); | 95 std::vector<std::unique_ptr<IPC::Message>>* source, |
| 96 std::vector<IPC::Message>* dest); |
96 | 97 |
97 private: | 98 private: |
98 friend class base::RefCountedThreadSafe<FrameSwapMessageQueue>; | 99 friend class base::RefCountedThreadSafe<FrameSwapMessageQueue>; |
99 | 100 |
100 FrameSwapMessageSubQueue* GetSubQueue(MessageDeliveryPolicy policy); | 101 FrameSwapMessageSubQueue* GetSubQueue(MessageDeliveryPolicy policy); |
101 | 102 |
102 ~FrameSwapMessageQueue(); | 103 ~FrameSwapMessageQueue(); |
103 | 104 |
104 mutable base::Lock lock_; | 105 mutable base::Lock lock_; |
105 scoped_ptr<FrameSwapMessageSubQueue> visual_state_queue_; | 106 std::unique_ptr<FrameSwapMessageSubQueue> visual_state_queue_; |
106 scoped_ptr<FrameSwapMessageSubQueue> swap_queue_; | 107 std::unique_ptr<FrameSwapMessageSubQueue> swap_queue_; |
107 std::vector<scoped_ptr<IPC::Message>> next_drain_messages_; | 108 std::vector<std::unique_ptr<IPC::Message>> next_drain_messages_; |
108 | 109 |
109 DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue); | 110 DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue); |
110 }; | 111 }; |
111 | 112 |
112 } // namespace content | 113 } // namespace content |
113 | 114 |
114 #endif // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ | 115 #endif // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
OLD | NEW |