Flutter Engine
The Flutter Engine
Classes | Functions
GrPorterDuffXferProcessor.cpp File Reference
#include "src/gpu/ganesh/effects/GrPorterDuffXferProcessor.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkColor.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/base/SkRandom.h"
#include "src/core/SkSLTypeShared.h"
#include "src/gpu/Blend.h"
#include "src/gpu/BlendFormula.h"
#include "src/gpu/KeyBuilder.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrProcessorAnalysis.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/gpu/ganesh/GrXferProcessor.h"
#include "src/gpu/ganesh/glsl/GrGLSLBlend.h"
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h"
#include <cstring>
#include <memory>
#include <string>

Go to the source code of this file.

Classes

class  PorterDuffXferProcessor
 
class  ShaderPDXferProcessor
 
class  PDLCDXferProcessor
 

Functions

static void append_color_output (const PorterDuffXferProcessor &xp, GrGLSLXPFragmentBuilder *fragBuilder, BlendFormula::OutputType outputType, const char *output, const char *inColor, const char *inCoverage)
 
static GrXPFactory::AnalysisProperties analysis_properties (const GrProcessorAnalysisColor &color, const GrProcessorAnalysisCoverage &coverage, const GrCaps &caps, GrClampType clampType, SkBlendMode mode)
 

Function Documentation

◆ analysis_properties()

static GrXPFactory::AnalysisProperties analysis_properties ( const GrProcessorAnalysisColor color,
const GrProcessorAnalysisCoverage coverage,
const GrCaps caps,
GrClampType  clampType,
SkBlendMode  mode 
)
inlinestatic

color.isOpaque() ||

Definition at line 401 of file GrPorterDuffXferProcessor.cpp.

403 {
404 using AnalysisProperties = GrXPFactory::AnalysisProperties;
405 AnalysisProperties props = AnalysisProperties::kNone;
406 bool hasCoverage = GrProcessorAnalysisCoverage::kNone != coverage;
408 BlendFormula formula = [&](){
409 if (isLCD) {
411 }
412 return skgpu::GetBlendFormula(color.isOpaque(), hasCoverage, mode);
413 }();
414
415 if (formula.canTweakAlphaForCoverage() && !isLCD) {
416 props |= AnalysisProperties::kCompatibleWithCoverageAsAlpha;
417 }
418
419 if (isLCD) {
420 // See comment in MakeSrcOverXferProcessor about color.isOpaque here
421 if (SkBlendMode::kSrcOver == mode && color.isConstant() && /*color.isOpaque() &&*/
424 props |= AnalysisProperties::kIgnoresInputColor;
425 } else {
426 // For LCD blending, if the color is not opaque we must read the dst in shader even if
427 // we have dual source blending. The opaqueness check must be done after blending so for
428 // simplicity we only allow src-over to not take the dst read path (though src, src-in,
429 // and DstATop would also work). We also fall into the dst read case for src-over if we
430 // do not have dual source blending.
432 /*!color.isOpaque() ||*/ // See comment in MakeSrcOverXferProcessor about isOpaque.
434 props |= AnalysisProperties::kReadsDstInShader;
435 }
436 }
437 } else {
438 // With dual-source blending we never need the destination color in the shader.
440 if (formula.hasSecondaryOutput()) {
441 props |= AnalysisProperties::kReadsDstInShader;
442 }
443 }
444 }
445
446 if (GrClampType::kAuto != clampType && SkBlendMode::kPlus == mode) {
447 props |= AnalysisProperties::kReadsDstInShader;
448 }
449
450 if (!formula.modifiesDst() || !formula.usesInputColor()) {
451 props |= AnalysisProperties::kIgnoresInputColor;
452 }
453 if (formula.unaffectedByDst() || (formula.unaffectedByDstIfOpaque() && color.isOpaque() &&
454 !hasCoverage)) {
455 props |= AnalysisProperties::kUnaffectedByDstValue;
456 }
457 return props;
458}
@ kPlus
r = min(s + d, 1)
@ kSrcOver
r = s + (1-sa)*d
static bool isLCD(const SkScalerContextRec &rec)
const GrShaderCaps * shaderCaps() const
Definition: GrCaps.h:63
bool hasSecondaryOutput() const
Definition: BlendFormula.h:66
bool unaffectedByDst() const
Definition: BlendFormula.h:72
bool canTweakAlphaForCoverage() const
Definition: BlendFormula.h:83
bool unaffectedByDstIfOpaque() const
Definition: BlendFormula.h:77
bool modifiesDst() const
Definition: BlendFormula.h:69
bool usesInputColor() const
Definition: BlendFormula.h:80
DlColor color
@ kNone
Definition: layer.h:53
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
BlendFormula GetBlendFormula(bool isOpaque, bool hasCoverage, SkBlendMode xfermode)
BlendFormula GetLCDBlendFormula(SkBlendMode xfermode)
bool fDstReadInShaderSupport
Definition: GrShaderCaps.h:34
bool fDualSourceBlendingSupport
Definition: SkSLUtil.h:84

◆ append_color_output()

static void append_color_output ( const PorterDuffXferProcessor xp,
GrGLSLXPFragmentBuilder fragBuilder,
BlendFormula::OutputType  outputType,
const char *  output,
const char *  inColor,
const char *  inCoverage 
)
static

Definition at line 73 of file GrPorterDuffXferProcessor.cpp.

76 {
77 SkASSERT(inCoverage);
78 SkASSERT(inColor);
79 switch (outputType) {
81 fragBuilder->codeAppendf("%s = half4(0.0);", output);
82 break;
84 fragBuilder->codeAppendf("%s = %s;", output, inCoverage);
85 break;
87 fragBuilder->codeAppendf("%s = %s * %s;", output, inColor, inCoverage);
88 break;
90 fragBuilder->codeAppendf("%s = %s.a * %s;", output, inColor, inCoverage);
91 break;
93 fragBuilder->codeAppendf("%s = (1.0 - %s.a) * %s;", output, inColor, inCoverage);
94 break;
96 fragBuilder->codeAppendf("%s = (half4(1.0) - %s) * %s;", output, inColor, inCoverage);
97 break;
98 default:
99 SK_ABORT("Unsupported output type.");
100 break;
101 }
102}
@ kISAModulate_OutputType
@ kSAModulate_OutputType
@ kModulate_OutputType
@ kISCModulate_OutputType
@ kNone_OutputType
@ kCoverage_OutputType
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
#define SkASSERT(cond)
Definition: SkAssert.h:116
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2