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