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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 } | 753 } |
754 | 754 |
755 | 755 |
756 //////////////////////////////////////////////////////////////////////////////// | 756 //////////////////////////////////////////////////////////////////////////////// |
757 namespace { | 757 namespace { |
758 class SingleAllocator : public SkBitmap::Allocator { | 758 class SingleAllocator : public SkBitmap::Allocator { |
759 public: | 759 public: |
760 SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { } | 760 SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { } |
761 ~SingleAllocator() {} | 761 ~SingleAllocator() {} |
762 // If the pixels in fPixels are big enough, use them. | 762 // If the pixels in fPixels are big enough, use them. |
763 virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) SK_OVERRIDE { | 763 bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) SK_OVERRIDE { |
764 SkASSERT(bm); | 764 SkASSERT(bm); |
765 if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) { | 765 if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) { |
766 bm->setPixels(fPixels, ct); | 766 bm->setPixels(fPixels, ct); |
767 fPixels = NULL; | 767 fPixels = NULL; |
768 fSize = 0; | 768 fSize = 0; |
769 return true; | 769 return true; |
770 } | 770 } |
771 return bm->tryAllocPixels(NULL, ct); | 771 return bm->tryAllocPixels(NULL, ct); |
772 } | 772 } |
773 bool ready() { return fPixels != NULL; } | 773 bool ready() { return fPixels != NULL; } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); | 808 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); |
809 decoder->setAllocator(allocator); | 809 decoder->setAllocator(allocator); |
810 decoder->setSampleSize(2); | 810 decoder->setSampleSize(2); |
811 SkBitmap bitmap; | 811 SkBitmap bitmap; |
812 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, | 812 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, |
813 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; | 813 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; |
814 REPORTER_ASSERT(r, success); | 814 REPORTER_ASSERT(r, success); |
815 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory | 815 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory |
816 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); | 816 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); |
817 } | 817 } |
OLD | NEW |