| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkData.h" | 11 #include "SkData.h" |
| 12 #include "SkDecodingImageGenerator.h" | 12 #include "SkDecodingImageGenerator.h" |
| 13 #include "SkError.h" | 13 #include "SkError.h" |
| 14 #include "SkImageGenerator.h" |
| 14 #include "SkPaint.h" | 15 #include "SkPaint.h" |
| 15 #include "SkPicture.h" | 16 #include "SkPicture.h" |
| 16 #include "SkPictureUtils.h" | 17 #include "SkPictureUtils.h" |
| 17 #include "SkRandom.h" | 18 #include "SkRandom.h" |
| 18 #include "SkRRect.h" | 19 #include "SkRRect.h" |
| 19 #include "SkShader.h" | 20 #include "SkShader.h" |
| 20 #include "SkStream.h" | 21 #include "SkStream.h" |
| 21 | 22 |
| 22 | 23 |
| 23 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { | 24 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // Create a bitmap that will be encoded. | 373 // Create a bitmap that will be encoded. |
| 373 SkBitmap original; | 374 SkBitmap original; |
| 374 make_bm(&original, 100, 100, SK_ColorBLUE, true); | 375 make_bm(&original, 100, 100, SK_ColorBLUE, true); |
| 375 SkDynamicMemoryWStream wStream; | 376 SkDynamicMemoryWStream wStream; |
| 376 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T
ype, 100)) { | 377 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T
ype, 100)) { |
| 377 return; | 378 return; |
| 378 } | 379 } |
| 379 SkAutoDataUnref data(wStream.copyToData()); | 380 SkAutoDataUnref data(wStream.copyToData()); |
| 380 | 381 |
| 381 SkBitmap bm; | 382 SkBitmap bm; |
| 382 bool installSuccess = SkDecodingImageGenerator::Install(data, &bm); | 383 bool installSuccess = SkInstallDiscardablePixelRef( |
| 384 SkNewDecodingImageGenerator(data, SkDecoderOptions()), &bm, NULL); |
| 385 |
| 383 REPORTER_ASSERT(reporter, installSuccess); | 386 REPORTER_ASSERT(reporter, installSuccess); |
| 384 | 387 |
| 385 // Write both bitmaps to pictures, and ensure that the resulting data stream
s are the same. | 388 // Write both bitmaps to pictures, and ensure that the resulting data stream
s are the same. |
| 386 // Flattening original will follow the old path of performing an encode, whi
le flattening bm | 389 // Flattening original will follow the old path of performing an encode, whi
le flattening bm |
| 387 // will use the already encoded data. | 390 // will use the already encoded data. |
| 388 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); | 391 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); |
| 389 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); | 392 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); |
| 390 REPORTER_ASSERT(reporter, picture1->equals(picture2)); | 393 REPORTER_ASSERT(reporter, picture1->equals(picture2)); |
| 391 // Now test that a parse error was generated when trying to create a new SkP
icture without | 394 // Now test that a parse error was generated when trying to create a new SkP
icture without |
| 392 // providing a function to decode the bitmap. | 395 // providing a function to decode the bitmap. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 test_gatherpixelrefs(reporter); | 636 test_gatherpixelrefs(reporter); |
| 634 test_bitmap_with_encoded_data(reporter); | 637 test_bitmap_with_encoded_data(reporter); |
| 635 test_clone_empty(reporter); | 638 test_clone_empty(reporter); |
| 636 test_clip_bound_opt(reporter); | 639 test_clip_bound_opt(reporter); |
| 637 test_clip_expansion(reporter); | 640 test_clip_expansion(reporter); |
| 638 test_hierarchical(reporter); | 641 test_hierarchical(reporter); |
| 639 } | 642 } |
| 640 | 643 |
| 641 #include "TestClassDef.h" | 644 #include "TestClassDef.h" |
| 642 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) | 645 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) |
| OLD | NEW |