| 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 ~SingleAllocator() {} | 763 ~SingleAllocator() {} |
| 764 // If the pixels in fPixels are big enough, use them. | 764 // If the pixels in fPixels are big enough, use them. |
| 765 virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) SK_OVERRIDE { | 765 virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) SK_OVERRIDE { |
| 766 SkASSERT(bm); | 766 SkASSERT(bm); |
| 767 if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) { | 767 if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) { |
| 768 bm->setPixels(fPixels, ct); | 768 bm->setPixels(fPixels, ct); |
| 769 fPixels = NULL; | 769 fPixels = NULL; |
| 770 fSize = 0; | 770 fSize = 0; |
| 771 return true; | 771 return true; |
| 772 } | 772 } |
| 773 return bm->allocPixels(NULL, ct); | 773 return bm->tryAllocPixels(NULL, ct); |
| 774 } | 774 } |
| 775 bool ready() { return fPixels != NULL; } | 775 bool ready() { return fPixels != NULL; } |
| 776 private: | 776 private: |
| 777 void* fPixels; | 777 void* fPixels; |
| 778 size_t fSize; | 778 size_t fSize; |
| 779 }; | 779 }; |
| 780 } // namespace | 780 } // namespace |
| 781 | 781 |
| 782 /* This tests for a bug in libjpeg where INT32 is typedefed to long | 782 /* This tests for a bug in libjpeg where INT32 is typedefed to long |
| 783 and memory can be written to outside of the array. */ | 783 and memory can be written to outside of the array. */ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 810 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); | 810 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); |
| 811 decoder->setAllocator(allocator); | 811 decoder->setAllocator(allocator); |
| 812 decoder->setSampleSize(2); | 812 decoder->setSampleSize(2); |
| 813 SkBitmap bitmap; | 813 SkBitmap bitmap; |
| 814 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, | 814 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, |
| 815 SkImageDecoder::kDecodePixels_Mode); | 815 SkImageDecoder::kDecodePixels_Mode); |
| 816 REPORTER_ASSERT(r, success); | 816 REPORTER_ASSERT(r, success); |
| 817 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory | 817 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory |
| 818 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); | 818 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); |
| 819 } | 819 } |
| OLD | NEW |