1 /* 2 * Copyright 2019 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 GrDataUtils_DEFINED 9 #define GrDataUtils_DEFINED 10 11 #include "include/core/SkColor.h" 12 #include "include/private/GrTypesPriv.h" 13 #include "include/private/SkTArray.h" 14 15 class GrImageInfo; 16 class GrCPixmap; 17 class GrPixmap; 18 class SkPixmap; 19 20 size_t GrNumBlocks(SkImage::CompressionType, SkISize baseDimensions); 21 22 // Returns a value that can be used to set rowBytes for a transfer function. 23 size_t GrCompressedRowBytes(SkImage::CompressionType, int w); 24 25 // Return the pixel dimensions of a compressed texture. The topmost levels 26 // of a compressed mipmapped texture (i.e., 1x1 or 2x2) still occupy a full 27 // block and thus objectively take up more pixels (e.g., 4x4 pixels for ETC1). 28 SkISize GrCompressedDimensions(SkImage::CompressionType, SkISize baseDimensions); 29 30 // Compute the size of the buffer required to hold all the mipLevels of the specified type 31 // of data when all rowBytes are tight. 32 // Note there may still be padding between the mipLevels to meet alignment requirements. 33 size_t GrComputeTightCombinedBufferSize(size_t bytesPerPixel, SkISize baseDimensions, 34 SkTArray<size_t>* individualMipOffsets, int mipLevelCount); 35 36 void GrFillInCompressedData(SkImage::CompressionType, SkISize dimensions, GrMipmapped, char* dest, 37 const SkColor4f& color); 38 39 bool GrConvertPixels(const GrPixmap& dst, const GrCPixmap& src, bool flipY = false); 40 41 /** Clears the dst image to a constant color. */ 42 bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, std::array<float, 4> color); 43 44 #if GR_TEST_UTILS 45 /** 46 * BC1 compress an image that contains only either opaque black or transparent black and one 47 * other color. 48 * opaque pixmaps -> kBC1_RGB8_UNORM 49 * transparent pixmaps -> kBC1_RGBA8_UNORM 50 */ 51 void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dstPixels); 52 #endif 53 54 #endif 55