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

Side by Side Diff: tools/flatten.cpp

Issue 1221303020: Add tools/flatten to flatten nested pictures in .skps. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: good catch clang Created 5 years, 5 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
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkData.h"
9 #include "SkForceLinking.h"
10 #include "SkImageGenerator.h"
11 #include "SkPicture.h"
12 #include "SkPictureRecorder.h"
13 #include "SkStream.h"
14 #include <stdio.h>
15
16 __SK_FORCE_IMAGE_DECODER_LINKING;
17
18 #define ASSERTF(cond, fmt, ...) if (!(cond)) { fprintf(stderr, fmt"\n", __VA_ARG S__); exit(1); }
19
20 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
21 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
22 return encoded && SkInstallDiscardablePixelRef(encoded, dst);
23 }
24
25 int main(int argc, char** argv) {
26 ASSERTF(argc == 3, "usage: %s nested.skp flat.skp", argv[0]);
27 const char *nestedPath = argv[1],
28 *flatPath = argv[2];
29
30 // Read nested.skp.
31 SkFILEStream stream(nestedPath);
32 ASSERTF(stream.isValid(), "Couldn't read %s.", nestedPath);
33 SkAutoTUnref<const SkPicture> nested(SkPicture::CreateFromStream(&stream, &l azy_decode_bitmap));
34 ASSERTF(nested, "Couldn't parse %s as a picture.", nestedPath);
35
36 // Play it back into a new picture using kPlaybackDrawPicture_RecordFlag.
37 SkPictureRecorder recorder;
38 uint32_t flags = SkPictureRecorder::kPlaybackDrawPicture_RecordFlag;
39 nested->playback(recorder.beginRecording(nested->cullRect(), nullptr, flags) );
40 SkAutoTUnref<const SkPicture> flat(recorder.endRecordingAsPicture());
41
42 // Write out that flat.skp
43 SkFILEWStream wstream(flatPath);
44 ASSERTF(wstream.isValid(), "Could not open %s.", flatPath);
45 flat->serialize(&wstream);
46 wstream.flush();
47
48 return 0;
49 }
OLDNEW
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698