Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrDisableColorXP.cpp
Go to the documentation of this file.
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
9
10#include "src/gpu/Blend.h"
14
15#include <memory>
16
17namespace skgpu {
18class KeyBuilder;
19class Swizzle;
20}
21
22/**
23 * This xfer processor disables color writing. Thus color and coverage and ignored and no blending
24 * occurs. This XP is usful for things like stenciling.
25 */
27public:
29
30private:
31 const char* name() const override { return "Disable Color"; }
32 bool onIsEqual(const GrXferProcessor& xpBase) const override { return true; }
33 void onAddToKey(const GrShaderCaps&, skgpu::KeyBuilder*) const override {}
34 void onGetBlendInfo(skgpu::BlendInfo* blendInfo) const override {
35 blendInfo->fWritesColor = false;
36 }
37 std::unique_ptr<ProgramImpl> makeProgramImpl() const override;
38
39 using INHERITED = GrXferProcessor;
40};
41
42std::unique_ptr<GrXferProcessor::ProgramImpl> DisableColorXP::makeProgramImpl() const {
43 class Impl : public ProgramImpl {
44 private:
45 void emitOutputsForBlendState(const EmitArgs& args) override {
46 if (args.fShaderCaps->fMustWriteToFragColor) {
47 // This emit code should be empty. However, on the nexus 6 there is a driver bug
48 // where if you do not give gl_FragColor a value, the gl context is lost and we end
49 // up drawing nothing. So this fix just sets the gl_FragColor arbitrarily to 0.
50 // https://bugs.chromium.org/p/chromium/issues/detail?id=445377
51 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
52 fragBuilder->codeAppendf("%s = half4(0);", args.fOutputPrimary);
53 }
54 }
55
56 void emitWriteSwizzle(GrGLSLXPFragmentBuilder*,
57 const skgpu::Swizzle&,
58 const char*,
59 const char*) const override {
60 // Don't write any swizzling. This makes sure the final shader does not output a color.
61 }
62 };
63
64 return std::make_unique<Impl>();
65}
66
68 return sk_make_sp<DisableColorXP>();
69}
70
72
73#if defined(GR_TEST_UTILS)
74const GrXPFactory* GrDisableColorXPFactory::TestGet(GrProcessorTestData*) {
76}
77#endif
#define GR_DEFINE_XP_FACTORY_TEST(...)
const char * name() const override
bool onIsEqual(const GrXferProcessor &xpBase) const override
void onAddToKey(const GrShaderCaps &, skgpu::KeyBuilder *) const override
void onGetBlendInfo(skgpu::BlendInfo *blendInfo) const override
std::unique_ptr< ProgramImpl > makeProgramImpl() const override
static sk_sp< const GrXferProcessor > MakeXferProcessor()
static const GrDisableColorXPFactory * Get()
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
@ kDisableColorXP_ClassID
Definition GrProcessor.h:43
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
bool fWritesColor
Definition Blend.h:98