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