SkPDF: skpdfdocument and skpdfpage use skpdfdevice in a const way

BUG=skia:3585

Review URL: https://codereview.chromium.org/1035513003
This commit is contained in:
halcanary 2015-03-25 08:45:42 -07:00 committed by Commit bot
parent 26b5d15dab
commit 6d622703e5
9 changed files with 51 additions and 55 deletions

View File

@ -62,7 +62,7 @@ protected:
private:
SkPDFCanon fCanon;
SkTDArray<SkPDFDevice*> fPageDevices;
SkTDArray<const SkPDFDevice*> fPageDevices;
SkAutoTUnref<SkCanvas> fCanvas;
SkScalar fRasterDpi;
};

View File

@ -705,7 +705,6 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize,
, fContentSize(pageSize)
, fExistingClipRegion(SkIRect::MakeSize(pageSize))
, fAnnotations(NULL)
, fResourceDict(NULL)
, fLastContentEntry(NULL)
, fLastMarginContentEntry(NULL)
, fDrawingArea(kContent_DrawingArea)
@ -735,7 +734,6 @@ SkPDFDevice::~SkPDFDevice() {
void SkPDFDevice::init() {
fAnnotations = NULL;
fResourceDict = NULL;
fContentEntries.free();
fLastContentEntry = NULL;
fMarginContentEntries.free();
@ -752,7 +750,6 @@ void SkPDFDevice::cleanUp(bool clearFontUsage) {
fFontResources.unrefAll();
fShaderResources.unrefAll();
SkSafeUnref(fAnnotations);
SkSafeUnref(fResourceDict);
fNamedDestinations.deleteAll();
if (clearFontUsage) {
@ -1249,44 +1246,41 @@ void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
fDrawingArea = drawingArea;
}
SkPDFResourceDict* SkPDFDevice::getResourceDict() {
if (NULL == fResourceDict) {
fResourceDict = SkNEW(SkPDFResourceDict);
if (fGraphicStateResources.count()) {
for (int i = 0; i < fGraphicStateResources.count(); i++) {
fResourceDict->insertResourceAsReference(
SkPDFResourceDict::kExtGState_ResourceType,
i, fGraphicStateResources[i]);
}
}
if (fXObjectResources.count()) {
for (int i = 0; i < fXObjectResources.count(); i++) {
fResourceDict->insertResourceAsReference(
SkPDFResourceDict::kXObject_ResourceType,
i, fXObjectResources[i]);
}
}
if (fFontResources.count()) {
for (int i = 0; i < fFontResources.count(); i++) {
fResourceDict->insertResourceAsReference(
SkPDFResourceDict::kFont_ResourceType,
i, fFontResources[i]);
}
}
if (fShaderResources.count()) {
SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
for (int i = 0; i < fShaderResources.count(); i++) {
fResourceDict->insertResourceAsReference(
SkPDFResourceDict::kPattern_ResourceType,
i, fShaderResources[i]);
}
SkPDFResourceDict* SkPDFDevice::createResourceDict() const {
SkAutoTUnref<SkPDFResourceDict> resourceDict(SkNEW(SkPDFResourceDict));
if (fGraphicStateResources.count()) {
for (int i = 0; i < fGraphicStateResources.count(); i++) {
resourceDict->insertResourceAsReference(
SkPDFResourceDict::kExtGState_ResourceType,
i, fGraphicStateResources[i]);
}
}
return fResourceDict;
if (fXObjectResources.count()) {
for (int i = 0; i < fXObjectResources.count(); i++) {
resourceDict->insertResourceAsReference(
SkPDFResourceDict::kXObject_ResourceType,
i, fXObjectResources[i]);
}
}
if (fFontResources.count()) {
for (int i = 0; i < fFontResources.count(); i++) {
resourceDict->insertResourceAsReference(
SkPDFResourceDict::kFont_ResourceType,
i, fFontResources[i]);
}
}
if (fShaderResources.count()) {
SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
for (int i = 0; i < fShaderResources.count(); i++) {
resourceDict->insertResourceAsReference(
SkPDFResourceDict::kPattern_ResourceType,
i, fShaderResources[i]);
}
}
return resourceDict.detach();
}
const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
@ -1539,7 +1533,7 @@ void SkPDFDevice::defineNamedDestination(SkData* nameData, const SkPoint& point,
SkNEW_ARGS(NamedDestination, (nameData, translatedPoint)));
}
void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) {
void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
int nDest = fNamedDestinations.count();
for (int i = 0; i < nDest; i++) {
NamedDestination* dest = fNamedDestinations[i];

View File

@ -35,7 +35,6 @@ class SkPDFResourceDict;
class SkPDFShader;
class SkPDFStream;
class SkRRect;
template <typename T> class SkTSet;
// Private classes.
struct ContentEntry;
@ -138,9 +137,9 @@ public:
// PDF specific methods.
/** Returns the resource dictionary for this device.
/** Create the resource dictionary for this device.
*/
SkPDFResourceDict* getResourceDict();
SkPDFResourceDict* createResourceDict() const;
/** Get the fonts used on this device.
*/
@ -150,7 +149,7 @@ public:
* @param dict Dictionary to add destinations to.
* @param page The PDF object representing the page for this device.
*/
void appendDestinations(SkPDFDict* dict, SkPDFObject* page);
void appendDestinations(SkPDFDict* dict, SkPDFObject* page) const;
/** Returns a copy of the media box for this device. The caller is required
* to unref() this when it is finished.
@ -202,7 +201,6 @@ private:
SkClipStack fExistingClipStack;
SkRegion fExistingClipRegion;
SkPDFArray* fAnnotations;
SkPDFResourceDict* fResourceDict;
SkTDArray<NamedDestination*> fNamedDestinations;
SkTDArray<SkPDFGraphicState*> fGraphicStateResources;

View File

@ -65,7 +65,7 @@ static void emit_pdf_footer(SkWStream* stream,
stream->writeText("\n%%EOF");
}
bool SkPDFDocument::EmitPDF(const SkTDArray<SkPDFDevice*>& pageDevices,
bool SkPDFDocument::EmitPDF(const SkTDArray<const SkPDFDevice*>& pageDevices,
SkWStream* stream) {
if (pageDevices.isEmpty()) {
return false;

View File

@ -28,7 +28,7 @@ namespace SkPDFDocument {
* should be created using the same SkPDFCanon.
* @param SkWStream The writable output stream to send the PDF to.
*/
bool EmitPDF(const SkTDArray<SkPDFDevice*>& pageDevices, SkWStream*);
bool EmitPDF(const SkTDArray<const SkPDFDevice*>& pageDevices, SkWStream*);
/** Get the count of unique font types used in the given pages.
*/

View File

@ -21,13 +21,13 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
// We don't want to keep around device because we'd have two copies
// of content, so reference or copy everything we need (content and
// resources).
SkPDFResourceDict* resourceDict = device->getResourceDict();
SkAutoTUnref<SkPDFResourceDict> resourceDict(device->createResourceDict());
SkAutoTDelete<SkStreamAsset> content(device->content());
this->setData(content.get());
SkAutoTUnref<SkPDFArray> bboxArray(device->copyMediaBox());
init(NULL, resourceDict, bboxArray);
this->init(NULL, resourceDict.get(), bboxArray);
// We invert the initial transform and apply that to the xobject so that
// it doesn't get applied twice. We can't just undo it because it's

View File

@ -13,7 +13,7 @@
#include "SkPDFPage.h"
#include "SkPDFResourceDict.h"
SkPDFPage::SkPDFPage(SkPDFDevice* content)
SkPDFPage::SkPDFPage(const SkPDFDevice* content)
: SkPDFDict("Page"),
fDevice(content) {
SkSafeRef(content);
@ -25,7 +25,9 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
const SkTSet<SkPDFObject*>& knownResourceObjects,
SkTSet<SkPDFObject*>* newResourceObjects) {
if (fContentStream.get() == NULL) {
this->insert("Resources", fDevice->getResourceDict());
SkAutoTUnref<SkPDFResourceDict> deviceResourceDict(
fDevice->createResourceDict());
this->insert("Resources", deviceResourceDict.get());
SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox()));
SkPDFArray* annots = fDevice->getAnnotations();
if (annots && annots->size() > 0) {

View File

@ -31,7 +31,7 @@ public:
* have content on it yet.
* @param content The page content.
*/
explicit SkPDFPage(SkPDFDevice* content);
explicit SkPDFPage(const SkPDFDevice* content);
~SkPDFPage();
/** Before a page and its contents can be sized and emitted, it must
@ -86,7 +86,7 @@ public:
private:
// Multiple pages may reference the content.
SkAutoTUnref<SkPDFDevice> fDevice;
SkAutoTUnref<const SkPDFDevice> fDevice;
// Once the content is finalized, put it into a stream for output.
SkAutoTUnref<SkPDFStream> fContentStream;

View File

@ -1101,8 +1101,10 @@ SkPDFImageShader* SkPDFImageShader::Create(
SkNEW_ARGS(SkPDFImageShader, (autoState->detach()));
imageShader->setData(content.get());
SkAutoTUnref<SkPDFResourceDict> resourceDict(
patternDevice->createResourceDict());
populate_tiling_pattern_dict(imageShader, patternBBox,
patternDevice->getResourceDict(), finalMatrix);
resourceDict.get(), finalMatrix);
imageShader->fShaderState->fImage.unlockPixels();