| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2015 Google Inc. | 2  * Copyright 2015 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 "SkData.h" | 8 #include "SkData.h" | 
| 9 #include "SkForceLinking.h" | 9 #include "SkForceLinking.h" | 
| 10 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" | 
| 11 #include "SkPicture.h" | 11 #include "SkPicture.h" | 
| 12 #include "SkPictureRecorder.h" | 12 #include "SkPictureRecorder.h" | 
| 13 #include "SkStream.h" | 13 #include "SkStream.h" | 
| 14 | 14 | 
| 15 #include <stdlib.h> | 15 #include <stdlib.h> | 
| 16 #include <stdio.h> | 16 #include <stdio.h> | 
| 17 | 17 | 
| 18 __SK_FORCE_IMAGE_DECODER_LINKING; | 18 __SK_FORCE_IMAGE_DECODER_LINKING; | 
| 19 | 19 | 
| 20 #define ASSERTF(cond, fmt, ...) if (!(cond)) { fprintf(stderr, fmt"\n", __VA_ARG
    S__); exit(1); } | 20 #define ASSERTF(cond, fmt, ...) if (!(cond)) { fprintf(stderr, fmt"\n", __VA_ARG
    S__); exit(1); } | 
| 21 | 21 | 
| 22 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { | 22 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { | 
| 23     SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); | 23     SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); | 
| 24     return encoded && SkInstallDiscardablePixelRef(encoded, dst); | 24     return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst); | 
| 25 } | 25 } | 
| 26 | 26 | 
| 27 int main(int argc, char** argv) { | 27 int main(int argc, char** argv) { | 
| 28     ASSERTF(argc == 3, "usage: %s nested.skp flat.skp", argv[0]); | 28     ASSERTF(argc == 3, "usage: %s nested.skp flat.skp", argv[0]); | 
| 29     const char *nestedPath = argv[1], | 29     const char *nestedPath = argv[1], | 
| 30                *flatPath   = argv[2]; | 30                *flatPath   = argv[2]; | 
| 31 | 31 | 
| 32     // Read nested.skp. | 32     // Read nested.skp. | 
| 33     SkFILEStream stream(nestedPath); | 33     SkFILEStream stream(nestedPath); | 
| 34     ASSERTF(stream.isValid(), "Couldn't read %s.", nestedPath); | 34     ASSERTF(stream.isValid(), "Couldn't read %s.", nestedPath); | 
| 35     SkAutoTUnref<const SkPicture> nested(SkPicture::CreateFromStream(&stream, &l
    azy_decode_bitmap)); | 35     SkAutoTUnref<const SkPicture> nested(SkPicture::CreateFromStream(&stream, &l
    azy_decode_bitmap)); | 
| 36     ASSERTF(nested, "Couldn't parse %s as a picture.", nestedPath); | 36     ASSERTF(nested, "Couldn't parse %s as a picture.", nestedPath); | 
| 37 | 37 | 
| 38     // Play it back into a new picture using kPlaybackDrawPicture_RecordFlag. | 38     // Play it back into a new picture using kPlaybackDrawPicture_RecordFlag. | 
| 39     SkPictureRecorder recorder; | 39     SkPictureRecorder recorder; | 
| 40     uint32_t flags = SkPictureRecorder::kPlaybackDrawPicture_RecordFlag; | 40     uint32_t flags = SkPictureRecorder::kPlaybackDrawPicture_RecordFlag; | 
| 41     nested->playback(recorder.beginRecording(nested->cullRect(), nullptr, flags)
    ); | 41     nested->playback(recorder.beginRecording(nested->cullRect(), nullptr, flags)
    ); | 
| 42     SkAutoTUnref<const SkPicture> flat(recorder.endRecordingAsPicture()); | 42     SkAutoTUnref<const SkPicture> flat(recorder.endRecordingAsPicture()); | 
| 43 | 43 | 
| 44     // Write out that flat.skp | 44     // Write out that flat.skp | 
| 45     SkFILEWStream wstream(flatPath); | 45     SkFILEWStream wstream(flatPath); | 
| 46     ASSERTF(wstream.isValid(), "Could not open %s.", flatPath); | 46     ASSERTF(wstream.isValid(), "Could not open %s.", flatPath); | 
| 47     flat->serialize(&wstream); | 47     flat->serialize(&wstream); | 
| 48     wstream.flush(); | 48     wstream.flush(); | 
| 49 | 49 | 
| 50     return 0; | 50     return 0; | 
| 51 } | 51 } | 
| OLD | NEW | 
|---|