1 // Copyright 2022 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 
16 #include <memory>
17 #include <string>
18 
19 namespace gfxstream {
20 namespace vk {
21 
22 // This class is responsible for decompressing ASTC textures on the CPU.
23 // This class is thread-safe and all its methods can be called by any thread.
24 class AstcCpuDecompressor {
25    public:
26     // Returns the global singleton instance of this class.
27     static AstcCpuDecompressor& get();
28 
29     virtual ~AstcCpuDecompressor() = 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     // imgWidth, imgHeight: width and height of the texture, in texels.
40     // blockWidth, blockHeight: ASTC encoding block size.
41     // astData: pointer to the ASTC data to decompress
42     // astcDataLength: size of astData
43     // output: where to white the decompressed output. This buffer must be able to hold at least
44     //         imgWidth * imgHeight * 4 bytes.
45     //
46     // Returns 0 on success, or a non-zero status code on error. Use getStatusString() to convert
47     // this status code to an error string.
48     virtual int32_t decompress(uint32_t imgWidth, uint32_t imgHeight, uint32_t blockWidth,
49                                uint32_t blockHeight, const uint8_t* astcData,
50                                size_t astcDataLength, uint8_t* output) = 0;
51 
52     // Returns an error string for a given status code. Will always return non-null.
53     virtual const char* getStatusString(int32_t statusCode) const = 0;
54 };
55 
56 }  // namespace vk
57 }  // namespace gfxstream
58