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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 } | 689 } |
690 | 690 |
691 | 691 |
692 //////////////////////////////////////////////////////////////////////////////// | 692 //////////////////////////////////////////////////////////////////////////////// |
693 namespace { | 693 namespace { |
694 class SingleAllocator : public SkBitmap::Allocator { | 694 class SingleAllocator : public SkBitmap::Allocator { |
695 public: | 695 public: |
696 SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { } | 696 SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { } |
697 ~SingleAllocator() {} | 697 ~SingleAllocator() {} |
698 // If the pixels in fPixels are big enough, use them. | 698 // If the pixels in fPixels are big enough, use them. |
699 bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) SK_OVERRIDE { | 699 bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) override { |
700 SkASSERT(bm); | 700 SkASSERT(bm); |
701 if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) { | 701 if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) { |
702 bm->setPixels(fPixels, ct); | 702 bm->setPixels(fPixels, ct); |
703 fPixels = NULL; | 703 fPixels = NULL; |
704 fSize = 0; | 704 fSize = 0; |
705 return true; | 705 return true; |
706 } | 706 } |
707 return bm->tryAllocPixels(NULL, ct); | 707 return bm->tryAllocPixels(NULL, ct); |
708 } | 708 } |
709 bool ready() { return fPixels != NULL; } | 709 bool ready() { return fPixels != NULL; } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); | 744 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); |
745 decoder->setAllocator(allocator); | 745 decoder->setAllocator(allocator); |
746 decoder->setSampleSize(2); | 746 decoder->setSampleSize(2); |
747 SkBitmap bitmap; | 747 SkBitmap bitmap; |
748 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, | 748 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, |
749 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; | 749 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; |
750 REPORTER_ASSERT(r, success); | 750 REPORTER_ASSERT(r, success); |
751 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory | 751 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory |
752 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); | 752 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); |
753 } | 753 } |
OLD | NEW |