OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_ | 5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_ |
6 #define CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_ | 6 #define CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 | 10 |
11 // These are memory allocation limits assigned to a context. | 11 // These are per context memory allocation limits set by the GpuMemoryManager |
12 // They will change over time, given memory availability, and browser state | 12 // and assigned to the browser and renderer context. |
13 // Exceeding these limits for an unreasonable amount of time will cause context | 13 // They will change over time, given memory availability, and browser state. |
14 // to be lost. | 14 |
15 class GpuMemoryAllocation { | 15 |
16 // Memory Allocation which will be assigned to the renderer context. | |
17 class GpuMemoryAllocationForRenderer { | |
piman
2012/03/15 20:14:32
style nit: if it has public fields, and essentiall
mmocny
2012/03/15 20:39:27
Fair, this is meant to act as a struct.
On 2012/0
| |
16 public: | 18 public: |
17 enum { | 19 enum { |
18 INVALID_RESOURCE_SIZE = -1 | 20 INVALID_RESOURCE_SIZE = -1 |
19 }; | 21 }; |
20 | 22 |
23 // Exceeding this limit for an unreasonable amount of time may cause context | |
24 // to be lost. | |
21 size_t gpu_resource_size_in_bytes; | 25 size_t gpu_resource_size_in_bytes; |
22 bool has_frontbuffer; | 26 bool suggest_have_backbuffer; |
23 bool has_backbuffer; | |
24 | 27 |
28 GpuMemoryAllocationForRenderer() | |
29 : gpu_resource_size_in_bytes(0), | |
30 suggest_have_backbuffer(false) { | |
31 } | |
32 | |
33 GpuMemoryAllocationForRenderer(size_t gpu_resource_size_in_bytes, | |
34 bool suggest_have_backbuffer) | |
35 : gpu_resource_size_in_bytes(gpu_resource_size_in_bytes), | |
36 suggest_have_backbuffer(suggest_have_backbuffer) { | |
37 } | |
38 | |
39 friend inline bool operator==(const GpuMemoryAllocationForRenderer& lhs, | |
piman
2012/03/15 20:14:32
No need for friend or inline. Also, if it's a non-
mmocny
2012/03/15 20:39:27
Since this is the global non-member version of op=
| |
40 const GpuMemoryAllocationForRenderer& rhs) { | |
41 return lhs.gpu_resource_size_in_bytes == rhs.gpu_resource_size_in_bytes && | |
42 lhs.suggest_have_backbuffer == rhs.suggest_have_backbuffer; | |
43 } | |
44 | |
45 friend inline bool operator!=(const GpuMemoryAllocationForRenderer& lhs, | |
46 const GpuMemoryAllocationForRenderer& rhs) { | |
47 return !(lhs == rhs); | |
48 } | |
49 }; | |
50 | |
51 // Memory Allocation which will be assigned to the browser. | |
52 class GpuMemoryAllocationForBrowser { | |
piman
2012/03/15 20:14:32
class->struct.
| |
53 public: | |
54 bool suggest_have_frontbuffer; | |
55 | |
56 GpuMemoryAllocationForBrowser() | |
57 : suggest_have_frontbuffer(false) { | |
58 } | |
59 | |
60 GpuMemoryAllocationForBrowser(bool suggest_have_frontbuffer) | |
61 : suggest_have_frontbuffer(suggest_have_frontbuffer) { | |
62 } | |
63 | |
64 friend inline bool operator==(const GpuMemoryAllocationForBrowser& lhs, | |
65 const GpuMemoryAllocationForBrowser& rhs) { | |
66 return lhs.suggest_have_frontbuffer == rhs.suggest_have_frontbuffer; | |
67 } | |
68 | |
69 friend inline bool operator!=(const GpuMemoryAllocationForBrowser& lhs, | |
70 const GpuMemoryAllocationForBrowser& rhs) { | |
71 return !(lhs == rhs); | |
72 } | |
73 }; | |
74 | |
75 // Combination of the above two Memory Allocations which will be created by the | |
76 // GpuMemoryManager. | |
77 class GpuMemoryAllocation : public GpuMemoryAllocationForRenderer, | |
78 public GpuMemoryAllocationForBrowser { | |
79 public: | |
25 GpuMemoryAllocation() | 80 GpuMemoryAllocation() |
26 : gpu_resource_size_in_bytes(0), | 81 : GpuMemoryAllocationForRenderer(), |
27 has_frontbuffer(false), | 82 GpuMemoryAllocationForBrowser() { |
28 has_backbuffer(false) { | |
29 } | 83 } |
30 | 84 |
31 GpuMemoryAllocation(size_t gpu_resource_size_in_bytes, | 85 GpuMemoryAllocation(size_t gpu_resource_size_in_bytes, |
32 bool has_frontbuffer, | 86 bool suggest_have_backbuffer, |
33 bool has_backbuffer) | 87 bool suggest_have_frontbuffer) |
34 : gpu_resource_size_in_bytes(gpu_resource_size_in_bytes), | 88 : GpuMemoryAllocationForRenderer(gpu_resource_size_in_bytes, |
35 has_frontbuffer(has_frontbuffer), | 89 suggest_have_backbuffer), |
36 has_backbuffer(has_backbuffer) { | 90 GpuMemoryAllocationForBrowser(suggest_have_frontbuffer) { |
91 } | |
92 | |
93 friend inline bool operator==(const GpuMemoryAllocation& lhs, | |
94 const GpuMemoryAllocation& rhs) { | |
95 return static_cast<const GpuMemoryAllocationForRenderer&>(lhs) == | |
96 static_cast<const GpuMemoryAllocationForRenderer&>(rhs) && | |
97 static_cast<const GpuMemoryAllocationForBrowser&>(lhs) == | |
98 static_cast<const GpuMemoryAllocationForBrowser&>(rhs); | |
99 } | |
100 | |
101 friend inline bool operator!=(const GpuMemoryAllocation& lhs, | |
102 const GpuMemoryAllocation& rhs) { | |
103 return !(lhs == rhs); | |
37 } | 104 } |
38 }; | 105 }; |
39 | 106 |
40 inline bool operator==(const GpuMemoryAllocation& lhs, | |
41 const GpuMemoryAllocation& rhs) { | |
42 return lhs.gpu_resource_size_in_bytes == rhs.gpu_resource_size_in_bytes && | |
43 lhs.has_frontbuffer == rhs.has_frontbuffer && | |
44 lhs.has_backbuffer == rhs.has_backbuffer; | |
45 } | |
46 | |
47 inline bool operator!=(const GpuMemoryAllocation& lhs, | |
48 const GpuMemoryAllocation& rhs) { | |
49 return !(lhs == rhs); | |
50 } | |
51 | |
52 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_ | 107 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_ |
OLD | NEW |