blob: 98915b6a92609080c9e079d87150da2e87269f76 [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 Salomon4bc0c1f2019-09-30 15:12:27 -040013#include "src/gpu/GrColorInfo.h"
Brian Salomonf30b1c12019-06-20 12:25:02 -040014#include "src/gpu/GrSwizzle.h"
Robert Phillips459b2952019-05-23 09:38:27 -040015
Brian Salomonf2ebdd92019-09-30 12:15:30 -040016class GrImageInfo;
17
Jim Van Verthe3671012019-09-18 09:53:31 -040018// Returns a value that can be used to set rowBytes for a transfer function.
19size_t GrCompressedRowBytes(SkImage::CompressionType, int w);
20
Robert Phillips41acc0e2020-01-06 13:29:53 -050021// 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
Robert Phillips28a5a432019-06-07 12:46:21 -040026// 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 Salomon85c3d682019-11-04 15:04:54 -050029size_t GrComputeTightCombinedBufferSize(size_t bytesPerPixel, SkISize baseDimensions,
Brian Salomonbb8dde82019-06-27 10:52:13 -040030 SkTArray<size_t>* individualMipOffsets, int mipLevelCount);
Robert Phillips28a5a432019-06-07 12:46:21 -040031
Robert Phillips48257d72019-12-16 14:20:53 -050032void GrFillInCompressedData(SkImage::CompressionType, SkISize dimensions, GrMipMapped, char* dest,
Brian Salomonbb8dde82019-06-27 10:52:13 -040033 const SkColor4f& color);
Brian Salomonf30b1c12019-06-20 12:25:02 -040034
35// Swizzle param is applied after loading and before converting from srcInfo to dstInfo.
Brian Salomonf2ebdd92019-09-30 12:15:30 -040036bool GrConvertPixels(const GrImageInfo& dstInfo, void* dst, size_t dstRB,
37 const GrImageInfo& srcInfo, const void* src, size_t srcRB,
Brian Salomon8f8354a2019-07-31 20:12:02 -040038 bool flipY = false);
Brian Salomonf30b1c12019-06-20 12:25:02 -040039
Brian Salomon85c3d682019-11-04 15:04:54 -050040/** Clears the dst image to a constant color. */
41bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, SkColor4f color);
42
Robert Phillipse0735522020-01-31 11:03:32 -050043#if GR_TEST_UTILS
Robert Phillipsac908022020-01-14 16:54:17 -050044/**
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);
Robert Phillipse0735522020-01-31 11:03:32 -050051#endif
Robert Phillipsac908022020-01-14 16:54:17 -050052
Robert Phillips459b2952019-05-23 09:38:27 -040053#endif