1 // 2 // Copyright 2022 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // AstcDecompressor.h: Decodes ASTC-encoded textures. 8 9 #ifndef IMAGE_UTIL_ASTC_CPU_DECOMPRESSOR_H_ 10 #define IMAGE_UTIL_ASTC_CPU_DECOMPRESSOR_H_ 11 12 #include <stdint.h> 13 14 #include <memory> 15 #include <string> 16 17 namespace angle 18 { 19 class WorkerThreadPool; 20 21 // This class is responsible for decompressing ASTC textures on the CPU. 22 // This class is thread-safe and all its methods can be called by any thread. 23 class AstcDecompressor 24 { 25 public: 26 // Returns the global singleton instance of this class. 27 static AstcDecompressor &get(); 28 29 virtual ~AstcDecompressor() = default; 30 31 // Whether the ASTC decompressor is available. Reasons why it may not be available include: 32 // - It wasn't compiled on this platform. 33 // - The CPU doesn't support AVX2 instructions. 34 // If this returns false, decompress() will fail. 35 virtual bool available() const = 0; 36 37 // Decompress an ASTC texture. 38 // 39 // singleThreadPool: a thread pool that runs tasks on the current thread. Must not be null. 40 // multiThreadPool: (optional) a multi-threaded pool. If non-null, this will be used if the 41 // image is large enough to benefit from it. 42 // imgWidth, imgHeight: width and height of the texture, in texels. 43 // blockWidth, blockHeight: ASTC encoding block size. 44 // input: pointer to the ASTC data to decompress 45 // inputLength: size of astData 46 // output: where to white the decompressed output. This buffer must be able to hold at least 47 // imgWidth * imgHeight * 4 bytes. 48 // 49 // Returns 0 on success, or a non-zero status code on error. Use getStatusString() to convert 50 // this status code to an error string. 51 virtual int32_t decompress(std::shared_ptr<WorkerThreadPool> singleThreadPool, 52 std::shared_ptr<WorkerThreadPool> multiThreadPool, 53 uint32_t imgWidth, 54 uint32_t imgHeight, 55 uint32_t blockWidth, 56 uint32_t blockHeight, 57 const uint8_t *input, 58 size_t inputLength, 59 uint8_t *output) = 0; 60 61 // Returns an error string for a given status code. Will always return non-null. 62 virtual const char *getStatusString(int32_t statusCode) const = 0; 63 }; 64 65 } // namespace angle 66 67 #endif // IMAGE_UTIL_ASTC_CPU_DECOMPRESSOR_H_ 68