We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / gpu / command_buffer / service / image_factory.cc
blobf09cfb89058990588c0dee2f1a872b69bfc498cb
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::GpuMemoryBuffer::Format ImageFactory::ImageFormatToGpuMemoryBufferFormat(
20 unsigned internalformat) {
21 switch (internalformat) {
22 case GL_RGB:
23 return gfx::GpuMemoryBuffer::RGBX_8888;
24 case GL_RGBA:
25 return gfx::GpuMemoryBuffer::RGBA_8888;
26 case GL_BGRA_EXT:
27 return gfx::GpuMemoryBuffer::BGRA_8888;
28 case GL_ATC_RGB_AMD:
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;
38 default:
39 NOTREACHED();
40 return gfx::GpuMemoryBuffer::RGBA_8888;
44 // static
45 gfx::GpuMemoryBuffer::Usage ImageFactory::ImageUsageToGpuMemoryBufferUsage(
46 unsigned usage) {
47 switch (usage) {
48 case GL_MAP_CHROMIUM:
49 return gfx::GpuMemoryBuffer::MAP;
50 case GL_SCANOUT_CHROMIUM:
51 return gfx::GpuMemoryBuffer::SCANOUT;
52 default:
53 NOTREACHED();
54 return gfx::GpuMemoryBuffer::MAP;
58 // static
59 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
60 unsigned internalformat,
61 gfx::GpuMemoryBuffer::Format format) {
62 return ImageFormatToGpuMemoryBufferFormat(internalformat) == format;
65 // static
66 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
67 gfx::GpuMemoryBuffer::Format format,
68 const gpu::Capabilities& capabilities) {
69 switch (format) {
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:
84 return true;
87 NOTREACHED();
88 return false;
91 // static
92 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
93 const gfx::Size& size,
94 gfx::GpuMemoryBuffer::Format format) {
95 switch (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:
108 return true;
111 NOTREACHED();
112 return false;
115 } // namespace gpu