Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / image_factory.cc
bloba80d17c8ddbff0dd25c3bd1dead32e54c8963942
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 return true;
86 NOTREACHED();
87 return false;
90 // static
91 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
92 const gfx::Size& size,
93 gfx::GpuMemoryBuffer::Format format) {
94 switch (format) {
95 case gfx::GpuMemoryBuffer::ATC:
96 case gfx::GpuMemoryBuffer::ATCIA:
97 case gfx::GpuMemoryBuffer::DXT1:
98 case gfx::GpuMemoryBuffer::DXT5:
99 case gfx::GpuMemoryBuffer::ETC1:
100 // Compressed images must have a width and height that's evenly divisible
101 // by the block size.
102 return size.width() % 4 == 0 && size.height() % 4 == 0;
103 case gfx::GpuMemoryBuffer::RGBA_8888:
104 case gfx::GpuMemoryBuffer::BGRA_8888:
105 case gfx::GpuMemoryBuffer::RGBX_8888:
106 return true;
109 NOTREACHED();
110 return false;
113 } // namespace gpu