blob: c20ad850f675999bd39163dcc72aeb21b086007f (
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
|
// 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_TRACKING_H_
#define CONTENT_COMMON_GPU_GPU_MEMORY_TRACKING_H_
#if defined(ENABLE_GPU)
#include "base/basictypes.h"
#include "content/common/gpu/gpu_memory_manager.h"
// All decoders in a context group point to a single GpuMemoryTrackingGroup,
// which tracks GPU resource consumption for the entire context group.
class GpuMemoryTrackingGroup {
public:
GpuMemoryTrackingGroup(base::ProcessId pid, GpuMemoryManager* memory_manager)
: pid_(pid),
size_(0),
memory_manager_(memory_manager) {
memory_manager_->AddTrackingGroup(this);
}
~GpuMemoryTrackingGroup() {
memory_manager_->RemoveTrackingGroup(this);
}
void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) {
if (old_size < new_size) {
size_t delta = new_size - old_size;
size_ += delta;
}
if (new_size < old_size) {
size_t delta = old_size - new_size;
DCHECK(size_ >= delta);
size_ -= delta;
}
memory_manager_->TrackMemoryAllocatedChange(old_size, new_size);
}
base::ProcessId GetPid() const {
return pid_;
}
size_t GetSize() const {
return size_;
}
private:
base::ProcessId pid_;
size_t size_;
GpuMemoryManager* memory_manager_;
};
#endif
#endif // CONTENT_COMMON_GPU_GPU_MEMORY_TRACKING_H_
|