blob: 0c2e4a0f490139cea4e43d41ea4669ecb09fd9c5 [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*/
halcanary70d15542015-11-22 12:55:04 -080023class SkPDFGraphicState final : public SkPDFObject {
halcanary9d524f22016-03-29 09:03:52 -070024
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000025public:
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000026 enum SkPDFSMaskMode {
27 kAlpha_SMaskMode,
28 kLuminosity_SMaskMode
29 };
30
halcanaryf361b712015-01-13 07:12:57 -080031 // Override emitObject so that we can populate the dictionary on
32 // demand.
halcanarya060eba2015-08-19 12:26:46 -070033 void emitObject(SkWStream* stream,
halcanary530032a2016-08-18 14:22:52 -070034 const SkPDFObjNumMap& objNumMap) const override;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000035
36 /** Get the graphic state for the passed SkPaint. The reference count of
37 * the object is incremented and it is the caller's responsibility to
vandebo@chromium.org6112c212011-05-13 03:50:38 +000038 * unreference it when done. This is needed to accommodate the weak
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000039 * reference pattern used when the returned object is new and has no
40 * other references.
41 * @param paint The SkPaint to emulate.
42 */
halcanary792c80f2015-02-20 07:21:05 -080043 static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon,
44 const SkPaint& paint);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000045
halcanary1437c1e2016-03-13 18:30:24 -070046 /** Make a graphic state that only sets the passed soft mask.
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000047 * @param sMask The form xobject to use as a soft mask.
48 * @param invert Indicates if the alpha of the sMask should be inverted.
49 * @param sMaskMode Whether to use alpha or luminosity for the sMask.
halcanarybe27a112015-04-01 13:31:19 -070050 *
51 * These are not de-duped.
vandebo@chromium.org6112c212011-05-13 03:50:38 +000052 */
halcanarydabd4f02016-08-03 11:16:56 -070053 static sk_sp<SkPDFDict> GetSMaskGraphicState(sk_sp<SkPDFObject> sMask,
halcanary1437c1e2016-03-13 18:30:24 -070054 bool invert,
55 SkPDFSMaskMode sMaskMode,
56 SkPDFCanon* canon);
vandebo@chromium.org6112c212011-05-13 03:50:38 +000057
halcanary1437c1e2016-03-13 18:30:24 -070058 /** Make a graphic state that only unsets the soft mask. */
59 static sk_sp<SkPDFDict> MakeNoSmaskGraphicState();
60 static sk_sp<SkPDFStream> MakeInvertFunction();
vandebo@chromium.org6112c212011-05-13 03:50:38 +000061
halcanarybe27a112015-04-01 13:31:19 -070062 bool operator==(const SkPDFGraphicState& rhs) const {
63 return 0 == memcmp(&fStrokeWidth, &rhs.fStrokeWidth, 12);
64 }
mtklein4e976072016-08-08 09:06:27 -070065 uint32_t hash() const { return SkOpts::hash(&fStrokeWidth, 12); }
halcanarye6ea2442015-01-21 13:13:22 -080066
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000067private:
halcanarybe27a112015-04-01 13:31:19 -070068 const SkScalar fStrokeWidth;
69 const SkScalar fStrokeMiter;
70 const uint8_t fAlpha;
71 const uint8_t fStrokeCap; // SkPaint::Cap
72 const uint8_t fStrokeJoin; // SkPaint::Join
73 const uint8_t fMode; // SkXfermode::Mode
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000074
halcanarybe27a112015-04-01 13:31:19 -070075 SkPDFGraphicState(const SkPaint&);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000076
commit-bot@chromium.orgab1c1382013-12-05 12:08:12 +000077 typedef SkPDFDict INHERITED;
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000078};
79
80#endif