File: frame_swap_message_queue.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (108 lines) | stat: -rw-r--r-- 3,955 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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/auto_reset.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/synchronization/lock.h"
#include "cc/base/swap_promise.h"
#include "content/common/content_export.h"
#include "content/renderer/message_delivery_policy.h"

namespace IPC {
class Message;
};

namespace content {

class FrameSwapMessageSubQueue;

// 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:
  class CONTENT_EXPORT SendMessageScope {
   public:
    virtual ~SendMessageScope() {}
  };

  FrameSwapMessageQueue();

  // Queues message to be returned on a matching DrainMessages call.
  //
  // |policy| determines how messages are matched with DrainMessages calls.
  // |source_frame_number| frame number to queue |msg| for.
  // |msg| - message to queue. The method takes ownership of |msg|.
  // |is_first| - output parameter. Set to true if this was the first message
  //              enqueued for the given source_frame_number.
  void QueueMessageForFrame(MessageDeliveryPolicy policy,
                            int source_frame_number,
                            scoped_ptr<IPC::Message> msg,
                            bool* is_first);

  // Returns true if there are no messages in the queue.
  bool Empty() const;

  // Should be called when a successful swap occurs. The messages for that swap
  // can be obtained by calling DrainMessages.
  //
  // |source_frame_number| frame number for which the swap occurred.
  void DidSwap(int source_frame_number);

  // Should be called when we know a swap will not occur. This also means we
  // won't be expecting a DrainMessages call.
  //
  // |source_frame_number| frame number for which the swap will not occur.
  // |reason| reason for the which the swap will not occur.
  // |messages| depending on |reason| it may make sense to deliver certain
  //            messages asynchronously. This vector will contain those
  //            messages.
  void DidNotSwap(int source_frame_number,
                  cc::SwapPromise::DidNotSwapReason reason,
                  ScopedVector<IPC::Message>* messages);

  // A SendMessageScope object must be held by the caller when this method is
  // called.
  //
  // |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|
  void DrainMessages(ScopedVector<IPC::Message>* messages);

  // SendMessageScope is used to make sure that messages sent from different
  // threads (impl/main) are scheduled in the right order on the IO threads.
  //
  // Returns an object that must be kept in scope till an IPC message containing
  // |messages| is sent.
  scoped_ptr<SendMessageScope> AcquireSendMessageScope();

  static void TransferMessages(ScopedVector<IPC::Message>& source,
                               std::vector<IPC::Message>* dest);

 private:
  friend class base::RefCountedThreadSafe<FrameSwapMessageQueue>;

  FrameSwapMessageSubQueue* GetSubQueue(MessageDeliveryPolicy policy);

  ~FrameSwapMessageQueue();

  mutable base::Lock lock_;
  scoped_ptr<FrameSwapMessageSubQueue> visual_state_queue_;
  scoped_ptr<FrameSwapMessageSubQueue> swap_queue_;
  ScopedVector<IPC::Message> next_drain_messages_;

  DISALLOW_COPY_AND_ASSIGN(FrameSwapMessageQueue);
};

}  // namespace content

#endif  // CONTENT_RENDERER_GPU_FRAME_SWAP_MESSAGE_QUEUE_H_