| 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 "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkMallocPixelRef.h" | 9 #include "SkMallocPixelRef.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 13); | 25 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 13); |
| 26 { | 26 { |
| 27 SkAutoTUnref<SkMallocPixelRef> pr( | 27 SkAutoTUnref<SkMallocPixelRef> pr( |
| 28 SkMallocPixelRef::NewAllocate(info, info.minRowBytes() - 1, NULL)); | 28 SkMallocPixelRef::NewAllocate(info, info.minRowBytes() - 1, NULL)); |
| 29 // rowbytes too small. | 29 // rowbytes too small. |
| 30 REPORTER_ASSERT(reporter, NULL == pr.get()); | 30 REPORTER_ASSERT(reporter, NULL == pr.get()); |
| 31 } | 31 } |
| 32 { | 32 { |
| 33 size_t rowBytes = info.minRowBytes() - 1; | 33 size_t rowBytes = info.minRowBytes() - 1; |
| 34 size_t size = info.getSafeSize(rowBytes); | 34 size_t size = info.getSafeSize(rowBytes); |
| 35 void* addr = sk_malloc_throw(size); | 35 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
| 36 SkAutoDataUnref data(SkData::NewFromMalloc(addr, size)); | |
| 37 SkAutoTUnref<SkMallocPixelRef> pr( | 36 SkAutoTUnref<SkMallocPixelRef> pr( |
| 38 SkMallocPixelRef::NewWithData(info, rowBytes, | 37 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data)); |
| 39 NULL, data.get())); | |
| 40 // rowbytes too small. | 38 // rowbytes too small. |
| 41 REPORTER_ASSERT(reporter, NULL == pr.get()); | 39 REPORTER_ASSERT(reporter, NULL == pr.get()); |
| 42 } | 40 } |
| 43 { | 41 { |
| 44 size_t rowBytes = info.minRowBytes() + 2; | 42 size_t rowBytes = info.minRowBytes() + 2; |
| 45 size_t size = info.getSafeSize(rowBytes) - 1; | 43 size_t size = info.getSafeSize(rowBytes) - 1; |
| 46 void* addr = sk_malloc_throw(size); | 44 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
| 47 SkAutoDataUnref data(SkData::NewFromMalloc(addr, size)); | |
| 48 SkAutoTUnref<SkMallocPixelRef> pr( | 45 SkAutoTUnref<SkMallocPixelRef> pr( |
| 49 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, | 46 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data)); |
| 50 data.get())); | |
| 51 // data too small. | 47 // data too small. |
| 52 REPORTER_ASSERT(reporter, NULL == pr.get()); | 48 REPORTER_ASSERT(reporter, NULL == pr.get()); |
| 53 } | 49 } |
| 54 size_t rowBytes = info.minRowBytes() + 7; | 50 size_t rowBytes = info.minRowBytes() + 7; |
| 55 size_t size = info.getSafeSize(rowBytes) + 9; | 51 size_t size = info.getSafeSize(rowBytes) + 9; |
| 56 { | 52 { |
| 57 SkAutoMalloc memory(size); | 53 SkAutoMalloc memory(size); |
| 58 SkAutoTUnref<SkMallocPixelRef> pr( | 54 SkAutoTUnref<SkMallocPixelRef> pr( |
| 59 SkMallocPixelRef::NewDirect(info, memory.get(), rowBytes, NULL)); | 55 SkMallocPixelRef::NewDirect(info, memory.get(), rowBytes, NULL)); |
| 60 REPORTER_ASSERT(reporter, pr.get() != NULL); | 56 REPORTER_ASSERT(reporter, pr.get() != NULL); |
| 61 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); | 57 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); |
| 62 } | 58 } |
| 63 { | 59 { |
| 64 SkAutoTUnref<SkMallocPixelRef> pr( | 60 SkAutoTUnref<SkMallocPixelRef> pr( |
| 65 SkMallocPixelRef::NewAllocate(info, rowBytes, NULL)); | 61 SkMallocPixelRef::NewAllocate(info, rowBytes, NULL)); |
| 66 REPORTER_ASSERT(reporter, pr.get() != NULL); | 62 REPORTER_ASSERT(reporter, pr.get() != NULL); |
| 67 REPORTER_ASSERT(reporter, pr->pixels()); | 63 REPORTER_ASSERT(reporter, pr->pixels()); |
| 68 } | 64 } |
| 69 { | 65 { |
| 70 void* addr = static_cast<void*>(new uint8_t[size]); | 66 void* addr = static_cast<void*>(new uint8_t[size]); |
| 71 SkAutoTUnref<SkMallocPixelRef> pr( | 67 SkAutoTUnref<SkMallocPixelRef> pr( |
| 72 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, addr, | 68 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, addr, |
| 73 delete_uint8_proc, NULL)); | 69 delete_uint8_proc, NULL)); |
| 74 REPORTER_ASSERT(reporter, pr.get() != NULL); | 70 REPORTER_ASSERT(reporter, pr.get() != NULL); |
| 75 REPORTER_ASSERT(reporter, addr == pr->pixels()); | 71 REPORTER_ASSERT(reporter, addr == pr->pixels()); |
| 76 } | 72 } |
| 77 { | 73 { |
| 78 int x = 0; | 74 int x = 0; |
| 79 SkAutoMalloc memory(size); | 75 SkAutoMalloc memory(size); |
| 80 REPORTER_ASSERT(reporter, memory.get() != NULL); | |
| 81 SkAutoTUnref<SkMallocPixelRef> pr( | 76 SkAutoTUnref<SkMallocPixelRef> pr( |
| 82 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, | 77 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, |
| 83 memory.get(), set_to_one_proc, | 78 memory.get(), set_to_one_proc, |
| 84 static_cast<void*>(&x))); | 79 static_cast<void*>(&x))); |
| 85 REPORTER_ASSERT(reporter, pr.get() != NULL); | 80 REPORTER_ASSERT(reporter, pr.get() != NULL); |
| 86 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); | 81 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); |
| 87 REPORTER_ASSERT(reporter, 0 == x); | 82 REPORTER_ASSERT(reporter, 0 == x); |
| 88 pr.reset(NULL); | 83 pr.reset(NULL); |
| 89 // make sure that set_to_one_proc was called. | 84 // make sure that set_to_one_proc was called. |
| 90 REPORTER_ASSERT(reporter, 1 == x); | 85 REPORTER_ASSERT(reporter, 1 == x); |
| 91 } | 86 } |
| 92 { | 87 { |
| 93 void* addr = static_cast<void*>(new uint8_t[size]); | 88 void* addr = static_cast<void*>(new uint8_t[size]); |
| 94 REPORTER_ASSERT(reporter, addr != NULL); | 89 REPORTER_ASSERT(reporter, addr != NULL); |
| 95 SkAutoTUnref<SkMallocPixelRef> pr( | 90 SkAutoTUnref<SkMallocPixelRef> pr( |
| 96 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, addr, | 91 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, addr, |
| 97 delete_uint8_proc, NULL)); | 92 delete_uint8_proc, NULL)); |
| 98 REPORTER_ASSERT(reporter, addr == pr->pixels()); | 93 REPORTER_ASSERT(reporter, addr == pr->pixels()); |
| 99 } | 94 } |
| 100 { | 95 { |
| 101 void* addr = sk_malloc_throw(size); | 96 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
| 102 SkAutoDataUnref data(SkData::NewFromMalloc(addr, size)); | |
| 103 REPORTER_ASSERT(reporter, data.get() != NULL); | |
| 104 SkData* dataPtr = data.get(); | 97 SkData* dataPtr = data.get(); |
| 105 REPORTER_ASSERT(reporter, dataPtr->unique()); | 98 REPORTER_ASSERT(reporter, dataPtr->unique()); |
| 106 SkAutoTUnref<SkMallocPixelRef> pr( | 99 SkAutoTUnref<SkMallocPixelRef> pr( |
| 107 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data.get())); | 100 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data.get())); |
| 108 REPORTER_ASSERT(reporter, !(dataPtr->unique())); | 101 REPORTER_ASSERT(reporter, !(dataPtr->unique())); |
| 109 data.reset(NULL); | 102 data.reset(NULL); |
| 110 REPORTER_ASSERT(reporter, dataPtr->unique()); | 103 REPORTER_ASSERT(reporter, dataPtr->unique()); |
| 111 REPORTER_ASSERT(reporter, dataPtr->data() == pr->pixels()); | 104 REPORTER_ASSERT(reporter, dataPtr->data() == pr->pixels()); |
| 112 } | 105 } |
| 113 } | 106 } |
| OLD | NEW |