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

Side by Side Diff: gm/image.cpp

Issue 579923002: Bis: Use SkImage::NewFromGenerator() instead of SkImage::newEncodedData() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkStream.h" 12 #include "SkStream.h"
12 #include "SkData.h" 13 #include "SkData.h"
13 14
14 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
15 #include "GrContext.h" 16 #include "GrContext.h"
16 #endif 17 #endif
17 18
18 static SkData* fileToData(const char path[]) { 19 static SkData* fileToData(const char path[]) {
19 SkFILEStream stream(path); 20 SkFILEStream stream(path);
20 if (!stream.isValid()) { 21 if (!stream.isValid()) {
21 return SkData::NewEmpty(); 22 return SkData::NewEmpty();
22 } 23 }
23 size_t size = stream.getLength(); 24 size_t size = stream.getLength();
24 void* mem = sk_malloc_throw(size); 25 void* mem = sk_malloc_throw(size);
25 stream.read(mem, size); 26 stream.read(mem, size);
26 return SkData::NewFromMalloc(mem, size); 27 return SkData::NewFromMalloc(mem, size);
27 } 28 }
28 29
29 static void drawJpeg(SkCanvas* canvas, const SkISize& size) { 30 static void drawJpeg(SkCanvas* canvas, const SkISize& size) {
30 // TODO: Make this draw a file that is checked in, so it can 31 // TODO: Make this draw a file that is checked in, so it can
31 // be exercised on machines other than mike's. Will require a 32 // be exercised on machines other than mike's. Will require a
32 // rebaseline. 33 // rebaseline.
33 SkAutoDataUnref data(fileToData("/Users/mike/Downloads/skia.google.jpeg")); 34 SkAutoDataUnref data(fileToData("/Users/mike/Downloads/skia.google.jpeg"));
34 SkImage* image = SkImage::NewEncodedData(data); 35 SkImage* image = SkImage::NewFromGenerator(
36 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator: :Options()));
35 if (image) { 37 if (image) {
36 SkAutoCanvasRestore acr(canvas, true); 38 SkAutoCanvasRestore acr(canvas, true);
37 canvas->scale(size.width() * 1.0f / image->width(), 39 canvas->scale(size.width() * 1.0f / image->width(),
38 size.height() * 1.0f / image->height()); 40 size.height() * 1.0f / image->height());
39 image->draw(canvas, 0, 0, NULL); 41 image->draw(canvas, 0, 0, NULL);
40 image->unref(); 42 image->unref();
41 } 43 }
42 } 44 }
43 45
44 static void drawContents(SkSurface* surface, SkColor fillC) { 46 static void drawContents(SkSurface* surface, SkColor fillC) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 206 }
205 207
206 private: 208 private:
207 typedef skiagm::GM INHERITED; 209 typedef skiagm::GM INHERITED;
208 }; 210 };
209 211
210 ////////////////////////////////////////////////////////////////////////////// 212 //////////////////////////////////////////////////////////////////////////////
211 213
212 static skiagm::GM* MyFactory(void*) { return new ImageGM; } 214 static skiagm::GM* MyFactory(void*) { return new ImageGM; }
213 static skiagm::GMRegistry reg(MyFactory); 215 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698