1 /*
2 * Copyright 2015 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 GrBlendFragmentProcessor_DEFINED
9 #define GrBlendFragmentProcessor_DEFINED
10
11 #include "include/core/SkBlendMode.h"
12 #include "include/core/SkRefCnt.h"
13
14 #include <memory>
15
16 class GrFragmentProcessor;
17
18 namespace GrBlendFragmentProcessor {
19
20 /**
21 * Blends src and dst inputs according to the blend mode. If either input is null, fInputColor is
22 * used instead.
23 * - When `shareBlendLogic` is false, the blend function logic is written directly into the code.
24 * - When `shareBlendLogic` is true, most Porter-Duff blends share the same code, and a uniform
25 * is used to pick the blend type. This can reduce our overall shader count.
26 */
27 std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> src,
28 std::unique_ptr<GrFragmentProcessor> dst,
29 SkBlendMode mode,
30 bool shareBlendLogic = true);
31 /**
32 * Blends src and dst inputs according to the blend mode. If either input is null, fInputColor is
33 * used instead. Hard-wires a single blend mode into the code (slightly reducing complexity).
34 */
35 template <SkBlendMode mode>
Make(std::unique_ptr<GrFragmentProcessor> src,std::unique_ptr<GrFragmentProcessor> dst)36 std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> src,
37 std::unique_ptr<GrFragmentProcessor> dst) {
38 return Make(std::move(src), std::move(dst), mode, /*shareBlendLogic=*/false);
39 }
40
41
42 } // namespace GrBlendFragmentProcessor
43
44 #endif
45