blob: a55342f433f17af45cf3d051bd3c5989794fbb03 [file] [log] [blame]
Robert Phillips459b2952019-05-23 09:38:27 -04001/*
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 Salomonf30b1c12019-06-20 12:25:02 -040013#include "src/gpu/GrSwizzle.h"
Robert Phillips459b2952019-05-23 09:38:27 -040014
Brian Salomonbb8dde82019-06-27 10:52:13 -040015size_t GrCompressedDataSize(SkImage::CompressionType, int w, int h);
Robert Phillips28a5a432019-06-07 12:46:21 -040016
17// Compute the size of the buffer required to hold all the mipLevels of the specified type
18// of data when all rowBytes are tight.
19// Note there may still be padding between the mipLevels to meet alignment requirements.
Brian Salomonbb8dde82019-06-27 10:52:13 -040020size_t GrComputeTightCombinedBufferSize(size_t bytesPerPixel, int baseWidth, int baseHeight,
21 SkTArray<size_t>* individualMipOffsets, int mipLevelCount);
Robert Phillips28a5a432019-06-07 12:46:21 -040022
Brian Salomonbb8dde82019-06-27 10:52:13 -040023void GrFillInData(GrPixelConfig, int baseWidth, int baseHeight,
24 const SkTArray<size_t>& individualMipOffsets, char* dest, const SkColor4f& color);
25
26void GrFillInCompressedData(SkImage::CompressionType, int width, int height, char* dest,
27 const SkColor4f& color);
Robert Phillips459b2952019-05-23 09:38:27 -040028
Brian Salomonf30b1c12019-06-20 12:25:02 -040029struct GrColorInfo {
30 GrColorType fColorType = GrColorType::kUnknown;
31 SkColorSpace* fColorSpace = nullptr;
32 SkAlphaType fAlphaType = kPremul_SkAlphaType;
33};
34
35struct GrPixelInfo {
36 GrColorInfo fColorInfo = {};
37 GrSurfaceOrigin fOrigin = kTopLeft_GrSurfaceOrigin;
38 int fWidth = 0;
39 int fHeight = 0;
40 size_t fRowBytes = 0;
41};
42
43// Swizzle param is applied after loading and before converting from srcInfo to dstInfo.
44bool GrConvertPixels(const GrPixelInfo& dstInfo, void* dst, const GrPixelInfo& srcInfo,
45 const void* src, GrSwizzle swizzle = GrSwizzle{});
46
Robert Phillips459b2952019-05-23 09:38:27 -040047#endif