blob: fcf7a07778aa77436df6cab41770296ba0444533 [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
Robert Phillips8043f322019-05-31 08:11:36 -040015// TODO: consolidate all the backend-specific flavors of this method to this
16size_t GrETC1CompressedDataSize(int w, int h);
Robert Phillips459b2952019-05-23 09:38:27 -040017
Robert Phillips28a5a432019-06-07 12:46:21 -040018// TODO: should this be grown into a replacement for GrPixelConfig?
19enum 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.
27size_t GrComputeTightCombinedBufferSize(GrCompression, size_t bytesPerPixel,
28 int baseWidth, int baseHeight,
29 SkTArray<size_t>* individualMipOffsets,
30 int mipLevelCount);
31
32void GrFillInData(GrCompression, GrPixelConfig,
33 int baseWidth, int baseHeight,
34 const SkTArray<size_t>& individualMipOffsets,
35 char* dest, const SkColor4f& color);
Robert Phillips459b2952019-05-23 09:38:27 -040036
Brian Salomonf30b1c12019-06-20 12:25:02 -040037struct GrColorInfo {
38 GrColorType fColorType = GrColorType::kUnknown;
39 SkColorSpace* fColorSpace = nullptr;
40 SkAlphaType fAlphaType = kPremul_SkAlphaType;
41};
42
43struct 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.
52bool GrConvertPixels(const GrPixelInfo& dstInfo, void* dst, const GrPixelInfo& srcInfo,
53 const void* src, GrSwizzle swizzle = GrSwizzle{});
54
Robert Phillips459b2952019-05-23 09:38:27 -040055#endif