SkPDF: SkPDFDevice has ptr to SkPDFDocument

This is necessary for pre-serialization of images.

BUG=skia:5087
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1802963002

Review URL: https://codereview.chromium.org/1802963002
This commit is contained in:
halcanary 2016-03-21 14:33:17 -07:00 committed by Commit bot
parent 2cab66be9c
commit 989da4a32c
6 changed files with 62 additions and 44 deletions

View File

@ -19,6 +19,7 @@
#include "SkPathOps.h" #include "SkPathOps.h"
#include "SkPDFBitmap.h" #include "SkPDFBitmap.h"
#include "SkPDFCanon.h" #include "SkPDFCanon.h"
#include "SkPDFDocument.h"
#include "SkPDFFont.h" #include "SkPDFFont.h"
#include "SkPDFFormXObject.h" #include "SkPDFFormXObject.h"
#include "SkPDFGraphicState.h" #include "SkPDFGraphicState.h"
@ -584,9 +585,11 @@ SkBaseDevice* SkPDFDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
return nullptr; return nullptr;
} }
SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height()); SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height());
return SkPDFDevice::Create(size, fRasterDpi, fCanon); return SkPDFDevice::Create(size, fRasterDpi, fDocument);
} }
SkPDFCanon* SkPDFDevice::getCanon() const { return fDocument->canon(); }
struct ContentEntry { struct ContentEntry {
GraphicStateEntry fState; GraphicStateEntry fState;
@ -700,7 +703,7 @@ private:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFCanon* canon, bool flip) SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFDocument* doc, bool flip)
: INHERITED(SkSurfaceProps(0, kUnknown_SkPixelGeometry)) : INHERITED(SkSurfaceProps(0, kUnknown_SkPixelGeometry))
, fPageSize(pageSize) , fPageSize(pageSize)
, fContentSize(pageSize) , fContentSize(pageSize)
@ -711,7 +714,7 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFCanon* canon
, fClipStack(nullptr) , fClipStack(nullptr)
, fFontGlyphUsage(new SkPDFGlyphSetMap) , fFontGlyphUsage(new SkPDFGlyphSetMap)
, fRasterDpi(rasterDpi) , fRasterDpi(rasterDpi)
, fCanon(canon) { , fDocument(doc) {
SkASSERT(pageSize.width() > 0); SkASSERT(pageSize.width() > 0);
SkASSERT(pageSize.height() > 0); SkASSERT(pageSize.height() > 0);
fLegacyBitmap.setInfo( fLegacyBitmap.setInfo(
@ -1057,7 +1060,7 @@ void SkPDFDevice::drawBitmap(const SkDraw& d,
SkMatrix transform = matrix; SkMatrix transform = matrix;
transform.postConcat(*d.fMatrix); transform.postConcat(*d.fMatrix);
const SkImage* image = fCanon->bitmapToImage(bitmap); const SkImage* image = fDocument->canon()->bitmapToImage(bitmap);
if (!image) { if (!image) {
return; return;
} }
@ -1081,7 +1084,7 @@ void SkPDFDevice::drawSprite(const SkDraw& d,
SkMatrix matrix; SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y));
const SkImage* image = fCanon->bitmapToImage(bitmap); const SkImage* image = fDocument->canon()->bitmapToImage(bitmap);
if (!image) { if (!image) {
return; return;
} }
@ -1196,7 +1199,7 @@ static void draw_transparent_text(SkPDFDevice* device,
void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& srcPaint) { SkScalar x, SkScalar y, const SkPaint& srcPaint) {
if (!SkPDFFont::CanEmbedTypeface(srcPaint.getTypeface(), fCanon)) { if (!SkPDFFont::CanEmbedTypeface(srcPaint.getTypeface(), fDocument->canon())) {
// https://bug.skia.org/3866 // https://bug.skia.org/3866
SkPath path; SkPath path;
srcPaint.getTextPath(text, len, x, y, &path); srcPaint.getTextPath(text, len, x, y, &path);
@ -1257,7 +1260,7 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
const SkScalar pos[], int scalarsPerPos, const SkScalar pos[], int scalarsPerPos,
const SkPoint& offset, const SkPaint& srcPaint) { const SkPoint& offset, const SkPaint& srcPaint) {
if (!SkPDFFont::CanEmbedTypeface(srcPaint.getTypeface(), fCanon)) { if (!SkPDFFont::CanEmbedTypeface(srcPaint.getTypeface(), fDocument->canon())) {
const SkPoint* positions = reinterpret_cast<const SkPoint*>(pos); const SkPoint* positions = reinterpret_cast<const SkPoint*>(pos);
SkAutoTMalloc<SkPoint> positionsBuffer; SkAutoTMalloc<SkPoint> positionsBuffer;
if (2 != scalarsPerPos) { if (2 != scalarsPerPos) {
@ -1680,7 +1683,7 @@ void SkPDFDevice::drawFormXObjectWithMask(int xObjectIndex,
} }
auto sMaskGS = SkPDFGraphicState::GetSMaskGraphicState( auto sMaskGS = SkPDFGraphicState::GetSMaskGraphicState(
mask, invertClip, SkPDFGraphicState::kAlpha_SMaskMode, fCanon); mask, invertClip, SkPDFGraphicState::kAlpha_SMaskMode, fDocument->canon());
SkMatrix identity; SkMatrix identity;
identity.reset(); identity.reset();
@ -1697,7 +1700,7 @@ void SkPDFDevice::drawFormXObjectWithMask(int xObjectIndex,
// Call makeNoSmaskGraphicState() instead of // Call makeNoSmaskGraphicState() instead of
// SkPDFGraphicState::MakeNoSmaskGraphicState so that the canon // SkPDFGraphicState::MakeNoSmaskGraphicState so that the canon
// can deduplicate. // can deduplicate.
sMaskGS = fCanon->makeNoSmaskGraphicState(); sMaskGS = fDocument->canon()->makeNoSmaskGraphicState();
SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()),
&content.entry()->fContent); &content.entry()->fContent);
} }
@ -2004,7 +2007,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint(
SkScalar rasterScale = SkScalar rasterScale =
SkIntToScalar(fRasterDpi) / DPI_FOR_RASTER_SCALE_ONE; SkIntToScalar(fRasterDpi) / DPI_FOR_RASTER_SCALE_ONE;
pdfShader.reset(SkPDFShader::GetPDFShader( pdfShader.reset(SkPDFShader::GetPDFShader(
fCanon, fRasterDpi, *shader, transform, bounds, rasterScale)); fDocument, fRasterDpi, *shader, transform, bounds, rasterScale));
if (pdfShader.get()) { if (pdfShader.get()) {
// pdfShader has been canonicalized so we can directly compare // pdfShader has been canonicalized so we can directly compare
@ -2035,12 +2038,12 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint(
sk_sp<SkPDFGraphicState> newGraphicState; sk_sp<SkPDFGraphicState> newGraphicState;
if (color == paint.getColor()) { if (color == paint.getColor()) {
newGraphicState.reset( newGraphicState.reset(
SkPDFGraphicState::GetGraphicStateForPaint(fCanon, paint)); SkPDFGraphicState::GetGraphicStateForPaint(fDocument->canon(), paint));
} else { } else {
SkPaint newPaint = paint; SkPaint newPaint = paint;
newPaint.setColor(color); newPaint.setColor(color);
newGraphicState.reset( newGraphicState.reset(
SkPDFGraphicState::GetGraphicStateForPaint(fCanon, newPaint)); SkPDFGraphicState::GetGraphicStateForPaint(fDocument->canon(), newPaint));
} }
int resourceIndex = addGraphicStateResource(newGraphicState.get()); int resourceIndex = addGraphicStateResource(newGraphicState.get());
entry->fGraphicStateIndex = resourceIndex; entry->fGraphicStateIndex = resourceIndex;
@ -2097,7 +2100,7 @@ void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID,
int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) {
sk_sp<SkPDFFont> newFont( sk_sp<SkPDFFont> newFont(
SkPDFFont::GetFontResource(fCanon, typeface, glyphID)); SkPDFFont::GetFontResource(fDocument->canon(), typeface, glyphID));
int resourceIndex = fFontResources.find(newFont.get()); int resourceIndex = fFontResources.find(newFont.get());
if (resourceIndex < 0) { if (resourceIndex < 0) {
resourceIndex = fFontResources.count(); resourceIndex = fFontResources.count();
@ -2261,14 +2264,20 @@ void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix,
// TODO(halcanary): de-dupe this by caching filtered images. // TODO(halcanary): de-dupe this by caching filtered images.
// (maybe in the resource cache?) // (maybe in the resource cache?)
} }
sk_sp<SkPDFObject> pdfimage(SkSafeRef(fCanon->findPDFBitmap(image))); sk_sp<SkPDFObject> pdfimage(SkSafeRef(fDocument->canon()->findPDFBitmap(image)));
if (!pdfimage) { if (!pdfimage) {
pdfimage.reset(SkPDFCreateBitmapObject( pdfimage.reset(SkPDFCreateBitmapObject(
image, fCanon->getPixelSerializer())); image, fDocument->canon()->getPixelSerializer()));
if (!pdfimage) { if (!pdfimage) {
return; return;
} }
fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); #if SK_PDF_SERIALIZE_IMAGES_EARLY // TODO(halcanary): enable.
sk_sp<SkData> encodedImage(image->refEncodedData());
if (!encodedImage) {
fDocument->serialize(pdfimage);
}
#endif
fDocument->canon()->addPDFBitmap(image->uniqueID(), pdfimage.get());
} }
SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()),
&content.entry()->fContent); &content.entry()->fContent);

View File

@ -25,6 +25,7 @@
class SkPDFArray; class SkPDFArray;
class SkPDFCanon; class SkPDFCanon;
class SkPDFDevice; class SkPDFDevice;
class SkPDFDocument;
class SkPDFDict; class SkPDFDict;
class SkPDFFont; class SkPDFFont;
class SkPDFFormXObject; class SkPDFFormXObject;
@ -59,20 +60,23 @@ public:
* while rendering, and it would be slower to be processed * while rendering, and it would be slower to be processed
* or sent online or to printer. A good choice is * or sent online or to printer. A good choice is
* SK_ScalarDefaultRasterDPI(72.0f). * SK_ScalarDefaultRasterDPI(72.0f).
* @param SkPDFCanon. Should be non-null, and shared by all * @param SkPDFDocument. A non-null pointer back to the
* devices in a document. * document. The document is repsonsible for
* de-duplicating across pages (via the SkPDFCanon) and
* for early serializing of large immutable objects, such
* as images (via SkPDFDocument::serialize()).
*/ */
static SkPDFDevice* Create(SkISize pageSize, static SkPDFDevice* Create(SkISize pageSize,
SkScalar rasterDpi, SkScalar rasterDpi,
SkPDFCanon* canon) { SkPDFDocument* doc) {
return new SkPDFDevice(pageSize, rasterDpi, canon, true); return new SkPDFDevice(pageSize, rasterDpi, doc, true);
} }
/** Create a PDF drawing context without fipping the y-axis. */ /** Create a PDF drawing context without fipping the y-axis. */
static SkPDFDevice* CreateUnflipped(SkISize pageSize, static SkPDFDevice* CreateUnflipped(SkISize pageSize,
SkScalar rasterDpi, SkScalar rasterDpi,
SkPDFCanon* canon) { SkPDFDocument* doc) {
return new SkPDFDevice(pageSize, rasterDpi, canon, false); return new SkPDFDevice(pageSize, rasterDpi, doc, false);
} }
virtual ~SkPDFDevice(); virtual ~SkPDFDevice();
@ -184,7 +188,7 @@ public:
return *(fFontGlyphUsage.get()); return *(fFontGlyphUsage.get());
} }
SkPDFCanon* getCanon() const { return fCanon; } SkPDFCanon* getCanon() const;
protected: protected:
const SkBitmap& onAccessBitmap() override { const SkBitmap& onAccessBitmap() override {
@ -261,12 +265,12 @@ private:
SkBitmap fLegacyBitmap; SkBitmap fLegacyBitmap;
SkPDFCanon* fCanon; // Owned by SkDocument_PDF SkPDFDocument* fDocument;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
SkPDFDevice(SkISize pageSize, SkPDFDevice(SkISize pageSize,
SkScalar rasterDpi, SkScalar rasterDpi,
SkPDFCanon* canon, SkPDFDocument* doc,
bool flip); bool flip);
ContentEntry* getLastContentEntry(); ContentEntry* getLastContentEntry();

View File

@ -276,7 +276,7 @@ SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height,
SkISize pageSize = SkISize::Make( SkISize pageSize = SkISize::Make(
SkScalarRoundToInt(width), SkScalarRoundToInt(height)); SkScalarRoundToInt(width), SkScalarRoundToInt(height));
sk_sp<SkPDFDevice> device( sk_sp<SkPDFDevice> device(
SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon)); SkPDFDevice::Create(pageSize, fRasterDpi, this));
fCanvas = sk_make_sp<SkPDFCanvas>(device); fCanvas = sk_make_sp<SkPDFCanvas>(device);
fPageDevices.push_back(std::move(device)); fPageDevices.push_back(std::move(device));
fCanvas->clipRect(trimBox); fCanvas->clipRect(trimBox);

View File

@ -11,6 +11,8 @@
#include "SkPDFMetadata.h" #include "SkPDFMetadata.h"
#include "SkPDFTypes.h" #include "SkPDFTypes.h"
class SkPDFDevice;
sk_sp<SkDocument> SkPDFMakeDocument( sk_sp<SkDocument> SkPDFMakeDocument(
SkWStream* stream, SkWStream* stream,
void (*doneProc)(SkWStream*, bool), void (*doneProc)(SkWStream*, bool),

View File

@ -12,6 +12,7 @@
#include "SkData.h" #include "SkData.h"
#include "SkPDFCanon.h" #include "SkPDFCanon.h"
#include "SkPDFDevice.h" #include "SkPDFDevice.h"
#include "SkPDFDocument.h"
#include "SkPDFFormXObject.h" #include "SkPDFFormXObject.h"
#include "SkPDFGraphicState.h" #include "SkPDFGraphicState.h"
#include "SkPDFResourceDict.h" #include "SkPDFResourceDict.h"
@ -485,10 +486,11 @@ SkPDFImageShader::~SkPDFImageShader() {}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static SkPDFObject* get_pdf_shader_by_state( static SkPDFObject* get_pdf_shader_by_state(
SkPDFCanon* canon, SkPDFDocument* doc,
SkScalar dpi, SkScalar dpi,
SkAutoTDelete<SkPDFShader::State>* autoState) { SkAutoTDelete<SkPDFShader::State>* autoState) {
const SkPDFShader::State& state = **autoState; const SkPDFShader::State& state = **autoState;
SkPDFCanon* canon = doc->canon();
if (state.fType == SkShader::kNone_GradientType && state.fImage.isNull()) { if (state.fType == SkShader::kNone_GradientType && state.fImage.isNull()) {
// TODO(vandebo) This drops SKComposeShader on the floor. We could // TODO(vandebo) This drops SKComposeShader on the floor. We could
// handle compose shader by pulling things up to a layer, drawing with // handle compose shader by pulling things up to a layer, drawing with
@ -498,11 +500,11 @@ static SkPDFObject* get_pdf_shader_by_state(
} else if (state.fType == SkShader::kNone_GradientType) { } else if (state.fType == SkShader::kNone_GradientType) {
SkPDFObject* shader = canon->findImageShader(state); SkPDFObject* shader = canon->findImageShader(state);
return shader ? SkRef(shader) return shader ? SkRef(shader)
: SkPDFImageShader::Create(canon, dpi, autoState); : SkPDFImageShader::Create(doc, dpi, autoState);
} else if (state.GradientHasAlpha()) { } else if (state.GradientHasAlpha()) {
SkPDFObject* shader = canon->findAlphaShader(state); SkPDFObject* shader = canon->findAlphaShader(state);
return shader ? SkRef(shader) return shader ? SkRef(shader)
: SkPDFAlphaFunctionShader::Create(canon, dpi, autoState); : SkPDFAlphaFunctionShader::Create(doc, dpi, autoState);
} else { } else {
SkPDFObject* shader = canon->findFunctionShader(state); SkPDFObject* shader = canon->findFunctionShader(state);
return shader ? SkRef(shader) return shader ? SkRef(shader)
@ -511,14 +513,14 @@ static SkPDFObject* get_pdf_shader_by_state(
} }
// static // static
SkPDFObject* SkPDFShader::GetPDFShader(SkPDFCanon* canon, SkPDFObject* SkPDFShader::GetPDFShader(SkPDFDocument* doc,
SkScalar dpi, SkScalar dpi,
const SkShader& shader, const SkShader& shader,
const SkMatrix& matrix, const SkMatrix& matrix,
const SkIRect& surfaceBBox, const SkIRect& surfaceBBox,
SkScalar rasterScale) { SkScalar rasterScale) {
SkAutoTDelete<SkPDFShader::State> state(new State(shader, matrix, surfaceBBox, rasterScale)); SkAutoTDelete<SkPDFShader::State> state(new State(shader, matrix, surfaceBBox, rasterScale));
return get_pdf_shader_by_state(canon, dpi, &state); return get_pdf_shader_by_state(doc, dpi, &state);
} }
static sk_sp<SkPDFDict> get_gradient_resource_dict( static sk_sp<SkPDFDict> get_gradient_resource_dict(
@ -579,14 +581,14 @@ static SkStream* create_pattern_fill_content(int gsIndex, SkRect& bounds) {
* luminosity mode. The shader pattern extends to the bbox. * luminosity mode. The shader pattern extends to the bbox.
*/ */
static sk_sp<SkPDFObject> create_smask_graphic_state( static sk_sp<SkPDFObject> create_smask_graphic_state(
SkPDFCanon* canon, SkScalar dpi, const SkPDFShader::State& state) { SkPDFDocument* doc, SkScalar dpi, const SkPDFShader::State& state) {
SkRect bbox; SkRect bbox;
bbox.set(state.fBBox); bbox.set(state.fBBox);
SkAutoTDelete<SkPDFShader::State> alphaToLuminosityState( SkAutoTDelete<SkPDFShader::State> alphaToLuminosityState(
state.CreateAlphaToLuminosityState()); state.CreateAlphaToLuminosityState());
sk_sp<SkPDFObject> luminosityShader( sk_sp<SkPDFObject> luminosityShader(
get_pdf_shader_by_state(canon, dpi, &alphaToLuminosityState)); get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState));
SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox));
@ -598,11 +600,11 @@ static sk_sp<SkPDFObject> create_smask_graphic_state(
return SkPDFGraphicState::GetSMaskGraphicState( return SkPDFGraphicState::GetSMaskGraphicState(
alphaMask.get(), false, alphaMask.get(), false,
SkPDFGraphicState::kLuminosity_SMaskMode, canon); SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon());
} }
SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create(
SkPDFCanon* canon, SkPDFDocument* doc,
SkScalar dpi, SkScalar dpi,
SkAutoTDelete<SkPDFShader::State>* autoState) { SkAutoTDelete<SkPDFShader::State>* autoState) {
const SkPDFShader::State& state = **autoState; const SkPDFShader::State& state = **autoState;
@ -612,14 +614,14 @@ SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create(
SkAutoTDelete<SkPDFShader::State> opaqueState(state.CreateOpaqueState()); SkAutoTDelete<SkPDFShader::State> opaqueState(state.CreateOpaqueState());
sk_sp<SkPDFObject> colorShader( sk_sp<SkPDFObject> colorShader(
get_pdf_shader_by_state(canon, dpi, &opaqueState)); get_pdf_shader_by_state(doc, dpi, &opaqueState));
if (!colorShader) { if (!colorShader) {
return nullptr; return nullptr;
} }
// Create resource dict with alpha graphics state as G0 and // Create resource dict with alpha graphics state as G0 and
// pattern shader as P0, then write content stream. // pattern shader as P0, then write content stream.
auto alphaGs = create_smask_graphic_state(canon, dpi, state); auto alphaGs = create_smask_graphic_state(doc, dpi, state);
SkPDFAlphaFunctionShader* alphaFunctionShader = SkPDFAlphaFunctionShader* alphaFunctionShader =
new SkPDFAlphaFunctionShader(autoState->release()); new SkPDFAlphaFunctionShader(autoState->release());
@ -633,7 +635,7 @@ SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create(
populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(),
SkMatrix::I()); SkMatrix::I());
canon->addAlphaShader(alphaFunctionShader); doc->canon()->addAlphaShader(alphaFunctionShader);
return alphaFunctionShader; return alphaFunctionShader;
} }
@ -820,7 +822,7 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create(
} }
SkPDFImageShader* SkPDFImageShader::Create( SkPDFImageShader* SkPDFImageShader::Create(
SkPDFCanon* canon, SkPDFDocument* doc,
SkScalar dpi, SkScalar dpi,
SkAutoTDelete<SkPDFShader::State>* autoState) { SkAutoTDelete<SkPDFShader::State>* autoState) {
const SkPDFShader::State& state = **autoState; const SkPDFShader::State& state = **autoState;
@ -860,7 +862,7 @@ SkPDFImageShader* SkPDFImageShader::Create(
SkISize size = SkISize::Make(SkScalarRoundToInt(deviceBounds.width()), SkISize size = SkISize::Make(SkScalarRoundToInt(deviceBounds.width()),
SkScalarRoundToInt(deviceBounds.height())); SkScalarRoundToInt(deviceBounds.height()));
sk_sp<SkPDFDevice> patternDevice( sk_sp<SkPDFDevice> patternDevice(
SkPDFDevice::CreateUnflipped(size, dpi, canon)); SkPDFDevice::CreateUnflipped(size, dpi, doc));
SkCanvas canvas(patternDevice.get()); SkCanvas canvas(patternDevice.get());
SkRect patternBBox; SkRect patternBBox;
@ -1030,7 +1032,7 @@ SkPDFImageShader* SkPDFImageShader::Create(
imageShader->fShaderState->fImage.unlockPixels(); imageShader->fShaderState->fImage.unlockPixels();
canon->addImageShader(imageShader); doc->canon()->addImageShader(imageShader);
return imageShader; return imageShader;
} }

View File

@ -14,6 +14,7 @@
#include "SkPDFTypes.h" #include "SkPDFTypes.h"
class SkPDFCanon; class SkPDFCanon;
class SkPDFDocument;
class SkMatrix; class SkMatrix;
class SkShader; class SkShader;
struct SkIRect; struct SkIRect;
@ -42,7 +43,7 @@ public:
* @param rasterScale Additional scale to be applied for early * @param rasterScale Additional scale to be applied for early
* rasterization. * rasterization.
*/ */
static SkPDFObject* GetPDFShader(SkPDFCanon* canon, static SkPDFObject* GetPDFShader(SkPDFDocument* doc,
SkScalar dpi, SkScalar dpi,
const SkShader& shader, const SkShader& shader,
const SkMatrix& matrix, const SkMatrix& matrix,
@ -72,7 +73,7 @@ private:
*/ */
class SkPDFAlphaFunctionShader final : public SkPDFStream { class SkPDFAlphaFunctionShader final : public SkPDFStream {
public: public:
static SkPDFAlphaFunctionShader* Create(SkPDFCanon*, static SkPDFAlphaFunctionShader* Create(SkPDFDocument*,
SkScalar dpi, SkScalar dpi,
SkAutoTDelete<SkPDFShader::State>*); SkAutoTDelete<SkPDFShader::State>*);
virtual ~SkPDFAlphaFunctionShader(); virtual ~SkPDFAlphaFunctionShader();
@ -86,7 +87,7 @@ private:
class SkPDFImageShader final : public SkPDFStream { class SkPDFImageShader final : public SkPDFStream {
public: public:
static SkPDFImageShader* Create(SkPDFCanon*, static SkPDFImageShader* Create(SkPDFDocument*,
SkScalar dpi, SkScalar dpi,
SkAutoTDelete<SkPDFShader::State>*); SkAutoTDelete<SkPDFShader::State>*);
virtual ~SkPDFImageShader(); virtual ~SkPDFImageShader();