Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: tests/PDFDocumentTest.cpp

Issue 1505763003: SkDocument::setDCTEncoder() for old versions of webkit (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-09 (Wednesday) 13:41:21 EST Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "Test.h" 7 #include "Test.h"
8 8
9 #include "Resources.h"
9 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkDocument.h" 11 #include "SkDocument.h"
11 #include "SkOSFile.h" 12 #include "SkOSFile.h"
12 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkPixelSerializer.h"
13 15
14 static void test_empty(skiatest::Reporter* reporter) { 16 static void test_empty(skiatest::Reporter* reporter) {
15 SkDynamicMemoryWStream stream; 17 SkDynamicMemoryWStream stream;
16 18
17 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); 19 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream));
18 20
19 doc->close(); 21 doc->close();
20 22
21 REPORTER_ASSERT(reporter, stream.bytesWritten() == 0); 23 REPORTER_ASSERT(reporter, stream.bytesWritten() == 0);
22 } 24 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 105 }
104 106
105 DEF_TEST(document_tests, reporter) { 107 DEF_TEST(document_tests, reporter) {
106 REQUIRE_PDF_DOCUMENT(document_tests, reporter); 108 REQUIRE_PDF_DOCUMENT(document_tests, reporter);
107 test_empty(reporter); 109 test_empty(reporter);
108 test_abort(reporter); 110 test_abort(reporter);
109 test_abortWithFile(reporter); 111 test_abortWithFile(reporter);
110 test_file(reporter); 112 test_file(reporter);
111 test_close(reporter); 113 test_close(reporter);
112 } 114 }
115
116 namespace {
117 class JPEGSerializer final : public SkPixelSerializer {
118 bool onUseEncodedData(const void*, size_t) override { return true; }
119 SkData* onEncode(const SkPixmap& pixmap) override {
120 SkBitmap bm;
121 return bm.installPixels(pixmap.info(),
122 pixmap.writable_addr(),
123 pixmap.rowBytes(),
124 pixmap.ctable(),
125 nullptr, nullptr)
126 ? SkImageEncoder::EncodeData(bm, SkImageEncoder::kJPEG_Type, 85)
127 : nullptr;
128 }
129 };
130 } // namespace
131
132 size_t count_bytes(const SkBitmap& bm, bool useDCT) {
133 SkDynamicMemoryWStream stream;
134 SkAutoTUnref<SkDocument> doc;
135 if (useDCT) {
136 SkAutoTUnref<SkPixelSerializer> serializer(new JPEGSerializer);
137 doc.reset(SkDocument::CreatePDF(
138 &stream, SK_ScalarDefaultRasterDPI, serializer));
139 } else {
140 doc.reset(SkDocument::CreatePDF(&stream));
141 }
142 SkCanvas* canvas = doc->beginPage(64, 64);
143 canvas->drawBitmap(bm, 0, 0);
144 doc->endPage();
145 doc->close();
146 return stream.bytesWritten();
147 }
148
149 DEF_TEST(document_dct_encoder, r) {
150 REQUIRE_PDF_DOCUMENT(document_dct_encoder, r);
151 SkBitmap bm;
152 if (GetResourceAsBitmap("mandrill_64.png", &bm)) {
153 // Lossy encoding works better on photographs.
154 REPORTER_ASSERT(r, count_bytes(bm, true) < count_bytes(bm, false));
155 }
156 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698