#include "src/gpu/ganesh/GrDataUtils.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkSize.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "modules/skcms/skcms.h"
#include "src/base/SkArenaAlloc.h"
#include "src/base/SkRectMemcpy.h"
#include "src/base/SkTLazy.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkRasterPipelineOpContexts.h"
#include "src/core/SkRasterPipelineOpList.h"
#include "src/core/SkTraceEvent.h"
#include "src/gpu/Swizzle.h"
#include "src/gpu/ganesh/GrImageInfo.h"
#include "src/gpu/ganesh/GrPixmap.h"
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <functional>
usingnamespaceskia_private;
#if defined(GPU_TEST_UTILS)
static int num_4x4_blocks(int size) {
return ((size + 3) & ~3) >> 2;
}
struct BC1Block {
uint16_t fColor0;
uint16_t fColor1;
uint32_t fIndices;
};
static uint16_t to565(SkColor col) {
int r5 = SkMulDiv255Round(31, SkColorGetR(col));
int g6 = SkMulDiv255Round(63, SkColorGetG(col));
int b5 = SkMulDiv255Round(31, SkColorGetB(col));
return (r5 << 11) | (g6 << 5) | b5;
}
static void create_BC1_block(SkColor col0, SkColor col1, BC1Block* block) {
block->fColor0 = to565(col0);
block->fColor1 = to565(col1);
SkASSERT(block->fColor0 <= block->fColor1);
if (col0 == SK_ColorTRANSPARENT) {
block->fIndices = 0xFFFFFFFF;
} else {
block->fIndices = 0;
}
}
void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dstPixels) {
BC1Block* dstBlocks = reinterpret_cast<BC1Block*>(dstPixels);
SkASSERT(pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType);
BC1Block block;
create_BC1_block(SK_ColorBLACK, otherColor, &block);
int numXBlocks = num_4x4_blocks(pixmap.width());
int numYBlocks = num_4x4_blocks(pixmap.height());
for (int y = 0; y < numYBlocks; ++y) {
for (int x = 0; x < numXBlocks; ++x) {
int shift = 0;
int offsetX = 4 * x, offsetY = 4 * y;
block.fIndices = 0;
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j, shift += 2) {
if (offsetX + j >= pixmap.width() || offsetY + i >= pixmap.height()) {
continue;
}
SkColor tmp = pixmap.getColor(offsetX + j, offsetY + i);
if (tmp == SK_ColorTRANSPARENT) {
block.fIndices |= 3 << shift;
} else if (tmp != SK_ColorBLACK) {
block.fIndices |= 1 << shift;
}
}
}
dstBlocks[y*numXBlocks + x] = block;
}
}
}
#endif
size_t GrComputeTightCombinedBufferSize(size_t bytesPerPixel, SkISize baseDimensions,
TArray<size_t>* individualMipOffsets, int mipLevelCount) { … }
static skgpu::Swizzle get_load_and_src_swizzle(GrColorType ct, SkRasterPipelineOp* load,
bool* isNormalized, bool* isSRGB) { … }
enum class LumMode { … };
static skgpu::Swizzle get_dst_swizzle_and_store(GrColorType ct, SkRasterPipelineOp* store,
LumMode* lumMode, bool* isNormalized,
bool* isSRGB) { … }
bool GrConvertPixels(const GrPixmap& dst, const GrCPixmap& src, bool flipY) { … }
bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, std::array<float, 4> color) { … }