| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "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 Loading... |
| 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 } |
| OLD | NEW |