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
This commit is contained in:
halcanary 2015-08-11 10:30:12 -07:00 committed by Commit bot
parent 4cf9e7e147
commit 8ee06f21a2
16 changed files with 66 additions and 0 deletions

View File

@ -253,6 +253,10 @@
'gputest.gyp:skgputest',
],
}],
[ 'not skia_pdf', {
'dependencies!': [ 'pdf.gyp:pdf' ],
'dependencies': [ 'pdf.gyp:nopdf' ],
}],
],
},
],

View File

@ -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)',

View File

@ -5,6 +5,13 @@
# This file builds the PDF backend.
{
'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',
@ -46,6 +53,7 @@
],
],
'direct_dependent_settings': {
'defines': [ 'SK_SUPPORT_PDF=1', ],
'include_dirs': [
'../include/core', # SkDocument.h
],

View File

@ -37,6 +37,10 @@
'-ldl',
],
}],
[ 'not skia_pdf', {
'dependencies!': [ 'pdf.gyp:pdf' ],
'dependencies': [ 'pdf.gyp:nopdf' ],
}],
],
'sources': [
'../tests/Test.h',

View File

@ -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) {

View File

@ -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; }

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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