blob: dddf439db31f18ecf8777f1f49d2c011632c3c34 [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"
15#include "SkTemplates.h"
halcanarybe27a112015-04-01 13:31:19 -070016#include "SkChecksum.h"
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000017
halcanarybe27a112015-04-01 13:31:19 -070018class SkPDFCanon;
vandebo@chromium.org6112c212011-05-13 03:50:38 +000019class SkPDFFormXObject;
20
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000021/** \class SkPDFGraphicState
22 SkPaint objects roughly correspond to graphic state dictionaries that can
vandebo@chromium.org6112c212011-05-13 03:50:38 +000023 be installed. So that a given dictionary is only output to the pdf file
halcanarybe27a112015-04-01 13:31:19 -070024 once, we want to canonicalize them.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000025*/
halcanarybe27a112015-04-01 13:31:19 -070026class SkPDFGraphicState : public SkPDFObject {
commit-bot@chromium.orgab1c1382013-12-05 12:08:12 +000027 SK_DECLARE_INST_COUNT(SkPDFGraphicState)
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000028public:
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000029 enum SkPDFSMaskMode {
30 kAlpha_SMaskMode,
31 kLuminosity_SMaskMode
32 };
33
halcanaryf361b712015-01-13 07:12:57 -080034 // Override emitObject so that we can populate the dictionary on
35 // demand.
halcanary37c46ca2015-03-31 12:30:20 -070036 virtual void emitObject(SkWStream* stream,
37 const SkPDFObjNumMap& objNumMap,
38 const SkPDFSubstituteMap& substitutes);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000039
40 /** Get the graphic state for the passed SkPaint. The reference count of
41 * the object is incremented and it is the caller's responsibility to
vandebo@chromium.org6112c212011-05-13 03:50:38 +000042 * unreference it when done. This is needed to accommodate the weak
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000043 * reference pattern used when the returned object is new and has no
44 * other references.
45 * @param paint The SkPaint to emulate.
46 */
halcanary792c80f2015-02-20 07:21:05 -080047 static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon,
48 const SkPaint& paint);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000049
vandebo@chromium.org6112c212011-05-13 03:50:38 +000050 /** Make a graphic state that only sets the passed soft mask. The
51 * reference count of the object is incremented and it is the caller's
52 * responsibility to unreference it when done.
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000053 * @param sMask The form xobject to use as a soft mask.
54 * @param invert Indicates if the alpha of the sMask should be inverted.
55 * @param sMaskMode Whether to use alpha or luminosity for the sMask.
halcanarybe27a112015-04-01 13:31:19 -070056 *
57 * These are not de-duped.
vandebo@chromium.org6112c212011-05-13 03:50:38 +000058 */
halcanarybe27a112015-04-01 13:31:19 -070059 static SkPDFDict* GetSMaskGraphicState(SkPDFFormXObject* sMask,
60 bool invert,
61 SkPDFSMaskMode sMaskMode);
vandebo@chromium.org6112c212011-05-13 03:50:38 +000062
63 /** Get a graphic state that only unsets the soft mask. The reference
64 * count of the object is incremented and it is the caller's responsibility
65 * to unreference it when done. This is needed to accommodate the weak
66 * reference pattern used when the returned object is new and has no
67 * other references.
halcanarybe27a112015-04-01 13:31:19 -070068 *
69 * The returned object is a singleton.
vandebo@chromium.org6112c212011-05-13 03:50:38 +000070 */
halcanarybe27a112015-04-01 13:31:19 -070071 static SkPDFDict* GetNoSMaskGraphicState();
vandebo@chromium.org6112c212011-05-13 03:50:38 +000072
halcanarybe27a112015-04-01 13:31:19 -070073 bool operator==(const SkPDFGraphicState& rhs) const {
74 return 0 == memcmp(&fStrokeWidth, &rhs.fStrokeWidth, 12);
75 }
76 uint32_t hash() const { return SkChecksum::Murmur3(&fStrokeWidth, 12); }
halcanarye6ea2442015-01-21 13:13:22 -080077
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000078private:
halcanarybe27a112015-04-01 13:31:19 -070079 const SkScalar fStrokeWidth;
80 const SkScalar fStrokeMiter;
81 const uint8_t fAlpha;
82 const uint8_t fStrokeCap; // SkPaint::Cap
83 const uint8_t fStrokeJoin; // SkPaint::Join
84 const uint8_t fMode; // SkXfermode::Mode
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000085
halcanarybe27a112015-04-01 13:31:19 -070086 SkPDFGraphicState(const SkPaint&);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000087
commit-bot@chromium.orgab1c1382013-12-05 12:08:12 +000088 typedef SkPDFDict INHERITED;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000089};
90
91#endif