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"
12 ImageFactory::ImageFactory() {
15 ImageFactory::~ImageFactory() {
19 gfx::BufferFormat
ImageFactory::DefaultBufferFormatForImageFormat(
20 unsigned internalformat
) {
21 switch (internalformat
) {
23 return gfx::BufferFormat::R_8
;
25 return gfx::BufferFormat::BGRX_8888
;
27 return gfx::BufferFormat::RGBA_8888
;
29 return gfx::BufferFormat::BGRA_8888
;
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
;
44 return gfx::BufferFormat::RGBA_8888
;
49 gfx::BufferUsage
ImageFactory::ImageUsageToGpuMemoryBufferUsage(
53 return gfx::BufferUsage::MAP
;
54 case GL_SCANOUT_CHROMIUM
:
55 return gfx::BufferUsage::SCANOUT
;
58 return gfx::BufferUsage::MAP
;
63 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
64 unsigned internalformat
,
65 gfx::BufferFormat 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
;
89 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
90 gfx::BufferFormat format
,
91 const gpu::Capabilities
& capabilities
) {
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
:
119 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
120 const gfx::Size
& size
,
121 gfx::BufferFormat 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
:
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;