| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkDiscardablePixelRef.h" | 8 #include "SkDiscardablePixelRef.h" |
| 9 #include "SkDiscardableMemory.h" | 9 #include "SkDiscardableMemory.h" |
| 10 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 SkASSERT(fGenerator != NULL); | 23 SkASSERT(fGenerator != NULL); |
| 24 SkASSERT(fSize > 0); | 24 SkASSERT(fSize > 0); |
| 25 SkASSERT(fRowBytes > 0); | 25 SkASSERT(fRowBytes > 0); |
| 26 // The SkImageGenerator contract requires fGenerator to always | 26 // The SkImageGenerator contract requires fGenerator to always |
| 27 // decode the same image on each call to getPixels(). | 27 // decode the same image on each call to getPixels(). |
| 28 this->setImmutable(); | 28 this->setImmutable(); |
| 29 SkSafeRef(fDMFactory); | 29 SkSafeRef(fDMFactory); |
| 30 } | 30 } |
| 31 | 31 |
| 32 SkDiscardablePixelRef::~SkDiscardablePixelRef() { | 32 SkDiscardablePixelRef::~SkDiscardablePixelRef() { |
| 33 if (this->isLocked()) { |
| 34 fDiscardableMemory->unlock(); |
| 35 } |
| 33 SkDELETE(fDiscardableMemory); | 36 SkDELETE(fDiscardableMemory); |
| 34 SkSafeUnref(fDMFactory); | 37 SkSafeUnref(fDMFactory); |
| 35 SkDELETE(fGenerator); | 38 SkDELETE(fGenerator); |
| 36 } | 39 } |
| 37 | 40 |
| 38 void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) { | 41 void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) { |
| 39 if (fDiscardableMemory != NULL) { | 42 if (fDiscardableMemory != NULL) { |
| 40 if (fDiscardableMemory->lock()) { | 43 if (fDiscardableMemory->lock()) { |
| 41 return fDiscardableMemory->data(); | 44 return fDiscardableMemory->data(); |
| 42 } | 45 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return dst->allocPixels(NULL, NULL); | 83 return dst->allocPixels(NULL, NULL); |
| 81 } | 84 } |
| 82 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, | 85 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, |
| 83 (generator, info, | 86 (generator, info, |
| 84 dst->getSize(), | 87 dst->getSize(), |
| 85 dst->rowBytes(), | 88 dst->rowBytes(), |
| 86 factory))); | 89 factory))); |
| 87 dst->setPixelRef(ref); | 90 dst->setPixelRef(ref); |
| 88 return true; | 91 return true; |
| 89 } | 92 } |
| OLD | NEW |