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 "gm.h" | 8 #include "gm.h" |
9 #include "SkBitmapFactory.h" | 9 #include "SkBitmapFactory.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 protected: | 25 protected: |
26 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 26 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
27 SkString filename(INHERITED::gResourcePath); | 27 SkString filename(INHERITED::gResourcePath); |
28 if (!filename.endsWith("/") && !filename.endsWith("\\")) { | 28 if (!filename.endsWith("/") && !filename.endsWith("\\")) { |
29 filename.append("/"); | 29 filename.append("/"); |
30 } | 30 } |
31 | 31 |
32 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl
ane-by-ddoo | 32 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl
ane-by-ddoo |
33 filename.append("plane.png"); | 33 filename.append("plane.png"); |
34 | 34 |
35 SkFILEStream stream(filename.c_str()); | 35 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str())); |
36 if (stream.isValid()) { | 36 if (NULL != stream.get()) { |
37 stream.rewind(); | 37 stream->rewind(); |
38 size_t length = stream.getLength(); | 38 size_t length = stream->getLength(); |
39 void* buffer = sk_malloc_throw(length); | 39 void* buffer = sk_malloc_throw(length); |
40 stream.read(buffer, length); | 40 stream->read(buffer, length); |
41 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length)); | 41 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length)); |
42 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); | 42 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); |
43 // Create a cache which will boot the pixels out anytime the | 43 // Create a cache which will boot the pixels out anytime the |
44 // bitmap is unlocked. | 44 // bitmap is unlocked. |
45 SkAutoTUnref<SkLruImageCache> cache(SkNEW_ARGS(SkLruImageCache, (1))
); | 45 SkAutoTUnref<SkLruImageCache> cache(SkNEW_ARGS(SkLruImageCache, (1))
); |
46 factory.setImageCache(cache); | 46 factory.setImageCache(cache); |
47 factory.installPixelRef(data, &fBitmap); | 47 factory.installPixelRef(data, &fBitmap); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
(...skipping 14 matching lines...) Expand all Loading... |
65 | 65 |
66 typedef GM INHERITED; | 66 typedef GM INHERITED; |
67 }; | 67 }; |
68 | 68 |
69 ////////////////////////////////////////////////////////////////////////////// | 69 ////////////////////////////////////////////////////////////////////////////// |
70 | 70 |
71 static GM* MyFactory(void*) { return new FactoryGM; } | 71 static GM* MyFactory(void*) { return new FactoryGM; } |
72 static GMRegistry reg(MyFactory); | 72 static GMRegistry reg(MyFactory); |
73 | 73 |
74 } | 74 } |
OLD | NEW |