| 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 #ifndef CONTENT_COMMON_GPU_CLIENT_GL_HELPER_READBACK_SUPPORT_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GL_HELPER_READBACK_SUPPORT_H_ |
| 6 #define CONTENT_COMMON_GPU_CLIENT_GL_HELPER_READBACK_SUPPORT_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_GL_HELPER_READBACK_SUPPORT_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "content/common/gpu/client/gl_helper.h" | 10 #include "content/common/gpu/client/gl_helper.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 class CONTENT_EXPORT GLHelperReadbackSupport { | 14 class CONTENT_EXPORT GLHelperReadbackSupport { |
| 15 public: | 15 public: |
| 16 enum FormatSupport { SUPPORTED, SWIZZLE, NOT_SUPPORTED }; |
| 17 |
| 16 GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl); | 18 GLHelperReadbackSupport(gpu::gles2::GLES2Interface* gl); |
| 17 | 19 |
| 18 ~GLHelperReadbackSupport(); | 20 ~GLHelperReadbackSupport(); |
| 19 | 21 |
| 20 // Checks whether the readback (Color read format and type) is supported | 22 // For a given color type retrieve whether readback is supported and if so |
| 21 // for the requested texture format by the hardware or not. | 23 // how it should be performed. The |format|, |type| and |bytes_per_pixel| are |
| 22 // For ex: some hardwares have rgb565 readback | 24 // the values that should be used with glReadPixels to facilitate the |
| 23 // support when binded with the frame buffer for others it may fail. | 25 // readback. If |can_swizzle| is true then this method will return SWIZZLE if |
| 24 // Here we pass the internal textureformat as skia config. | 26 // the data needs to be swizzled before using the returned |format| otherwise |
| 25 bool IsReadbackConfigSupported(SkColorType texture_format); | 27 // the method will return SUPPORTED to indicate that readback is permitted of |
| 26 | 28 // this color othewise NOT_SUPPORTED will be returned. This method always |
| 29 // overwrites the out values irrespective of the return value. |
| 30 FormatSupport GetReadbackConfig(SkColorType color_type, |
| 31 bool can_swizzle, |
| 32 GLenum* format, |
| 33 GLenum* type, |
| 34 size_t* bytes_per_pixel); |
| 27 // Provides the additional readback format/type pairing for a render target | 35 // Provides the additional readback format/type pairing for a render target |
| 28 // of a given format/type pairing | 36 // of a given format/type pairing |
| 29 void GetAdditionalFormat(GLint format, GLint type, GLint *format_out, | 37 void GetAdditionalFormat(GLenum format, GLenum type, GLenum *format_out, |
| 30 GLint *type_out); | 38 GLenum *type_out); |
| 31 private: | 39 private: |
| 32 enum FormatSupport { FORMAT_NOT_SUPPORTED = 0, FORMAT_SUPPORTED, }; | |
| 33 | |
| 34 struct FormatCacheEntry { | 40 struct FormatCacheEntry { |
| 35 GLint format; | 41 GLenum format; |
| 36 GLint type; | 42 GLenum type; |
| 37 GLint read_format; | 43 GLenum read_format; |
| 38 GLint read_type; | 44 GLenum read_type; |
| 39 }; | 45 }; |
| 40 | 46 |
| 41 // This populates the format_support_table with the list of supported | 47 // This populates the format_support_table with the list of supported |
| 42 // formats. | 48 // formats. |
| 43 void InitializeReadbackSupport(); | 49 void InitializeReadbackSupport(); |
| 44 | 50 |
| 45 // This api is called once per format and it is done in the | 51 // This api is called once per format and it is done in the |
| 46 // InitializeReadbackSupport. We should not use this any where | 52 // InitializeReadbackSupport. We should not use this any where |
| 47 // except the InitializeReadbackSupport.Calling this at other places | 53 // except the InitializeReadbackSupport.Calling this at other places |
| 48 // can distrub the state of normal gl operations. | 54 // can distrub the state of normal gl operations. |
| 49 void CheckForReadbackSupport(SkColorType texture_format); | 55 void CheckForReadbackSupport(SkColorType texture_format); |
| 50 | 56 |
| 51 // Helper functions for checking the supported texture formats. | 57 // Helper functions for checking the supported texture formats. |
| 52 // Avoid using this API in between texture operations, as this does some | 58 // Avoid using this API in between texture operations, as this does some |
| 53 // teture opertions (bind, attach) internally. | 59 // teture opertions (bind, attach) internally. |
| 54 bool SupportsFormat(GLint format, GLint type); | 60 bool SupportsFormat(GLenum format, GLenum type); |
| 55 | 61 |
| 56 FormatSupport format_support_table_[kLastEnum_SkColorType + 1]; | 62 FormatSupport format_support_table_[kLastEnum_SkColorType + 1]; |
| 57 | 63 |
| 58 gpu::gles2::GLES2Interface* gl_; | 64 gpu::gles2::GLES2Interface* gl_; |
| 59 std::vector<struct FormatCacheEntry> format_cache_; | 65 std::vector<struct FormatCacheEntry> format_cache_; |
| 60 }; | 66 }; |
| 61 | 67 |
| 62 } // namespace content | 68 } // namespace content |
| 63 | 69 |
| 64 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_READBACK_SUPPORT_H_ | 70 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_READBACK_SUPPORT_H_ |
| OLD | NEW |