| 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 // TODO(sikugu): kAlpha_8_SkColorType support check is failing on mesa. | 28 |
| 29 // See crbug.com/415667. | 29 CheckForReadbackSupport(kAlpha_8_SkColorType); |
| 30 CheckForReadbackSupport(kRGB_565_SkColorType); | 30 CheckForReadbackSupport(kRGB_565_SkColorType); |
| 31 CheckForReadbackSupport(kARGB_4444_SkColorType); | 31 CheckForReadbackSupport(kARGB_4444_SkColorType); |
| 32 CheckForReadbackSupport(kRGBA_8888_SkColorType); | 32 CheckForReadbackSupport(kRGBA_8888_SkColorType); |
| 33 CheckForReadbackSupport(kBGRA_8888_SkColorType); | 33 CheckForReadbackSupport(kBGRA_8888_SkColorType); |
| 34 // Further any formats, support should be checked here. | 34 // Further any formats, support should be checked here. |
| 35 } | 35 } |
| 36 | 36 |
| 37 void GLHelperReadbackSupport::CheckForReadbackSupport( | 37 void GLHelperReadbackSupport::CheckForReadbackSupport( |
| 38 SkColorType texture_format) { | 38 SkColorType texture_format) { |
| 39 bool supports_format = false; | 39 bool supports_format = false; |
| 40 switch (texture_format) { | 40 switch (texture_format) { |
| 41 case kAlpha_8_SkColorType: |
| 42 supports_format = SupportsFormat(GL_ALPHA, GL_UNSIGNED_BYTE); |
| 43 break; |
| 41 case kRGB_565_SkColorType: | 44 case kRGB_565_SkColorType: |
| 42 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); | 45 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
| 43 break; | 46 break; |
| 44 case kRGBA_8888_SkColorType: | 47 case kRGBA_8888_SkColorType: |
| 45 // This is the baseline, assume always true. | 48 // This is the baseline, assume always true. |
| 46 supports_format = true; | 49 supports_format = true; |
| 47 break; | 50 break; |
| 48 case kBGRA_8888_SkColorType: | 51 case kBGRA_8888_SkColorType: |
| 49 supports_format = SupportsFormat(GL_BGRA_EXT, GL_UNSIGNED_BYTE); | 52 supports_format = SupportsFormat(GL_BGRA_EXT, GL_UNSIGNED_BYTE); |
| 50 break; | 53 break; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 GLHelperReadbackSupport::GetReadbackConfig(SkColorType color_type, | 131 GLHelperReadbackSupport::GetReadbackConfig(SkColorType color_type, |
| 129 bool can_swizzle, | 132 bool can_swizzle, |
| 130 GLenum* format, | 133 GLenum* format, |
| 131 GLenum* type, | 134 GLenum* type, |
| 132 size_t* bytes_per_pixel) { | 135 size_t* bytes_per_pixel) { |
| 133 DCHECK(format && type && bytes_per_pixel); | 136 DCHECK(format && type && bytes_per_pixel); |
| 134 *bytes_per_pixel = 4; | 137 *bytes_per_pixel = 4; |
| 135 *type = GL_UNSIGNED_BYTE; | 138 *type = GL_UNSIGNED_BYTE; |
| 136 GLenum new_format = 0, new_type = 0; | 139 GLenum new_format = 0, new_type = 0; |
| 137 switch (color_type) { | 140 switch (color_type) { |
| 141 case kAlpha_8_SkColorType: |
| 142 if (format_support_table_[color_type] == |
| 143 GLHelperReadbackSupport::SUPPORTED) { |
| 144 *format = GL_ALPHA; |
| 145 *type = GL_UNSIGNED_BYTE; |
| 146 *bytes_per_pixel = 1; |
| 147 return GLHelperReadbackSupport::SUPPORTED; |
| 148 } |
| 149 break; |
| 138 case kRGB_565_SkColorType: | 150 case kRGB_565_SkColorType: |
| 139 if (format_support_table_[color_type] == | 151 if (format_support_table_[color_type] == |
| 140 GLHelperReadbackSupport::SUPPORTED) { | 152 GLHelperReadbackSupport::SUPPORTED) { |
| 141 *format = GL_RGB; | 153 *format = GL_RGB; |
| 142 *type = GL_UNSIGNED_SHORT_5_6_5; | 154 *type = GL_UNSIGNED_SHORT_5_6_5; |
| 143 *bytes_per_pixel = 2; | 155 *bytes_per_pixel = 2; |
| 144 return GLHelperReadbackSupport::SUPPORTED; | 156 return GLHelperReadbackSupport::SUPPORTED; |
| 145 } | 157 } |
| 146 break; | 158 break; |
| 147 case kRGBA_8888_SkColorType: | 159 case kRGBA_8888_SkColorType: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 174 return GLHelperReadbackSupport::NOT_SUPPORTED; | 186 return GLHelperReadbackSupport::NOT_SUPPORTED; |
| 175 default: | 187 default: |
| 176 NOTREACHED(); | 188 NOTREACHED(); |
| 177 break; | 189 break; |
| 178 } | 190 } |
| 179 | 191 |
| 180 return GLHelperReadbackSupport::NOT_SUPPORTED; | 192 return GLHelperReadbackSupport::NOT_SUPPORTED; |
| 181 } | 193 } |
| 182 | 194 |
| 183 } // namespace content | 195 } // namespace content |
| OLD | NEW |