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 24 matching lines...) Expand all Loading... |
35 SkFILEStream stream(filename.c_str()); | 35 SkFILEStream stream(filename.c_str()); |
36 if (stream.isValid()) { | 36 if (stream.isValid()) { |
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, (0))
); | 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 |
51 virtual SkString onShortName() { | 51 virtual SkString onShortName() { |
52 return SkString("factory"); | 52 return SkString("factory"); |
53 } | 53 } |
54 | 54 |
55 virtual SkISize onISize() { | 55 virtual SkISize onISize() { |
56 return make_isize(640, 480); | 56 return make_isize(640, 480); |
57 } | 57 } |
58 | 58 |
59 virtual void onDraw(SkCanvas* canvas) { | 59 virtual void onDraw(SkCanvas* canvas) { |
60 canvas->drawBitmap(fBitmap, 0, 0); | 60 canvas->drawBitmap(fBitmap, 0, 0); |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 SkBitmap fBitmap; | 64 SkBitmap fBitmap; |
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 |