OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/common/gpu/client/gl_helper_readback_support.h" | |
6 #include "base/logging.h" | |
7 | |
8 namespace content { | |
9 | |
10 GLHelperReadbackSupport::GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl, | |
11 GLHelper* helper) | |
12 : gl_(gl), helper_(helper) { | |
13 InitializeReadbackSupport(); | |
14 } | |
15 | |
16 GLHelperReadbackSupport::~GLHelperReadbackSupport() {} | |
17 | |
18 void GLHelperReadbackSupport::InitializeReadbackSupport() { | |
19 // We are concerned about 16, 32-bit formats only. | |
20 // The below are the most used 16, 32-bit formats. | |
21 // In future if any new format support is needed that should be added here. | |
22 // Initialize the array with FORMAT_NOT_SUPPORTED as we dont know the | |
23 // supported formats yet. | |
24 for (int i = 0; i < SkBitmap::kConfigCount; ++i) { | |
25 format_support_table_[i] = FORMAT_NOT_SUPPORTED; | |
26 } | |
27 CheckForReadbackSupport(SkBitmap::kRGB_565_Config); | |
28 CheckForReadbackSupport(SkBitmap::kARGB_4444_Config); | |
29 CheckForReadbackSupport(SkBitmap::kARGB_8888_Config); | |
30 // Further any formats, support should be checked here. | |
31 } | |
32 | |
33 void GLHelperReadbackSupport::CheckForReadbackSupport( | |
34 SkBitmap::Config texture_format) { | |
35 bool supports_format = false; | |
36 switch (texture_format) { | |
37 case SkBitmap::kRGB_565_Config: | |
38 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); | |
39 break; | |
40 case SkBitmap::kARGB_8888_Config: | |
41 supports_format = SupportsFormat(GL_RGBA, GL_UNSIGNED_BYTE); | |
42 break; | |
43 case SkBitmap::kARGB_4444_Config: | |
44 supports_format = false; | |
45 break; | |
46 default: | |
47 NOTREACHED(); | |
48 supports_format = false; | |
49 break; | |
50 } | |
no sievers
2014/02/28 19:25:53
just to be paranoid since you use SkBitmap::Config
sivag
2014/03/04 09:46:45
Done.
| |
51 format_support_table_[texture_format] = | |
52 supports_format ? FORMAT_SUPPORTED : FORMAT_NOT_SUPPORTED; | |
53 } | |
54 | |
55 bool GLHelperReadbackSupport::SupportsFormat(GLint format, GLint type) { | |
56 const int kTestSize = 64; | |
57 GLuint dst_texture = 0u; | |
58 bool supports_format = false; | |
59 gl_->GenTextures(1, &dst_texture); | |
no sievers
2014/02/28 19:25:53
nit: instead of Gen/Delete you can use ScopedTextu
sivag
2014/03/04 09:46:45
Done.
| |
60 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | |
61 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
62 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
63 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
64 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
65 gl_->TexImage2D( | |
66 GL_TEXTURE_2D, 0, format, kTestSize, kTestSize, 0, format, type, NULL); | |
67 ScopedFramebuffer dst_framebuffer(gl_); | |
68 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | |
69 dst_framebuffer); | |
70 gl_->FramebufferTexture2D( | |
71 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dst_texture, 0); | |
72 GLint ext_format = 0, ext_type = 0; | |
73 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); | |
74 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); | |
75 gl_->DeleteTextures(1, &dst_texture); | |
76 if ((ext_format == format) && (ext_type == type)) { | |
77 supports_format = true; | |
78 } | |
79 return supports_format; | |
80 } | |
81 | |
82 bool GLHelperReadbackSupport::IsReadbackConfigSupported( | |
83 SkBitmap::Config texture_format) { | |
84 switch (format_support_table_[texture_format]) { | |
85 case FORMAT_SUPPORTED: | |
86 return true; | |
87 case FORMAT_NOT_SUPPORTED: | |
no sievers
2014/02/28 19:25:53
case FORMAT_NOT_SUPPORTED:
return false;
default
sivag
2014/03/04 09:46:45
Done.
sivag
2014/03/04 09:46:45
Done.
| |
88 default: | |
89 return false; | |
90 } | |
91 } | |
92 | |
93 } // namespace content | |
OLD | NEW |