| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 10 #include "SkBitmapHeap.h" | 9 #include "SkBitmapHeap.h" |
| 11 #include "SkColor.h" | 10 #include "SkColor.h" |
| 12 #include "SkFlattenable.h" | 11 #include "SkFlattenable.h" |
| 13 #include "SkOrderedWriteBuffer.h" | 12 #include "SkOrderedWriteBuffer.h" |
| 14 #include "SkPictureFlat.h" | 13 #include "SkPictureFlat.h" |
| 15 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 16 #include "SkShader.h" | 15 #include "SkShader.h" |
| 17 #include "Test.h" | 16 #include "Test.h" |
| 17 #include "TestClassDef.h" |
| 18 | 18 |
| 19 class FlatDictionary : public SkFlatDictionary<SkShader> { | 19 class FlatDictionary : public SkFlatDictionary<SkShader> { |
| 20 | 20 |
| 21 public: | 21 public: |
| 22 FlatDictionary(SkFlatController* controller) | 22 FlatDictionary(SkFlatController* controller) |
| 23 : SkFlatDictionary<SkShader>(controller) { | 23 : SkFlatDictionary<SkShader>(controller) { |
| 24 fFlattenProc = &flattenFlattenableProc; | 24 fFlattenProc = &flattenFlattenableProc; |
| 25 // No need for an unflattenProc | 25 // No need for an unflattenProc |
| 26 } | 26 } |
| 27 static void flattenFlattenableProc(SkOrderedWriteBuffer& buffer, const void*
obj) { | 27 static void flattenFlattenableProc(SkOrderedWriteBuffer& buffer, const void*
obj) { |
| 28 buffer.writeFlattenable((SkFlattenable*)obj); | 28 buffer.writeFlattenable((SkFlattenable*)obj); |
| 29 } | 29 } |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 class SkBitmapHeapTester { | 32 class SkBitmapHeapTester { |
| 33 | 33 |
| 34 public: | 34 public: |
| 35 static int32_t GetRefCount(const SkBitmapHeapEntry* entry) { | 35 static int32_t GetRefCount(const SkBitmapHeapEntry* entry) { |
| 36 return entry->fRefCount; | 36 return entry->fRefCount; |
| 37 } | 37 } |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 static void TestBitmapHeap(skiatest::Reporter* reporter) { | 40 DEF_TEST(BitmapHeap, reporter) { |
| 41 // Create a bitmap shader. | 41 // Create a bitmap shader. |
| 42 SkBitmap bm; | 42 SkBitmap bm; |
| 43 bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 43 bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
| 44 bm.allocPixels(); | 44 bm.allocPixels(); |
| 45 bm.eraseColor(SK_ColorRED); | 45 bm.eraseColor(SK_ColorRED); |
| 46 uint32_t* pixel = bm.getAddr32(1,0); | 46 uint32_t* pixel = bm.getAddr32(1,0); |
| 47 *pixel = SK_ColorBLUE; | 47 *pixel = SK_ColorBLUE; |
| 48 | 48 |
| 49 SkShader* bitmapShader = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_
TileMode, | 49 SkShader* bitmapShader = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_
TileMode, |
| 50 SkShader::kRepeat_Tile
Mode); | 50 SkShader::kRepeat_Tile
Mode); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 heap.deferAddingOwners(); | 84 heap.deferAddingOwners(); |
| 85 index = dictionary.find(*bitmapShader); | 85 index = dictionary.find(*bitmapShader); |
| 86 heap.endAddingOwnersDeferral(false); | 86 heap.endAddingOwnersDeferral(false); |
| 87 | 87 |
| 88 // The dictionary should report the same index since the new entry is identi
cal. | 88 // 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. | 89 // The bitmap heap should contain the bitmap, but with no references. |
| 90 REPORTER_ASSERT(reporter, 1 == index); | 90 REPORTER_ASSERT(reporter, 1 == index); |
| 91 REPORTER_ASSERT(reporter, heap.count() == 1); | 91 REPORTER_ASSERT(reporter, heap.count() == 1); |
| 92 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); | 92 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); |
| 93 } | 93 } |
| 94 | |
| 95 #include "TestClassDef.h" | |
| 96 DEFINE_TESTCLASS("BitmapHeap", TestBitmapHeapClass, TestBitmapHeap) | |
| OLD | NEW |