File: gpu_memory_buffer_support.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (166 lines) | stat: -rw-r--r-- 5,285 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2016 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.

#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"

#include <GLES2/gl2.h>
#include <GLES2/gl2extchromium.h>

#include "base/logging.h"
#include "gpu/command_buffer/common/capabilities.h"

namespace gpu {

namespace {

gfx::BufferFormat BufferFormatForInternalFormat(unsigned internalformat) {
  switch (internalformat) {
    case GL_RED_EXT:
      return gfx::BufferFormat::R_8;
    case GL_RG_EXT:
      return gfx::BufferFormat::RG_88;
    case GL_RGB:
      return gfx::BufferFormat::BGRX_8888;
    case GL_RGBA:
      return gfx::BufferFormat::RGBA_8888;
    case GL_BGRA_EXT:
      return gfx::BufferFormat::BGRA_8888;
    case GL_ATC_RGB_AMD:
      return gfx::BufferFormat::ATC;
    case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
      return gfx::BufferFormat::ATCIA;
    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
      return gfx::BufferFormat::DXT1;
    case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
      return gfx::BufferFormat::DXT5;
    case GL_ETC1_RGB8_OES:
      return gfx::BufferFormat::ETC1;
    case GL_RGB_YCRCB_420_CHROMIUM:
      return gfx::BufferFormat::YVU_420;
    case GL_RGB_YCBCR_420V_CHROMIUM:
      return gfx::BufferFormat::YUV_420_BIPLANAR;
    case GL_RGB_YCBCR_422_CHROMIUM:
      return gfx::BufferFormat::UYVY_422;
    default:
      NOTREACHED();
      return gfx::BufferFormat::RGBA_8888;
  }
}

}  // namespace

gfx::BufferFormat DefaultBufferFormatForImageFormat(unsigned internalformat) {
  switch (internalformat) {
    case GL_RGB:
      return gfx::BufferFormat::BGRX_8888;
    case GL_RGBA:
      return gfx::BufferFormat::RGBA_8888;
    default:
      NOTREACHED();
      return gfx::BufferFormat::RGBA_8888;
  }
}

bool IsImageFormatCompatibleWithGpuMemoryBufferFormat(
    unsigned internalformat,
    gfx::BufferFormat format) {
  switch (format) {
    case gfx::BufferFormat::ATC:
    case gfx::BufferFormat::ATCIA:
    case gfx::BufferFormat::BGRA_8888:
    case gfx::BufferFormat::BGRX_8888:
    case gfx::BufferFormat::DXT1:
    case gfx::BufferFormat::DXT5:
    case gfx::BufferFormat::ETC1:
    case gfx::BufferFormat::R_8:
    case gfx::BufferFormat::RG_88:
    case gfx::BufferFormat::RGBA_8888:
    case gfx::BufferFormat::YVU_420:
    case gfx::BufferFormat::YUV_420_BIPLANAR:
    case gfx::BufferFormat::UYVY_422:
      return format == BufferFormatForInternalFormat(internalformat);
    case gfx::BufferFormat::BGR_565:
    case gfx::BufferFormat::RGBX_8888:
      return internalformat == GL_RGB;
    case gfx::BufferFormat::RGBA_4444:
      return internalformat == GL_RGBA;
  }

  NOTREACHED();
  return false;
}

bool IsGpuMemoryBufferFormatSupported(gfx::BufferFormat format,
                                      const gpu::Capabilities& capabilities) {
  switch (format) {
    case gfx::BufferFormat::ATC:
    case gfx::BufferFormat::ATCIA:
      return capabilities.texture_format_atc;
    case gfx::BufferFormat::BGRA_8888:
    case gfx::BufferFormat::BGRX_8888:
      return capabilities.texture_format_bgra8888;
    case gfx::BufferFormat::DXT1:
      return capabilities.texture_format_dxt1;
    case gfx::BufferFormat::DXT5:
      return capabilities.texture_format_dxt5;
    case gfx::BufferFormat::ETC1:
      return capabilities.texture_format_etc1;
    case gfx::BufferFormat::R_8:
    case gfx::BufferFormat::RG_88:
      return capabilities.texture_rg;
    case gfx::BufferFormat::UYVY_422:
      return capabilities.image_ycbcr_422;
    case gfx::BufferFormat::BGR_565:
    case gfx::BufferFormat::RGBA_4444:
    case gfx::BufferFormat::RGBA_8888:
    case gfx::BufferFormat::RGBX_8888:
    case gfx::BufferFormat::YVU_420:
      return true;
    case gfx::BufferFormat::YUV_420_BIPLANAR:
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
      // TODO(dcastagna): Determine ycbcr_420v_image on CrOS at runtime
      // querying minigbm. crbug.com/646148
      return true;
#else
      return capabilities.image_ycbcr_420v;
#endif
  }

  NOTREACHED();
  return false;
}

bool IsImageSizeValidForGpuMemoryBufferFormat(const gfx::Size& size,
                                              gfx::BufferFormat format) {
  switch (format) {
    case gfx::BufferFormat::ATC:
    case gfx::BufferFormat::ATCIA:
    case gfx::BufferFormat::DXT1:
    case gfx::BufferFormat::DXT5:
    case gfx::BufferFormat::ETC1:
      // Compressed images must have a width and height that's evenly divisible
      // by the block size.
      return size.width() % 4 == 0 && size.height() % 4 == 0;
    case gfx::BufferFormat::R_8:
    case gfx::BufferFormat::RG_88:
    case gfx::BufferFormat::BGR_565:
    case gfx::BufferFormat::RGBA_4444:
    case gfx::BufferFormat::RGBA_8888:
    case gfx::BufferFormat::RGBX_8888:
    case gfx::BufferFormat::BGRA_8888:
    case gfx::BufferFormat::BGRX_8888:
      return true;
    case gfx::BufferFormat::YVU_420:
    case gfx::BufferFormat::YUV_420_BIPLANAR:
      // U and V planes are subsampled by a factor of 2.
      return size.width() % 2 == 0 && size.height() % 2 == 0;
    case gfx::BufferFormat::UYVY_422:
      return size.width() % 2 == 0;
  }

  NOTREACHED();
  return false;
}

}  // namespace gpu