Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1922)

Side by Side Diff: src/pdf/SkPDFShader.h

Issue 2193973002: SkPDF: PDFShader code modernized. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-02 (Tuesday) 17:24:52 EDT Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFGraphicState.cpp ('k') | src/pdf/SkPDFShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #ifndef SkPDFShader_DEFINED 9 #ifndef SkPDFShader_DEFINED
10 #define SkPDFShader_DEFINED 10 #define SkPDFShader_DEFINED
11 11
12 #include "SkBitmapKey.h"
12 #include "SkPDFTypes.h" 13 #include "SkPDFTypes.h"
14 #include "SkShader.h"
13 15
14 class SkPDFCanon; 16 class SkPDFCanon;
15 class SkPDFDocument; 17 class SkPDFDocument;
16 class SkMatrix; 18 class SkMatrix;
17 class SkShader;
18 struct SkIRect; 19 struct SkIRect;
19 20
20 /** \class SkPDFShader 21 /** \class SkPDFShader
21 22
22 In PDF parlance, this is a pattern, used in place of a color when the 23 In PDF parlance, this is a pattern, used in place of a color when the
23 pattern color space is selected. 24 pattern color space is selected.
24 */ 25 */
25 26
26 class SkPDFShader { 27 class SkPDFShader {
27 public: 28 public:
28 class State;
29
30 /** Get the PDF shader for the passed SkShader. If the SkShader is 29 /** Get the PDF shader for the passed SkShader. If the SkShader is
31 * invalid in some way, returns nullptr. The reference count of 30 * invalid in some way, returns nullptr. The reference count of
32 * the object is incremented and it is the caller's responsibility to 31 * the object is incremented and it is the caller's responsibility to
33 * unreference it when done. This is needed to accommodate the weak 32 * unreference it when done. This is needed to accommodate the weak
34 * reference pattern used when the returned object is new and has no 33 * reference pattern used when the returned object is new and has no
35 * other references. 34 * other references.
36 * @param shader The SkShader to emulate. 35 * @param shader The SkShader to emulate.
37 * @param matrix The current transform. (PDF shaders are absolutely 36 * @param matrix The current transform. (PDF shaders are absolutely
38 * positioned, relative to where the page is drawn.) 37 * positioned, relative to where the page is drawn.)
39 * @param surfceBBox The bounding box of the drawing surface (with matrix 38 * @param surfceBBox The bounding box of the drawing surface (with matrix
40 * already applied). 39 * already applied).
41 * @param rasterScale Additional scale to be applied for early 40 * @param rasterScale Additional scale to be applied for early
42 * rasterization. 41 * rasterization.
43 */ 42 */
44 static SkPDFObject* GetPDFShader(SkPDFDocument* doc, 43 static sk_sp<SkPDFObject> GetPDFShader(SkPDFDocument* doc,
45 SkScalar dpi, 44 SkScalar dpi,
46 SkShader* shader, 45 SkShader* shader,
47 const SkMatrix& matrix, 46 const SkMatrix& matrix,
48 const SkIRect& surfaceBBox, 47 const SkIRect& surfaceBBox,
49 SkScalar rasterScale); 48 SkScalar rasterScale);
50 49
51 static sk_sp<SkPDFArray> MakeRangeObject(); 50 static sk_sp<SkPDFArray> MakeRangeObject();
52 };
53 51
54 class SkPDFFunctionShader final : public SkPDFDict { 52 class State {
55 public: 53 public:
56 static SkPDFFunctionShader* Create(SkPDFCanon*, 54 SkShader::GradientType fType;
57 std::unique_ptr<SkPDFShader::State>*); 55 SkShader::GradientInfo fInfo;
58 virtual ~SkPDFFunctionShader(); 56 std::unique_ptr<SkColor[]> fColors;
59 bool equals(const SkPDFShader::State&) const; 57 std::unique_ptr<SkScalar[]> fStops;
58 SkMatrix fCanvasTransform;
59 SkMatrix fShaderTransform;
60 SkIRect fBBox;
60 61
61 private: 62 SkBitmapKey fBitmapKey;
62 std::unique_ptr<const SkPDFShader::State> fShaderState; 63 SkShader::TileMode fImageTileModes[2];
63 SkPDFFunctionShader(SkPDFShader::State*);
64 typedef SkPDFDict INHERITED;
65 };
66 64
67 /** 65 State(SkShader* shader, const SkMatrix& canvasTransform,
68 * A shader for PDF gradients. This encapsulates the function shader 66 const SkIRect& bbox, SkScalar rasterScale,
69 * inside a tiling pattern while providing a common pattern interface. 67 SkBitmap* dstImage);
70 * The encapsulation allows the use of a SMask for transparency gradients.
71 */
72 class SkPDFAlphaFunctionShader final : public SkPDFStream {
73 public:
74 static SkPDFAlphaFunctionShader* Create(SkPDFDocument*,
75 SkScalar dpi,
76 std::unique_ptr<SkPDFShader::State>* );
77 virtual ~SkPDFAlphaFunctionShader();
78 bool equals(const SkPDFShader::State&) const;
79 68
80 private: 69 bool operator==(const State& b) const;
81 std::unique_ptr<const SkPDFShader::State> fShaderState;
82 SkPDFAlphaFunctionShader(SkPDFShader::State*);
83 typedef SkPDFStream INHERITED;
84 };
85 70
86 class SkPDFImageShader final : public SkPDFStream { 71 State MakeAlphaToLuminosityState() const;
87 public: 72 State MakeOpaqueState() const;
88 static SkPDFImageShader* Create(SkPDFDocument*,
89 SkScalar dpi,
90 std::unique_ptr<SkPDFShader::State>*);
91 virtual ~SkPDFImageShader();
92 bool equals(const SkPDFShader::State&) const;
93 73
94 private: 74 bool GradientHasAlpha() const;
95 std::unique_ptr<const SkPDFShader::State> fShaderState; 75
96 SkPDFImageShader(SkPDFShader::State*); 76 State(State&&) = default;
97 typedef SkPDFStream INHERITED; 77 State& operator=(State&&) = default;
78
79 private:
80 State(const State& other);
81 State& operator=(const State& rhs);
82 void allocateGradientInfoStorage();
83 };
98 }; 84 };
99 85
100 #endif 86 #endif
OLDNEW
« no previous file with comments | « src/pdf/SkPDFGraphicState.cpp ('k') | src/pdf/SkPDFShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698