Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / command_buffer / service / image_factory.cc
blobf940498abf7edcf6922223a7fbe208fe4141193d
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_R8:
23 return gfx::GpuMemoryBuffer::R_8;
24 case GL_RGB:
25 return gfx::GpuMemoryBuffer::RGBX_8888;
26 case GL_RGBA:
27 return gfx::GpuMemoryBuffer::RGBA_8888;
28 case GL_BGRA_EXT:
29 return gfx::GpuMemoryBuffer::BGRA_8888;
30 case GL_ATC_RGB_AMD:
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;
42 default:
43 NOTREACHED();
44 return gfx::GpuMemoryBuffer::RGBA_8888;
48 // static
49 gfx::GpuMemoryBuffer::Usage ImageFactory::ImageUsageToGpuMemoryBufferUsage(
50 unsigned usage) {
51 switch (usage) {
52 case GL_MAP_CHROMIUM:
53 return gfx::GpuMemoryBuffer::MAP;
54 case GL_SCANOUT_CHROMIUM:
55 return gfx::GpuMemoryBuffer::SCANOUT;
56 default:
57 NOTREACHED();
58 return gfx::GpuMemoryBuffer::MAP;
62 // static
63 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
64 unsigned internalformat,
65 gfx::GpuMemoryBuffer::Format format) {
66 return ImageFormatToGpuMemoryBufferFormat(internalformat) == format;
69 // static
70 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
71 gfx::GpuMemoryBuffer::Format format,
72 const gpu::Capabilities& capabilities) {
73 switch (format) {
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:
91 return true;
94 NOTREACHED();
95 return false;
98 // static
99 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
100 const gfx::Size& size,
101 gfx::GpuMemoryBuffer::Format format) {
102 switch (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:
116 return true;
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;
122 NOTREACHED();
123 return false;
126 } // namespace gpu