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 "content/common/gpu/client/gl_helper_readback_support.h" | 5 #include "content/common/gpu/client/gl_helper_readback_support.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "gpu/GLES2/gl2extchromium.h" | 7 #include "gpu/GLES2/gl2extchromium.h" |
8 #include "third_party/skia/include/core/SkImageInfo.h" | 8 #include "third_party/skia/include/core/SkImageInfo.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 GLHelperReadbackSupport::GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl) | 12 GLHelperReadbackSupport::GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl) |
13 : gl_(gl) { | 13 : gl_(gl) { |
14 InitializeReadbackSupport(); | 14 InitializeReadbackSupport(); |
15 } | 15 } |
16 | 16 |
17 GLHelperReadbackSupport::~GLHelperReadbackSupport() {} | 17 GLHelperReadbackSupport::~GLHelperReadbackSupport() {} |
18 | 18 |
19 void GLHelperReadbackSupport::InitializeReadbackSupport() { | 19 void GLHelperReadbackSupport::InitializeReadbackSupport() { |
20 // We are concerned about 16, 32-bit formats only. The below are the most | 20 // We are concerned about 16, 32-bit formats only. The below are the most |
21 // used 16, 32-bit formats. In future if any new format support is needed | 21 // used 16, 32-bit formats. In future if any new format support is needed |
22 // that should be added here. Initialize the array with | 22 // that should be added here. Initialize the array with |
23 // GLHelperReadbackSupport::NOT_SUPPORTED as we dont know the supported | 23 // GLHelperReadbackSupport::NOT_SUPPORTED as we dont know the supported |
24 // formats yet. | 24 // formats yet. |
25 for (int i = 0; i <= kLastEnum_SkColorType; ++i) { | 25 for (int i = 0; i <= kLastEnum_SkColorType; ++i) { |
26 format_support_table_[i] = GLHelperReadbackSupport::NOT_SUPPORTED; | 26 format_support_table_[i] = GLHelperReadbackSupport::NOT_SUPPORTED; |
27 } | 27 } |
28 | |
29 CheckForReadbackSupport(kAlpha_8_SkColorType); | |
28 CheckForReadbackSupport(kRGB_565_SkColorType); | 30 CheckForReadbackSupport(kRGB_565_SkColorType); |
29 CheckForReadbackSupport(kARGB_4444_SkColorType); | 31 CheckForReadbackSupport(kARGB_4444_SkColorType); |
30 CheckForReadbackSupport(kRGBA_8888_SkColorType); | 32 CheckForReadbackSupport(kRGBA_8888_SkColorType); |
31 CheckForReadbackSupport(kBGRA_8888_SkColorType); | 33 CheckForReadbackSupport(kBGRA_8888_SkColorType); |
32 // Further any formats, support should be checked here. | 34 // Further any formats, support should be checked here. |
33 } | 35 } |
34 | 36 |
35 void GLHelperReadbackSupport::CheckForReadbackSupport( | 37 void GLHelperReadbackSupport::CheckForReadbackSupport( |
36 SkColorType texture_format) { | 38 SkColorType texture_format) { |
37 bool supports_format = false; | 39 bool supports_format = false; |
38 switch (texture_format) { | 40 switch (texture_format) { |
39 case kRGB_565_SkColorType: | 41 case kRGB_565_SkColorType: |
40 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); | 42 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
41 break; | 43 break; |
44 // kAlpha_8_SkColorType is supported here via a special encoding | |
45 // using a 32-bit texture to represent an 8-bit image. | |
46 case kAlpha_8_SkColorType: | |
42 case kRGBA_8888_SkColorType: | 47 case kRGBA_8888_SkColorType: |
43 // This is the baseline, assume always true. | 48 // This is the baseline, assume always true. |
44 supports_format = true; | 49 supports_format = true; |
45 break; | 50 break; |
46 case kBGRA_8888_SkColorType: | 51 case kBGRA_8888_SkColorType: |
47 supports_format = SupportsFormat(GL_BGRA_EXT, GL_UNSIGNED_BYTE); | 52 supports_format = SupportsFormat(GL_BGRA_EXT, GL_UNSIGNED_BYTE); |
48 break; | 53 break; |
49 case kARGB_4444_SkColorType: | 54 case kARGB_4444_SkColorType: |
50 supports_format = false; | 55 supports_format = false; |
51 break; | 56 break; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 switch (color_type) { | 138 switch (color_type) { |
134 case kRGB_565_SkColorType: | 139 case kRGB_565_SkColorType: |
135 if (format_support_table_[color_type] == | 140 if (format_support_table_[color_type] == |
136 GLHelperReadbackSupport::SUPPORTED) { | 141 GLHelperReadbackSupport::SUPPORTED) { |
137 *format = GL_RGB; | 142 *format = GL_RGB; |
138 *type = GL_UNSIGNED_SHORT_5_6_5; | 143 *type = GL_UNSIGNED_SHORT_5_6_5; |
139 *bytes_per_pixel = 2; | 144 *bytes_per_pixel = 2; |
140 return GLHelperReadbackSupport::SUPPORTED; | 145 return GLHelperReadbackSupport::SUPPORTED; |
141 } | 146 } |
142 break; | 147 break; |
148 case kAlpha_8_SkColorType: | |
piman
2014/09/17 19:52:31
I think we need more logic to handle this.
In the
sivag
2014/09/18 13:19:03
Done.
| |
143 case kRGBA_8888_SkColorType: | 149 case kRGBA_8888_SkColorType: |
144 *format = GL_RGBA; | 150 *format = GL_RGBA; |
145 if (can_swizzle) { | 151 if (can_swizzle) { |
146 // If GL_BGRA_EXT is advertised as the readback format through | 152 // If GL_BGRA_EXT is advertised as the readback format through |
147 // GL_IMPLEMENTATION_COLOR_READ_FORMAT then assume it is preferred by | 153 // GL_IMPLEMENTATION_COLOR_READ_FORMAT then assume it is preferred by |
148 // the implementation for performance. | 154 // the implementation for performance. |
149 GetAdditionalFormat(*format, *type, &new_format, &new_type); | 155 GetAdditionalFormat(*format, *type, &new_format, &new_type); |
150 | 156 |
151 if (new_format == GL_BGRA_EXT && new_type == GL_UNSIGNED_BYTE) { | 157 if (new_format == GL_BGRA_EXT && new_type == GL_UNSIGNED_BYTE) { |
152 *format = GL_BGRA_EXT; | 158 *format = GL_BGRA_EXT; |
(...skipping 17 matching lines...) Expand all Loading... | |
170 return GLHelperReadbackSupport::NOT_SUPPORTED; | 176 return GLHelperReadbackSupport::NOT_SUPPORTED; |
171 default: | 177 default: |
172 NOTREACHED(); | 178 NOTREACHED(); |
173 break; | 179 break; |
174 } | 180 } |
175 | 181 |
176 return GLHelperReadbackSupport::NOT_SUPPORTED; | 182 return GLHelperReadbackSupport::NOT_SUPPORTED; |
177 } | 183 } |
178 | 184 |
179 } // namespace content | 185 } // namespace content |
OLD | NEW |