1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 9 #ifndef SkPDFShader_DEFINED 10 #define SkPDFShader_DEFINED 11 12 #include "SkBitmapKey.h" 13 #include "SkPDFTypes.h" 14 #include "SkShader.h" 15 16 class SkPDFCanon; 17 class SkPDFDocument; 18 class SkMatrix; 19 struct SkIRect; 20 21 /** Make a PDF shader for the passed SkShader. If the SkShader is invalid in 22 * some way, returns nullptr. 23 * 24 * In PDF parlance, this is a pattern, used in place of a color when the 25 * pattern color space is selected. 26 * 27 * May cache the shader in the document for later re-use. If this function is 28 * called again with an equivalent shader, a new reference to the cached pdf 29 * shader may be returned. 30 * 31 * @param doc The parent document, must be non-null. 32 * @param shader The SkShader to emulate. 33 * @param ctm The current transform matrix. (PDF shaders are absolutely 34 * positioned, relative to where the page is drawn.) 35 * @param surfceBBox The bounding box of the drawing surface (with matrix 36 * already applied). 37 * @param paintColor Color+Alpha of the paint. Color is usually ignored, 38 * unless it is a alpha shader. 39 */ 40 sk_sp<SkPDFObject> SkPDFMakeShader(SkPDFDocument* doc, 41 SkShader* shader, 42 const SkMatrix& ctm, 43 const SkIRect& surfaceBBox, 44 SkColor paintColor); 45 46 SK_BEGIN_REQUIRE_DENSE 47 struct SkPDFImageShaderKey { 48 SkMatrix fCanvasTransform; 49 SkMatrix fShaderTransform; 50 SkIRect fBBox; 51 SkBitmapKey fBitmapKey; 52 SkShader::TileMode fImageTileModes[2]; 53 SkColor fPaintColor; 54 }; 55 SK_END_REQUIRE_DENSE 56 57 inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) { 58 SkASSERT(a.fBitmapKey.fID != 0); 59 SkASSERT(b.fBitmapKey.fID != 0); 60 return a.fCanvasTransform == b.fCanvasTransform 61 && a.fShaderTransform == b.fShaderTransform 62 && a.fBBox == b.fBBox 63 && a.fBitmapKey == b.fBitmapKey 64 && a.fImageTileModes[0] == b.fImageTileModes[0] 65 && a.fImageTileModes[1] == b.fImageTileModes[1] 66 && a.fPaintColor == b.fPaintColor; 67 } 68 #endif 69