- add sources.
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / common / gpu_memory_allocation.h
1 // Copyright 2013 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.
4
5 #ifndef GPU_COMMAND_BUFFER_COMMON_GPU_MEMORY_ALLOCATION_H_
6 #define GPU_COMMAND_BUFFER_COMMON_GPU_MEMORY_ALLOCATION_H_
7
8 #include "base/basictypes.h"
9
10 namespace gpu {
11
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.
15 struct MemoryAllocation {
16   enum PriorityCutoff {
17     // Allow no allocations.
18     CUTOFF_ALLOW_NOTHING,
19     // Allow only allocations that are strictly required for correct rendering.
20     // For compositors, this is what is visible.
21     CUTOFF_ALLOW_REQUIRED_ONLY,
22     // Allow allocations that are not strictly needed for correct rendering, but
23     // are nice to have for performance. For compositors, this includes textures
24     // that are a few screens away from being visible.
25     CUTOFF_ALLOW_NICE_TO_HAVE,
26     // Allow all allocations.
27     CUTOFF_ALLOW_EVERYTHING,
28   };
29
30   // Limits when this renderer is visible.
31   uint64 bytes_limit_when_visible;
32   PriorityCutoff priority_cutoff_when_visible;
33
34   MemoryAllocation()
35       : bytes_limit_when_visible(0),
36         priority_cutoff_when_visible(CUTOFF_ALLOW_NOTHING) {
37   }
38
39   MemoryAllocation(uint64 bytes_limit_when_visible)
40       : bytes_limit_when_visible(bytes_limit_when_visible),
41         priority_cutoff_when_visible(CUTOFF_ALLOW_EVERYTHING) {
42   }
43
44   bool Equals(const MemoryAllocation& other) const {
45     return bytes_limit_when_visible ==
46                other.bytes_limit_when_visible &&
47         priority_cutoff_when_visible == other.priority_cutoff_when_visible;
48   }
49 };
50
51 // Memory Allocation request which is sent by a client, to help GpuMemoryManager
52 // more ideally split memory allocations across clients.
53 struct ManagedMemoryStats {
54   // Bytes required for correct rendering.
55   uint64 bytes_required;
56
57   // Bytes that are not strictly required for correctness, but, if allocated,
58   // will provide good performance.
59   uint64 bytes_nice_to_have;
60
61   // The number of bytes currently allocated.
62   uint64 bytes_allocated;
63
64   // Whether or not a backbuffer is currently requested (the memory usage
65   // of the buffer is known by the GPU process).
66   bool backbuffer_requested;
67
68   ManagedMemoryStats()
69       : bytes_required(0),
70         bytes_nice_to_have(0),
71         bytes_allocated(0),
72         backbuffer_requested(false) {
73   }
74
75   ManagedMemoryStats(uint64 bytes_required,
76                         uint64 bytes_nice_to_have,
77                         uint64 bytes_allocated,
78                         bool backbuffer_requested)
79       : bytes_required(bytes_required),
80         bytes_nice_to_have(bytes_nice_to_have),
81         bytes_allocated(bytes_allocated),
82         backbuffer_requested(backbuffer_requested) {
83   }
84
85   bool Equals(const ManagedMemoryStats& other) const {
86     return bytes_required == other.bytes_required &&
87         bytes_nice_to_have == other.bytes_nice_to_have &&
88         bytes_allocated == other.bytes_allocated &&
89         backbuffer_requested == other.backbuffer_requested;
90   }
91 };
92
93 }  // namespace content
94
95 #endif // GPU_COMMAND_BUFFER_COMMON_GPU_MEMORY_ALLOCATION_H_