| 1 |
/* |
| 2 |
* Copyright 2020 Google LLC. |
| 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 |
#ifndef GrTessellationShader_DEFINED |
| 8 |
#define GrTessellationShader_DEFINED |
| 9 |
|
| 10 |
#include "include/core/SkMatrix.h" |
| 11 |
#include "src/base/SkArenaAlloc.h" |
| 12 |
#include "src/core/SkColorData.h" |
| 13 |
#include "src/gpu/ganesh/GrGeometryProcessor.h" |
| 14 |
#include "src/gpu/ganesh/GrProgramInfo.h" |
| 15 |
|
| 16 |
#include <cstdint> |
| 17 |
|
| 18 |
class GrAppliedClip; |
| 19 |
class GrCaps; |
| 20 |
class GrDstProxyView; |
| 21 |
class GrPipeline; |
| 22 |
class GrProcessorSet; |
| 23 |
class GrSurfaceProxyView; |
| 24 |
enum class GrAAType : unsigned int; |
| 25 |
enum class GrLoadOp; |
| 26 |
enum class GrPrimitiveType : uint8_t; |
| 27 |
enum class GrXferBarrierFlags; |
| 28 |
struct GrUserStencilSettings; |
| 29 |
|
| 30 |
// This is a common base class for shaders in the GPU tessellator. |
| 31 |
class GrTessellationShader : public GrGeometryProcessor { |
| 32 |
public: |
| 33 |
GrTessellationShader(ClassID classID, GrPrimitiveType primitiveType, |
| 34 |
const SkMatrix& viewMatrix, |
| 35 |
const SkPMColor4f& color) |
| 36 |
: GrGeometryProcessor(classID) |
| 37 |
, fPrimitiveType(primitiveType) |
| 38 |
, fViewMatrix(viewMatrix) |
| 39 |
, fColor(color) { |
| 40 |
} |
| 41 |
|
| 42 |
GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 43 |
const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 44 |
const SkPMColor4f& color() const { return fColor;} |
| 45 |
|
| 46 |
struct ProgramArgs { |
| 47 |
SkArenaAlloc* fArena; |
| 48 |
const GrSurfaceProxyView& fWriteView; |
| 49 |
bool fUsesMSAASurface; |
| 50 |
const GrDstProxyView* fDstProxyView; |
| 51 |
GrXferBarrierFlags fXferBarrierFlags; |
| 52 |
GrLoadOp fColorLoadOp; |
| 53 |
const GrCaps* fCaps; |
| 54 |
}; |
| 55 |
|
| 56 |
static const GrPipeline* MakePipeline(const ProgramArgs&, GrAAType, |
| 57 |
GrAppliedClip&&, GrProcessorSet&&); |
| 58 |
|
| 59 |
static GrProgramInfo* MakeProgram(const ProgramArgs& args, |
| 60 |
const GrTessellationShader* shader, |
| 61 |
const GrPipeline* pipeline, |
| 62 |
const GrUserStencilSettings* stencil) { |
| 63 |
return args.fArena->make<GrProgramInfo>(*args.fCaps, args.fWriteView, args.fUsesMSAASurface, |
| 64 |
pipeline, stencil, shader, shader->fPrimitiveType, |
| 65 |
args.fXferBarrierFlags, args.fColorLoadOp); |
| 66 |
} |
| 67 |
|
| 68 |
// SkSL functions that calculate Wang's formula for cubics or conics. |
| 69 |
static const char* WangsFormulaSkSL(); |
| 70 |
|
| 71 |
private: |
| 72 |
const GrPrimitiveType fPrimitiveType; |
| 73 |
const SkMatrix fViewMatrix; |
| 74 |
const SkPMColor4f fColor; |
| 75 |
}; |
| 76 |
|
| 77 |
#endif |