Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / image_factory.cc
blob75e5d2218a9671545ebe573948c26e953d882b58
1 // Copyright 2014 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 #include "gpu/command_buffer/service/image_factory.h"
7 #include "gpu/command_buffer/common/capabilities.h"
8 #include "ui/gl/gl_bindings.h"
10 namespace gpu {
12 ImageFactory::ImageFactory() {
15 ImageFactory::~ImageFactory() {
18 // static
19 gfx::BufferFormat ImageFactory::DefaultBufferFormatForImageFormat(
20 unsigned internalformat) {
21 switch (internalformat) {
22 case GL_R8:
23 return gfx::BufferFormat::R_8;
24 case GL_RGB:
25 return gfx::BufferFormat::BGRX_8888;
26 case GL_RGBA:
27 return gfx::BufferFormat::RGBA_8888;
28 case GL_BGRA_EXT:
29 return gfx::BufferFormat::BGRA_8888;
30 case GL_ATC_RGB_AMD:
31 return gfx::BufferFormat::ATC;
32 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
33 return gfx::BufferFormat::ATCIA;
34 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
35 return gfx::BufferFormat::DXT1;
36 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
37 return gfx::BufferFormat::DXT5;
38 case GL_ETC1_RGB8_OES:
39 return gfx::BufferFormat::ETC1;
40 case GL_RGB_YUV_420_CHROMIUM:
41 return gfx::BufferFormat::YUV_420;
42 default:
43 NOTREACHED();
44 return gfx::BufferFormat::RGBA_8888;
48 // static
49 gfx::BufferUsage ImageFactory::ImageUsageToGpuMemoryBufferUsage(
50 unsigned usage) {
51 switch (usage) {
52 case GL_MAP_CHROMIUM:
53 return gfx::BufferUsage::MAP;
54 case GL_SCANOUT_CHROMIUM:
55 return gfx::BufferUsage::SCANOUT;
56 default:
57 NOTREACHED();
58 return gfx::BufferUsage::MAP;
62 // static
63 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
64 unsigned internalformat,
65 gfx::BufferFormat format) {
66 switch (format) {
67 case gfx::BufferFormat::ATC:
68 case gfx::BufferFormat::ATCIA:
69 case gfx::BufferFormat::BGRA_8888:
70 case gfx::BufferFormat::BGRX_8888:
71 case gfx::BufferFormat::DXT1:
72 case gfx::BufferFormat::DXT5:
73 case gfx::BufferFormat::ETC1:
74 case gfx::BufferFormat::R_8:
75 case gfx::BufferFormat::RGBA_8888:
76 case gfx::BufferFormat::YUV_420:
77 return format == DefaultBufferFormatForImageFormat(internalformat);
78 case gfx::BufferFormat::RGBA_4444:
79 return internalformat == GL_RGBA;
80 case gfx::BufferFormat::UYVY_422:
81 return internalformat == GL_RGB;
84 NOTREACHED();
85 return false;
88 // static
89 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
90 gfx::BufferFormat format,
91 const gpu::Capabilities& capabilities) {
92 switch (format) {
93 case gfx::BufferFormat::ATC:
94 case gfx::BufferFormat::ATCIA:
95 return capabilities.texture_format_atc;
96 case gfx::BufferFormat::BGRA_8888:
97 return capabilities.texture_format_bgra8888;
98 case gfx::BufferFormat::DXT1:
99 return capabilities.texture_format_dxt1;
100 case gfx::BufferFormat::DXT5:
101 return capabilities.texture_format_dxt5;
102 case gfx::BufferFormat::ETC1:
103 return capabilities.texture_format_etc1;
104 case gfx::BufferFormat::R_8:
105 return capabilities.texture_rg;
106 case gfx::BufferFormat::RGBA_4444:
107 case gfx::BufferFormat::RGBA_8888:
108 case gfx::BufferFormat::BGRX_8888:
109 case gfx::BufferFormat::YUV_420:
110 case gfx::BufferFormat::UYVY_422:
111 return true;
114 NOTREACHED();
115 return false;
118 // static
119 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
120 const gfx::Size& size,
121 gfx::BufferFormat format) {
122 switch (format) {
123 case gfx::BufferFormat::ATC:
124 case gfx::BufferFormat::ATCIA:
125 case gfx::BufferFormat::DXT1:
126 case gfx::BufferFormat::DXT5:
127 case gfx::BufferFormat::ETC1:
128 // Compressed images must have a width and height that's evenly divisible
129 // by the block size.
130 return size.width() % 4 == 0 && size.height() % 4 == 0;
131 case gfx::BufferFormat::R_8:
132 case gfx::BufferFormat::RGBA_4444:
133 case gfx::BufferFormat::RGBA_8888:
134 case gfx::BufferFormat::BGRA_8888:
135 case gfx::BufferFormat::BGRX_8888:
136 return true;
137 case gfx::BufferFormat::YUV_420:
138 // U and V planes are subsampled by a factor of 2.
139 return size.width() % 2 == 0 && size.height() % 2 == 0;
140 case gfx::BufferFormat::UYVY_422:
141 return size.width() % 2 == 0;
144 NOTREACHED();
145 return false;
148 } // namespace gpu