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 */ 38 sk_sp<SkPDFObject> SkPDFMakeShader(SkPDFDocument* doc, 39 SkShader* shader, 40 const SkMatrix& ctm, 41 const SkIRect& surfaceBBox); 42 43 SK_BEGIN_REQUIRE_DENSE 44 struct SkPDFImageShaderKey { 45 SkMatrix fCanvasTransform; 46 SkMatrix fShaderTransform; 47 SkIRect fBBox; 48 SkBitmapKey fBitmapKey; 49 SkShader::TileMode fImageTileModes[2]; 50 }; 51 SK_END_REQUIRE_DENSE 52 53 inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) { 54 SkASSERT(a.fBitmapKey.fID != 0); 55 SkASSERT(b.fBitmapKey.fID != 0); 56 return a.fCanvasTransform == b.fCanvasTransform 57 && a.fShaderTransform == b.fShaderTransform 58 && a.fBBox == b.fBBox 59 && a.fBitmapKey == b.fBitmapKey 60 && a.fImageTileModes[0] == b.fImageTileModes[0] 61 && a.fImageTileModes[1] == b.fImageTileModes[1]; 62 } 63 #endif 64