Chromium Code Reviews| 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" | |
| 10 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 11 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkDecodingImageGenerator.h" | |
| 12 #include "SkDiscardablePixelRef.h" | |
| 12 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
| 13 #include "SkLruImageCache.h" | |
| 14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
| 15 #include "SkDiscardableMemoryPool.h" | |
| 15 #include "SkStream.h" | 16 #include "SkStream.h" |
| 16 | 17 |
| 17 namespace skiagm { | 18 namespace skiagm { |
| 18 | 19 |
| 19 /** | 20 /** |
| 20 * Draw a PNG created by SkBitmapFactory. | 21 * Draw a PNG created by SkBitmapFactory. |
| 21 */ | 22 */ |
| 22 class FactoryGM : public GM { | 23 class FactoryGM : public GM { |
| 23 public: | 24 public: |
| 24 FactoryGM() {} | 25 FactoryGM() {} |
| 25 | 26 |
| 26 protected: | 27 protected: |
| 27 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 28 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
| 28 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl ane-by-ddoo | 29 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl ane-by-ddoo |
| 29 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str( ), | 30 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str( ), |
| 30 "plane.png"); | 31 "plane.png"); |
| 31 | 32 |
| 32 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str())); | 33 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str())); |
| 33 if (NULL != stream.get()) { | 34 if (NULL != stream.get()) { |
| 34 stream->rewind(); | 35 stream->rewind(); |
| 35 size_t length = stream->getLength(); | 36 size_t length = stream->getLength(); |
| 36 void* buffer = sk_malloc_throw(length); | 37 void* buffer = sk_malloc_throw(length); |
| 37 stream->read(buffer, length); | 38 stream->read(buffer, length); |
| 38 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length)); | 39 SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length)); |
| 39 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); | 40 |
| 41 SkASSERT(NULL == data.get()); | |
|
scroggo
2013/12/03 23:00:01
How is data NULL here? Did you test with the resou
hal.canary
2013/12/04 00:01:36
I meant to write !=, and I haven't gotten around t
hal.canary
2013/12/04 14:30:33
Tested with `out/Debug/gm --match factory --resour
| |
| 40 // Create a cache which will boot the pixels out anytime the | 42 // Create a cache which will boot the pixels out anytime the |
| 41 // bitmap is unlocked. | 43 // bitmap is unlocked. |
| 42 SkAutoTUnref<SkLruImageCache> cache(SkNEW_ARGS(SkLruImageCache, (1)) ); | 44 SkAutoTUnref<SkDiscardableMemoryPool> pool( |
| 43 factory.setImageCache(cache); | 45 SkNEW_ARGS(SkDiscardableMemoryPool, (1))); |
| 44 factory.installPixelRef(data, &fBitmap); | 46 SkAssertResult(SkDecodingImageGenerator::Install(data, |
| 47 &fBitmap, pool)); | |
| 45 } | 48 } |
| 46 } | 49 } |
| 47 | 50 |
| 48 virtual SkString onShortName() { | 51 virtual SkString onShortName() { |
| 49 return SkString("factory"); | 52 return SkString("factory"); |
| 50 } | 53 } |
| 51 | 54 |
| 52 virtual SkISize onISize() { | 55 virtual SkISize onISize() { |
| 53 return make_isize(640, 480); | 56 return make_isize(640, 480); |
| 54 } | 57 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 67 | 70 |
| 68 typedef GM INHERITED; | 71 typedef GM INHERITED; |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 ////////////////////////////////////////////////////////////////////////////// | 74 ////////////////////////////////////////////////////////////////////////////// |
| 72 | 75 |
| 73 static GM* MyFactory(void*) { return new FactoryGM; } | 76 static GM* MyFactory(void*) { return new FactoryGM; } |
| 74 static GMRegistry reg(MyFactory); | 77 static GMRegistry reg(MyFactory); |
| 75 | 78 |
| 76 } | 79 } |
| OLD | NEW |