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 public: | 16 // Memory Allocation which will be assigned to the renderer context. |
| 17 struct GpuMemoryAllocationForRenderer { |
17 enum { | 18 enum { |
18 INVALID_RESOURCE_SIZE = -1 | 19 INVALID_RESOURCE_SIZE = -1 |
19 }; | 20 }; |
20 | 21 |
| 22 // Exceeding this limit for an unreasonable amount of time may cause context |
| 23 // to be lost. |
21 size_t gpu_resource_size_in_bytes; | 24 size_t gpu_resource_size_in_bytes; |
22 bool has_frontbuffer; | 25 bool suggest_have_backbuffer; |
23 bool has_backbuffer; | |
24 | 26 |
| 27 GpuMemoryAllocationForRenderer() |
| 28 : gpu_resource_size_in_bytes(0), |
| 29 suggest_have_backbuffer(false) { |
| 30 } |
| 31 |
| 32 GpuMemoryAllocationForRenderer(size_t gpu_resource_size_in_bytes, |
| 33 bool suggest_have_backbuffer) |
| 34 : gpu_resource_size_in_bytes(gpu_resource_size_in_bytes), |
| 35 suggest_have_backbuffer(suggest_have_backbuffer) { |
| 36 } |
| 37 |
| 38 bool operator==(const GpuMemoryAllocationForRenderer& other) const { |
| 39 return gpu_resource_size_in_bytes == other.gpu_resource_size_in_bytes && |
| 40 suggest_have_backbuffer == other.suggest_have_backbuffer; |
| 41 } |
| 42 bool operator!=(const GpuMemoryAllocationForRenderer& other) const { |
| 43 return !(*this == other); |
| 44 } |
| 45 }; |
| 46 |
| 47 // Memory Allocation which will be assigned to the browser. |
| 48 struct GpuMemoryAllocationForBrowser { |
| 49 bool suggest_have_frontbuffer; |
| 50 |
| 51 GpuMemoryAllocationForBrowser() |
| 52 : suggest_have_frontbuffer(false) { |
| 53 } |
| 54 |
| 55 GpuMemoryAllocationForBrowser(bool suggest_have_frontbuffer) |
| 56 : suggest_have_frontbuffer(suggest_have_frontbuffer) { |
| 57 } |
| 58 |
| 59 bool operator==(const GpuMemoryAllocationForBrowser& other) const { |
| 60 return suggest_have_frontbuffer == other.suggest_have_frontbuffer; |
| 61 } |
| 62 bool operator!=(const GpuMemoryAllocationForBrowser& other) const { |
| 63 return !(*this == other); |
| 64 } |
| 65 }; |
| 66 |
| 67 // Combination of the above two Memory Allocations which will be created by the |
| 68 // GpuMemoryManager. |
| 69 struct GpuMemoryAllocation : public GpuMemoryAllocationForRenderer, |
| 70 public GpuMemoryAllocationForBrowser { |
25 GpuMemoryAllocation() | 71 GpuMemoryAllocation() |
26 : gpu_resource_size_in_bytes(0), | 72 : GpuMemoryAllocationForRenderer(), |
27 has_frontbuffer(false), | 73 GpuMemoryAllocationForBrowser() { |
28 has_backbuffer(false) { | |
29 } | 74 } |
30 | 75 |
31 GpuMemoryAllocation(size_t gpu_resource_size_in_bytes, | 76 GpuMemoryAllocation(size_t gpu_resource_size_in_bytes, |
32 bool has_frontbuffer, | 77 bool suggest_have_backbuffer, |
33 bool has_backbuffer) | 78 bool suggest_have_frontbuffer) |
34 : gpu_resource_size_in_bytes(gpu_resource_size_in_bytes), | 79 : GpuMemoryAllocationForRenderer(gpu_resource_size_in_bytes, |
35 has_frontbuffer(has_frontbuffer), | 80 suggest_have_backbuffer), |
36 has_backbuffer(has_backbuffer) { | 81 GpuMemoryAllocationForBrowser(suggest_have_frontbuffer) { |
| 82 } |
| 83 |
| 84 bool operator==(const GpuMemoryAllocation& other) const { |
| 85 return static_cast<const GpuMemoryAllocationForRenderer&>(*this) == |
| 86 static_cast<const GpuMemoryAllocationForRenderer&>(other) && |
| 87 static_cast<const GpuMemoryAllocationForBrowser&>(*this) == |
| 88 static_cast<const GpuMemoryAllocationForBrowser&>(other); |
| 89 } |
| 90 bool operator!=(const GpuMemoryAllocation& other) const { |
| 91 return !(*this == other); |
37 } | 92 } |
38 }; | 93 }; |
39 | 94 |
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_ | 95 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_ |
OLD | NEW |