OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_image_memory.h" | 5 #include "ui/gl/gl_image_memory.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "ui/gfx/buffer_format_util.h" | 12 #include "ui/gfx/buffer_format_util.h" |
13 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/gl_context.h" | 14 #include "ui/gl/gl_context.h" |
15 #include "ui/gl/gl_version_info.h" | 15 #include "ui/gl/gl_version_info.h" |
16 | 16 |
17 using gfx::BufferFormat; | 17 using gfx::BufferFormat; |
18 | 18 |
19 namespace gl { | 19 namespace gl { |
20 namespace { | 20 namespace { |
21 | 21 |
22 bool ValidInternalFormat(unsigned internalformat) { | 22 bool ValidInternalFormat(unsigned internalformat) { |
23 switch (internalformat) { | 23 switch (internalformat) { |
24 case GL_ATC_RGB_AMD: | 24 case GL_ATC_RGB_AMD: |
25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: | 25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
26 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | 26 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
27 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: | 27 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
28 case GL_ETC1_RGB8_OES: | 28 case GL_ETC1_RGB8_OES: |
29 case GL_RED: | 29 case GL_R8: |
Zhenyao Mo
2016/02/22 22:53:08
Please also keep GL_RED
| |
30 case GL_RGB: | 30 case GL_RGB: |
31 case GL_RGBA: | 31 case GL_RGBA: |
32 case GL_BGRA_EXT: | 32 case GL_BGRA_EXT: |
33 return true; | 33 return true; |
34 default: | 34 default: |
35 return false; | 35 return false; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 bool ValidFormat(BufferFormat format) { | 39 bool ValidFormat(BufferFormat format) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 return GL_ATC_RGB_AMD; | 92 return GL_ATC_RGB_AMD; |
93 case BufferFormat::ATCIA: | 93 case BufferFormat::ATCIA: |
94 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | 94 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; |
95 case BufferFormat::DXT1: | 95 case BufferFormat::DXT1: |
96 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 96 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
97 case BufferFormat::DXT5: | 97 case BufferFormat::DXT5: |
98 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 98 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
99 case BufferFormat::ETC1: | 99 case BufferFormat::ETC1: |
100 return GL_ETC1_RGB8_OES; | 100 return GL_ETC1_RGB8_OES; |
101 case BufferFormat::R_8: | 101 case BufferFormat::R_8: |
102 return GL_RED; | 102 return gfx::GLContext::GetCurrent()->GetVersionInfo()->IsES3Capable() |
103 ? GL_R8 | |
104 : GL_RED; | |
103 case BufferFormat::RGBA_4444: | 105 case BufferFormat::RGBA_4444: |
104 case BufferFormat::RGBA_8888: | 106 case BufferFormat::RGBA_8888: |
105 return GL_RGBA; | 107 return GL_RGBA; |
106 case BufferFormat::BGRA_8888: | 108 case BufferFormat::BGRA_8888: |
107 return GL_BGRA_EXT; | 109 return GL_BGRA_EXT; |
108 case BufferFormat::RGBX_8888: | 110 case BufferFormat::RGBX_8888: |
109 case BufferFormat::BGRX_8888: | 111 case BufferFormat::BGRX_8888: |
110 return GL_RGB; | 112 return GL_RGB; |
111 case BufferFormat::YUV_420: | 113 case BufferFormat::YUV_420: |
112 case BufferFormat::YUV_420_BIPLANAR: | 114 case BufferFormat::YUV_420_BIPLANAR: |
113 case BufferFormat::UYVY_422: | 115 case BufferFormat::UYVY_422: |
114 NOTREACHED(); | 116 NOTREACHED(); |
115 return 0; | 117 return 0; |
116 } | 118 } |
117 | 119 |
118 NOTREACHED(); | 120 NOTREACHED(); |
119 return 0; | 121 return 0; |
120 } | 122 } |
121 | 123 |
122 GLenum DataFormat(BufferFormat format) { | 124 GLenum DataFormat(BufferFormat format) { |
123 switch (format) { | 125 switch (format) { |
124 case BufferFormat::RGBX_8888: | 126 case BufferFormat::RGBX_8888: |
125 return GL_RGBA; | 127 return GL_RGBA; |
126 case BufferFormat::BGRX_8888: | 128 case BufferFormat::BGRX_8888: |
127 return GL_BGRA_EXT; | 129 return GL_BGRA_EXT; |
130 case BufferFormat::R_8: | |
131 return GL_RED; | |
Zhenyao Mo
2016/02/22 22:53:08
Why not let TextureFormat() deal with it here?
Daniele Castagna
2016/02/22 23:16:33
TextureFormat returns GL_R8 for ES3.
IIUC DataForm
| |
128 case BufferFormat::RGBA_4444: | 132 case BufferFormat::RGBA_4444: |
129 case BufferFormat::RGBA_8888: | 133 case BufferFormat::RGBA_8888: |
130 case BufferFormat::BGRA_8888: | 134 case BufferFormat::BGRA_8888: |
131 case BufferFormat::R_8: | |
132 case BufferFormat::ATC: | 135 case BufferFormat::ATC: |
133 case BufferFormat::ATCIA: | 136 case BufferFormat::ATCIA: |
134 case BufferFormat::DXT1: | 137 case BufferFormat::DXT1: |
135 case BufferFormat::DXT5: | 138 case BufferFormat::DXT5: |
136 case BufferFormat::ETC1: | 139 case BufferFormat::ETC1: |
137 return TextureFormat(format); | 140 return TextureFormat(format); |
138 case BufferFormat::YUV_420: | 141 case BufferFormat::YUV_420: |
139 case BufferFormat::YUV_420_BIPLANAR: | 142 case BufferFormat::YUV_420_BIPLANAR: |
140 case BufferFormat::UYVY_422: | 143 case BufferFormat::UYVY_422: |
141 NOTREACHED(); | 144 NOTREACHED(); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 return false; | 447 return false; |
445 } | 448 } |
446 | 449 |
447 // static | 450 // static |
448 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { | 451 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { |
449 DCHECK(ValidFormat(format)); | 452 DCHECK(ValidFormat(format)); |
450 return TextureFormat(format); | 453 return TextureFormat(format); |
451 } | 454 } |
452 | 455 |
453 } // namespace gl | 456 } // namespace gl |
OLD | NEW |