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

Side by Side Diff: tools/Resources.cpp

Issue 2206633004: Move off SK_SUPPORT_LEGACY_DATA_FACTORIES. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Gotta catch 'em all. Created 4 years, 4 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
OLDNEW
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"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkImage.h" 12 #include "SkImage.h"
13 #include "SkImageGenerator.h" 13 #include "SkImageGenerator.h"
14 #include "SkOSFile.h" 14 #include "SkOSFile.h"
15 #include "SkStream.h" 15 #include "SkStream.h"
16 #include "SkTypeface.h" 16 #include "SkTypeface.h"
17 17
18 DEFINE_string2(resourcePath, i, "resources", "Directory with test resources: ima ges, fonts, etc."); 18 DEFINE_string2(resourcePath, i, "resources", "Directory with test resources: ima ges, fonts, etc.");
19 19
20 SkString GetResourcePath(const char* resource) { 20 SkString GetResourcePath(const char* resource) {
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 sk_sp<SkData> resourceData(SkData::MakeFromFileName(resourcePath.c_str()));
31 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourc eData)); 31 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourc eData.get()));
32 return gen && gen->tryGenerateBitmap(dst); 32 return gen && gen->tryGenerateBitmap(dst);
33 } 33 }
34 34
35 sk_sp<SkImage> GetResourceAsImage(const char* resource) { 35 sk_sp<SkImage> GetResourceAsImage(const char* resource) {
36 SkString path = GetResourcePath(resource); 36 SkString path = GetResourcePath(resource);
37 sk_sp<SkData> resourceData(SkData::NewFromFileName(path.c_str())); 37 sk_sp<SkData> resourceData(SkData::MakeFromFileName(path.c_str()));
38 return SkImage::MakeFromEncoded(resourceData); 38 return SkImage::MakeFromEncoded(resourceData);
39 } 39 }
40 40
41 SkStreamAsset* GetResourceAsStream(const char* resource) { 41 SkStreamAsset* GetResourceAsStream(const char* resource) {
42 SkString resourcePath = GetResourcePath(resource); 42 SkString resourcePath = GetResourcePath(resource);
43 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str())); 43 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str()));
44 if (stream->isValid()) { 44 if (stream->isValid()) {
45 return stream.release(); 45 return stream.release();
46 } else { 46 } else {
47 SkDebugf("Resource %s not found.\n", resource); 47 SkDebugf("Resource %s not found.\n", resource);
48 return nullptr; 48 return nullptr;
49 } 49 }
50 } 50 }
51 51
52 sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) { 52 sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) {
53 SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource)); 53 SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource));
54 if (!stream) { 54 if (!stream) {
55 return nullptr; 55 return nullptr;
56 } 56 }
57 return SkTypeface::MakeFromStream(stream.release()); 57 return SkTypeface::MakeFromStream(stream.release());
58 } 58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698