1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "effects/GrDisableColorXP.h"
#include "GrPipeline.h"
#include "GrProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLXferProcessor.h"
/**
* This xfer processor disables color writing. Thus color and coverage and ignored and no blending
* occurs. This XP is usful for things like stenciling.
*/
class DisableColorXP : public GrXferProcessor {
public:
static GrXferProcessor* Create() { return new DisableColorXP; }
~DisableColorXP() override {}
const char* name() const override { return "Disable Color"; }
GrGLSLXferProcessor* createGLSLInstance() const override;
private:
DisableColorXP();
GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineAnalysis&,
bool doesStencilWrite,
GrColor* color,
const GrCaps& caps) const override {
return GrXferProcessor::kIgnoreColor_OptFlag;
}
void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override;
bool onIsEqual(const GrXferProcessor& xpBase) const override {
return true;
}
typedef GrXferProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
class GLDisableColorXP : public GrGLSLXferProcessor {
public:
GLDisableColorXP(const GrProcessor&) {}
~GLDisableColorXP() override {}
static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*) {}
private:
void emitOutputsForBlendState(const EmitArgs& args) override {
// This emit code should be empty. However, on the nexus 6 there is a driver bug where if
// you do not give gl_FragColor a value, the gl context is lost and we end up drawing
// nothing. So this fix just sets the gl_FragColor arbitrarily to 0.
GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
fragBuilder->codeAppendf("%s = vec4(0);", args.fOutputPrimary);
}
void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {}
typedef GrGLSLXferProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
DisableColorXP::DisableColorXP() {
this->initClassID<DisableColorXP>();
}
void DisableColorXP::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
GLDisableColorXP::GenKey(*this, caps, b);
}
GrGLSLXferProcessor* DisableColorXP::createGLSLInstance() const { return new GLDisableColorXP(*this); }
void DisableColorXP::onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const {
blendInfo->fWriteColor = false;
}
///////////////////////////////////////////////////////////////////////////////
GrXferProcessor* GrDisableColorXPFactory::onCreateXferProcessor(const GrCaps& caps,
const GrPipelineAnalysis& analysis,
bool hasMixedSamples,
const DstTexture* dst) const {
SkASSERT(!analysis.fUsesPLSDstRead);
return DisableColorXP::Create();
}
GR_DEFINE_XP_FACTORY_TEST(GrDisableColorXPFactory);
#if GR_TEST_UTILS
const GrXPFactory* GrDisableColorXPFactory::TestGet(GrProcessorTestData*) {
return GrDisableColorXPFactory::Get();
}
#endif
|