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

Side by Side Diff: tests/PictureTest.cpp

Issue 93703004: Change SkDecodingImageGenerator API (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebased Created 6 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 | Annotate | Revision Log
« no previous file with comments | « tests/ImageDecodingTest.cpp ('k') | tools/LazyDecodeBitmap.cpp » ('j') | 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 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"
16 #include "SkPaint.h" 18 #include "SkPaint.h"
17 #include "SkPicture.h" 19 #include "SkPicture.h"
18 #include "SkPictureUtils.h" 20 #include "SkPictureUtils.h"
19 #include "SkRandom.h" 21 #include "SkRandom.h"
20 #include "SkRRect.h" 22 #include "SkRRect.h"
21 #include "SkShader.h" 23 #include "SkShader.h"
22 #include "SkStream.h" 24 #include "SkStream.h"
23 25
24 26
25 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { 27 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
331 SkPicture picture; 333 SkPicture picture;
332 SkCanvas* recordingCanvas = picture.beginRecording(100, 100); 334 SkCanvas* recordingCanvas = picture.beginRecording(100, 100);
333 recordingCanvas->drawBitmap(bm, 0, 0); 335 recordingCanvas->drawBitmap(bm, 0, 0);
334 picture.endRecording(); 336 picture.endRecording();
335 337
336 SkCanvas canvas; 338 SkCanvas canvas;
337 canvas.drawPicture(picture); 339 canvas.drawPicture(picture);
338 } 340 }
339 #endif 341 #endif
340 342
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
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 = SkDecodingImageGenerator::Install(data, &bm); 384 bool installSuccess = SkInstallDiscardablePixelRef(
385 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator::Option s()), &bm, NULL);
385 REPORTER_ASSERT(reporter, installSuccess); 386 REPORTER_ASSERT(reporter, installSuccess);
386 387
387 // 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.
388 // 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
389 // will use the already encoded data. 390 // will use the already encoded data.
390 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); 391 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original));
391 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); 392 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm));
392 REPORTER_ASSERT(reporter, picture1->equals(picture2)); 393 REPORTER_ASSERT(reporter, picture1->equals(picture2));
393 // 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
394 // providing a function to decode the bitmap. 395 // providing a function to decode the bitmap.
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 test_bad_bitmap(); 633 test_bad_bitmap();
633 #endif 634 #endif
634 test_peephole(); 635 test_peephole();
635 test_gatherpixelrefs(reporter); 636 test_gatherpixelrefs(reporter);
636 test_bitmap_with_encoded_data(reporter); 637 test_bitmap_with_encoded_data(reporter);
637 test_clone_empty(reporter); 638 test_clone_empty(reporter);
638 test_clip_bound_opt(reporter); 639 test_clip_bound_opt(reporter);
639 test_clip_expansion(reporter); 640 test_clip_expansion(reporter);
640 test_hierarchical(reporter); 641 test_hierarchical(reporter);
641 } 642 }
OLDNEW
« no previous file with comments | « tests/ImageDecodingTest.cpp ('k') | tools/LazyDecodeBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698