OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 return SkOSPath::Join(FLAGS_resourcePath[0], resource); | 21 return SkOSPath::Join(FLAGS_resourcePath[0], resource); |
22 } | 22 } |
23 | 23 |
24 void SetResourcePath(const char* resource) { | 24 void SetResourcePath(const char* resource) { |
25 FLAGS_resourcePath.set(0, resource); | 25 FLAGS_resourcePath.set(0, resource); |
26 } | 26 } |
27 | 27 |
28 bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) { | 28 bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) { |
29 SkString resourcePath = GetResourcePath(resource); | 29 SkString resourcePath = GetResourcePath(resource); |
30 SkAutoTUnref<SkData> resourceData(SkData::NewFromFileName(resourcePath.c_str ())); | 30 SkAutoTUnref<SkData> resourceData(SkData::NewFromFileName(resourcePath.c_str ())); |
31 return resourceData && SkInstallDiscardablePixelRef(resourceData, dst); | 31 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourc eData)); |
32 return gen && gen->tryGenerateBitmap(dst); | |
hal.canary
2015/09/24 20:18:10
this no longer exercises discardable memory!
reed1
2015/09/25 08:05:16
Yes, discardable bitmaps is a deprecated feature.
| |
32 } | 33 } |
33 | 34 |
34 SkImage* GetResourceAsImage(const char* resource) { | 35 SkImage* GetResourceAsImage(const char* resource) { |
35 SkString path = GetResourcePath(resource); | 36 SkString path = GetResourcePath(resource); |
36 SkAutoTUnref<SkData> resourceData(SkData::NewFromFileName(path.c_str())); | 37 SkAutoTUnref<SkData> resourceData(SkData::NewFromFileName(path.c_str())); |
37 return SkImage::NewFromEncoded(resourceData); | 38 return SkImage::NewFromEncoded(resourceData); |
38 } | 39 } |
39 | 40 |
40 SkStreamAsset* GetResourceAsStream(const char* resource) { | 41 SkStreamAsset* GetResourceAsStream(const char* resource) { |
41 SkString resourcePath = GetResourcePath(resource); | 42 SkString resourcePath = GetResourcePath(resource); |
42 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str())); | 43 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str())); |
43 if (stream->isValid()) { | 44 if (stream->isValid()) { |
44 return stream.detach(); | 45 return stream.detach(); |
45 } else { | 46 } else { |
46 SkDebugf("Resource %s not found.\n", resource); | 47 SkDebugf("Resource %s not found.\n", resource); |
47 return nullptr; | 48 return nullptr; |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 SkTypeface* GetResourceAsTypeface(const char* resource) { | 52 SkTypeface* GetResourceAsTypeface(const char* resource) { |
52 SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource)); | 53 SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource)); |
53 if (!stream) { | 54 if (!stream) { |
54 return nullptr; | 55 return nullptr; |
55 } | 56 } |
56 return SkTypeface::CreateFromStream(stream.detach()); | 57 return SkTypeface::CreateFromStream(stream.detach()); |
57 } | 58 } |
OLD | NEW |