SkPDF: add canon assert before adding code that might break it

Motivation: We can write subsets (by page) of pdf documents (but this
in't yet exposed in the public API), but it is a bad idea to mix pages
from multiple documents (de-duping will break).  This assert verifies
that we don't do this by accident in the future.

BUG=skia:3585

Review URL: https://codereview.chromium.org/1037573005
This commit is contained in:
halcanary 2015-03-25 08:38:03 -07:00 committed by Commit bot
parent 7a0118465a
commit 26b5d15dab
3 changed files with 7 additions and 1 deletions

View File

@ -180,6 +180,10 @@ public:
return *(fFontGlyphUsage.get());
}
#ifdef SK_DEBUG
SkPDFCanon* getCanon() const { return fCanon; }
#endif // SK_DEBUG
protected:
const SkBitmap& onAccessBitmap() SK_OVERRIDE {
return fLegacyBitmap;

View File

@ -70,9 +70,12 @@ bool SkPDFDocument::EmitPDF(const SkTDArray<SkPDFDevice*>& pageDevices,
if (pageDevices.isEmpty()) {
return false;
}
SkTDArray<SkPDFPage*> pages;
for (int i = 0; i < pageDevices.count(); i++) {
SkASSERT(pageDevices[i]);
SkASSERT(i == 0 ||
pageDevices[i - 1]->getCanon() == pageDevices[i]->getCanon());
// Reference from new passed to pages.
pages.push(SkNEW_ARGS(SkPDFPage, (pageDevices[i])));
}

View File

@ -26,7 +26,6 @@ namespace SkPDFDocument {
*
* @param pageDevices An array of pages, in order. All pages
* should be created using the same SkPDFCanon.
* TODO(halcanary): ASSERT this condition.
* @param SkWStream The writable output stream to send the PDF to.
*/
bool EmitPDF(const SkTDArray<SkPDFDevice*>& pageDevices, SkWStream*);