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

Side by Side Diff: gm/factory.cpp

Issue 15740024: Reland 'Add path utils, plus a test for it.' (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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
« no previous file with comments | « no previous file | gm/gm_expectations.h » ('j') | src/utils/SkOSFile.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
epoger 2013/05/28 17:48:11 Would using the Commit Queue (or its trybots [1])
scroggo 2013/05/28 17:56:36 I suspect that it would have, although I did not s
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
epoger 2013/05/28 17:48:11 IMHO, when relanding patches I think it's preferab
scroggo 2013/05/28 17:56:36 I'll make a mental note to do that next time. That
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 "SkBitmapFactory.h" 9 #include "SkBitmapFactory.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
13 #include "SkLruImageCache.h" 13 #include "SkLruImageCache.h"
14 #include "SkOSFile.h"
14 #include "SkStream.h" 15 #include "SkStream.h"
15 16
16 namespace skiagm { 17 namespace skiagm {
17 18
18 /** 19 /**
19 * Draw a PNG created by SkBitmapFactory. 20 * Draw a PNG created by SkBitmapFactory.
20 */ 21 */
21 class FactoryGM : public GM { 22 class FactoryGM : public GM {
22 public: 23 public:
23 FactoryGM() {} 24 FactoryGM() {}
24 25
25 protected: 26 protected:
26 virtual void onOnceBeforeDraw() SK_OVERRIDE { 27 virtual void onOnceBeforeDraw() SK_OVERRIDE {
27 SkString filename(INHERITED::gResourcePath);
28 if (!filename.endsWith("/") && !filename.endsWith("\\")) {
29 filename.append("/");
30 }
31
32 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl ane-by-ddoo 28 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl ane-by-ddoo
33 filename.append("plane.png"); 29 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str( ),
30 "plane.png");
34 31
35 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str())); 32 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str()));
36 if (NULL != stream.get()) { 33 if (NULL != stream.get()) {
37 stream->rewind(); 34 stream->rewind();
38 size_t length = stream->getLength(); 35 size_t length = stream->getLength();
39 void* buffer = sk_malloc_throw(length); 36 void* buffer = sk_malloc_throw(length);
40 stream->read(buffer, length); 37 stream->read(buffer, length);
41 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length)); 38 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length));
42 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); 39 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget);
43 // Create a cache which will boot the pixels out anytime the 40 // Create a cache which will boot the pixels out anytime the
(...skipping 21 matching lines...) Expand all
65 62
66 typedef GM INHERITED; 63 typedef GM INHERITED;
67 }; 64 };
68 65
69 ////////////////////////////////////////////////////////////////////////////// 66 //////////////////////////////////////////////////////////////////////////////
70 67
71 static GM* MyFactory(void*) { return new FactoryGM; } 68 static GM* MyFactory(void*) { return new FactoryGM; }
72 static GMRegistry reg(MyFactory); 69 static GMRegistry reg(MyFactory);
73 70
74 } 71 }
OLDNEW
« no previous file with comments | « no previous file | gm/gm_expectations.h » ('j') | src/utils/SkOSFile.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698