Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / common / gpu / gpu_memory_allocation.h
bloba2a9b9ac72594607b3e9fb398e7d40d34ce94d21
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_
6 #define CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_
8 #include "base/basictypes.h"
10 namespace content {
12 // These are per context memory allocation limits set by the GpuMemoryManager
13 // and assigned to the browser and renderer context.
14 // They will change over time, given memory availability, and browser state.
16 // Memory Allocation which will be assigned to the renderer context.
17 struct GpuMemoryAllocationForRenderer {
18 enum PriorityCutoff {
19 // Allow no allocations.
20 kPriorityCutoffAllowNothing,
21 // Allow only allocations that are strictly required for correct rendering.
22 // For compositors, this is what is visible.
23 kPriorityCutoffAllowOnlyRequired,
24 // Allow allocations that are not strictly needed for correct rendering, but
25 // are nice to have for performance. For compositors, this includes textures
26 // that are a few screens away from being visible.
27 kPriorityCutoffAllowNiceToHave,
28 // Allow all allocations.
29 kPriorityCutoffAllowEverything,
32 // Limits when this renderer is visible.
33 uint64 bytes_limit_when_visible;
34 PriorityCutoff priority_cutoff_when_visible;
36 // Limits when this renderer is not visible.
37 uint64 bytes_limit_when_not_visible;
38 PriorityCutoff priority_cutoff_when_not_visible;
39 bool have_backbuffer_when_not_visible;
41 GpuMemoryAllocationForRenderer()
42 : bytes_limit_when_visible(0),
43 priority_cutoff_when_visible(kPriorityCutoffAllowNothing),
44 bytes_limit_when_not_visible(0),
45 priority_cutoff_when_not_visible(kPriorityCutoffAllowNothing),
46 have_backbuffer_when_not_visible(false) {
49 GpuMemoryAllocationForRenderer(uint64 bytes_limit_when_visible)
50 : bytes_limit_when_visible(bytes_limit_when_visible),
51 priority_cutoff_when_visible(kPriorityCutoffAllowEverything),
52 bytes_limit_when_not_visible(0),
53 priority_cutoff_when_not_visible(kPriorityCutoffAllowNothing),
54 have_backbuffer_when_not_visible(false) {
57 bool Equals(const GpuMemoryAllocationForRenderer& other) const {
58 return bytes_limit_when_visible ==
59 other.bytes_limit_when_visible &&
60 priority_cutoff_when_visible == other.priority_cutoff_when_visible &&
61 bytes_limit_when_not_visible == other.bytes_limit_when_not_visible &&
62 priority_cutoff_when_not_visible ==
63 other.priority_cutoff_when_not_visible &&
64 have_backbuffer_when_not_visible ==
65 other.have_backbuffer_when_not_visible;
69 // Memory Allocation which will be assigned to the browser.
70 struct GpuMemoryAllocationForBrowser {
71 bool suggest_have_frontbuffer;
73 GpuMemoryAllocationForBrowser()
74 : suggest_have_frontbuffer(false) {
77 GpuMemoryAllocationForBrowser(bool suggest_have_frontbuffer)
78 : suggest_have_frontbuffer(suggest_have_frontbuffer) {
81 bool Equals(const GpuMemoryAllocationForBrowser& other) const {
82 return suggest_have_frontbuffer == other.suggest_have_frontbuffer;
86 // Combination of the above two Memory Allocations which will be created by the
87 // GpuMemoryManager.
88 struct GpuMemoryAllocation {
89 GpuMemoryAllocationForRenderer renderer_allocation;
90 GpuMemoryAllocationForBrowser browser_allocation;
92 enum BufferAllocation {
93 kHasNoFrontbuffer = 0,
94 kHasFrontbuffer = 1,
97 GpuMemoryAllocation() {
100 GpuMemoryAllocation(uint64 gpu_resource_size_in_bytes,
101 BufferAllocation buffer_allocation)
102 : renderer_allocation(gpu_resource_size_in_bytes),
103 browser_allocation(buffer_allocation == kHasFrontbuffer) {
106 bool Equals(const GpuMemoryAllocation& other) const {
107 return renderer_allocation.Equals(other.renderer_allocation) &&
108 browser_allocation.Equals(other.browser_allocation);
112 // Memory Allocation request which is sent by a client, to help GpuMemoryManager
113 // more ideally split memory allocations across clients.
114 struct GpuManagedMemoryStats {
115 // Bytes required for correct rendering.
116 uint64 bytes_required;
118 // Bytes that are not strictly required for correctness, but, if allocated,
119 // will provide good performance.
120 uint64 bytes_nice_to_have;
122 // The number of bytes currently allocated.
123 uint64 bytes_allocated;
125 // Whether or not a backbuffer is currently requested (the memory usage
126 // of the buffer is known by the GPU process).
127 bool backbuffer_requested;
129 GpuManagedMemoryStats()
130 : bytes_required(0),
131 bytes_nice_to_have(0),
132 bytes_allocated(0),
133 backbuffer_requested(false) {
136 GpuManagedMemoryStats(uint64 bytes_required,
137 uint64 bytes_nice_to_have,
138 uint64 bytes_allocated,
139 bool backbuffer_requested)
140 : bytes_required(bytes_required),
141 bytes_nice_to_have(bytes_nice_to_have),
142 bytes_allocated(bytes_allocated),
143 backbuffer_requested(backbuffer_requested) {
146 bool Equals(const GpuManagedMemoryStats& other) const {
147 return bytes_required == other.bytes_required &&
148 bytes_nice_to_have == other.bytes_nice_to_have &&
149 bytes_allocated == other.bytes_allocated &&
150 backbuffer_requested == other.backbuffer_requested;
154 } // namespace content
156 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_