Chromium Code Reviews| Index: content/common/gpu/client/gl_helper_readback_support.cc |
| diff --git a/content/common/gpu/client/gl_helper_readback_support.cc b/content/common/gpu/client/gl_helper_readback_support.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..88d36e65421cb922e0df36755977bb6fd4cf7107 |
| --- /dev/null |
| +++ b/content/common/gpu/client/gl_helper_readback_support.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/gpu/client/gl_helper_readback_support.h" |
| +#include "base/logging.h" |
| + |
| +namespace content { |
| + |
| +GLHelperReadbackSupport::GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl, |
| + GLHelper* helper) |
| + : gl_(gl), helper_(helper) { |
| + InitializeReadbackSupport(); |
| +} |
| + |
| +GLHelperReadbackSupport::~GLHelperReadbackSupport() {} |
| + |
| +void GLHelperReadbackSupport::InitializeReadbackSupport() { |
| + // We are concerned about 16, 32-bit formats only. |
| + // The below are the most used 16, 32-bit formats. |
| + // In future if any new format support is needed that should be added here. |
| + // Initialize the array with FORMAT_NOT_SUPPORTED as we dont know the |
| + // supported formats yet. |
| + for (int i = 0; i < SkBitmap::kConfigCount; ++i) { |
| + format_support_table_[i] = FORMAT_NOT_SUPPORTED; |
| + } |
| + CheckForReadbackSupport(SkBitmap::kRGB_565_Config); |
| + CheckForReadbackSupport(SkBitmap::kARGB_4444_Config); |
| + CheckForReadbackSupport(SkBitmap::kARGB_8888_Config); |
| + // Further any formats, support should be checked here. |
| +} |
| + |
| +void GLHelperReadbackSupport::CheckForReadbackSupport( |
| + SkBitmap::Config texture_format) { |
| + bool supports_format = false; |
| + switch (texture_format) { |
| + case SkBitmap::kRGB_565_Config: |
| + supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
| + break; |
| + case SkBitmap::kARGB_8888_Config: |
| + supports_format = SupportsFormat(GL_RGBA, GL_UNSIGNED_BYTE); |
| + break; |
| + case SkBitmap::kARGB_4444_Config: |
| + supports_format = false; |
| + break; |
| + default: |
| + NOTREACHED(); |
| + supports_format = false; |
| + break; |
| + } |
|
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.
|
| + format_support_table_[texture_format] = |
| + supports_format ? FORMAT_SUPPORTED : FORMAT_NOT_SUPPORTED; |
| +} |
| + |
| +bool GLHelperReadbackSupport::SupportsFormat(GLint format, GLint type) { |
| + const int kTestSize = 64; |
| + GLuint dst_texture = 0u; |
| + bool supports_format = false; |
| + 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.
|
| + ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
| + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| + gl_->TexImage2D( |
| + GL_TEXTURE_2D, 0, format, kTestSize, kTestSize, 0, format, type, NULL); |
| + ScopedFramebuffer dst_framebuffer(gl_); |
| + ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| + dst_framebuffer); |
| + gl_->FramebufferTexture2D( |
| + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dst_texture, 0); |
| + GLint ext_format = 0, ext_type = 0; |
| + gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); |
| + gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); |
| + gl_->DeleteTextures(1, &dst_texture); |
| + if ((ext_format == format) && (ext_type == type)) { |
| + supports_format = true; |
| + } |
| + return supports_format; |
| +} |
| + |
| +bool GLHelperReadbackSupport::IsReadbackConfigSupported( |
| + SkBitmap::Config texture_format) { |
| + switch (format_support_table_[texture_format]) { |
| + case FORMAT_SUPPORTED: |
| + return true; |
| + 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.
|
| + default: |
| + return false; |
| + } |
| +} |
| + |
| +} // namespace content |