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::RGBX_8888
;
25 return gfx::GpuMemoryBuffer::RGBA_8888
;
27 return gfx::GpuMemoryBuffer::BGRA_8888
;
29 return gfx::GpuMemoryBuffer::ATC
;
30 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
:
31 return gfx::GpuMemoryBuffer::ATCIA
;
32 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
33 return gfx::GpuMemoryBuffer::DXT1
;
34 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
35 return gfx::GpuMemoryBuffer::DXT5
;
36 case GL_ETC1_RGB8_OES
:
37 return gfx::GpuMemoryBuffer::ETC1
;
40 return gfx::GpuMemoryBuffer::RGBA_8888
;
45 gfx::GpuMemoryBuffer::Usage
ImageFactory::ImageUsageToGpuMemoryBufferUsage(
49 return gfx::GpuMemoryBuffer::MAP
;
50 case GL_SCANOUT_CHROMIUM
:
51 return gfx::GpuMemoryBuffer::SCANOUT
;
54 return gfx::GpuMemoryBuffer::MAP
;
59 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
60 unsigned internalformat
,
61 gfx::GpuMemoryBuffer::Format format
) {
62 return ImageFormatToGpuMemoryBufferFormat(internalformat
) == format
;
66 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
67 gfx::GpuMemoryBuffer::Format format
,
68 const gpu::Capabilities
& capabilities
) {
70 case gfx::GpuMemoryBuffer::ATC
:
71 case gfx::GpuMemoryBuffer::ATCIA
:
72 return capabilities
.texture_format_atc
;
73 case gfx::GpuMemoryBuffer::BGRA_8888
:
74 return capabilities
.texture_format_bgra8888
;
75 case gfx::GpuMemoryBuffer::DXT1
:
76 return capabilities
.texture_format_dxt1
;
77 case gfx::GpuMemoryBuffer::DXT5
:
78 return capabilities
.texture_format_dxt5
;
79 case gfx::GpuMemoryBuffer::ETC1
:
80 return capabilities
.texture_format_etc1
;
81 case gfx::GpuMemoryBuffer::RGBA_8888
:
82 case gfx::GpuMemoryBuffer::RGBX_8888
:
83 case gfx::GpuMemoryBuffer::YUV_420
:
92 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
93 const gfx::Size
& size
,
94 gfx::GpuMemoryBuffer::Format format
) {
96 case gfx::GpuMemoryBuffer::ATC
:
97 case gfx::GpuMemoryBuffer::ATCIA
:
98 case gfx::GpuMemoryBuffer::DXT1
:
99 case gfx::GpuMemoryBuffer::DXT5
:
100 case gfx::GpuMemoryBuffer::ETC1
:
101 // Compressed images must have a width and height that's evenly divisible
102 // by the block size.
103 return size
.width() % 4 == 0 && size
.height() % 4 == 0;
104 case gfx::GpuMemoryBuffer::RGBA_8888
:
105 case gfx::GpuMemoryBuffer::BGRA_8888
:
106 case gfx::GpuMemoryBuffer::RGBX_8888
:
107 case gfx::GpuMemoryBuffer::YUV_420
: