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

Side by Side Diff: gm/image.cpp

Issue 15747004: Add path utils, plus a test for it. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove unnecessary changes. Created 7 years, 6 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 | Annotate | Revision Log
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 "SkData.h"
12 #include "SkOSFile.h"
11 #include "SkStream.h" 13 #include "SkStream.h"
12 #include "SkData.h"
13 14
14 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
15 #include "GrContext.h" 16 #include "GrContext.h"
16 17
17 namespace skiagm { 18 namespace skiagm {
18 extern GrContext* GetGr(); 19 extern GrContext* GetGr();
19 }; 20 };
20 #endif 21 #endif
21 22
22 static SkData* fileToData(const char path[]) { 23 static SkData* fileToData(const char path[]) {
23 SkFILEStream stream(path); 24 SkFILEStream stream(path);
24 if (!stream.isValid()) { 25 if (!stream.isValid()) {
25 return SkData::NewEmpty(); 26 return SkData::NewEmpty();
26 } 27 }
27 size_t size = stream.getLength(); 28 size_t size = stream.getLength();
28 void* mem = sk_malloc_throw(size); 29 void* mem = sk_malloc_throw(size);
29 stream.read(mem, size); 30 stream.read(mem, size);
30 return SkData::NewFromMalloc(mem, size); 31 return SkData::NewFromMalloc(mem, size);
31 } 32 }
32 33
33 static void drawJpeg(SkCanvas* canvas, const SkISize& size) { 34 static void drawJpeg(SkString filename, SkCanvas* canvas, const SkISize& size) {
34 SkAutoDataUnref data(fileToData("/Users/mike/Downloads/skia.google.jpeg")); 35 SkAutoDataUnref data(fileToData(filename.c_str()));
35 SkImage* image = SkImage::NewEncodedData(data); 36 SkImage* image = SkImage::NewEncodedData(data);
36 if (image) { 37 if (image) {
37 SkAutoCanvasRestore acr(canvas, true); 38 SkAutoCanvasRestore acr(canvas, true);
38 canvas->scale(size.width() * 1.0f / image->width(), 39 canvas->scale(size.width() * 1.0f / image->width(),
39 size.height() * 1.0f / image->height()); 40 size.height() * 1.0f / image->height());
40 image->draw(canvas,0, 0, NULL); 41 image->draw(canvas,0, 0, NULL);
41 image->unref(); 42 image->unref();
42 } 43 }
43 } 44 }
44 45
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 protected: 117 protected:
117 virtual SkString onShortName() { 118 virtual SkString onShortName() {
118 return SkString("image-surface"); 119 return SkString("image-surface");
119 } 120 }
120 121
121 virtual SkISize onISize() { 122 virtual SkISize onISize() {
122 return SkISize::Make(800, 500); 123 return SkISize::Make(800, 500);
123 } 124 }
124 125
125 virtual void onDraw(SkCanvas* canvas) { 126 virtual void onDraw(SkCanvas* canvas) {
126 drawJpeg(canvas, this->getISize()); 127 SkString filename = SkOSPathUtils::SkPathJoin(
128 INHERITED::gResourcePath.c_str(), "CMYK.jpg");
scroggo 2013/05/24 16:23:37 Changing this file will require a rebaseline (assu
epoger 2013/05/24 16:42:55 I think your best bet is to leave this change out
scroggo 2013/05/24 17:36:05 Done.
129 drawJpeg(filename, canvas, this->getISize());
127 130
128 canvas->scale(2, 2); 131 canvas->scale(2, 2);
129 132
130 static const char* kLabel1 = "Original Img"; 133 static const char* kLabel1 = "Original Img";
131 static const char* kLabel2 = "Modified Img"; 134 static const char* kLabel2 = "Modified Img";
132 static const char* kLabel3 = "Cur Surface"; 135 static const char* kLabel3 = "Cur Surface";
133 136
134 static const char* kLabel4 = "Pre-Alloc Img"; 137 static const char* kLabel4 = "Pre-Alloc Img";
135 static const char* kLabel5 = "New Alloc Img"; 138 static const char* kLabel5 = "New Alloc Img";
136 static const char* kLabel6 = "SkPicture"; 139 static const char* kLabel6 = "SkPicture";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 188 }
186 189
187 private: 190 private:
188 typedef skiagm::GM INHERITED; 191 typedef skiagm::GM INHERITED;
189 }; 192 };
190 193
191 ////////////////////////////////////////////////////////////////////////////// 194 //////////////////////////////////////////////////////////////////////////////
192 195
193 static skiagm::GM* MyFactory(void*) { return new ImageGM; } 196 static skiagm::GM* MyFactory(void*) { return new ImageGM; }
194 static skiagm::GMRegistry reg(MyFactory); 197 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « gm/gmmain.cpp ('k') | gyp/tests.gyp » ('j') | include/core/SkOSFile.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698