1/*
2 * Copyright 2006 The Android Open Source Project
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 SkXfermodePriv_DEFINED
9#define SkXfermodePriv_DEFINED
10
11#include "include/core/SkBlendMode.h"
12#include "include/core/SkColor.h"
13#include "include/core/SkRefCnt.h"
14
15class GrFragmentProcessor;
16class GrTexture;
17class GrXPFactory;
18class SkRasterPipeline;
19class SkString;
20
21class SkXfermode : public SkRefCnt {
22public:
23 virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
24 const SkAlpha aa[]) const = 0;
25
26 /** Return an SkXfermode object for the specified mode.
27 */
28 static sk_sp<SkXfermode> Make(SkBlendMode);
29
30 /**
31 * Skia maintains global xfermode objects corresponding to each BlendMode. This returns a
32 * ptr to that global xfermode (or null if the mode is srcover). Thus the caller may use
33 * the returned ptr, but it should leave its refcnt untouched.
34 */
35 static SkXfermode* Peek(SkBlendMode mode) {
36 sk_sp<SkXfermode> xfer = Make(mode);
37 if (!xfer) {
38 SkASSERT(SkBlendMode::kSrcOver == mode);
39 return nullptr;
40 }
41 SkASSERT(!xfer->unique());
42 return xfer.get();
43 }
44
45 enum SrcColorOpacity {
46 // The src color is known to be opaque (alpha == 255)
47 kOpaque_SrcColorOpacity = 0,
48 // The src color is known to be fully transparent (color == 0)
49 kTransparentBlack_SrcColorOpacity = 1,
50 // The src alpha is known to be fully transparent (alpha == 0)
51 kTransparentAlpha_SrcColorOpacity = 2,
52 // The src color opacity is unknown
53 kUnknown_SrcColorOpacity = 3
54 };
55
56 static bool IsOpaque(SkBlendMode, SrcColorOpacity);
57
58protected:
59 SkXfermode() {}
60};
61
62#endif
63