Home | History | Annotate | Download | only in gpu
      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.
      4 
      5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_
      6 #define CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_
      7 
      8 #include "base/basictypes.h"
      9 
     10 namespace content {
     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 
     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,
     30   };
     31 
     32   // Limits when this renderer is visible.
     33   uint64 bytes_limit_when_visible;
     34   PriorityCutoff priority_cutoff_when_visible;
     35 
     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;
     40 
     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) {
     47   }
     48 
     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) {
     55   }
     56 
     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;
     66   }
     67 };
     68 
     69 // Memory Allocation which will be assigned to the browser.
     70 struct GpuMemoryAllocationForBrowser {
     71   bool suggest_have_frontbuffer;
     72 
     73   GpuMemoryAllocationForBrowser()
     74       : suggest_have_frontbuffer(false) {
     75   }
     76 
     77   GpuMemoryAllocationForBrowser(bool suggest_have_frontbuffer)
     78       : suggest_have_frontbuffer(suggest_have_frontbuffer) {
     79   }
     80 
     81   bool Equals(const GpuMemoryAllocationForBrowser& other) const {
     82       return suggest_have_frontbuffer == other.suggest_have_frontbuffer;
     83   }
     84 };
     85 
     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;
     91 
     92   enum BufferAllocation {
     93     kHasNoFrontbuffer = 0,
     94     kHasFrontbuffer = 1,
     95   };
     96 
     97   GpuMemoryAllocation() {
     98   }
     99 
    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) {
    104   }
    105 
    106   bool Equals(const GpuMemoryAllocation& other) const {
    107       return renderer_allocation.Equals(other.renderer_allocation) &&
    108           browser_allocation.Equals(other.browser_allocation);
    109   }
    110 };
    111 
    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;
    117 
    118   // Bytes that are not strictly required for correctness, but, if allocated,
    119   // will provide good performance.
    120   uint64 bytes_nice_to_have;
    121 
    122   // The number of bytes currently allocated.
    123   uint64 bytes_allocated;
    124 
    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;
    128 
    129   GpuManagedMemoryStats()
    130       : bytes_required(0),
    131         bytes_nice_to_have(0),
    132         bytes_allocated(0),
    133         backbuffer_requested(false) {
    134   }
    135 
    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) {
    144   }
    145 
    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;
    151   }
    152 };
    153 
    154 }  // namespace content
    155 
    156 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_
    157