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::GpuMemoryBuffer::Format
ImageFactory::ImageFormatToGpuMemoryBufferFormat(
20 unsigned internalformat
) {
21 switch (internalformat
) {
23 return gfx::GpuMemoryBuffer::R_8
;
25 return gfx::GpuMemoryBuffer::RGBX_8888
;
27 return gfx::GpuMemoryBuffer::RGBA_8888
;
29 return gfx::GpuMemoryBuffer::BGRA_8888
;
31 return gfx::GpuMemoryBuffer::ATC
;
32 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
:
33 return gfx::GpuMemoryBuffer::ATCIA
;
34 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
35 return gfx::GpuMemoryBuffer::DXT1
;
36 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
37 return gfx::GpuMemoryBuffer::DXT5
;
38 case GL_ETC1_RGB8_OES
:
39 return gfx::GpuMemoryBuffer::ETC1
;
40 case GL_RGB_YUV_420_CHROMIUM
:
41 return gfx::GpuMemoryBuffer::YUV_420
;
44 return gfx::GpuMemoryBuffer::RGBA_8888
;
49 gfx::GpuMemoryBuffer::Usage
ImageFactory::ImageUsageToGpuMemoryBufferUsage(
53 return gfx::GpuMemoryBuffer::MAP
;
54 case GL_SCANOUT_CHROMIUM
:
55 return gfx::GpuMemoryBuffer::SCANOUT
;
58 return gfx::GpuMemoryBuffer::MAP
;
63 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
64 unsigned internalformat
,
65 gfx::GpuMemoryBuffer::Format format
) {
66 return ImageFormatToGpuMemoryBufferFormat(internalformat
) == format
;
70 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
71 gfx::GpuMemoryBuffer::Format format
,
72 const gpu::Capabilities
& capabilities
) {
74 case gfx::GpuMemoryBuffer::ATC
:
75 case gfx::GpuMemoryBuffer::ATCIA
:
76 return capabilities
.texture_format_atc
;
77 case gfx::GpuMemoryBuffer::BGRA_8888
:
78 return capabilities
.texture_format_bgra8888
;
79 case gfx::GpuMemoryBuffer::DXT1
:
80 return capabilities
.texture_format_dxt1
;
81 case gfx::GpuMemoryBuffer::DXT5
:
82 return capabilities
.texture_format_dxt5
;
83 case gfx::GpuMemoryBuffer::ETC1
:
84 return capabilities
.texture_format_etc1
;
85 case gfx::GpuMemoryBuffer::R_8
:
86 return capabilities
.texture_rg
;
87 case gfx::GpuMemoryBuffer::RGBA_4444
:
88 case gfx::GpuMemoryBuffer::RGBA_8888
:
89 case gfx::GpuMemoryBuffer::RGBX_8888
:
90 case gfx::GpuMemoryBuffer::YUV_420
:
99 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
100 const gfx::Size
& size
,
101 gfx::GpuMemoryBuffer::Format format
) {
103 case gfx::GpuMemoryBuffer::ATC
:
104 case gfx::GpuMemoryBuffer::ATCIA
:
105 case gfx::GpuMemoryBuffer::DXT1
:
106 case gfx::GpuMemoryBuffer::DXT5
:
107 case gfx::GpuMemoryBuffer::ETC1
:
108 // Compressed images must have a width and height that's evenly divisible
109 // by the block size.
110 return size
.width() % 4 == 0 && size
.height() % 4 == 0;
111 case gfx::GpuMemoryBuffer::R_8
:
112 case gfx::GpuMemoryBuffer::RGBA_4444
:
113 case gfx::GpuMemoryBuffer::RGBA_8888
:
114 case gfx::GpuMemoryBuffer::BGRA_8888
:
115 case gfx::GpuMemoryBuffer::RGBX_8888
:
117 case gfx::GpuMemoryBuffer::YUV_420
:
118 // U and V planes are subsampled by a factor of 2.
119 return size
.width() % 2 == 0 && size
.height() % 2 == 0;