#include "src/gpu/ganesh/gradients/GrGradientShader.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/ganesh/GrBackendSurface.h"
#include "include/gpu/ganesh/GrRecordingContext.h"
#include "include/gpu/ganesh/GrTypes.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkOnce.h"
#include "include/private/base/SkSpan_impl.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/base/SkArenaAlloc.h"
#include "src/base/SkMathPriv.h"
#include "src/base/SkVx.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkRasterPipelineOpContexts.h"
#include "src/core/SkRasterPipelineOpList.h"
#include "src/core/SkRuntimeEffectPriv.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrColorInfo.h"
#include "src/gpu/ganesh/GrColorSpaceXform.h"
#include "src/gpu/ganesh/GrFPArgs.h"
#include "src/gpu/ganesh/GrFragmentProcessor.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrSamplerState.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/gpu/ganesh/effects/GrMatrixEffect.h"
#include "src/gpu/ganesh/effects/GrSkSLFP.h"
#include "src/gpu/ganesh/effects/GrTextureEffect.h"
#include "src/gpu/ganesh/gradients/GrGradientBitmapCache.h"
#include "src/shaders/SkShaderBase.h"
#include "src/shaders/gradients/SkGradientBaseShader.h"
#include <algorithm>
#include <array>
#include <cstddef>
#include <tuple>
#include <utility>
struct SkV4;
#if defined(GPU_TEST_UTILS)
#include "src/base/SkRandom.h"
#include "src/gpu/ganesh/GrTestUtils.h"
#endif
usingnamespaceskia_private;
Vec4;
static const SkScalar kLowPrecisionIntervalLimit = …;
static const int kMaxNumCachedGradientBitmaps = …;
static const int kGradientTextureSize = …;
static std::unique_ptr<GrFragmentProcessor> make_textured_colorizer(
const SkPMColor4f* colors,
const SkScalar* positions,
int count,
bool colorsAreOpaque,
const SkGradientShader::Interpolation& interpolation,
const SkColorSpace* intermediateColorSpace,
const SkColorSpace* dstColorSpace,
const GrFPArgs& args) { … }
static std::unique_ptr<GrFragmentProcessor> make_single_interval_colorizer(const SkPMColor4f& start,
const SkPMColor4f& end) { … }
static std::unique_ptr<GrFragmentProcessor> make_dual_interval_colorizer(const SkPMColor4f& c0,
const SkPMColor4f& c1,
const SkPMColor4f& c2,
const SkPMColor4f& c3,
float threshold) { … }
static constexpr int kMaxUnrolledColorCount = …;
static constexpr int kMaxUnrolledIntervalCount = …;
static std::unique_ptr<GrFragmentProcessor> make_unrolled_colorizer(int intervalCount,
const SkPMColor4f* scale,
const SkPMColor4f* bias,
SkRect thresholds1_7,
SkRect thresholds9_13) { … }
static constexpr int kMaxLoopingColorCount = …;
static constexpr int kMaxLoopingIntervalCount = …;
static std::unique_ptr<GrFragmentProcessor> make_looping_colorizer(int intervalCount,
const SkPMColor4f* scale,
const SkPMColor4f* bias,
const SkScalar* thresholds) { … }
int build_intervals(int inputLength,
const SkPMColor4f* inColors,
const SkScalar* inPositions,
int outputLength,
SkPMColor4f* outScales,
SkPMColor4f* outBiases,
SkScalar* outThresholds) { … }
static std::unique_ptr<GrFragmentProcessor> make_unrolled_binary_colorizer(
const SkPMColor4f* colors, const SkScalar* positions, int count) { … }
static std::unique_ptr<GrFragmentProcessor> make_looping_binary_colorizer(const SkPMColor4f* colors,
const SkScalar* positions,
int count) { … }
static std::unique_ptr<GrFragmentProcessor> make_uniform_colorizer(const SkPMColor4f* colors,
const SkScalar* positions,
int count,
bool premul,
const GrFPArgs& args) { … }
static std::unique_ptr<GrFragmentProcessor> make_clamped_gradient(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor,
bool colorsAreOpaque) { … }
static std::unique_ptr<GrFragmentProcessor> make_tiled_gradient(
const GrFPArgs& args,
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
bool mirror,
bool colorsAreOpaque) { … }
static std::unique_ptr<GrFragmentProcessor> make_interpolated_to_dst(
std::unique_ptr<GrFragmentProcessor> gradient,
const SkGradientShader::Interpolation& interpolation,
SkColorSpace* intermediateColorSpace,
const GrColorInfo& dstInfo,
bool allOpaque) { … }
namespace GrGradientShader {
static GrFPResult apply_matrix(std::unique_ptr<GrFragmentProcessor> fp,
const SkShaders::MatrixRec& rec,
const SkMatrix& postInv) { … }
std::unique_ptr<GrFragmentProcessor> MakeGradientFP(const SkGradientBaseShader& shader,
const GrFPArgs& args,
const SkShaders::MatrixRec& mRec,
std::unique_ptr<GrFragmentProcessor> layout,
const SkMatrix* overrideMatrix) { … }
std::unique_ptr<GrFragmentProcessor> MakeLinear(const SkLinearGradient& shader,
const GrFPArgs& args,
const SkShaders::MatrixRec& mRec) { … }
#if defined(GPU_TEST_UTILS)
RandomParams::RandomParams(SkRandom* random) {
fColorCount = random->nextRangeU(2, kMaxRandomGradientColors);
fUseColors4f = random->nextBool();
if (fColorCount == 1 || (fColorCount >= 2 && random->nextBool())) {
fStops = nullptr;
} else {
fStops = fStopStorage;
}
if (fUseColors4f) {
fColorSpace = GrTest::TestColorSpace(random);
}
SkScalar stop = 0.f;
for (int i = 0; i < fColorCount; ++i) {
if (fUseColors4f) {
fColors4f[i].fR = random->nextUScalar1();
fColors4f[i].fG = random->nextUScalar1();
fColors4f[i].fB = random->nextUScalar1();
fColors4f[i].fA = random->nextUScalar1();
} else {
fColors[i] = random->nextU();
}
if (fStops) {
fStops[i] = stop;
stop = i < fColorCount - 1 ? stop + random->nextUScalar1() * (1.f - stop) : 1.f;
}
}
fTileMode = static_cast<SkTileMode>(random->nextULessThan(kSkTileModeCount));
}
#endif
}