Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / image_factory.cc
blobcfc543bb9c19cf3a5f255b57bb2071002181a0a9
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 case GL_RGB_YCBCR_422_CHROMIUM:
43 return gfx::BufferFormat::UYVY_422;
44 default:
45 NOTREACHED();
46 return gfx::BufferFormat::RGBA_8888;
50 // static
51 gfx::BufferUsage ImageFactory::ImageUsageToGpuMemoryBufferUsage(
52 unsigned usage) {
53 switch (usage) {
54 case GL_MAP_CHROMIUM:
55 return gfx::BufferUsage::MAP;
56 case GL_SCANOUT_CHROMIUM:
57 return gfx::BufferUsage::SCANOUT;
58 default:
59 NOTREACHED();
60 return gfx::BufferUsage::MAP;
64 // static
65 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
66 unsigned internalformat,
67 gfx::BufferFormat format) {
68 switch (format) {
69 case gfx::BufferFormat::ATC:
70 case gfx::BufferFormat::ATCIA:
71 case gfx::BufferFormat::BGRA_8888:
72 case gfx::BufferFormat::BGRX_8888:
73 case gfx::BufferFormat::DXT1:
74 case gfx::BufferFormat::DXT5:
75 case gfx::BufferFormat::ETC1:
76 case gfx::BufferFormat::R_8:
77 case gfx::BufferFormat::RGBA_8888:
78 case gfx::BufferFormat::YUV_420:
79 case gfx::BufferFormat::YUV_420_BIPLANAR:
80 case gfx::BufferFormat::UYVY_422:
81 return format == DefaultBufferFormatForImageFormat(internalformat);
82 case gfx::BufferFormat::RGBA_4444:
83 return internalformat == GL_RGBA;
86 NOTREACHED();
87 return false;
90 // static
91 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
92 gfx::BufferFormat format,
93 const gpu::Capabilities& capabilities) {
94 switch (format) {
95 case gfx::BufferFormat::ATC:
96 case gfx::BufferFormat::ATCIA:
97 return capabilities.texture_format_atc;
98 case gfx::BufferFormat::BGRA_8888:
99 return capabilities.texture_format_bgra8888;
100 case gfx::BufferFormat::DXT1:
101 return capabilities.texture_format_dxt1;
102 case gfx::BufferFormat::DXT5:
103 return capabilities.texture_format_dxt5;
104 case gfx::BufferFormat::ETC1:
105 return capabilities.texture_format_etc1;
106 case gfx::BufferFormat::R_8:
107 return capabilities.texture_rg;
108 case gfx::BufferFormat::UYVY_422:
109 return capabilities.image_ycbcr_422;
110 case gfx::BufferFormat::RGBA_4444:
111 case gfx::BufferFormat::RGBA_8888:
112 case gfx::BufferFormat::BGRX_8888:
113 case gfx::BufferFormat::YUV_420:
114 return true;
115 case gfx::BufferFormat::YUV_420_BIPLANAR:
116 return false;
119 NOTREACHED();
120 return false;
123 // static
124 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
125 const gfx::Size& size,
126 gfx::BufferFormat format) {
127 switch (format) {
128 case gfx::BufferFormat::ATC:
129 case gfx::BufferFormat::ATCIA:
130 case gfx::BufferFormat::DXT1:
131 case gfx::BufferFormat::DXT5:
132 case gfx::BufferFormat::ETC1:
133 // Compressed images must have a width and height that's evenly divisible
134 // by the block size.
135 return size.width() % 4 == 0 && size.height() % 4 == 0;
136 case gfx::BufferFormat::R_8:
137 case gfx::BufferFormat::RGBA_4444:
138 case gfx::BufferFormat::RGBA_8888:
139 case gfx::BufferFormat::BGRA_8888:
140 case gfx::BufferFormat::BGRX_8888:
141 return true;
142 case gfx::BufferFormat::YUV_420:
143 case gfx::BufferFormat::YUV_420_BIPLANAR:
144 // U and V planes are subsampled by a factor of 2.
145 return size.width() % 2 == 0 && size.height() % 2 == 0;
146 case gfx::BufferFormat::UYVY_422:
147 return size.width() % 2 == 0;
150 NOTREACHED();
151 return false;
154 } // namespace gpu