Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: components/display_compositor/gl_helper_readback_support.cc

Issue 807853003: Use GLHelper support to validate format before processing texture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/compositor/surface_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/logging.h" 5 #include "base/logging.h"
6 #include "components/display_compositor/gl_helper_readback_support.h" 6 #include "components/display_compositor/gl_helper_readback_support.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 display_compositor { 10 namespace display_compositor {
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 CheckForReadbackSupport(kAlpha_8_SkColorType);
29 // See crbug.com/415667.
30 CheckForReadbackSupport(kRGB_565_SkColorType); 29 CheckForReadbackSupport(kRGB_565_SkColorType);
31 CheckForReadbackSupport(kARGB_4444_SkColorType); 30 CheckForReadbackSupport(kARGB_4444_SkColorType);
32 CheckForReadbackSupport(kRGBA_8888_SkColorType); 31 CheckForReadbackSupport(kRGBA_8888_SkColorType);
33 CheckForReadbackSupport(kBGRA_8888_SkColorType); 32 CheckForReadbackSupport(kBGRA_8888_SkColorType);
34 // Further any formats, support should be checked here. 33 // Further any formats, support should be checked here.
35 } 34 }
36 35
37 void GLHelperReadbackSupport::CheckForReadbackSupport( 36 void GLHelperReadbackSupport::CheckForReadbackSupport(
38 SkColorType texture_format) { 37 SkColorType texture_format) {
39 bool supports_format = false; 38 bool supports_format = false;
40 switch (texture_format) { 39 switch (texture_format) {
40 case kAlpha_8_SkColorType:
41 supports_format = SupportsFormat(GL_ALPHA, GL_UNSIGNED_BYTE);
42 break;
41 case kRGB_565_SkColorType: 43 case kRGB_565_SkColorType:
42 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); 44 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
43 break; 45 break;
44 case kRGBA_8888_SkColorType: 46 case kRGBA_8888_SkColorType:
45 // This is the baseline, assume always true. 47 // This is the baseline, assume always true.
46 supports_format = true; 48 supports_format = true;
47 break; 49 break;
48 case kBGRA_8888_SkColorType: 50 case kBGRA_8888_SkColorType:
49 supports_format = SupportsFormat(GL_BGRA_EXT, GL_UNSIGNED_BYTE); 51 supports_format = SupportsFormat(GL_BGRA_EXT, GL_UNSIGNED_BYTE);
50 break; 52 break;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 GLHelperReadbackSupport::GetReadbackConfig(SkColorType color_type, 119 GLHelperReadbackSupport::GetReadbackConfig(SkColorType color_type,
118 bool can_swizzle, 120 bool can_swizzle,
119 GLenum* format, 121 GLenum* format,
120 GLenum* type, 122 GLenum* type,
121 size_t* bytes_per_pixel) { 123 size_t* bytes_per_pixel) {
122 DCHECK(format && type && bytes_per_pixel); 124 DCHECK(format && type && bytes_per_pixel);
123 *bytes_per_pixel = 4; 125 *bytes_per_pixel = 4;
124 *type = GL_UNSIGNED_BYTE; 126 *type = GL_UNSIGNED_BYTE;
125 GLenum new_format = 0, new_type = 0; 127 GLenum new_format = 0, new_type = 0;
126 switch (color_type) { 128 switch (color_type) {
129 case kAlpha_8_SkColorType:
130 if (format_support_table_[color_type] ==
131 GLHelperReadbackSupport::SUPPORTED) {
132 *format = GL_ALPHA;
133 *type = GL_UNSIGNED_BYTE;
134 *bytes_per_pixel = 1;
135 return GLHelperReadbackSupport::SUPPORTED;
136 }
137
138 break;
127 case kRGB_565_SkColorType: 139 case kRGB_565_SkColorType:
128 if (format_support_table_[color_type] == 140 if (format_support_table_[color_type] ==
129 GLHelperReadbackSupport::SUPPORTED) { 141 GLHelperReadbackSupport::SUPPORTED) {
130 *format = GL_RGB; 142 *format = GL_RGB;
131 *type = GL_UNSIGNED_SHORT_5_6_5; 143 *type = GL_UNSIGNED_SHORT_5_6_5;
132 *bytes_per_pixel = 2; 144 *bytes_per_pixel = 2;
133 return GLHelperReadbackSupport::SUPPORTED; 145 return GLHelperReadbackSupport::SUPPORTED;
134 } 146 }
135 break; 147 break;
136 case kRGBA_8888_SkColorType: 148 case kRGBA_8888_SkColorType:
(...skipping 26 matching lines...) Expand all
163 return GLHelperReadbackSupport::NOT_SUPPORTED; 175 return GLHelperReadbackSupport::NOT_SUPPORTED;
164 default: 176 default:
165 NOTREACHED(); 177 NOTREACHED();
166 break; 178 break;
167 } 179 }
168 180
169 return GLHelperReadbackSupport::NOT_SUPPORTED; 181 return GLHelperReadbackSupport::NOT_SUPPORTED;
170 } 182 }
171 183
172 } // namespace display_compositor 184 } // namespace display_compositor
OLDNEW
« no previous file with comments | « no previous file | content/browser/compositor/surface_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698