xref: /aosp_15_r20/external/skia/src/pdf/SkPDFGraphicState.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2010 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 
9 #ifndef SkPDFGraphicState_DEFINED
10 #define SkPDFGraphicState_DEFINED
11 
12 #include "include/core/SkScalar.h"
13 #include "include/private/base/SkMacros.h"
14 #include "src/core/SkChecksum.h"
15 #include "src/pdf/SkPDFTypes.h"
16 
17 #include <cstdint>
18 #include <cstring>
19 
20 class SkPDFDocument;
21 class SkPaint;
22 
23 /** \class SkPDFGraphicState
24     SkPaint objects roughly correspond to graphic state dictionaries that can
25     be installed. So that a given dictionary is only output to the pdf file
26     once, we want to canonicalize them.
27 */
28 namespace SkPDFGraphicState {
29     enum SkPDFSMaskMode {
30         kAlpha_SMaskMode,
31         kLuminosity_SMaskMode
32     };
33 
34     /** Get the graphic state for the passed SkPaint.
35      */
36     SkPDFIndirectReference GetGraphicStateForPaint(SkPDFDocument*, const SkPaint&);
37 
38     /** Make a graphic state that only sets the passed soft mask.
39      *  @param sMask     The form xobject to use as a soft mask.
40      *  @param invert    Indicates if the alpha of the sMask should be inverted.
41      *  @param sMaskMode Whether to use alpha or luminosity for the sMask.
42      *
43      *  These are not de-duped.
44      */
45     SkPDFIndirectReference GetSMaskGraphicState(SkPDFIndirectReference sMask,
46                                                 bool invert,
47                                                 SkPDFSMaskMode sMaskMode,
48                                                 SkPDFDocument* doc);
49 }  // namespace SkPDFGraphicState
50 
51 SK_BEGIN_REQUIRE_DENSE
52 struct SkPDFStrokeGraphicState {
53     SkScalar fStrokeWidth;
54     SkScalar fStrokeMiter;
55     SkScalar fAlpha;
56     uint8_t fStrokeCap;   // SkPaint::Cap
57     uint8_t fStrokeJoin;  // SkPaint::Join
58     uint8_t fBlendMode;   // SkBlendMode
59     uint8_t fPADDING = 0;
60     bool operator==(const SkPDFStrokeGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
61     bool operator!=(const SkPDFStrokeGraphicState& o) const { return !(*this == o); }
62 
63     using Hash = SkForceDirectHash<SkPDFStrokeGraphicState>;
64 };
65 SK_END_REQUIRE_DENSE
66 
67 SK_BEGIN_REQUIRE_DENSE
68 struct SkPDFFillGraphicState {
69     SkScalar fAlpha;
70     uint8_t fBlendMode;
71     uint8_t fPADDING[3] = {0, 0, 0};
72     bool operator==(const SkPDFFillGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
73     bool operator!=(const SkPDFFillGraphicState& o) const { return !(*this == o); }
74 
75     using Hash = SkForceDirectHash<SkPDFFillGraphicState>;
76 };
77 SK_END_REQUIRE_DENSE
78 
79 #endif
80