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

Side by Side Diff: tests/PDFPrimitivesTest.cpp

Issue 869783003: Cleanup SkPDFObject::emit* (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 months 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/SkPDFTypes.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 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
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 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 for (size_t offset = 0 ; offset < data->size() - len; offset++) { 63 for (size_t offset = 0 ; offset < data->size() - len; offset++) {
64 if (memcmp(data->bytes() + offset, buffer, len) == 0) { 64 if (memcmp(data->bytes() + offset, buffer, len) == 0) {
65 return true; 65 return true;
66 } 66 }
67 } 67 }
68 68
69 return false; 69 return false;
70 } 70 }
71 71
72 static void emit_object(SkPDFObject* object,
73 SkWStream* stream,
74 SkPDFCatalog* catalog,
75 bool indirect) {
76 SkPDFObject* realObject = catalog->getSubstituteObject(object);
77 if (indirect) {
78 catalog->emitObjectNumber(stream, realObject);
79 stream->writeText(" obj\n");
80 realObject->emitObject(stream, catalog);
81 stream->writeText("\nendobj\n");
82 } else {
83 realObject->emitObject(stream, catalog);
84 }
85 }
86
87 static size_t get_output_size(SkPDFObject* object,
88 SkPDFCatalog* catalog,
89 bool indirect) {
90 SkDynamicMemoryWStream buffer;
91 emit_object(object, &buffer, catalog, indirect);
92 return buffer.getOffset();
93 }
94
72 static void CheckObjectOutput(skiatest::Reporter* reporter, SkPDFObject* obj, 95 static void CheckObjectOutput(skiatest::Reporter* reporter, SkPDFObject* obj,
73 const char* expectedData, size_t expectedSize, 96 const char* expectedData, size_t expectedSize,
74 bool indirect, bool compression) { 97 bool indirect, bool compression) {
75 SkPDFDocument::Flags docFlags = (SkPDFDocument::Flags) 0; 98 SkPDFDocument::Flags docFlags = (SkPDFDocument::Flags) 0;
76 if (!compression) { 99 if (!compression) {
77 docFlags = SkTBitOr(docFlags, SkPDFDocument::kFavorSpeedOverSize_Flags); 100 docFlags = SkTBitOr(docFlags, SkPDFDocument::kFavorSpeedOverSize_Flags);
78 } 101 }
79 SkPDFCatalog catalog(docFlags); 102 SkPDFCatalog catalog(docFlags);
80 size_t directSize = obj->getOutputSize(&catalog, false); 103 size_t directSize = get_output_size(obj, &catalog, false);
81 REPORTER_ASSERT(reporter, directSize == expectedSize); 104 REPORTER_ASSERT(reporter, directSize == expectedSize);
82 105
83 SkDynamicMemoryWStream buffer; 106 SkDynamicMemoryWStream buffer;
84 obj->emit(&buffer, &catalog, false); 107 emit_object(obj, &buffer, &catalog, false);
85 REPORTER_ASSERT(reporter, directSize == buffer.getOffset()); 108 REPORTER_ASSERT(reporter, directSize == buffer.getOffset());
86 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData, 109 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData,
87 directSize)); 110 directSize));
88 111
89 if (indirect) { 112 if (indirect) {
90 // Indirect output. 113 // Indirect output.
91 static char header[] = "1 0 obj\n"; 114 static char header[] = "1 0 obj\n";
92 static size_t headerLen = strlen(header); 115 static size_t headerLen = strlen(header);
93 static char footer[] = "\nendobj\n"; 116 static char footer[] = "\nendobj\n";
94 static size_t footerLen = strlen(footer); 117 static size_t footerLen = strlen(footer);
95 118
96 catalog.addObject(obj, false); 119 catalog.addObject(obj, false);
97 120
98 size_t indirectSize = obj->getOutputSize(&catalog, true); 121 size_t indirectSize = get_output_size(obj, &catalog, true);
99 REPORTER_ASSERT(reporter, 122 REPORTER_ASSERT(reporter,
100 indirectSize == directSize + headerLen + footerLen); 123 indirectSize == directSize + headerLen + footerLen);
101 124
102 buffer.reset(); 125 buffer.reset();
103 obj->emit(&buffer, &catalog, true); 126 emit_object(obj, &buffer, &catalog, true);
104 REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset()); 127 REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset());
105 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen)); 128 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen));
106 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData, 129 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData,
107 directSize)); 130 directSize));
108 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen + directSize, 131 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen + directSize,
109 footer, footerLen)); 132 footer, footerLen));
110 } 133 }
111 } 134 }
112 135
113 static void SimpleCheckObjectOutput(skiatest::Reporter* reporter, 136 static void SimpleCheckObjectOutput(skiatest::Reporter* reporter,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 243
221 stub->insert("Value", int33.get()); 244 stub->insert("Value", int33.get());
222 stubResource->insert("InnerValue", int44.get()); 245 stubResource->insert("InnerValue", int44.get());
223 stub->addResource(stubResource.get()); 246 stub->addResource(stubResource.get());
224 247
225 SkPDFCatalog catalog((SkPDFDocument::Flags)0); 248 SkPDFCatalog catalog((SkPDFDocument::Flags)0);
226 catalog.addObject(proxy.get(), false); 249 catalog.addObject(proxy.get(), false);
227 catalog.setSubstitute(proxy.get(), stub.get()); 250 catalog.setSubstitute(proxy.get(), stub.get());
228 251
229 SkDynamicMemoryWStream buffer; 252 SkDynamicMemoryWStream buffer;
230 proxy->emit(&buffer, &catalog, false); 253 emit_object(proxy, &buffer, &catalog, false);
231 SkTSet<SkPDFObject*>* substituteResources = 254 SkTSet<SkPDFObject*>* substituteResources =
232 catalog.getSubstituteList(false); 255 catalog.getSubstituteList(false);
233 for (int i = 0; i < substituteResources->count(); ++i) { 256 for (int i = 0; i < substituteResources->count(); ++i) {
234 (*substituteResources)[i]->emit(&buffer, &catalog, true); 257 emit_object((*substituteResources)[i], &buffer, &catalog, true);
235 } 258 }
236 259
237 char objectResult[] = "2 0 obj\n<</Value 33\n>>\nendobj\n"; 260 char objectResult[] = "2 0 obj\n<</Value 33\n>>\nendobj\n";
238 catalog.setFileOffset(proxy.get(), 0); 261 catalog.setFileOffset(proxy.get(), 0);
239 262
240 size_t outputSize = catalog.getSubstituteObject(proxy.get()) 263 size_t outputSize = get_output_size(
241 ->getOutputSize(&catalog, true); 264 catalog.getSubstituteObject(proxy.get()), &catalog, true);
242 REPORTER_ASSERT(reporter, outputSize == strlen(objectResult)); 265 REPORTER_ASSERT(reporter, outputSize == strlen(objectResult));
243 266
244 char expectedResult[] = 267 char expectedResult[] =
245 "<</Value 33\n>>1 0 obj\n<</InnerValue 44\n>>\nendobj\n"; 268 "<</Value 33\n>>1 0 obj\n<</InnerValue 44\n>>\nendobj\n";
246 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); 269 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult));
247 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, 270 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
248 buffer.getOffset())); 271 buffer.getOffset()));
249 } 272 }
250 273
251 // Create a bitmap that would be very eficiently compressed in a ZIP. 274 // Create a bitmap that would be very eficiently compressed in a ZIP.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 505
483 // Filter just created; should be unvisited. 506 // Filter just created; should be unvisited.
484 REPORTER_ASSERT(reporter, !filter->visited()); 507 REPORTER_ASSERT(reporter, !filter->visited());
485 SkPaint paint; 508 SkPaint paint;
486 paint.setImageFilter(filter.get()); 509 paint.setImageFilter(filter.get());
487 canvas.drawRect(SkRect::MakeWH(100, 100), paint); 510 canvas.drawRect(SkRect::MakeWH(100, 100), paint);
488 511
489 // Filter was used in rendering; should be visited. 512 // Filter was used in rendering; should be visited.
490 REPORTER_ASSERT(reporter, filter->visited()); 513 REPORTER_ASSERT(reporter, filter->visited());
491 } 514 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFTypes.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698