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