Flutter Engine
The Flutter Engine
Classes | Functions
SkPDFShader.h File Reference
#include "include/core/SkColor.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkMacros.h"
#include "src/core/SkChecksum.h"
#include "src/pdf/SkBitmapKey.h"
#include "src/pdf/SkPDFTypes.h"

Go to the source code of this file.

Classes

struct  SkPDFImageShaderKey
 

Functions

SkPDFIndirectReference SkPDFMakeShader (SkPDFDocument *doc, SkShader *shader, const SkMatrix &ctm, const SkIRect &surfaceBBox, SkColor4f paintColor)
 
SK_END_REQUIRE_DENSE bool operator== (const SkPDFImageShaderKey &a, const SkPDFImageShaderKey &b)
 

Function Documentation

◆ operator==()

SK_END_REQUIRE_DENSE bool operator== ( const SkPDFImageShaderKey a,
const SkPDFImageShaderKey b 
)
inline

Definition at line 60 of file SkPDFShader.h.

60 {
61 SkASSERT(a.fBitmapKey.fID != 0);
62 SkASSERT(b.fBitmapKey.fID != 0);
63 return a.fTransform == b.fTransform
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 && a.fPaintColor == b.fPaintColor;
69}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool b
struct MyStruct a[10]

◆ SkPDFMakeShader()

SkPDFIndirectReference SkPDFMakeShader ( SkPDFDocument doc,
SkShader shader,
const SkMatrix ctm,
const SkIRect surfaceBBox,
SkColor4f  paintColor 
)

Make a PDF shader for the passed SkShader. If the SkShader is invalid in some way, returns nullptr.

In PDF parlance, this is a pattern, used in place of a color when the pattern color space is selected.

May cache the shader in the document for later re-use. If this function is called again with an equivalent shader, a new reference to the cached pdf shader may be returned.

Parameters
docThe parent document, must be non-null.
shaderThe SkShader to emulate.
ctmThe current transform matrix. (PDF shaders are absolutely positioned, relative to where the page is drawn.)
surfaceBBoxThe bounding box of the drawing surface (with matrix already applied).
paintColorColor+Alpha of the paint. Color is usually ignored, unless it is a alpha shader.

Definition at line 334 of file SkPDFShader.cpp.

338 {
339 SkASSERT(shader);
340 SkASSERT(doc);
341 if (as_SB(shader)->asGradient() != SkShaderBase::GradientType::kNone) {
342 return SkPDFGradientShader::Make(doc, shader, canvasTransform, surfaceBBox);
343 }
344 if (surfaceBBox.isEmpty()) {
345 return SkPDFIndirectReference();
346 }
348
349 paintColor = adjust_color(shader, paintColor);
350 SkMatrix shaderTransform;
351 SkTileMode imageTileModes[2];
352 if (SkImage* skimg = shader->isAImage(&shaderTransform, imageTileModes)) {
353 SkMatrix finalMatrix = SkMatrix::Concat(canvasTransform, shaderTransform);
355 finalMatrix,
356 surfaceBBox,
358 {imageTileModes[0], imageTileModes[1]},
359 paintColor};
360 SkPDFIndirectReference* shaderPtr = doc->fImageShaderMap.find(key);
361 if (shaderPtr) {
362 return *shaderPtr;
363 }
364 SkPDFIndirectReference pdfShader =
366 finalMatrix,
367 imageTileModes[0],
368 imageTileModes[1],
369 SkRect::Make(surfaceBBox),
370 skimg,
371 paintColor);
372 doc->fImageShaderMap.set(std::move(key), pdfShader);
373 return pdfShader;
374 }
375 // Don't bother to de-dup fallback shader.
376 return make_fallback_shader(doc, shader, canvasTransform, surfaceBBox, paintColor);
377}
SkBitmapKey SkBitmapKeyFromImage(const SkImage *image)
static SkPDFIndirectReference make_image_shader(SkPDFDocument *doc, SkMatrix finalMatrix, SkTileMode tileModesX, SkTileMode tileModesY, SkRect bBox, const SkImage *image, SkColor4f paintColor)
Definition: SkPDFShader.cpp:84
static SkPDFIndirectReference make_fallback_shader(SkPDFDocument *doc, SkShader *shader, const SkMatrix &canvasTransform, const SkIRect &surfaceBBox, SkColor4f paintColor)
static SkColor4f adjust_color(SkShader *shader, SkColor4f paintColor)
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
SkTileMode
Definition: SkTileMode.h:13
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1775
skia_private::THashMap< SkPDFImageShaderKey, SkPDFIndirectReference, SkPDFImageShaderKey::Hash > fImageShaderMap
SkImage * isAImage(SkMatrix *localMatrix, SkTileMode xy[2]) const
Definition: SkShader.cpp:22
SkPDFIndirectReference Make(SkPDFDocument *doc, SkShader *shader, const SkMatrix &matrix, const SkIRect &surfaceBBox)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
bool isEmpty() const
Definition: SkRect.h:202
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669