Pass a struct of functions instead of a function to the compressed blitter

R=robertphillips@google.com

Author: krajcevski@google.com

Review URL: https://codereview.chromium.org/443303006
This commit is contained in:
krajcevski 2014-08-07 11:10:22 -07:00 committed by Commit bot
parent 86bc1247d2
commit 45a0bf5059
4 changed files with 77 additions and 12 deletions

View File

@ -1991,6 +1991,23 @@ static void decompress_astc_block(uint8_t* dst, int dstRowBytes,
}
}
// This is the type passed as the CompressorType argument of the compressed
// blitter for the ASTC format. The static functions required to be in this
// struct are documented in SkTextureCompressor_Blitter.h
struct CompressorASTC {
static inline void CompressA8Vertical(uint8_t* dst, const uint8_t* src) {
compress_a8_astc_block<GetAlphaTranspose>(&dst, src, 12);
}
static inline void CompressA8Horizontal(uint8_t* dst, const uint8_t* src,
int srcRowBytes) {
compress_a8_astc_block<GetAlpha>(&dst, src, srcRowBytes);
}
static inline void UpdateBlock(uint8_t* dst, const uint8_t* src) {
}
};
////////////////////////////////////////////////////////////////////////////////
namespace SkTextureCompressor {
@ -2030,7 +2047,7 @@ SkBlitter* CreateASTCBlitter(int width, int height, void* outputBuffer,
}
return allocator->createT<
SkTCompressedAlphaBlitter<12, 16, CompressA8ASTCBlockVertical>, int, int, void* >
SkTCompressedAlphaBlitter<12, 16, CompressorASTC>, int, int, void* >
(width, height, outputBuffer);
}

View File

@ -13,16 +13,30 @@
namespace SkTextureCompressor {
// The function used to compress an A8 block. This function is expected to be
// used as a template argument to SkCompressedAlphaBlitter. The layout of the
// block is also expected to be in column-major order.
typedef void (*CompressA8Proc)(uint8_t* dst, const uint8_t block[]);
// This class implements a blitter that blits directly into a buffer that will
// be used as an compressed alpha texture. We compute this buffer by
// buffering scan lines and then outputting them all at once. The number of
// scan lines buffered is controlled by kBlockSize
template<int BlockDim, int EncodedBlockSize, CompressA8Proc CompressionProc>
//
// The CompressorType is a struct with a bunch of static methods that provides
// the specialized compression functionality of the blitter. A complete CompressorType
// will implement the following static functions;
//
// struct CompressorType {
// // The function used to compress an A8 block. The layout of the
// // block is also expected to be in column-major order.
// static void CompressA8Vertical(uint8_t* dst, const uint8_t block[]);
//
// // The function used to compress an A8 block. The layout of the
// // block is also expected to be in row-major order.
// static void CompressA8Horizontal(uint8_t* dst, const uint8_t block[]);
//
// // The function used to update an already compressed block. This will
// // most likely be implementation dependent.
// static void UpdateBlock(uint8_t* dst, const uint8_t* src);
// };
//
template<int BlockDim, int EncodedBlockSize, typename CompressorType>
class SkTCompressedAlphaBlitter : public SkBlitter {
public:
SkTCompressedAlphaBlitter(int width, int height, void *compressedBuffer)
@ -339,7 +353,7 @@ private:
this->updateBlockColumns(block, col, colsLeft, curAlphaColumn);
// Write this block
CompressionProc(outPtr, reinterpret_cast<uint8_t*>(block));
CompressorType::CompressA8Vertical(outPtr, reinterpret_cast<uint8_t*>(block));
outPtr += EncodedBlockSize;
curX += colsLeft;
}
@ -355,7 +369,7 @@ private:
// While we can keep advancing, just keep writing the block.
uint8_t lastBlock[EncodedBlockSize];
CompressionProc(lastBlock, reinterpret_cast<uint8_t*>(block));
CompressorType::CompressA8Vertical(lastBlock, reinterpret_cast<uint8_t*>(block));
while((finalX - curX) >= BlockDim) {
memcpy(outPtr, lastBlock, EncodedBlockSize);
outPtr += EncodedBlockSize;
@ -393,7 +407,7 @@ private:
// If we didn't land on a block boundary, output the block...
if ((curX % BlockDim) > 1) {
CompressionProc(outPtr, reinterpret_cast<uint8_t*>(block));
CompressorType::CompressA8Vertical(outPtr, reinterpret_cast<uint8_t*>(block));
}
fNextRun = 0;

View File

@ -414,6 +414,23 @@ void decompress_latc_block(uint8_t* dst, int dstRowBytes, const uint8_t* src) {
}
}
// This is the type passed as the CompressorType argument of the compressed
// blitter for the LATC format. The static functions required to be in this
// struct are documented in SkTextureCompressor_Blitter.h
struct CompressorLATC {
static inline void CompressA8Vertical(uint8_t* dst, const uint8_t block[]) {
compress_a8_latc_block<PackColumnMajor>(&dst, block, 4);
}
static inline void CompressA8Horizontal(uint8_t* dst, const uint8_t* src,
int srcRowBytes) {
compress_a8_latc_block<PackRowMajor>(&dst, src, srcRowBytes);
}
static inline void UpdateBlock(uint8_t* dst, const uint8_t* src) {
}
};
////////////////////////////////////////////////////////////////////////////////
namespace SkTextureCompressor {
@ -444,7 +461,7 @@ SkBlitter* CreateLATCBlitter(int width, int height, void* outputBuffer,
sk_bzero(outputBuffer, width * height / 2);
return allocator->createT<
SkTCompressedAlphaBlitter<4, 8, CompressA8LATCBlockVertical>, int, int, void* >
SkTCompressedAlphaBlitter<4, 8, CompressorLATC>, int, int, void* >
(width, height, outputBuffer);
#elif COMPRESS_LATC_SLOW
// TODO (krajcevski)

View File

@ -590,6 +590,23 @@ static void decompress_r11_eac_block(uint8_t* dst, int dstRowBytes, const uint8_
}
}
// This is the type passed as the CompressorType argument of the compressed
// blitter for the R11 EAC format. The static functions required to be in this
// struct are documented in SkTextureCompressor_Blitter.h
struct CompressorR11EAC {
static inline void CompressA8Vertical(uint8_t* dst, const uint8_t* src) {
compress_block_vertical(dst, src);
}
static inline void CompressA8Horizontal(uint8_t* dst, const uint8_t* src,
int srcRowBytes) {
*(reinterpret_cast<uint64_t*>(dst)) = compress_r11eac_block_fast(src, srcRowBytes);
}
static inline void UpdateBlock(uint8_t* dst, const uint8_t* src) {
}
};
////////////////////////////////////////////////////////////////////////////////
namespace SkTextureCompressor {
@ -628,7 +645,7 @@ SkBlitter* CreateR11EACBlitter(int width, int height, void* outputBuffer,
}
return allocator->createT<
SkTCompressedAlphaBlitter<4, 8, compress_block_vertical>, int, int, void*>
SkTCompressedAlphaBlitter<4, 8, CompressorR11EAC>, int, int, void*>
(width, height, outputBuffer);
}