Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 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" |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrColorInfo.h" |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrSwizzle.h" |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 15 | |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 16 | class GrImageInfo; |
| 17 | |
Jim Van Verth | e367101 | 2019-09-18 09:53:31 -0400 | [diff] [blame] | 18 | // Returns a value that can be used to set rowBytes for a transfer function. |
| 19 | size_t GrCompressedRowBytes(SkImage::CompressionType, int w); |
| 20 | |
Robert Phillips | 41acc0e | 2020-01-06 13:29:53 -0500 | [diff] [blame] | 21 | // Return the pixel dimensions of a compressed texture. The topmost levels |
| 22 | // of a compressed mipmapped texture (i.e., 1x1 or 2x2) still occupy a full |
| 23 | // block and thus objectively take up more pixels (e.g., 4x4 pixels for ETC1). |
| 24 | SkISize GrCompressedDimensions(SkImage::CompressionType, SkISize baseDimensions); |
| 25 | |
Robert Phillips | 28a5a43 | 2019-06-07 12:46:21 -0400 | [diff] [blame] | 26 | // Compute the size of the buffer required to hold all the mipLevels of the specified type |
| 27 | // of data when all rowBytes are tight. |
| 28 | // Note there may still be padding between the mipLevels to meet alignment requirements. |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 29 | size_t GrComputeTightCombinedBufferSize(size_t bytesPerPixel, SkISize baseDimensions, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 30 | SkTArray<size_t>* individualMipOffsets, int mipLevelCount); |
Robert Phillips | 28a5a43 | 2019-06-07 12:46:21 -0400 | [diff] [blame] | 31 | |
Robert Phillips | 48257d7 | 2019-12-16 14:20:53 -0500 | [diff] [blame] | 32 | void GrFillInCompressedData(SkImage::CompressionType, SkISize dimensions, GrMipMapped, char* dest, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 33 | const SkColor4f& color); |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 34 | |
| 35 | // Swizzle param is applied after loading and before converting from srcInfo to dstInfo. |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 36 | bool GrConvertPixels(const GrImageInfo& dstInfo, void* dst, size_t dstRB, |
| 37 | const GrImageInfo& srcInfo, const void* src, size_t srcRB, |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 38 | bool flipY = false); |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 39 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 40 | /** Clears the dst image to a constant color. */ |
| 41 | bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, SkColor4f color); |
| 42 | |
Robert Phillips | e073552 | 2020-01-31 11:03:32 -0500 | [diff] [blame] | 43 | #if GR_TEST_UTILS |
Robert Phillips | ac90802 | 2020-01-14 16:54:17 -0500 | [diff] [blame] | 44 | /** |
| 45 | * BC1 compress an image that contains only either opaque black or transparent black and one |
| 46 | * other color. |
| 47 | * opaque pixmaps -> kBC1_RGB8_UNORM |
| 48 | * transparent pixmaps -> kBC1_RGBA8_UNORM |
| 49 | */ |
| 50 | void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dstPixels); |
Robert Phillips | e073552 | 2020-01-31 11:03:32 -0500 | [diff] [blame] | 51 | #endif |
Robert Phillips | ac90802 | 2020-01-14 16:54:17 -0500 | [diff] [blame] | 52 | |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 53 | #endif |