blob: 062aaa67e635a6fa820d4aeac685e0e3e719726a [file] [log] [blame]
vandebo@chromium.orgda912d62011-03-08 18:31:02 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
vandebo@chromium.orgda912d62011-03-08 18:31:02 +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.orgda912d62011-03-08 18:31:02 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
vandebo@chromium.orgda912d62011-03-08 18:31:02 +00009#ifndef SkPDFShader_DEFINED
10#define SkPDFShader_DEFINED
11
halcanarydabd4f02016-08-03 11:16:56 -070012#include "SkBitmapKey.h"
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000013#include "SkPDFTypes.h"
halcanarydabd4f02016-08-03 11:16:56 -070014#include "SkShader.h"
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000015
halcanary792c80f2015-02-20 07:21:05 -080016class SkPDFCanon;
halcanary989da4a2016-03-21 14:33:17 -070017class SkPDFDocument;
halcanary530ea8e2015-01-23 06:17:35 -080018class SkMatrix;
halcanary530ea8e2015-01-23 06:17:35 -080019struct SkIRect;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000020
21/** \class SkPDFShader
22
23 In PDF parlance, this is a pattern, used in place of a color when the
24 pattern color space is selected.
25*/
26
vandebo@chromium.org421d6442011-07-20 17:39:01 +000027class SkPDFShader {
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000028public:
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000029 /** Get the PDF shader for the passed SkShader. If the SkShader is
halcanary96fcdcc2015-08-27 07:41:13 -070030 * invalid in some way, returns nullptr. The reference count of
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000031 * the object is incremented and it is the caller's responsibility to
32 * unreference it when done. This is needed to accommodate the weak
33 * reference pattern used when the returned object is new and has no
34 * other references.
fmalitac3796c72015-01-13 08:06:11 -080035 * @param shader The SkShader to emulate.
36 * @param matrix The current transform. (PDF shaders are absolutely
37 * positioned, relative to where the page is drawn.)
38 * @param surfceBBox The bounding box of the drawing surface (with matrix
39 * already applied).
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000040 */
halcanarydabd4f02016-08-03 11:16:56 -070041 static sk_sp<SkPDFObject> GetPDFShader(SkPDFDocument* doc,
halcanarydabd4f02016-08-03 11:16:56 -070042 SkShader* shader,
43 const SkMatrix& matrix,
Hal Canarya0622582017-06-29 18:51:35 -040044 const SkIRect& surfaceBBox);
halcanary1437c1e2016-03-13 18:30:24 -070045
46 static sk_sp<SkPDFArray> MakeRangeObject();
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000047
Hal Canary94fd66c2017-07-05 11:25:42 -040048 SK_BEGIN_REQUIRE_DENSE
49 struct State {
halcanarydabd4f02016-08-03 11:16:56 -070050 SkMatrix fCanvasTransform;
51 SkMatrix fShaderTransform;
52 SkIRect fBBox;
halcanarydabd4f02016-08-03 11:16:56 -070053 SkBitmapKey fBitmapKey;
54 SkShader::TileMode fImageTileModes[2];
halcanarydabd4f02016-08-03 11:16:56 -070055 };
Hal Canary94fd66c2017-07-05 11:25:42 -040056 SK_END_REQUIRE_DENSE
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000057};
58
Hal Canary94fd66c2017-07-05 11:25:42 -040059inline bool operator==(const SkPDFShader::State& a, const SkPDFShader::State& b) {
60 SkASSERT(a.fBitmapKey.fID != 0);
61 SkASSERT(b.fBitmapKey.fID != 0);
62 return a.fCanvasTransform == b.fCanvasTransform
63 && a.fShaderTransform == b.fShaderTransform
64 && a.fBBox == b.fBBox
65 && a.fBitmapKey == b.fBitmapKey
66 && a.fImageTileModes[0] == b.fImageTileModes[0]
67 && a.fImageTileModes[1] == b.fImageTileModes[1];
68}
69
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000070#endif