blob: 4323252bcd1d463bbd7f5171631d418b6d9ef392 [file] [log] [blame]
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 The Android Open Source Project
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00009#ifndef SkPDFGraphicState_DEFINED
10#define SkPDFGraphicState_DEFINED
11
halcanaryfa251062016-07-29 10:13:18 -070012#include "SkPDFTypes.h"
mtklein4e976072016-08-08 09:06:27 -070013#include "SkOpts.h"
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000014
martina.kollarovab8d6af12016-06-29 05:12:31 -070015class SkPaint;
halcanarybe27a112015-04-01 13:31:19 -070016class SkPDFCanon;
vandebo@chromium.org6112c212011-05-13 03:50:38 +000017
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000018/** \class SkPDFGraphicState
19 SkPaint objects roughly correspond to graphic state dictionaries that can
vandebo@chromium.org6112c212011-05-13 03:50:38 +000020 be installed. So that a given dictionary is only output to the pdf file
halcanarybe27a112015-04-01 13:31:19 -070021 once, we want to canonicalize them.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000022*/
Hal Canary80fa7ce2017-06-28 16:04:20 -040023namespace SkPDFGraphicState {
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000024 enum SkPDFSMaskMode {
25 kAlpha_SMaskMode,
26 kLuminosity_SMaskMode
27 };
28
Hal Canary5c1b3602017-04-17 16:30:06 -040029 /** Get the graphic state for the passed SkPaint.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000030 */
Hal Canary80fa7ce2017-06-28 16:04:20 -040031 sk_sp<SkPDFDict> GetGraphicStateForPaint(SkPDFCanon*, const SkPaint&);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000032
halcanary1437c1e2016-03-13 18:30:24 -070033 /** Make a graphic state that only sets the passed soft mask.
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000034 * @param sMask The form xobject to use as a soft mask.
35 * @param invert Indicates if the alpha of the sMask should be inverted.
36 * @param sMaskMode Whether to use alpha or luminosity for the sMask.
halcanarybe27a112015-04-01 13:31:19 -070037 *
38 * These are not de-duped.
vandebo@chromium.org6112c212011-05-13 03:50:38 +000039 */
Hal Canary80fa7ce2017-06-28 16:04:20 -040040 sk_sp<SkPDFDict> GetSMaskGraphicState(sk_sp<SkPDFObject> sMask,
41 bool invert,
42 SkPDFSMaskMode sMaskMode,
43 SkPDFCanon* canon);
vandebo@chromium.org6112c212011-05-13 03:50:38 +000044
Hal Canary80fa7ce2017-06-28 16:04:20 -040045 sk_sp<SkPDFStream> MakeInvertFunction();
46}
vandebo@chromium.org6112c212011-05-13 03:50:38 +000047
Hal Canary80fa7ce2017-06-28 16:04:20 -040048SK_BEGIN_REQUIRE_DENSE
49struct SkPDFStrokeGraphicState {
50 SkScalar fStrokeWidth;
51 SkScalar fStrokeMiter;
52 uint8_t fStrokeCap; // SkPaint::Cap
53 uint8_t fStrokeJoin; // SkPaint::Join
54 uint8_t fAlpha;
55 uint8_t fBlendMode;
56 bool operator==(const SkPDFStrokeGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
57 bool operator!=(const SkPDFStrokeGraphicState& o) const { return !(*this == o); }
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000058};
Hal Canary80fa7ce2017-06-28 16:04:20 -040059SK_END_REQUIRE_DENSE
60
61SK_BEGIN_REQUIRE_DENSE
62struct SkPDFFillGraphicState {
63 uint8_t fAlpha;
64 uint8_t fBlendMode;
65 bool operator==(const SkPDFFillGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
66 bool operator!=(const SkPDFFillGraphicState& o) const { return !(*this == o); }
67};
68SK_END_REQUIRE_DENSE
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000069
70#endif