summaryrefslogtreecommitdiffstats
path: root/content/common/gpu/gpu_memory_allocation.h
blob: 3e1197971d94408c158f8887b1c0d6291d687495 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_
#define CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_
#pragma once

#include "base/basictypes.h"

// These are per context memory allocation limits set by the GpuMemoryManager
// and assigned to the browser and renderer context.
// They will change over time, given memory availability, and browser state.

// Memory Allocation which will be assigned to the renderer context.
struct GpuMemoryAllocationForRenderer {
  enum {
    INVALID_RESOURCE_SIZE = -1
  };

  // Exceeding this limit for an unreasonable amount of time may cause context
  // to be lost.
  size_t gpu_resource_size_in_bytes;
  bool suggest_have_backbuffer;

  GpuMemoryAllocationForRenderer()
      : gpu_resource_size_in_bytes(0),
        suggest_have_backbuffer(false) {
  }

  GpuMemoryAllocationForRenderer(size_t gpu_resource_size_in_bytes,
                                 bool suggest_have_backbuffer)
      : gpu_resource_size_in_bytes(gpu_resource_size_in_bytes),
        suggest_have_backbuffer(suggest_have_backbuffer) {
  }

  bool operator==(const GpuMemoryAllocationForRenderer& other) const {
    return gpu_resource_size_in_bytes == other.gpu_resource_size_in_bytes &&
           suggest_have_backbuffer == other.suggest_have_backbuffer;
  }
  bool operator!=(const GpuMemoryAllocationForRenderer& other) const {
    return !(*this == other);
  }
};

// Memory Allocation which will be assigned to the browser.
struct GpuMemoryAllocationForBrowser {
  bool suggest_have_frontbuffer;

  GpuMemoryAllocationForBrowser()
      : suggest_have_frontbuffer(false) {
  }

  GpuMemoryAllocationForBrowser(bool suggest_have_frontbuffer)
      : suggest_have_frontbuffer(suggest_have_frontbuffer) {
  }

  bool operator==(const GpuMemoryAllocationForBrowser& other) const {
      return suggest_have_frontbuffer == other.suggest_have_frontbuffer;
  }
  bool operator!=(const GpuMemoryAllocationForBrowser& other) const {
    return !(*this == other);
  }
};

// Combination of the above two Memory Allocations which will be created by the
// GpuMemoryManager.
struct GpuMemoryAllocation : public GpuMemoryAllocationForRenderer,
                             public GpuMemoryAllocationForBrowser {
  // Bitmap
  enum BufferAllocation {
    kHasNoBuffers = 0,
    kHasFrontbuffer = 1,
    kHasBackbuffer = 2
  };

  GpuMemoryAllocation()
      : GpuMemoryAllocationForRenderer(),
        GpuMemoryAllocationForBrowser() {
  }

  GpuMemoryAllocation(size_t gpu_resource_size_in_bytes,
                      int allocationBitmap)
      : GpuMemoryAllocationForRenderer(gpu_resource_size_in_bytes,
            (allocationBitmap & kHasBackbuffer) == kHasBackbuffer),
        GpuMemoryAllocationForBrowser(
            (allocationBitmap & kHasFrontbuffer) == kHasFrontbuffer) {
  }

  bool operator==(const GpuMemoryAllocation& other) const {
      return static_cast<const GpuMemoryAllocationForRenderer&>(*this) ==
             static_cast<const GpuMemoryAllocationForRenderer&>(other) &&
             static_cast<const GpuMemoryAllocationForBrowser&>(*this) ==
             static_cast<const GpuMemoryAllocationForBrowser&>(other);
  }
  bool operator!=(const GpuMemoryAllocation& other) const {
    return !(*this == other);
  }
};

#endif // CONTENT_COMMON_GPU_GPU_MEMORY_ALLOCATION_H_