| 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" | |
| 15 #include "SkStream.h" | 14 #include "SkStream.h" |
| 16 | 15 |
| 17 namespace skiagm { | 16 namespace skiagm { |
| 18 | 17 |
| 19 /** | 18 /** |
| 20 * Draw a PNG created by SkBitmapFactory. | 19 * Draw a PNG created by SkBitmapFactory. |
| 21 */ | 20 */ |
| 22 class FactoryGM : public GM { | 21 class FactoryGM : public GM { |
| 23 public: | 22 public: |
| 24 FactoryGM() {} | 23 FactoryGM() {} |
| 25 | 24 |
| 26 protected: | 25 protected: |
| 27 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 26 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
| 27 SkString filename(INHERITED::gResourcePath); |
| 28 if (!filename.endsWith("/") && !filename.endsWith("\\")) { |
| 29 filename.append("/"); |
| 30 } |
| 31 |
| 28 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl
ane-by-ddoo | 32 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl
ane-by-ddoo |
| 29 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(
), | 33 filename.append("plane.png"); |
| 30 "plane.png"); | |
| 31 | 34 |
| 32 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str())); | 35 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str())); |
| 33 if (NULL != stream.get()) { | 36 if (NULL != stream.get()) { |
| 34 stream->rewind(); | 37 stream->rewind(); |
| 35 size_t length = stream->getLength(); | 38 size_t length = stream->getLength(); |
| 36 void* buffer = sk_malloc_throw(length); | 39 void* buffer = sk_malloc_throw(length); |
| 37 stream->read(buffer, length); | 40 stream->read(buffer, length); |
| 38 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length)); | 41 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length)); |
| 39 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); | 42 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); |
| 40 // Create a cache which will boot the pixels out anytime the | 43 // Create a cache which will boot the pixels out anytime the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 62 | 65 |
| 63 typedef GM INHERITED; | 66 typedef GM INHERITED; |
| 64 }; | 67 }; |
| 65 | 68 |
| 66 ////////////////////////////////////////////////////////////////////////////// | 69 ////////////////////////////////////////////////////////////////////////////// |
| 67 | 70 |
| 68 static GM* MyFactory(void*) { return new FactoryGM; } | 71 static GM* MyFactory(void*) { return new FactoryGM; } |
| 69 static GMRegistry reg(MyFactory); | 72 static GMRegistry reg(MyFactory); |
| 70 | 73 |
| 71 } | 74 } |
| OLD | NEW |