#include "src/gpu/ganesh/ops/LatticeOp.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.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/SkPoint_impl.h"
#include "include/private/base/SkTArray.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/base/SkArenaAlloc.h"
#include "src/base/SkSafeMath.h"
#include "src/base/SkVx.h"
#include "src/core/SkLatticeIter.h"
#include "src/core/SkSLTypeShared.h"
#include "src/gpu/BufferWriter.h"
#include "src/gpu/KeyBuilder.h"
#include "src/gpu/SkBackingFit.h"
#include "src/gpu/ganesh/GrAppliedClip.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrColorSpaceXform.h"
#include "src/gpu/ganesh/GrGeometryProcessor.h"
#include "src/gpu/ganesh/GrOpFlushState.h"
#include "src/gpu/ganesh/GrPaint.h"
#include "src/gpu/ganesh/GrProcessorAnalysis.h"
#include "src/gpu/ganesh/GrProcessorSet.h"
#include "src/gpu/ganesh/GrProgramInfo.h"
#include "src/gpu/ganesh/GrShaderVar.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/GrUserStencilSettings.h"
#include "src/gpu/ganesh/glsl/GrGLSLColorSpaceXformHelper.h"
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/ganesh/glsl/GrGLSLVarying.h"
#include "src/gpu/ganesh/ops/GrMeshDrawOp.h"
#include "src/gpu/ganesh/ops/GrSimpleMeshDrawOpHelper.h"
#if defined(GPU_TEST_UTILS)
#include "src/base/SkRandom.h"
#include "src/gpu/ganesh/GrDrawOpTest.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrTestUtils.h"
#endif
#include <cstddef>
#include <utility>
class GrDstProxyView;
class GrGLSLProgramDataManager;
class GrMeshDrawTarget;
enum class GrXferBarrierFlags;
struct GrShaderCaps;
struct GrSimpleMesh;
namespace skgpu::ganesh {
class SurfaceDrawContext;
}
usingnamespaceskia_private;
namespace skgpu::ganesh::LatticeOp {
namespace {
class LatticeGP : public GrGeometryProcessor { … };
class NonAALatticeOp final : public GrMeshDrawOp { … };
}
GrOp::Owner MakeNonAA(GrRecordingContext* context,
GrPaint&& paint,
const SkMatrix& viewMatrix,
GrSurfaceProxyView view,
SkAlphaType alphaType,
sk_sp<GrColorSpaceXform> colorSpaceXform,
GrSamplerState::Filter filter,
std::unique_ptr<SkLatticeIter> iter,
const SkRect& dst) { … }
}
#if defined(GPU_TEST_UTILS)
static void init_random_divs(int divs[], int count, int subsetStart, int subsetStop,
SkRandom* random) {
divs[0] = 0;
for (int i = 1; i < count; ++i) {
divs[i] = 1;
}
int subsetLength = subsetStop - subsetStart;
for (int i = 0; i < subsetLength - count; ++i) {
int entry = random->nextULessThan(count + 1);
if (entry < count) {
divs[entry]++;
}
}
int offset = subsetStart;
for (int i = 0; i < count; ++i) {
divs[i] += offset;
offset = divs[i];
}
}
GR_DRAW_OP_TEST_DEFINE(NonAALatticeOp) {
SkCanvas::Lattice lattice;
std::unique_ptr<int[]> xdivs;
std::unique_ptr<int[]> ydivs;
std::unique_ptr<SkCanvas::Lattice::RectType[]> flags;
std::unique_ptr<SkColor[]> colors;
SkIRect subset;
SkISize dims;
dims.fWidth = random->nextRangeU(1, 1000);
dims.fHeight = random->nextRangeU(1, 1000);
GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin
: kBottomLeft_GrSurfaceOrigin;
const GrBackendFormat format =
context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kNo);
auto proxy = context->priv().proxyProvider()->createProxy(format,
dims,
GrRenderable::kNo,
1,
skgpu::Mipmapped::kNo,
SkBackingFit::kExact,
skgpu::Budgeted::kYes,
GrProtected::kNo,
"LatticeOp");
do {
if (random->nextBool()) {
subset.fLeft = random->nextULessThan(dims.fWidth);
subset.fRight = random->nextRangeU(subset.fLeft + 1, dims.fWidth);
subset.fTop = random->nextULessThan(dims.fHeight);
subset.fBottom = random->nextRangeU(subset.fTop + 1, dims.fHeight);
} else {
subset.setXYWH(0, 0, dims.fWidth, dims.fHeight);
}
lattice.fBounds = ⊂
lattice.fXCount = random->nextRangeU(1, subset.width());
lattice.fYCount = random->nextRangeU(1, subset.height());
xdivs.reset(new int[lattice.fXCount]);
ydivs.reset(new int[lattice.fYCount]);
init_random_divs(xdivs.get(), lattice.fXCount, subset.fLeft, subset.fRight, random);
init_random_divs(ydivs.get(), lattice.fYCount, subset.fTop, subset.fBottom, random);
lattice.fXDivs = xdivs.get();
lattice.fYDivs = ydivs.get();
bool hasFlags = random->nextBool();
if (hasFlags) {
int n = (lattice.fXCount + 1) * (lattice.fYCount + 1);
flags.reset(new SkCanvas::Lattice::RectType[n]);
colors.reset(new SkColor[n]);
for (int i = 0; i < n; ++i) {
flags[i] = random->nextBool() ? SkCanvas::Lattice::kTransparent
: SkCanvas::Lattice::kDefault;
}
lattice.fRectTypes = flags.get();
lattice.fColors = colors.get();
} else {
lattice.fRectTypes = nullptr;
lattice.fColors = nullptr;
}
} while (!SkLatticeIter::Valid(dims.fWidth, dims.fHeight, lattice));
SkRect dst;
dst.fLeft = random->nextRangeScalar(-2000.5f, 1000.f);
dst.fTop = random->nextRangeScalar(-2000.5f, 1000.f);
dst.fRight = dst.fLeft + random->nextRangeScalar(0.5f, 1000.f);
dst.fBottom = dst.fTop + random->nextRangeScalar(0.5f, 1000.f);
std::unique_ptr<SkLatticeIter> iter(new SkLatticeIter(lattice, dst));
SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
auto csxf = GrTest::TestColorXform(random);
GrSamplerState::Filter filter =
random->nextBool() ? GrSamplerState::Filter::kNearest : GrSamplerState::Filter::kLinear;
GrSurfaceProxyView view(
std::move(proxy), origin,
context->priv().caps()->getReadSwizzle(format, GrColorType::kRGBA_8888));
return skgpu::ganesh::LatticeOp::NonAALatticeOp::Make(context,
std::move(paint),
viewMatrix,
std::move(view),
kPremul_SkAlphaType,
std::move(csxf),
filter,
std::move(iter),
dst);
}
#endif