diff options
author | halcanary <halcanary@google.com> | 2015-08-11 10:30:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-11 10:30:12 -0700 |
commit | 8ee06f21a27bbffaf613a312c6f24bbbb21c650a (patch) | |
tree | 781cfcac8ec506a9fcb9cbddf943f5ff37eba355 | |
parent | 4cf9e7e14797f87f08b2078fa1afaf731cbf8f52 (diff) |
SkPDF: allow PDF module to be disabled in DM and SampleApp
To disable PDF:
GYP_DEFINES='skia_pdf=0' bin/sync-and-gyp
ninja -C out/Debug dm SampleApp
When disabled, SkDocument::CreatePDF() always returns NULL.
Review URL: https://codereview.chromium.org/1279123007
-rw-r--r-- | gyp/SampleApp.gyp | 4 | ||||
-rw-r--r-- | gyp/common_variables.gypi | 2 | ||||
-rw-r--r-- | gyp/pdf.gyp | 8 | ||||
-rw-r--r-- | gyp/tests.gypi | 4 | ||||
-rw-r--r-- | samplecode/SampleApp.cpp | 2 | ||||
-rw-r--r-- | src/doc/SkDocument_PDF_None.cpp | 9 | ||||
-rw-r--r-- | tests/AnnotationTest.cpp | 3 | ||||
-rw-r--r-- | tests/CanvasTest.cpp | 5 | ||||
-rw-r--r-- | tests/DeflateWStream.cpp | 3 | ||||
-rw-r--r-- | tests/DocumentTest.cpp | 8 | ||||
-rw-r--r-- | tests/FlateTest.cpp | 3 | ||||
-rw-r--r-- | tests/PDFInvalidBitmapTest.cpp | 3 | ||||
-rw-r--r-- | tests/PDFJpegEmbedTest.cpp | 3 | ||||
-rw-r--r-- | tests/PDFPrimitivesTest.cpp | 3 | ||||
-rw-r--r-- | tests/ToUnicodeTest.cpp | 3 | ||||
-rw-r--r-- | tests/skpdf_opaquesrcmodetosrcover.cpp | 3 |
16 files changed, 66 insertions, 0 deletions
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp index 0d8b1b34a9..67692b7fb1 100644 --- a/gyp/SampleApp.gyp +++ b/gyp/SampleApp.gyp @@ -253,6 +253,10 @@ 'gputest.gyp:skgputest', ], }], + [ 'not skia_pdf', { + 'dependencies!': [ 'pdf.gyp:pdf' ], + 'dependencies': [ 'pdf.gyp:nopdf' ], + }], ], }, ], diff --git a/gyp/common_variables.gypi b/gyp/common_variables.gypi index 7a168a1940..21fb09dd5c 100644 --- a/gyp/common_variables.gypi +++ b/gyp/common_variables.gypi @@ -131,6 +131,7 @@ 'skia_gdi%': 0, 'skia_gpu%': 1, 'skia_osx_deployment_target%': '', + 'skia_pdf%': 1, 'skia_profile_enabled%': 0, 'skia_win_debuggers_path%': '', 'skia_shared_lib%': 0, @@ -208,6 +209,7 @@ 'skia_win_ltcg%': 1, 'sknx_no_simd%': 0, 'skia_osx_deployment_target%': '<(skia_osx_deployment_target)', + 'skia_pdf%': '<(skia_pdf)', 'skia_profile_enabled%': '<(skia_profile_enabled)', 'skia_shared_lib%': '<(skia_shared_lib)', 'skia_opencl%': '<(skia_opencl)', diff --git a/gyp/pdf.gyp b/gyp/pdf.gyp index 693d3307da..1e69d9164e 100644 --- a/gyp/pdf.gyp +++ b/gyp/pdf.gyp @@ -6,6 +6,13 @@ { 'targets': [ { + 'target_name': 'nopdf', + 'type': 'static_library', + 'dependencies': [ 'skia_lib.gyp:skia_lib', ], + 'sources': [ '<(skia_src_path)/doc/SkDocument_PDF_None.cpp', ], + 'defines': [ 'SK_SUPPORT_PDF=0', ], + }, + { 'target_name': 'pdf', 'product_name': 'skia_pdf', 'type': 'static_library', @@ -46,6 +53,7 @@ ], ], 'direct_dependent_settings': { + 'defines': [ 'SK_SUPPORT_PDF=1', ], 'include_dirs': [ '../include/core', # SkDocument.h ], diff --git a/gyp/tests.gypi b/gyp/tests.gypi index 24a0c9ae09..a6ad5d2cc6 100644 --- a/gyp/tests.gypi +++ b/gyp/tests.gypi @@ -37,6 +37,10 @@ '-ldl', ], }], + [ 'not skia_pdf', { + 'dependencies!': [ 'pdf.gyp:pdf' ], + 'dependencies': [ 'pdf.gyp:nopdf' ], + }], ], 'sources': [ '../tests/Test.h', diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 2d12bfd672..486feedb79 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -1171,8 +1171,10 @@ void SampleWindow::onDraw(SkCanvas* canvas) { void SampleWindow::saveToPdf() { +#if SK_SUPPORT_PDF fSaveToPdf = true; this->inval(NULL); +#endif // SK_SUPPORT_PDF } SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { diff --git a/src/doc/SkDocument_PDF_None.cpp b/src/doc/SkDocument_PDF_None.cpp new file mode 100644 index 0000000000..4759acf2a0 --- /dev/null +++ b/src/doc/SkDocument_PDF_None.cpp @@ -0,0 +1,9 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkDocument.h" +SkDocument* SkDocument::CreatePDF(SkWStream*, SkScalar) { return NULL; } +SkDocument* SkDocument::CreatePDF(const char path[], SkScalar) { return NULL; } diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp index 7a1ca97a55..a40a5f427b 100644 --- a/tests/AnnotationTest.cpp +++ b/tests/AnnotationTest.cpp @@ -12,6 +12,8 @@ #include "SkStream.h" #include "Test.h" +#if SK_SUPPORT_PDF + /** Returns true if data (may contain null characters) contains needle (null * terminated). */ static bool ContainsString(const char* data, size_t dataSize, const char* needle) { @@ -74,3 +76,4 @@ DEF_TEST(Annotation_NamedDestination, reporter) { REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/example ")); } +#endif // SK_SUPPORT_PDF diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index 970a37074f..78253ac900 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -568,6 +568,8 @@ static void TestPdfDevice(skiatest::Reporter* reporter, CanvasTestStep* testStep) { SkDynamicMemoryWStream outStream; SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); +#if SK_SUPPORT_PDF + REPORTER_ASSERT(reporter, doc); SkCanvas* canvas = doc->beginPage(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight)); REPORTER_ASSERT(reporter, canvas); @@ -575,6 +577,9 @@ static void TestPdfDevice(skiatest::Reporter* reporter, testStep->draw(canvas, d, reporter); REPORTER_ASSERT(reporter, doc->close()); +#else + REPORTER_ASSERT(reporter, !doc); +#endif // SK_SUPPORT_PDF } // The following class groups static functions that need to access diff --git a/tests/DeflateWStream.cpp b/tests/DeflateWStream.cpp index b22574671b..930ecb4144 100644 --- a/tests/DeflateWStream.cpp +++ b/tests/DeflateWStream.cpp @@ -9,6 +9,8 @@ #include "SkRandom.h" #include "Test.h" +#if SK_SUPPORT_PDF + DEF_TEST(SkDeflateWStream, r) { SkRandom random(123456); for (int i = 0; i < 50; ++i) { @@ -70,3 +72,4 @@ DEF_TEST(SkDeflateWStream, r) { } } } +#endif // SK_SUPPORT_PDF diff --git a/tests/DocumentTest.cpp b/tests/DocumentTest.cpp index 8bfb502700..5bd6ba6a03 100644 --- a/tests/DocumentTest.cpp +++ b/tests/DocumentTest.cpp @@ -1,9 +1,16 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "Test.h" #include "SkCanvas.h" #include "SkDocument.h" #include "SkOSFile.h" #include "SkStream.h" +#if SK_SUPPORT_PDF static void test_empty(skiatest::Reporter* reporter) { SkDynamicMemoryWStream stream; @@ -103,3 +110,4 @@ DEF_TEST(document_tests, reporter) { test_file(reporter); test_close(reporter); } +#endif // SK_SUPPORT_PDF diff --git a/tests/FlateTest.cpp b/tests/FlateTest.cpp index 40efe1a5d8..8387f527d1 100644 --- a/tests/FlateTest.cpp +++ b/tests/FlateTest.cpp @@ -10,6 +10,8 @@ #include "SkStream.h" #include "Test.h" +#if SK_SUPPORT_PDF + // A memory stream that reports zero size with the standard call, like // an unseekable file stream would. class SkZeroSizeMemStream : public SkMemoryStream { @@ -112,3 +114,4 @@ DEF_TEST(Flate, reporter) { TestFlate(reporter, &fileStream, 512); TestFlate(reporter, &fileStream, 10240); } +#endif // SK_SUPPORT_PDF diff --git a/tests/PDFInvalidBitmapTest.cpp b/tests/PDFInvalidBitmapTest.cpp index 8a9b1fa132..6a547066d5 100644 --- a/tests/PDFInvalidBitmapTest.cpp +++ b/tests/PDFInvalidBitmapTest.cpp @@ -15,6 +15,8 @@ #include "Test.h" +#if SK_SUPPORT_PDF + namespace { // SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels @@ -58,3 +60,4 @@ DEF_TEST(PDFInvalidBitmap, reporter) { // This test passes if it does not crash. } +#endif // SK_SUPPORT_PDF diff --git a/tests/PDFJpegEmbedTest.cpp b/tests/PDFJpegEmbedTest.cpp index cfe6776bf5..021161bf9f 100644 --- a/tests/PDFJpegEmbedTest.cpp +++ b/tests/PDFJpegEmbedTest.cpp @@ -14,6 +14,8 @@ #include "Resources.h" #include "Test.h" +#if SK_SUPPORT_PDF + // Returned bitmap is lazy. Only lazy bitmaps hold onto the original data. static SkBitmap bitmap_from_data(SkData* data) { SkASSERT(data); @@ -125,3 +127,4 @@ DEF_TEST(JpegIdentification, r) { } } } +#endif // SK_SUPPORT_PDF diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 013d58657b..22d8d16328 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -22,6 +22,8 @@ #include "SkTypes.h" #include "Test.h" +#if SK_SUPPORT_PDF + #define DUMMY_TEXT "DCT compessed stream." namespace { @@ -413,3 +415,4 @@ DEF_TEST(PDFImageFilter, reporter) { // Filter was used in rendering; should be visited. REPORTER_ASSERT(reporter, filter->visited()); } +#endif // SK_SUPPORT_PDF diff --git a/tests/ToUnicodeTest.cpp b/tests/ToUnicodeTest.cpp index 33fcc80ef7..4dcb2df0b2 100644 --- a/tests/ToUnicodeTest.cpp +++ b/tests/ToUnicodeTest.cpp @@ -11,6 +11,8 @@ #include "SkStream.h" #include "Test.h" +#if SK_SUPPORT_PDF + static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, const char* buffer, size_t len) { SkAutoDataUnref data(stream.copyToData()); @@ -178,3 +180,4 @@ endbfrange\n"; REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, buffer2.getOffset())); } +#endif // SK_SUPPORT_PDF diff --git a/tests/skpdf_opaquesrcmodetosrcover.cpp b/tests/skpdf_opaquesrcmodetosrcover.cpp index f742f3ddd6..8c7fc75162 100644 --- a/tests/skpdf_opaquesrcmodetosrcover.cpp +++ b/tests/skpdf_opaquesrcmodetosrcover.cpp @@ -9,6 +9,8 @@ #include "SkStream.h" #include "Test.h" +#if SK_SUPPORT_PDF + static void run_test(SkWStream* out, SkXfermode::Mode mode, U8CPU alpha) { SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(out)); SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f); @@ -44,3 +46,4 @@ DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) { REPORTER_ASSERT(r, srcMode.getOffset() > srcOverMode.getOffset()); // The two PDFs should not be equal because they have a non-opaque alpha. } +#endif // SK_SUPPORT_PDF |