summaryrefslogtreecommitdiffstats
path: root/content/common/gpu/gpu_memory_manager_client.h
blob: 3a941e2589806b67b0c4b362252d1fb28066c628 (plain)
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
109
110
// Copyright (c) 2012 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_COMMON_GPU_GPU_MEMORY_MANAGER_CLIENT_H_
#define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_CLIENT_H_

#include <list>

#include "base/basictypes.h"
#include "content/common/content_export.h"
#include "gpu/command_buffer/common/gpu_memory_allocation.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "ui/gfx/size.h"

namespace content {

class GpuMemoryManager;
class GpuMemoryTrackingGroup;

// The interface that the GPU memory manager uses to manipulate a client (to
// send it allocation information and query its properties).
class CONTENT_EXPORT GpuMemoryManagerClient {
 public:
  virtual ~GpuMemoryManagerClient() {}

  // Returns surface size.
  virtual gfx::Size GetSurfaceSize() const = 0;

  // Returns the memory tracker for this stub.
  virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const = 0;

  // Sets buffer usage depending on Memory Allocation
  virtual void SetMemoryAllocation(
      const gpu::MemoryAllocation& allocation) = 0;

  virtual void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) = 0;

  // Returns in bytes the total amount of GPU memory for the GPU which this
  // context is currently rendering on. Returns false if no extension exists
  // to get the exact amount of GPU memory.
  virtual bool GetTotalGpuMemory(uint64* bytes) = 0;
};

// The state associated with a GPU memory manager client. This acts as the
// handle through which the client interacts with the GPU memory manager.
class CONTENT_EXPORT GpuMemoryManagerClientState {
 public:
  ~GpuMemoryManagerClientState();
  void SetVisible(bool visible);
  void SetManagedMemoryStats(const gpu::ManagedMemoryStats& stats);

 private:
  friend class GpuMemoryManager;

  GpuMemoryManagerClientState(GpuMemoryManager* memory_manager,
                              GpuMemoryManagerClient* client,
                              GpuMemoryTrackingGroup* tracking_group,
                              bool has_surface,
                              bool visible);

  // The memory manager this client is hanging off of.
  GpuMemoryManager* memory_manager_;

  // The client to send allocations to.
  GpuMemoryManagerClient* client_;

  // The tracking group for this client.
  GpuMemoryTrackingGroup* tracking_group_;

  // Offscreen commandbuffers will not have a surface.
  const bool has_surface_;

  // Whether or not this client is visible.
  bool visible_;

  // If the client has a surface, then this is an iterator in the
  // clients_visible_mru_ if this client is visible and
  // clients_nonvisible_mru_ if this is non-visible. Otherwise this is an
  // iterator in clients_nonsurface_.
  std::list<GpuMemoryManagerClientState*>::iterator list_iterator_;
  bool list_iterator_valid_;

  // Statistics about memory usage.
  gpu::ManagedMemoryStats managed_memory_stats_;
  bool managed_memory_stats_received_;

  // When managed_memory_stats_.bytes_nicetohave leaves the range
  // [low_, high_], then re-adjust memory limits.
  uint64 bytes_nicetohave_limit_low_;
  uint64 bytes_nicetohave_limit_high_;

  // The allocation for this client, used transiently during memory policy
  // calculation.
  uint64 bytes_allocation_when_visible_;

  // The ideal allocation for this client for three performance levels, used
  // transiently during memory policy calculation.
  uint64 bytes_allocation_ideal_nicetohave_;
  uint64 bytes_allocation_ideal_required_;
  uint64 bytes_allocation_ideal_minimum_;

  // Set to disable allocating a frontbuffer or to disable allocations
  // for clients that don't have surfaces.
  bool hibernated_;
};

}  // namespace content

#endif  // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_CLIENT_H_