tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | #ifndef Resources_DEFINED |
| 9 | #define Resources_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkImage.h" |
| 12 | #include "include/core/SkString.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 13 | |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 14 | class SkBitmap; |
Mike Reed | 463c848 | 2016-12-21 12:01:12 -0500 | [diff] [blame] | 15 | class SkData; |
bungeman | 3ffa126 | 2015-04-30 17:12:58 -0400 | [diff] [blame] | 16 | class SkStreamAsset; |
| 17 | class SkTypeface; |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 18 | |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 19 | SkString GetResourcePath(const char* resource = ""); |
Mike Reed | 0933bc9 | 2017-12-09 01:27:41 +0000 | [diff] [blame] | 20 | |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 21 | void SetResourcePath(const char* ); |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 22 | |
Mike Reed | 0933bc9 | 2017-12-09 01:27:41 +0000 | [diff] [blame] | 23 | bool DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst); |
| 24 | |
Mike Reed | cca2300 | 2017-12-08 21:09:12 +0000 | [diff] [blame] | 25 | sk_sp<SkData> GetResourceAsData(const char* resource); |
Mike Reed | 0933bc9 | 2017-12-09 01:27:41 +0000 | [diff] [blame] | 26 | |
| 27 | inline bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) { |
| 28 | return DecodeDataToBitmap(GetResourceAsData(resource), dst); |
| 29 | } |
| 30 | |
| 31 | inline sk_sp<SkImage> GetResourceAsImage(const char* resource) { |
| 32 | return SkImage::MakeFromEncoded(GetResourceAsData(resource)); |
| 33 | } |
| 34 | |
| 35 | std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource); |
| 36 | |
Mike Reed | 271d1d9 | 2018-09-03 21:10:10 -0400 | [diff] [blame] | 37 | sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource, int ttcIndex = 0); |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 38 | |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 39 | #endif // Resources_DEFINED |