| 1 |
/* |
| 2 |
* Copyright 2024 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 |
|
| 8 |
#include "include/gpu/graphite/precompile/PrecompileMaskFilter.h" |
| 9 |
|
| 10 |
#include "include/gpu/graphite/precompile/PaintOptions.h" |
| 11 |
#include "include/gpu/graphite/precompile/PrecompileColorFilter.h" |
| 12 |
#include "include/gpu/graphite/precompile/PrecompileShader.h" |
| 13 |
#include "src/gpu/graphite/Caps.h" |
| 14 |
#include "src/gpu/graphite/InternalDrawTypeFlags.h" |
| 15 |
#include "src/gpu/graphite/KeyContext.h" |
| 16 |
#include "src/gpu/graphite/PrecompileInternal.h" |
| 17 |
#include "src/gpu/graphite/RenderPassDesc.h" |
| 18 |
#include "src/gpu/graphite/Renderer.h" |
| 19 |
#include "src/gpu/graphite/precompile/PrecompileImageFiltersPriv.h" |
| 20 |
|
| 21 |
namespace skgpu::graphite { |
| 22 |
|
| 23 |
PrecompileMaskFilter::~PrecompileMaskFilter() = default; |
| 24 |
|
| 25 |
// The PrecompileMaskFilter-derived classes do not use the PrecompileBase::addToKey virtual since |
| 26 |
// they, in general, do not themselves contribute to a given SkPaint/Pipeline but, rather, |
| 27 |
// create separate SkPaints/Pipelines from whole cloth (in createPipelines). |
| 28 |
void PrecompileMaskFilter::addToKey(const KeyContext& keyContext, int desiredCombination) const { |
| 29 |
SkASSERT(false); |
| 30 |
} |
| 31 |
|
| 32 |
//-------------------------------------------------------------------------------------------------- |
| 33 |
// TODO(b/342413572): the analytic blurmasks are triggered off of the simple DrawType thus |
| 34 |
// over-generate when a simple draw doesn't have a blur mask. |
| 35 |
class PrecompileBlurMaskFilter : public PrecompileMaskFilter { |
| 36 |
public: |
| 37 |
PrecompileBlurMaskFilter() {} |
| 38 |
|
| 39 |
private: |
| 40 |
void createPipelines( |
| 41 |
const KeyContext& keyContext, |
| 42 |
const PaintOptions& paintOptions, |
| 43 |
const RenderPassDesc& renderPassDescIn, |
| 44 |
const PaintOptionsPriv::ProcessCombination& processCombination) const override { |
| 45 |
const Caps* caps = keyContext.caps(); |
| 46 |
// TODO: pull Protected-ness from 'renderPassDescIn' |
| 47 |
TextureInfo info = caps->getDefaultSampledTextureInfo(kAlpha_8_SkColorType, |
| 48 |
Mipmapped::kNo, |
| 49 |
Protected::kNo, |
| 50 |
Renderable::kYes); |
| 51 |
|
| 52 |
RenderPassDesc coverageRenderPassDesc = RenderPassDesc::Make( |
| 53 |
caps, |
| 54 |
info, |
| 55 |
LoadOp::kClear, |
| 56 |
StoreOp::kStore, |
| 57 |
DepthStencilFlags::kDepth, |
| 58 |
{ 0.0f, 0.0f, 0.0f, 0.0f }, |
| 59 |
/* requiresMSAA= */ false, |
| 60 |
skgpu::Swizzle("a000"), |
| 61 |
caps->getDstReadStrategy()); |
| 62 |
|
| 63 |
PrecompileImageFiltersPriv::CreateBlurImageFilterPipelines(keyContext, |
| 64 |
coverageRenderPassDesc, |
| 65 |
processCombination); |
| 66 |
|
| 67 |
// c.f. AutoLayerForImageFilter::addMaskFilterLayer. The following PaintOptions handle |
| 68 |
// the case where an explicit layer must be created. |
| 69 |
{ |
| 70 |
// The restore draw takes over all the shading effects. The mask filter blur will have |
| 71 |
// been converted to an image filter applied to the coverage layer. That coverage |
| 72 |
// will then be used as the coverage mask for the restoreOptions. |
| 73 |
PaintOptions restoreOptions = paintOptions; |
| 74 |
restoreOptions.setMaskFilters({}); |
| 75 |
restoreOptions.priv().buildCombinations( |
| 76 |
keyContext, |
| 77 |
static_cast<DrawTypeFlags>(InternalDrawTypeFlags::kCoverageMask), |
| 78 |
/* withPrimitiveBlender= */ false, |
| 79 |
Coverage::kSingleChannel, |
| 80 |
renderPassDescIn, |
| 81 |
processCombination); |
| 82 |
} |
| 83 |
|
| 84 |
{ |
| 85 |
// The initial draw into the coverage layer is just a solid white kSrcOver SkPaint |
| 86 |
// These options cover the case where the coverage draw can be done with the |
| 87 |
// AnalyticRRect RenderStep. |
| 88 |
// TODO: gate the inclusion of this option on the drawType being kSimple |
| 89 |
PaintOptions coverageOptions; |
| 90 |
coverageOptions.setShaders({{ PrecompileShaders::Color() }}); |
| 91 |
coverageOptions.setBlendModes(SKSPAN_INIT_ONE(SkBlendMode::kSrcOver)); |
| 92 |
|
| 93 |
coverageOptions.priv().buildCombinations( |
| 94 |
keyContext, |
| 95 |
DrawTypeFlags::kAnalyticRRect, |
| 96 |
/* withPrimitiveBlender= */ false, |
| 97 |
Coverage::kSingleChannel, |
| 98 |
coverageRenderPassDesc, |
| 99 |
processCombination); |
| 100 |
} |
| 101 |
} |
| 102 |
}; |
| 103 |
|
| 104 |
sk_sp<PrecompileMaskFilter> PrecompileMaskFilters::Blur() { |
| 105 |
return sk_make_sp<PrecompileBlurMaskFilter>(); |
| 106 |
} |
| 107 |
|
| 108 |
} // namespace skgpu::graphite |