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 | 7 |
8 namespace content { | 8 namespace content { |
9 | 9 |
10 GLHelperReadbackSupport::GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl) | 10 GLHelperReadbackSupport::GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl) |
11 : gl_(gl) { | 11 : gl_(gl) { |
12 InitializeReadbackSupport(); | 12 InitializeReadbackSupport(); |
13 } | 13 } |
14 | 14 |
15 GLHelperReadbackSupport::~GLHelperReadbackSupport() {} | 15 GLHelperReadbackSupport::~GLHelperReadbackSupport() {} |
16 | 16 |
17 void GLHelperReadbackSupport::InitializeReadbackSupport() { | 17 void GLHelperReadbackSupport::InitializeReadbackSupport() { |
18 // We are concerned about 16, 32-bit formats only. | 18 // We are concerned about 16, 32-bit formats only. |
19 // The below are the most used 16, 32-bit formats. | 19 // The below are the most used 16, 32-bit formats. |
20 // In future if any new format support is needed that should be added here. | 20 // In future if any new format support is needed that should be added here. |
21 // Initialize the array with FORMAT_NOT_SUPPORTED as we dont know the | 21 // Initialize the array with FORMAT_NOT_SUPPORTED as we dont know the |
22 // supported formats yet. | 22 // supported formats yet. |
23 for (int i = 0; i < SkBitmap::kConfigCount; ++i) { | 23 for (int i = 0; i <= kLastEnum_SkColorType; ++i) { |
24 format_support_table_[i] = FORMAT_NOT_SUPPORTED; | 24 format_support_table_[i] = FORMAT_NOT_SUPPORTED; |
25 } | 25 } |
26 CheckForReadbackSupport(SkBitmap::kRGB_565_Config); | 26 CheckForReadbackSupport(kRGB_565_SkColorType); |
27 CheckForReadbackSupport(SkBitmap::kARGB_4444_Config); | 27 CheckForReadbackSupport(kARGB_4444_SkColorType); |
28 CheckForReadbackSupport(SkBitmap::kARGB_8888_Config); | 28 CheckForReadbackSupport(kN32_SkColorType); |
29 // Further any formats, support should be checked here. | 29 // Further any formats, support should be checked here. |
30 } | 30 } |
31 | 31 |
32 void GLHelperReadbackSupport::CheckForReadbackSupport( | 32 void GLHelperReadbackSupport::CheckForReadbackSupport( |
33 SkBitmap::Config texture_format) { | 33 SkColorType texture_format) { |
34 bool supports_format = false; | 34 bool supports_format = false; |
35 switch (texture_format) { | 35 switch (texture_format) { |
36 case SkBitmap::kRGB_565_Config: | 36 case kRGB_565_SkColorType: |
37 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); | 37 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
38 break; | 38 break; |
39 case SkBitmap::kARGB_8888_Config: | 39 case kN32_SkColorType: |
40 // This is the baseline, assume always true. | 40 // This is the baseline, assume always true. |
41 supports_format = true; | 41 supports_format = true; |
42 break; | 42 break; |
43 case SkBitmap::kARGB_4444_Config: | 43 case kARGB_4444_SkColorType: |
44 supports_format = false; | 44 supports_format = false; |
45 break; | 45 break; |
46 default: | 46 default: |
47 NOTREACHED(); | 47 NOTREACHED(); |
48 supports_format = false; | 48 supports_format = false; |
49 break; | 49 break; |
50 } | 50 } |
51 DCHECK((int)texture_format < (int)SkBitmap::kConfigCount); | 51 DCHECK((int)texture_format <= (int)kLastEnum_SkColorType); |
52 format_support_table_[texture_format] = | 52 format_support_table_[texture_format] = |
53 supports_format ? FORMAT_SUPPORTED : FORMAT_NOT_SUPPORTED; | 53 supports_format ? FORMAT_SUPPORTED : FORMAT_NOT_SUPPORTED; |
54 } | 54 } |
55 | 55 |
56 void GLHelperReadbackSupport::GetAdditionalFormat(GLint format, GLint type, | 56 void GLHelperReadbackSupport::GetAdditionalFormat(GLint format, GLint type, |
57 GLint *format_out, | 57 GLint *format_out, |
58 GLint *type_out) { | 58 GLint *type_out) { |
59 for (unsigned int i = 0; i < format_cache_.size(); i++) { | 59 for (unsigned int i = 0; i < format_cache_.size(); i++) { |
60 if (format_cache_[i].format == format && format_cache_[i].type == type) { | 60 if (format_cache_[i].format == format && format_cache_[i].type == type) { |
61 *format_out = format_cache_[i].read_format; | 61 *format_out = format_cache_[i].read_format; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 bool supports_format = false; | 93 bool supports_format = false; |
94 GLint ext_format = 0, ext_type = 0; | 94 GLint ext_format = 0, ext_type = 0; |
95 GetAdditionalFormat(format, type, &ext_format, &ext_type); | 95 GetAdditionalFormat(format, type, &ext_format, &ext_type); |
96 if ((ext_format == format) && (ext_type == type)) { | 96 if ((ext_format == format) && (ext_type == type)) { |
97 supports_format = true; | 97 supports_format = true; |
98 } | 98 } |
99 return supports_format; | 99 return supports_format; |
100 } | 100 } |
101 | 101 |
102 bool GLHelperReadbackSupport::IsReadbackConfigSupported( | 102 bool GLHelperReadbackSupport::IsReadbackConfigSupported( |
103 SkBitmap::Config texture_format) { | 103 SkColorType texture_format) { |
104 switch (format_support_table_[texture_format]) { | 104 switch (format_support_table_[texture_format]) { |
105 case FORMAT_SUPPORTED: | 105 case FORMAT_SUPPORTED: |
106 return true; | 106 return true; |
107 case FORMAT_NOT_SUPPORTED: | 107 case FORMAT_NOT_SUPPORTED: |
108 return false; | 108 return false; |
109 default: | 109 default: |
110 NOTREACHED(); | 110 NOTREACHED(); |
111 return false; | 111 return false; |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 } // namespace content | 115 } // namespace content |
OLD | NEW |