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