blob: db13cd50b358a385b4eb9968322fcedfa2f541e3 [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).
halcanary530ea8e2015-01-23 06:17:35 -080040 * @param rasterScale Additional scale to be applied for early
41 * rasterization.
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000042 */
halcanarydabd4f02016-08-03 11:16:56 -070043 static sk_sp<SkPDFObject> GetPDFShader(SkPDFDocument* doc,
44 SkScalar dpi,
45 SkShader* shader,
46 const SkMatrix& matrix,
47 const SkIRect& surfaceBBox,
48 SkScalar rasterScale);
halcanary1437c1e2016-03-13 18:30:24 -070049
50 static sk_sp<SkPDFArray> MakeRangeObject();
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000051
halcanarydabd4f02016-08-03 11:16:56 -070052 class State {
53 public:
54 SkShader::GradientType fType;
55 SkShader::GradientInfo fInfo;
56 std::unique_ptr<SkColor[]> fColors;
57 std::unique_ptr<SkScalar[]> fStops;
58 SkMatrix fCanvasTransform;
59 SkMatrix fShaderTransform;
60 SkIRect fBBox;
halcanary530ea8e2015-01-23 06:17:35 -080061
halcanarydabd4f02016-08-03 11:16:56 -070062 SkBitmapKey fBitmapKey;
63 SkShader::TileMode fImageTileModes[2];
halcanary530ea8e2015-01-23 06:17:35 -080064
halcanarydabd4f02016-08-03 11:16:56 -070065 State(SkShader* shader, const SkMatrix& canvasTransform,
66 const SkIRect& bbox, SkScalar rasterScale,
67 SkBitmap* dstImage);
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000068
halcanarydabd4f02016-08-03 11:16:56 -070069 bool operator==(const State& b) const;
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000070
halcanarydabd4f02016-08-03 11:16:56 -070071 State MakeAlphaToLuminosityState() const;
72 State MakeOpaqueState() const;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000073
halcanarydabd4f02016-08-03 11:16:56 -070074 bool GradientHasAlpha() const;
75
76 State(State&&) = default;
77 State& operator=(State&&) = default;
78
79 private:
80 State(const State& other);
81 State& operator=(const State& rhs);
82 void allocateGradientInfoStorage();
83 };
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000084};
85
86#endif