OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkSurface.h" | 9 #include "SkSurface.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDecodingImageGenerator.h" | 11 #include "SkDecodingImageGenerator.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 | 14 |
15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
16 #include "GrContext.h" | 16 #include "GrContext.h" |
17 #endif | 17 #endif |
18 | 18 |
19 static SkData* fileToData(const char path[]) { | |
20 SkFILEStream stream(path); | |
21 if (!stream.isValid()) { | |
22 return SkData::NewEmpty(); | |
23 } | |
24 size_t size = stream.getLength(); | |
25 void* mem = sk_malloc_throw(size); | |
26 stream.read(mem, size); | |
27 return SkData::NewFromMalloc(mem, size); | |
28 } | |
29 | |
30 static void drawJpeg(SkCanvas* canvas, const SkISize& size) { | 19 static void drawJpeg(SkCanvas* canvas, const SkISize& size) { |
31 // TODO: Make this draw a file that is checked in, so it can | 20 // TODO: Make this draw a file that is checked in, so it can |
32 // be exercised on machines other than mike's. Will require a | 21 // be exercised on machines other than mike's. Will require a |
33 // rebaseline. | 22 // rebaseline. |
34 SkAutoDataUnref data(fileToData("/Users/mike/Downloads/skia.google.jpeg")); | 23 SkAutoDataUnref data(SkData::NewFromFileName("/Users/mike/Downloads/skia.goo gle.jpeg")); |
tfarina
2014/09/19 16:14:49
The code of NewFromFileName (https://skia.googleso
| |
24 if (NULL == data.get()) { | |
tfarina
2014/09/19 16:14:49
OK
| |
25 return; | |
26 } | |
35 SkImage* image = SkImage::NewFromGenerator( | 27 SkImage* image = SkImage::NewFromGenerator( |
36 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator: :Options())); | 28 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator: :Options())); |
37 if (image) { | 29 if (image) { |
38 SkAutoCanvasRestore acr(canvas, true); | 30 SkAutoCanvasRestore acr(canvas, true); |
39 canvas->scale(size.width() * 1.0f / image->width(), | 31 canvas->scale(size.width() * 1.0f / image->width(), |
40 size.height() * 1.0f / image->height()); | 32 size.height() * 1.0f / image->height()); |
41 image->draw(canvas, 0, 0, NULL); | 33 image->draw(canvas, 0, 0, NULL); |
42 image->unref(); | 34 image->unref(); |
43 } | 35 } |
44 } | 36 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 } | 198 } |
207 | 199 |
208 private: | 200 private: |
209 typedef skiagm::GM INHERITED; | 201 typedef skiagm::GM INHERITED; |
210 }; | 202 }; |
211 | 203 |
212 ////////////////////////////////////////////////////////////////////////////// | 204 ////////////////////////////////////////////////////////////////////////////// |
213 | 205 |
214 static skiagm::GM* MyFactory(void*) { return new ImageGM; } | 206 static skiagm::GM* MyFactory(void*) { return new ImageGM; } |
215 static skiagm::GMRegistry reg(MyFactory); | 207 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |