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
;
42 case GL_RGB_YCBCR_422_CHROMIUM
:
43 return gfx::BufferFormat::UYVY_422
;
46 return gfx::BufferFormat::RGBA_8888
;
51 gfx::BufferUsage
ImageFactory::ImageUsageToGpuMemoryBufferUsage(
55 return gfx::BufferUsage::MAP
;
56 case GL_SCANOUT_CHROMIUM
:
57 return gfx::BufferUsage::SCANOUT
;
60 return gfx::BufferUsage::MAP
;
65 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
66 unsigned internalformat
,
67 gfx::BufferFormat 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
;
91 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
92 gfx::BufferFormat format
,
93 const gpu::Capabilities
& capabilities
) {
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
:
115 case gfx::BufferFormat::YUV_420_BIPLANAR
:
124 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
125 const gfx::Size
& size
,
126 gfx::BufferFormat 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
:
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;