Flutter Engine
The Flutter Engine
Functions
SkCompressedDataUtils.h File Reference
#include "include/core/SkRefCnt.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkTArray.h"
#include <cstddef>

Go to the source code of this file.

Functions

static constexpr bool SkTextureCompressionTypeIsOpaque (SkTextureCompressionType compression)
 
size_t SkCompressedDataSize (SkTextureCompressionType, SkISize baseDimensions, skia_private::TArray< size_t > *individualMipOffsets, bool mipmapped)
 
size_t SkCompressedBlockSize (SkTextureCompressionType type)
 
size_t SkCompressedFormatDataSize (SkTextureCompressionType compressionType, SkISize dimensions, bool mipmapped)
 
bool SkDecompress (sk_sp< SkData > data, SkISize dimensions, SkTextureCompressionType compressionType, SkBitmap *dst)
 

Function Documentation

◆ SkCompressedBlockSize()

size_t SkCompressedBlockSize ( SkTextureCompressionType  type)

◆ SkCompressedDataSize()

size_t SkCompressedDataSize ( SkTextureCompressionType  type,
SkISize  baseDimensions,
skia_private::TArray< size_t > *  individualMipOffsets,
bool  mipmapped 
)

Definition at line 254 of file SkCompressedDataUtils.cpp.

255 {
256 SkASSERT(!individualMipOffsets || individualMipOffsets->empty());
257
258 int numMipLevels = 1;
259 if (mipmapped) {
260 numMipLevels = SkMipmap::ComputeLevelCount(dimensions.width(), dimensions.height()) + 1;
261 }
262
263 size_t totalSize = 0;
264 switch (type) {
266 break;
270 for (int i = 0; i < numMipLevels; ++i) {
271 int numBlocks = num_4x4_blocks(dimensions.width()) *
272 num_4x4_blocks(dimensions.height());
273
274 if (individualMipOffsets) {
275 individualMipOffsets->push_back(totalSize);
276 }
277
278 static_assert(sizeof(ETC1Block) == sizeof(BC1Block));
279 totalSize += numBlocks * sizeof(ETC1Block);
280
281 dimensions = {std::max(1, dimensions.width()/2), std::max(1, dimensions.height()/2)};
282 }
283 break;
284 }
285 }
286
287 return totalSize;
288}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int num_4x4_blocks(int size)
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition: SkMipmap.cpp:134
bool empty() const
Definition: SkTArray.h:199
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ SkCompressedFormatDataSize()

size_t SkCompressedFormatDataSize ( SkTextureCompressionType  compressionType,
SkISize  dimensions,
bool  mipmapped 
)

Returns the data size for the given SkTextureCompressionType

Definition at line 303 of file SkCompressedDataUtils.cpp.

304 {
305 return SkCompressedDataSize(compressionType, dimensions, nullptr, mipmapped);
306}
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)

◆ SkDecompress()

bool SkDecompress ( sk_sp< SkData data,
SkISize  dimensions,
SkTextureCompressionType  compressionType,
SkBitmap dst 
)

Definition at line 237 of file SkCompressedDataUtils.cpp.

240 {
242
243 const uint8_t* bytes = data->bytes();
244 switch (compressionType) {
245 case Type::kNone: return false;
246 case Type::kETC2_RGB8_UNORM: return decompress_etc1(dimensions, bytes, dst);
247 case Type::kBC1_RGB8_UNORM: return decompress_bc1(dimensions, bytes, true, dst);
248 case Type::kBC1_RGBA8_UNORM: return decompress_bc1(dimensions, bytes, false, dst);
249 }
250
252}
static bool decompress_bc1(SkISize dimensions, const uint8_t *srcData, bool isOpaque, SkBitmap *dst)
static bool decompress_etc1(SkISize dimensions, const uint8_t *srcData, SkBitmap *dst)
SkTextureCompressionType
dst
Definition: cp.py:12
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ SkTextureCompressionTypeIsOpaque()

static constexpr bool SkTextureCompressionTypeIsOpaque ( SkTextureCompressionType  compression)
staticconstexpr

Definition at line 22 of file SkCompressedDataUtils.h.

22 {
23 switch (compression) {
24 case SkTextureCompressionType::kNone: return true;
28 }
29
31}