File: widget_swap_queue.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (63 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download | duplicates (8)
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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_COMPOSITING_WIDGET_SWAP_QUEUE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_COMPOSITING_WIDGET_SWAP_QUEUE_H_

#include <map>
#include "base/synchronization/lock.h"
#include "third_party/blink/public/mojom/widget/platform_widget.mojom-blink.h"
#include "third_party/blink/renderer/platform/allow_discouraged_type.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

// Queue used to keep track of which VisualStateRequestCallback should be
// invoked after a particular compositor frame swap. The callbacks are
// guaranteed to be processed after the frame is processed, but there is no
// guarantee that nothing else happens between processing the frame and
// processing the callback.
class WidgetSwapQueue {
 public:
  using VisualStateRequestCallback =
      mojom::blink::WidgetCompositor::VisualStateRequestCallback;
  WidgetSwapQueue() = default;
  ~WidgetSwapQueue() = default;
  WidgetSwapQueue(const WidgetSwapQueue&) = delete;
  WidgetSwapQueue& operator=(const WidgetSwapQueue&) = delete;

  // Returns true if there are no callback in the queue.
  bool Empty() const { return queue_.empty(); }

  // Queues the callback to be returned on a matching Drain call.
  //
  // |source_frame_number| - frame number to queue |callback| for.
  // |callback| - callback to queue. The method takes ownership of |callback|.
  // |is_first| - output parameter. Set to true if this was the first message
  //              enqueued for the given source_frame_number.
  void Queue(int source_frame_number,
             VisualStateRequestCallback callback,
             bool* is_first);

  // The method will append cllbacks queued for frame numbers lower or equal to
  // |source_frame_number|
  //
  // |source_frame_number| - swapped frame number.
  void Drain(int source_frame_number);

  // The method will clear |next_callbacks_| after copying to |callbacks|.
  //
  // |callbacks| - vector to store callbacks.
  void GetCallbacks(Vector<VisualStateRequestCallback>* callbacks);

 private:
  base::Lock lock_;
  std::map<int, Vector<VisualStateRequestCallback>> queue_
      ALLOW_DISCOURAGED_TYPE("TODO(crbug.com/1404327)");
  Vector<VisualStateRequestCallback> next_callbacks_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_COMPOSITING_WIDGET_SWAP_QUEUE_H_