| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkBitmapHeap.h" | 9 #include "SkBitmapHeap.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| 11 #include "SkFlattenable.h" | 11 #include "SkFlattenable.h" |
| 12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
| 13 #include "SkPictureFlat.h" | 13 #include "SkPictureFlat.h" |
| 14 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 15 #include "SkShader.h" | 15 #include "SkShader.h" |
| 16 #include "Test.h" | 16 #include "Test.h" |
| 17 | 17 |
| 18 struct SimpleFlatController : public SkFlatController { | 18 struct SimpleFlatController : public SkFlatController { |
| 19 SimpleFlatController() : SkFlatController() {} | 19 SimpleFlatController() : SkFlatController() {} |
| 20 virtual void* allocThrow(size_t bytes) SK_OVERRIDE { return sk_malloc_throw(
bytes); } | 20 ~SimpleFlatController() { fAllocations.freeAll(); } |
| 21 virtual void unalloc(void* ptr) SK_OVERRIDE { sk_free(ptr); } | 21 virtual void* allocThrow(size_t bytes) SK_OVERRIDE { |
| 22 fAllocations.push(sk_malloc_throw(bytes)); |
| 23 return fAllocations.top(); |
| 24 } |
| 25 virtual void unalloc(void*) SK_OVERRIDE { } |
| 22 void setBitmapStorage(SkBitmapHeap* h) { this->setBitmapHeap(h); } | 26 void setBitmapStorage(SkBitmapHeap* h) { this->setBitmapHeap(h); } |
| 27 private: |
| 28 SkTDArray<void*> fAllocations; |
| 23 }; | 29 }; |
| 24 | 30 |
| 25 struct SkShaderTraits { | 31 struct SkShaderTraits { |
| 26 static void Flatten(SkWriteBuffer& buffer, const SkShader& shader) { | 32 static void Flatten(SkWriteBuffer& buffer, const SkShader& shader) { |
| 27 buffer.writeFlattenable(&shader); | 33 buffer.writeFlattenable(&shader); |
| 28 } | 34 } |
| 29 }; | 35 }; |
| 30 typedef SkFlatDictionary<SkShader, SkShaderTraits> FlatDictionary; | 36 typedef SkFlatDictionary<SkShader, SkShaderTraits> FlatDictionary; |
| 31 | 37 |
| 32 class SkBitmapHeapTester { | 38 class SkBitmapHeapTester { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 heap.deferAddingOwners(); | 88 heap.deferAddingOwners(); |
| 83 index = dictionary.find(*bitmapShader); | 89 index = dictionary.find(*bitmapShader); |
| 84 heap.endAddingOwnersDeferral(false); | 90 heap.endAddingOwnersDeferral(false); |
| 85 | 91 |
| 86 // The dictionary should report the same index since the new entry is identi
cal. | 92 // The dictionary should report the same index since the new entry is identi
cal. |
| 87 // The bitmap heap should contain the bitmap, but with no references. | 93 // The bitmap heap should contain the bitmap, but with no references. |
| 88 REPORTER_ASSERT(reporter, 1 == index); | 94 REPORTER_ASSERT(reporter, 1 == index); |
| 89 REPORTER_ASSERT(reporter, heap.count() == 1); | 95 REPORTER_ASSERT(reporter, heap.count() == 1); |
| 90 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); | 96 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); |
| 91 } | 97 } |
| OLD | NEW |