GrXferProcessor.h revision 378092f3d10b1dd62967f419c35cfefec7c10ee7
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#ifndef GrXferProcessor_DEFINED
9#define GrXferProcessor_DEFINED
10
11#include "GrColor.h"
12#include "GrFragmentProcessor.h"
13#include "GrTypes.h"
14#include "SkXfermode.h"
15
16/**
17 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst
18 * color. It does this by emitting fragment shader code and controlling the fixed-function blend
19 * state. The inputs to its shader code are the final computed src color and fractional pixel
20 * coverage. The GrXferProcessor's shader code writes the fragment shader output color that goes
21 * into the fixed-function blend. When dual-source blending is available, it may also write a
22 * seconday fragment shader output color. When allowed by the backend API, the GrXferProcessor may
23 * read the destination color. The GrXferProcessor is responsible for setting the blend coefficients
24 * and blend constant color.
25 *
26 * A GrXferProcessor is never installed directly into our draw state, but instead is created from a
27 * GrXPFactory once we have finalized the state of our draw.
28 */
29class GrXferProcessor : public GrFragmentProcessor {
30private:
31
32    typedef GrFragmentProcessor INHERITED;
33};
34
35/**
36 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is
37 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the
38 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF along with all the
39 * draw information to create a GrXferProcessor (XP) which can implement the desired blending for
40 * the draw.
41 *
42 * Before the XP is created, the XPF is able to answer queries about what functionality the XPs it
43 * creates will have. For example, can it create an XP that supports RGB coverage or will the XP
44 * blend with the destination color.
45 */
46class GrXPFactory : public GrProgramElement {
47public:
48    virtual const GrXferProcessor* createXferProcessor() const = 0;
49
50    /**
51     * This function returns true if the GrXferProcessor generated from this factory will be able to
52     * correctly blend when using RGB coverage. The knownColor and knownColorFlags represent the
53     * final computed color from the color stages.
54     */
55    virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const = 0;
56
57private:
58    typedef GrProgramElement INHERITED;
59};
60
61#endif
62
63