OLD | NEW |
---|---|
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 SkDynamicMemoryWStream buffer; | 230 SkDynamicMemoryWStream buffer; |
231 int2ref->emitObject(&buffer, &catalog); | 231 int2ref->emitObject(&buffer, &catalog); |
232 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); | 232 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); |
233 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, | 233 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
234 buffer.getOffset())); | 234 buffer.getOffset())); |
235 } | 235 } |
236 | 236 |
237 static void TestSubstitute(skiatest::Reporter* reporter) { | 237 static void TestSubstitute(skiatest::Reporter* reporter) { |
238 SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict()); | 238 SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict()); |
239 SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict()); | 239 SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict()); |
240 SkAutoTUnref<SkPDFInt> int33(new SkPDFInt(33)); | |
241 SkAutoTUnref<SkPDFDict> stubResource(new SkPDFDict()); | |
242 SkAutoTUnref<SkPDFInt> int44(new SkPDFInt(44)); | |
243 | 240 |
244 stub->insert("Value", int33.get()); | 241 proxy->insert("Value", new SkPDFInt(33))->unref(); |
mtklein
2015/01/26 23:38:59
If we're getting serious about PDF memory allocati
hal.canary
2015/02/09 23:35:01
Acknowledged.
Let's do that *after* making these
| |
245 stubResource->insert("InnerValue", int44.get()); | 242 stub->insert("Value", new SkPDFInt(44))->unref(); |
246 stub->addResource(stubResource.get()); | |
247 | 243 |
248 SkPDFCatalog catalog((SkPDFDocument::Flags)0); | 244 SkPDFCatalog catalog((SkPDFDocument::Flags)0); |
249 catalog.addObject(proxy.get(), false); | 245 catalog.addObject(proxy.get(), false); |
250 catalog.setSubstitute(proxy.get(), stub.get()); | 246 catalog.setSubstitute(proxy.get(), stub.get()); |
251 | 247 |
252 SkDynamicMemoryWStream buffer; | 248 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy)); |
253 emit_object(proxy, &buffer, &catalog, false); | 249 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub)); |
254 SkTSet<SkPDFObject*>* substituteResources = | |
255 catalog.getSubstituteList(false); | |
256 for (int i = 0; i < substituteResources->count(); ++i) { | |
257 emit_object((*substituteResources)[i], &buffer, &catalog, true); | |
258 } | |
259 | |
260 char objectResult[] = "2 0 obj\n<</Value 33\n>>\nendobj\n"; | |
261 catalog.setFileOffset(proxy.get(), 0); | |
262 | |
263 size_t outputSize = get_output_size( | |
264 catalog.getSubstituteObject(proxy.get()), &catalog, true); | |
265 REPORTER_ASSERT(reporter, outputSize == strlen(objectResult)); | |
266 | |
267 char expectedResult[] = | |
268 "<</Value 33\n>>1 0 obj\n<</InnerValue 44\n>>\nendobj\n"; | |
269 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); | |
270 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, | |
271 buffer.getOffset())); | |
272 } | 250 } |
273 | 251 |
274 // Create a bitmap that would be very eficiently compressed in a ZIP. | 252 // Create a bitmap that would be very eficiently compressed in a ZIP. |
275 static void setup_bitmap(SkBitmap* bitmap, int width, int height) { | 253 static void setup_bitmap(SkBitmap* bitmap, int width, int height) { |
276 bitmap->allocN32Pixels(width, height); | 254 bitmap->allocN32Pixels(width, height); |
277 bitmap->eraseColor(SK_ColorWHITE); | 255 bitmap->eraseColor(SK_ColorWHITE); |
278 } | 256 } |
279 | 257 |
280 static void TestImage(skiatest::Reporter* reporter, const SkBitmap& bitmap, | 258 static void TestImage(skiatest::Reporter* reporter, const SkBitmap& bitmap, |
281 const char* expected, bool useDCTEncoder) { | 259 const char* expected, bool useDCTEncoder) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 483 |
506 // Filter just created; should be unvisited. | 484 // Filter just created; should be unvisited. |
507 REPORTER_ASSERT(reporter, !filter->visited()); | 485 REPORTER_ASSERT(reporter, !filter->visited()); |
508 SkPaint paint; | 486 SkPaint paint; |
509 paint.setImageFilter(filter.get()); | 487 paint.setImageFilter(filter.get()); |
510 canvas.drawRect(SkRect::MakeWH(100, 100), paint); | 488 canvas.drawRect(SkRect::MakeWH(100, 100), paint); |
511 | 489 |
512 // Filter was used in rendering; should be visited. | 490 // Filter was used in rendering; should be visited. |
513 REPORTER_ASSERT(reporter, filter->visited()); | 491 REPORTER_ASSERT(reporter, filter->visited()); |
514 } | 492 } |
OLD | NEW |