blob: c6305bab45172c2ca869f9b1ce16bad11f397a1e [file] [log] [blame]
krajcevskiae614402014-06-10 14:52:28 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkTextureCompressor_DEFINED
9#define SkTextureCompressor_DEFINED
10
krajcevskieecc35f2014-06-20 11:43:00 -070011#include "SkImageInfo.h"
krajcevskiad1df152014-07-21 11:44:37 -070012#include "SkBlitter.h"
krajcevskieecc35f2014-06-20 11:43:00 -070013
krajcevskiae614402014-06-10 14:52:28 -070014class SkBitmap;
15class SkData;
16
17namespace SkTextureCompressor {
18 // Various texture compression formats that we support.
19 enum Format {
krajcevskif3d15dc2014-06-30 08:47:33 -070020 // Alpha only formats.
krajcevskib2ef1812014-07-25 07:33:01 -070021 kLATC_Format, // 4x4 blocks, compresses A8
22 kR11_EAC_Format, // 4x4 blocks, compresses A8
23 kASTC_12x12_Format, // 12x12 blocks, compresses A8
krajcevskiae614402014-06-10 14:52:28 -070024
krajcevskib2ef1812014-07-25 07:33:01 -070025 kLast_Format = kASTC_12x12_Format
krajcevskiae614402014-06-10 14:52:28 -070026 };
27 static const int kFormatCnt = kLast_Format + 1;
28
krajcevski6c354882014-07-22 07:44:00 -070029 // Returns the size of the compressed data given the width, height, and
30 // desired compression format. If the width and height are not an appropriate
31 // multiple of the block size, then this function returns an error (-1).
32 int GetCompressedDataSize(Format fmt, int width, int height);
33
krajcevskiae614402014-06-10 14:52:28 -070034 // Returns an SkData holding a blob of compressed data that corresponds
35 // to the bitmap. If the bitmap colorType cannot be compressed using the
36 // associated format, then we return NULL. The caller is responsible for
37 // calling unref() on the returned data.
38 SkData* CompressBitmapToFormat(const SkBitmap& bitmap, Format format);
krajcevskieecc35f2014-06-20 11:43:00 -070039
40 // Compresses the given src data into dst. The src data is assumed to be
41 // large enough to hold width*height pixels. The dst data is expected to
42 // be large enough to hold the compressed data according to the format.
43 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcColorType,
krajcevski630598c2014-07-14 12:00:04 -070044 int width, int height, int rowBytes, Format format,
45 bool opt = true /* Use optimization if available */);
46
47 // This typedef defines what the nominal aspects of a compression function
48 // are. The typedef is not meant to be used by clients of the API, but rather
49 // allows SIMD optimized compression functions to be implemented.
50 typedef bool (*CompressionProc)(uint8_t* dst, const uint8_t* src,
51 int width, int height, int rowBytes);
krajcevskiad1df152014-07-21 11:44:37 -070052
krajcevski6c354882014-07-22 07:44:00 -070053 // Returns the blitter for the given compression format. Note, the blitter
54 // is intended to be used with the proper input. I.e. if you try to blit
55 // RGB source data into an R11 EAC texture, you're gonna have a bad time.
56 SkBlitter* CreateBlitterForFormat(int width, int height, void* compressedBuffer,
57 Format format);
krajcevski25a67bc2014-07-29 11:44:26 -070058
59 // Returns the desired dimensions of the block size for the given format. These dimensions
60 // don't necessarily correspond to the hardware-specified dimensions, since there may
61 // be specialized algorithms that operate on multiple blocks at once. These dimensions
62 // reflect that optimization and return the appropriate operable dimensions.
63 void GetBlockDimensions(Format format, int* dimX, int* dimY);
krajcevskiae614402014-06-10 14:52:28 -070064}
65
66#endif