File: client_discardable_manager.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 3,318 bytes parent folder | download | duplicates (3)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_CLIENT_CLIENT_DISCARDABLE_MANAGER_H_
#define GPU_COMMAND_BUFFER_CLIENT_CLIENT_DISCARDABLE_MANAGER_H_

#include <map>
#include <set>

#include "base/containers/queue.h"
#include "gpu/command_buffer/client/gpu_command_buffer_client_export.h"
#include "gpu/command_buffer/common/command_buffer.h"
#include "gpu/command_buffer/common/discardable_handle.h"

namespace gpu {

// ClientDiscardableManager is a helper class used by the
// ClientDiscardableTextureManager. It allows for the creation and management
// of ClientDiscardableHandles.
class GPU_COMMAND_BUFFER_CLIENT_EXPORT ClientDiscardableManager {
 public:
  ClientDiscardableManager();

  ClientDiscardableManager(const ClientDiscardableManager&) = delete;
  ClientDiscardableManager& operator=(const ClientDiscardableManager&) = delete;

  ~ClientDiscardableManager();

  // Note that the handles bound to an id are not guaranteed to outlive the
  // handle id. GetHandle may return an empty handle if the corresponding handle
  // was deleted on the service.
  ClientDiscardableHandle::Id CreateHandle(CommandBuffer* command_buffer);
  bool LockHandle(ClientDiscardableHandle::Id handle_id);
  void FreeHandle(ClientDiscardableHandle::Id handle_id);
  bool HandleIsValid(ClientDiscardableHandle::Id handle_id) const;
  ClientDiscardableHandle GetHandle(ClientDiscardableHandle::Id handle_id);
  bool HandleIsDeleted(ClientDiscardableHandle::Id handle_id);

  // For diagnostic tracing only.
  bool HandleIsDeletedForTracing(ClientDiscardableHandle::Id handle_id) const;

  // Test only functions.
  void CheckPendingForTesting(CommandBuffer* command_buffer) {
    CheckPending(command_buffer);
  }
  void SetElementCountForTesting(uint32_t count) {
    elements_per_allocation_ = count;
    allocation_size_ = count * element_size_;
  }

 private:
  bool FindAllocation(CommandBuffer* command_buffer,
                      scoped_refptr<Buffer>* buffer,
                      int32_t* shm_id,
                      uint32_t* offset);
  bool FindExistingAllocation(CommandBuffer* command_buffer,
                              scoped_refptr<Buffer>* buffer,
                              int32_t* shm_id,
                              uint32_t* offset);
  void ReturnAllocation(CommandBuffer* command_buffer,
                        const ClientDiscardableHandle& handle);
  void CheckPending(CommandBuffer* command_buffer);
  // Return true if we found at least one deleted entry.
  bool CheckDeleted(CommandBuffer* command_buffer);
  bool CreateNewAllocation(CommandBuffer* command_buffer);

 private:
  size_t allocation_size_;
  size_t element_size_ = sizeof(base::subtle::Atomic32);
  size_t elements_per_allocation_ = allocation_size_ / element_size_;

  struct Allocation;
  std::vector<std::unique_ptr<Allocation>> allocations_;
  std::map<ClientDiscardableHandle::Id, ClientDiscardableHandle> handles_;

  // Handles that are pending service deletion, and can be re-used once
  // ClientDiscardableHandle::CanBeReUsed returns true.
  base::queue<ClientDiscardableHandle> pending_handles_;
};

}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_CLIENT_CLIENT_DISCARDABLE_MANAGER_H_