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 "src/gpu/GrColorInfo.h"
14#include "src/gpu/GrSwizzle.h"
15
16class GrImageInfo;
17
18// Returns a value that can be used to set rowBytes for a transfer function.
19size_t GrCompressedRowBytes(SkImage::CompressionType, int w);
20
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).
24SkISize GrCompressedDimensions(SkImage::CompressionType, SkISize baseDimensions);
25
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.
29size_t GrComputeTightCombinedBufferSize(size_t bytesPerPixel, SkISize baseDimensions,
30 SkTArray<size_t>* individualMipOffsets, int mipLevelCount);
31
32void GrFillInCompressedData(SkImage::CompressionType, SkISize dimensions, GrMipMapped, char* dest,
33 const SkColor4f& color);
34
35// Swizzle param is applied after loading and before converting from srcInfo to dstInfo.
36bool GrConvertPixels(const GrImageInfo& dstInfo, void* dst, size_t dstRB,
37 const GrImageInfo& srcInfo, const void* src, size_t srcRB,
38 bool flipY = false);
39
40/** Clears the dst image to a constant color. */
41bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, SkColor4f color);
42
43#if GR_TEST_UTILS
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 */
50void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dstPixels);
51#endif
52
53#endif
54