| 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 <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "base/threading/thread_checker.h" |
| 16 #include "cc/output/swap_promise.h" | 17 #include "cc/output/swap_promise.h" |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "content/renderer/message_delivery_policy.h" | 19 #include "content/renderer/message_delivery_policy.h" |
| 19 | 20 |
| 20 namespace IPC { | 21 namespace IPC { |
| 21 class Message; | 22 class Message; |
| 22 }; | 23 }; |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 class FrameSwapMessageSubQueue; | 27 class FrameSwapMessageSubQueue; |
| 27 | 28 |
| 28 // Queue used to keep track of which IPC::Messages should be sent after a | 29 // Queue used to keep track of which IPC::Messages should be sent after a |
| 29 // particular compositor frame swap. The messages are guaranteed to be processed | 30 // particular compositor frame swap. The messages are guaranteed to be processed |
| 30 // after the frame is processed, but there is no guarantee that nothing else | 31 // after the frame is processed, but there is no guarantee that nothing else |
| 31 // happens between processing the frame and processing the messages. | 32 // happens between processing the frame and processing the messages. |
| 32 class CONTENT_EXPORT FrameSwapMessageQueue | 33 class CONTENT_EXPORT FrameSwapMessageQueue |
| 33 : public base::RefCountedThreadSafe<FrameSwapMessageQueue> { | 34 : public base::RefCountedThreadSafe<FrameSwapMessageQueue> { |
| 34 public: | 35 public: |
| 35 class CONTENT_EXPORT SendMessageScope { | 36 class CONTENT_EXPORT SendMessageScope { |
| 36 public: | 37 public: |
| 37 virtual ~SendMessageScope() {} | 38 virtual ~SendMessageScope() {} |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 FrameSwapMessageQueue(); | 41 explicit FrameSwapMessageQueue(int32_t routing_id); |
| 41 | 42 |
| 42 // Queues message to be returned on a matching DrainMessages call. | 43 // Queues message to be returned on a matching DrainMessages call. |
| 43 // | 44 // |
| 44 // |policy| determines how messages are matched with DrainMessages calls. | 45 // |policy| determines how messages are matched with DrainMessages calls. |
| 45 // |source_frame_number| frame number to queue |msg| for. | 46 // |source_frame_number| frame number to queue |msg| for. |
| 46 // |msg| - message to queue. The method takes ownership of |msg|. | 47 // |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 // |is_first| - output parameter. Set to true if this was the first message |
| 48 // enqueued for the given source_frame_number. | 49 // enqueued for the given source_frame_number. |
| 49 void QueueMessageForFrame(MessageDeliveryPolicy policy, | 50 void QueueMessageForFrame(MessageDeliveryPolicy policy, |
| 50 int source_frame_number, | 51 int source_frame_number, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Returns an object that must be kept in scope till an IPC message containing | 92 // Returns an object that must be kept in scope till an IPC message containing |
| 92 // |messages| is sent. | 93 // |messages| is sent. |
| 93 std::unique_ptr<SendMessageScope> AcquireSendMessageScope(); | 94 std::unique_ptr<SendMessageScope> AcquireSendMessageScope(); |
| 94 | 95 |
| 95 static void TransferMessages( | 96 static void TransferMessages( |
| 96 std::vector<std::unique_ptr<IPC::Message>>* source, | 97 std::vector<std::unique_ptr<IPC::Message>>* source, |
| 97 std::vector<IPC::Message>* dest); | 98 std::vector<IPC::Message>* dest); |
| 98 | 99 |
| 99 uint32_t AllocateFrameToken(); | 100 uint32_t AllocateFrameToken(); |
| 100 | 101 |
| 102 int32_t routing_id() const { return routing_id_; } |
| 103 |
| 104 void NotifyFramesAreDiscarded(bool frames_are_discarded); |
| 105 bool AreFramesDiscarded(); |
| 106 |
| 101 private: | 107 private: |
| 102 friend class base::RefCountedThreadSafe<FrameSwapMessageQueue>; | 108 friend class base::RefCountedThreadSafe<FrameSwapMessageQueue>; |
| 103 | 109 |
| 104 FrameSwapMessageSubQueue* GetSubQueue(MessageDeliveryPolicy policy); | 110 FrameSwapMessageSubQueue* GetSubQueue(MessageDeliveryPolicy policy); |
| 105 | 111 |
| 106 ~FrameSwapMessageQueue(); | 112 ~FrameSwapMessageQueue(); |
| 107 | 113 |
| 108 mutable base::Lock lock_; | 114 mutable base::Lock lock_; |
| 109 std::unique_ptr<FrameSwapMessageSubQueue> visual_state_queue_; | 115 std::unique_ptr<FrameSwapMessageSubQueue> visual_state_queue_; |
| 110 std::unique_ptr<FrameSwapMessageSubQueue> swap_queue_; | 116 std::unique_ptr<FrameSwapMessageSubQueue> swap_queue_; |
| 111 std::vector<std::unique_ptr<IPC::Message>> next_drain_messages_; | 117 std::vector<std::unique_ptr<IPC::Message>> next_drain_messages_; |
| 112 uint32_t last_used_frame_token_ = 0; | 118 uint32_t last_used_frame_token_ = 0; |
| 119 int32_t routing_id_ = 0; |
| 120 bool frames_are_discarded_ = false; |
| 121 THREAD_CHECKER(impl_thread_checker_); |
| 113 | 122 |
| 114 DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue); | 123 DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue); |
| 115 }; | 124 }; |
| 116 | 125 |
| 117 } // namespace content | 126 } // namespace content |
| 118 | 127 |
| 119 #endif // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ | 128 #endif // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_ |
| OLD | NEW |