xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrDataUtils.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/base/SkTArray.h"
13 
14 #include <array>
15 #include <cstddef>
16 
17 class GrCPixmap;
18 class GrImageInfo;
19 class GrPixmap;
20 struct SkISize;
21 class SkPixmap;
22 
23 // Compute the size of the buffer required to hold all the mipLevels of the specified type
24 // of data when all rowBytes are tight.
25 // Note there may still be padding between the mipLevels to meet alignment requirements.
26 size_t GrComputeTightCombinedBufferSize(
27         size_t bytesPerPixel, SkISize baseDimensions,
28         skia_private::TArray<size_t>* individualMipOffsets, int mipLevelCount);
29 
30 bool GrConvertPixels(const GrPixmap& dst, const GrCPixmap& src, bool flipY = false);
31 
32 /** Clears the dst image to a constant color. */
33 bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, std::array<float, 4> color);
34 
35 #if defined(GPU_TEST_UTILS)
36 /**
37  * BC1 compress an image that contains only either opaque black or transparent black and one
38  * other color.
39  *   opaque pixmaps      -> kBC1_RGB8_UNORM
40  *   transparent pixmaps -> kBC1_RGBA8_UNORM
41  */
42 void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dstPixels);
43 #endif
44 
45 #endif
46