Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: tests/ImageDecodingTest.cpp

Issue 510423005: make allocPixels throw on failure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/DrawBitmapRectTest.cpp ('k') | tests/KtxTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « tests/DrawBitmapRectTest.cpp ('k') | tests/KtxTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698