| 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 "SkOrderedWriteBuffer.h" | 12 #include "SkOrderedWriteBuffer.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 #include "TestClassDef.h" | 17 #include "TestClassDef.h" |
| 18 | 18 |
| 19 class FlatDictionary : public SkFlatDictionary<SkShader> { | 19 struct SkShaderTraits { |
| 20 | 20 static void flatten(SkOrderedWriteBuffer& buffer, const SkShader& shader) { |
| 21 public: | 21 buffer.writeFlattenable(&shader); |
| 22 FlatDictionary(SkFlatController* controller) | |
| 23 : SkFlatDictionary<SkShader>(controller) { | |
| 24 fFlattenProc = &flattenFlattenableProc; | |
| 25 // No need for an unflattenProc | |
| 26 } | |
| 27 static void flattenFlattenableProc(SkOrderedWriteBuffer& buffer, const void*
obj) { | |
| 28 buffer.writeFlattenable((SkFlattenable*)obj); | |
| 29 } | 22 } |
| 30 }; | 23 }; |
| 24 typedef SkFlatDictionary<SkShader, SkShaderTraits> FlatDictionary; |
| 31 | 25 |
| 32 class SkBitmapHeapTester { | 26 class SkBitmapHeapTester { |
| 33 | 27 |
| 34 public: | 28 public: |
| 35 static int32_t GetRefCount(const SkBitmapHeapEntry* entry) { | 29 static int32_t GetRefCount(const SkBitmapHeapEntry* entry) { |
| 36 return entry->fRefCount; | 30 return entry->fRefCount; |
| 37 } | 31 } |
| 38 }; | 32 }; |
| 39 | 33 |
| 40 DEF_TEST(BitmapHeap, reporter) { | 34 DEF_TEST(BitmapHeap, reporter) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 heap.deferAddingOwners(); | 78 heap.deferAddingOwners(); |
| 85 index = dictionary.find(*bitmapShader); | 79 index = dictionary.find(*bitmapShader); |
| 86 heap.endAddingOwnersDeferral(false); | 80 heap.endAddingOwnersDeferral(false); |
| 87 | 81 |
| 88 // The dictionary should report the same index since the new entry is identi
cal. | 82 // The dictionary should report the same index since the new entry is identi
cal. |
| 89 // The bitmap heap should contain the bitmap, but with no references. | 83 // The bitmap heap should contain the bitmap, but with no references. |
| 90 REPORTER_ASSERT(reporter, 1 == index); | 84 REPORTER_ASSERT(reporter, 1 == index); |
| 91 REPORTER_ASSERT(reporter, heap.count() == 1); | 85 REPORTER_ASSERT(reporter, heap.count() == 1); |
| 92 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); | 86 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); |
| 93 } | 87 } |
| OLD | NEW |