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 | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame^] | 13 | #include "src/gpu/GrSwizzle.h" |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 14 | |
Robert Phillips | 8043f32 | 2019-05-31 08:11:36 -0400 | [diff] [blame] | 15 | // TODO: consolidate all the backend-specific flavors of this method to this |
| 16 | size_t GrETC1CompressedDataSize(int w, int h); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 17 | |
Robert Phillips | 28a5a43 | 2019-06-07 12:46:21 -0400 | [diff] [blame] | 18 | // TODO: should this be grown into a replacement for GrPixelConfig? |
| 19 | enum class GrCompression { |
| 20 | kNone, |
| 21 | kETC1, |
| 22 | }; |
| 23 | |
| 24 | // Compute the size of the buffer required to hold all the mipLevels of the specified type |
| 25 | // of data when all rowBytes are tight. |
| 26 | // Note there may still be padding between the mipLevels to meet alignment requirements. |
| 27 | size_t GrComputeTightCombinedBufferSize(GrCompression, size_t bytesPerPixel, |
| 28 | int baseWidth, int baseHeight, |
| 29 | SkTArray<size_t>* individualMipOffsets, |
| 30 | int mipLevelCount); |
| 31 | |
| 32 | void GrFillInData(GrCompression, GrPixelConfig, |
| 33 | int baseWidth, int baseHeight, |
| 34 | const SkTArray<size_t>& individualMipOffsets, |
| 35 | char* dest, const SkColor4f& color); |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 36 | |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame^] | 37 | struct GrColorInfo { |
| 38 | GrColorType fColorType = GrColorType::kUnknown; |
| 39 | SkColorSpace* fColorSpace = nullptr; |
| 40 | SkAlphaType fAlphaType = kPremul_SkAlphaType; |
| 41 | }; |
| 42 | |
| 43 | struct GrPixelInfo { |
| 44 | GrColorInfo fColorInfo = {}; |
| 45 | GrSurfaceOrigin fOrigin = kTopLeft_GrSurfaceOrigin; |
| 46 | int fWidth = 0; |
| 47 | int fHeight = 0; |
| 48 | size_t fRowBytes = 0; |
| 49 | }; |
| 50 | |
| 51 | // Swizzle param is applied after loading and before converting from srcInfo to dstInfo. |
| 52 | bool GrConvertPixels(const GrPixelInfo& dstInfo, void* dst, const GrPixelInfo& srcInfo, |
| 53 | const void* src, GrSwizzle swizzle = GrSwizzle{}); |
| 54 | |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 55 | #endif |