aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp
blob: c5ee9b8571c285c9b44572fe252c343dbf8fcd8b (plain)
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
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "effects/GrExtractAlphaFragmentProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"

class GLExtractAlphaFragmentProcessor : public GrGLFragmentProcessor {
public:
    GLExtractAlphaFragmentProcessor() {}

    void emitCode(EmitArgs& args) override {
        GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
        fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor);
        this->emitChild(0, "alpha4", args.fOutputColor, args);
    }

private:
    typedef GrGLFragmentProcessor INHERITED;
};

GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() const {
    return SkNEW(GLExtractAlphaFragmentProcessor);
}

void GrExtractAlphaFragmentProcessor::onGetGLProcessorKey(const GrGLSLCaps&,
                                                          GrProcessorKeyBuilder*) const {
}

bool GrExtractAlphaFragmentProcessor::onIsEqual(const GrFragmentProcessor&) const { return true; }

void GrExtractAlphaFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) const {
    if (inout->validFlags() & kA_GrColorComponentFlag) {
        GrColor color = GrColorPackA4(GrColorUnpackA(inout->color()));
        inout->setToOther(kRGBA_GrColorComponentFlags, color,
                          GrInvariantOutput::kWill_ReadInput);
    } else {
        inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
    }
    this->childProcessor(0).computeInvariantOutput(inout);
}