blob: d816f721201d36fc6d7595cc28caa347ffbf1cfb [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 The Android Open Source Project
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000010#ifndef SkPDFGraphicState_DEFINED
11#define SkPDFGraphicState_DEFINED
12
13#include "SkPaint.h"
14#include "SkPDFTypes.h"
halcanarybe27a112015-04-01 13:31:19 -070015#include "SkChecksum.h"
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000016
halcanarybe27a112015-04-01 13:31:19 -070017class SkPDFCanon;
vandebo@chromium.org6112c212011-05-13 03:50:38 +000018class SkPDFFormXObject;
19
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000020/** \class SkPDFGraphicState
21 SkPaint objects roughly correspond to graphic state dictionaries that can
vandebo@chromium.org6112c212011-05-13 03:50:38 +000022 be installed. So that a given dictionary is only output to the pdf file
halcanarybe27a112015-04-01 13:31:19 -070023 once, we want to canonicalize them.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000024*/
halcanary70d15542015-11-22 12:55:04 -080025class SkPDFGraphicState final : public SkPDFObject {
mtklein2766c002015-06-26 11:45:03 -070026
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000027public:
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000028 enum SkPDFSMaskMode {
29 kAlpha_SMaskMode,
30 kLuminosity_SMaskMode
31 };
32
halcanaryf361b712015-01-13 07:12:57 -080033 // Override emitObject so that we can populate the dictionary on
34 // demand.
halcanarya060eba2015-08-19 12:26:46 -070035 void emitObject(SkWStream* stream,
36 const SkPDFObjNumMap& objNumMap,
37 const SkPDFSubstituteMap& substitutes) const override;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000038
39 /** Get the graphic state for the passed SkPaint. The reference count of
40 * the object is incremented and it is the caller's responsibility to
vandebo@chromium.org6112c212011-05-13 03:50:38 +000041 * unreference it when done. This is needed to accommodate the weak
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000042 * reference pattern used when the returned object is new and has no
43 * other references.
44 * @param paint The SkPaint to emulate.
45 */
halcanary792c80f2015-02-20 07:21:05 -080046 static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon,
47 const SkPaint& paint);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000048
vandebo@chromium.org6112c212011-05-13 03:50:38 +000049 /** Make a graphic state that only sets the passed soft mask. The
50 * reference count of the object is incremented and it is the caller's
51 * responsibility to unreference it when done.
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000052 * @param sMask The form xobject to use as a soft mask.
53 * @param invert Indicates if the alpha of the sMask should be inverted.
54 * @param sMaskMode Whether to use alpha or luminosity for the sMask.
halcanarybe27a112015-04-01 13:31:19 -070055 *
56 * These are not de-duped.
vandebo@chromium.org6112c212011-05-13 03:50:38 +000057 */
halcanarybe27a112015-04-01 13:31:19 -070058 static SkPDFDict* GetSMaskGraphicState(SkPDFFormXObject* sMask,
59 bool invert,
60 SkPDFSMaskMode sMaskMode);
vandebo@chromium.org6112c212011-05-13 03:50:38 +000061
62 /** Get a graphic state that only unsets the soft mask. The reference
63 * count of the object is incremented and it is the caller's responsibility
64 * to unreference it when done. This is needed to accommodate the weak
65 * reference pattern used when the returned object is new and has no
66 * other references.
halcanarybe27a112015-04-01 13:31:19 -070067 *
68 * The returned object is a singleton.
vandebo@chromium.org6112c212011-05-13 03:50:38 +000069 */
halcanarybe27a112015-04-01 13:31:19 -070070 static SkPDFDict* GetNoSMaskGraphicState();
vandebo@chromium.org6112c212011-05-13 03:50:38 +000071
halcanarybe27a112015-04-01 13:31:19 -070072 bool operator==(const SkPDFGraphicState& rhs) const {
73 return 0 == memcmp(&fStrokeWidth, &rhs.fStrokeWidth, 12);
74 }
75 uint32_t hash() const { return SkChecksum::Murmur3(&fStrokeWidth, 12); }
halcanarye6ea2442015-01-21 13:13:22 -080076
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000077private:
halcanarybe27a112015-04-01 13:31:19 -070078 const SkScalar fStrokeWidth;
79 const SkScalar fStrokeMiter;
80 const uint8_t fAlpha;
81 const uint8_t fStrokeCap; // SkPaint::Cap
82 const uint8_t fStrokeJoin; // SkPaint::Join
83 const uint8_t fMode; // SkXfermode::Mode
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000084
halcanarybe27a112015-04-01 13:31:19 -070085 SkPDFGraphicState(const SkPaint&);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000086
commit-bot@chromium.orgab1c1382013-12-05 12:08:12 +000087 typedef SkPDFDict INHERITED;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000088};
89
90#endif