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 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 #include "SkDecodingImageGenerator.h" | 14 #include "SkDecodingImageGenerator.h" |
15 #include "SkError.h" | 15 #include "SkError.h" |
16 #include "SkImageEncoder.h" | |
17 #include "SkImageGenerator.h" | |
18 #include "SkPaint.h" | 16 #include "SkPaint.h" |
19 #include "SkPicture.h" | 17 #include "SkPicture.h" |
20 #include "SkPictureUtils.h" | 18 #include "SkPictureUtils.h" |
21 #include "SkRandom.h" | 19 #include "SkRandom.h" |
22 #include "SkRRect.h" | 20 #include "SkRRect.h" |
23 #include "SkShader.h" | 21 #include "SkShader.h" |
24 #include "SkStream.h" | 22 #include "SkStream.h" |
25 | 23 |
26 | 24 |
27 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { | 25 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 SkPicture picture; | 331 SkPicture picture; |
334 SkCanvas* recordingCanvas = picture.beginRecording(100, 100); | 332 SkCanvas* recordingCanvas = picture.beginRecording(100, 100); |
335 recordingCanvas->drawBitmap(bm, 0, 0); | 333 recordingCanvas->drawBitmap(bm, 0, 0); |
336 picture.endRecording(); | 334 picture.endRecording(); |
337 | 335 |
338 SkCanvas canvas; | 336 SkCanvas canvas; |
339 canvas.drawPicture(picture); | 337 canvas.drawPicture(picture); |
340 } | 338 } |
341 #endif | 339 #endif |
342 | 340 |
| 341 #include "SkImageEncoder.h" |
| 342 |
343 static SkData* encode_bitmap_to_data(size_t* offset, const SkBitmap& bm) { | 343 static SkData* encode_bitmap_to_data(size_t* offset, const SkBitmap& bm) { |
344 *offset = 0; | 344 *offset = 0; |
345 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | 345 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
346 } | 346 } |
347 | 347 |
348 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 348 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
349 SkPicture picture; | 349 SkPicture picture; |
350 SkCanvas* canvas = picture.beginRecording(bitmap.width(), bitmap.height()); | 350 SkCanvas* canvas = picture.beginRecording(bitmap.width(), bitmap.height()); |
351 canvas->drawBitmap(bitmap, 0, 0); | 351 canvas->drawBitmap(bitmap, 0, 0); |
352 SkDynamicMemoryWStream wStream; | 352 SkDynamicMemoryWStream wStream; |
(...skipping 21 matching lines...) Expand all Loading... |
374 // Create a bitmap that will be encoded. | 374 // Create a bitmap that will be encoded. |
375 SkBitmap original; | 375 SkBitmap original; |
376 make_bm(&original, 100, 100, SK_ColorBLUE, true); | 376 make_bm(&original, 100, 100, SK_ColorBLUE, true); |
377 SkDynamicMemoryWStream wStream; | 377 SkDynamicMemoryWStream wStream; |
378 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T
ype, 100)) { | 378 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T
ype, 100)) { |
379 return; | 379 return; |
380 } | 380 } |
381 SkAutoDataUnref data(wStream.copyToData()); | 381 SkAutoDataUnref data(wStream.copyToData()); |
382 | 382 |
383 SkBitmap bm; | 383 SkBitmap bm; |
384 bool installSuccess = SkInstallDiscardablePixelRef( | 384 bool installSuccess = SkDecodingImageGenerator::Install(data, &bm); |
385 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator::Option
s()), &bm, NULL); | |
386 REPORTER_ASSERT(reporter, installSuccess); | 385 REPORTER_ASSERT(reporter, installSuccess); |
387 | 386 |
388 // Write both bitmaps to pictures, and ensure that the resulting data stream
s are the same. | 387 // Write both bitmaps to pictures, and ensure that the resulting data stream
s are the same. |
389 // Flattening original will follow the old path of performing an encode, whi
le flattening bm | 388 // Flattening original will follow the old path of performing an encode, whi
le flattening bm |
390 // will use the already encoded data. | 389 // will use the already encoded data. |
391 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); | 390 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); |
392 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); | 391 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); |
393 REPORTER_ASSERT(reporter, picture1->equals(picture2)); | 392 REPORTER_ASSERT(reporter, picture1->equals(picture2)); |
394 // Now test that a parse error was generated when trying to create a new SkP
icture without | 393 // Now test that a parse error was generated when trying to create a new SkP
icture without |
395 // providing a function to decode the bitmap. | 394 // providing a function to decode the bitmap. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 test_bad_bitmap(); | 632 test_bad_bitmap(); |
634 #endif | 633 #endif |
635 test_peephole(); | 634 test_peephole(); |
636 test_gatherpixelrefs(reporter); | 635 test_gatherpixelrefs(reporter); |
637 test_bitmap_with_encoded_data(reporter); | 636 test_bitmap_with_encoded_data(reporter); |
638 test_clone_empty(reporter); | 637 test_clone_empty(reporter); |
639 test_clip_bound_opt(reporter); | 638 test_clip_bound_opt(reporter); |
640 test_clip_expansion(reporter); | 639 test_clip_expansion(reporter); |
641 test_hierarchical(reporter); | 640 test_hierarchical(reporter); |
642 } | 641 } |
OLD | NEW |