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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 public: | 27 public: |
28 static int32_t GetRefCount(const SkBitmapHeapEntry* entry) { | 28 static int32_t GetRefCount(const SkBitmapHeapEntry* entry) { |
29 return entry->fRefCount; | 29 return entry->fRefCount; |
30 } | 30 } |
31 }; | 31 }; |
32 | 32 |
33 DEF_TEST(BitmapHeap, reporter) { | 33 DEF_TEST(BitmapHeap, reporter) { |
34 // Create a bitmap shader. | 34 // Create a bitmap shader. |
35 SkBitmap bm; | 35 SkBitmap bm; |
36 bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 36 bm.allocN32Pixels(2, 2); |
37 bm.allocPixels(); | |
38 bm.eraseColor(SK_ColorRED); | 37 bm.eraseColor(SK_ColorRED); |
39 uint32_t* pixel = bm.getAddr32(1,0); | 38 uint32_t* pixel = bm.getAddr32(1,0); |
40 *pixel = SK_ColorBLUE; | 39 *pixel = SK_ColorBLUE; |
41 | 40 |
42 SkShader* bitmapShader = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_
TileMode, | 41 SkShader* bitmapShader = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_
TileMode, |
43 SkShader::kRepeat_Tile
Mode); | 42 SkShader::kRepeat_Tile
Mode); |
44 SkAutoTUnref<SkShader> aur(bitmapShader); | 43 SkAutoTUnref<SkShader> aur(bitmapShader); |
45 | 44 |
46 // Flatten, storing it in the bitmap heap. | 45 // Flatten, storing it in the bitmap heap. |
47 SkBitmapHeap heap(1, 1); | 46 SkBitmapHeap heap(1, 1); |
(...skipping 29 matching lines...) Expand all Loading... |
77 heap.deferAddingOwners(); | 76 heap.deferAddingOwners(); |
78 index = dictionary.find(*bitmapShader); | 77 index = dictionary.find(*bitmapShader); |
79 heap.endAddingOwnersDeferral(false); | 78 heap.endAddingOwnersDeferral(false); |
80 | 79 |
81 // The dictionary should report the same index since the new entry is identi
cal. | 80 // The dictionary should report the same index since the new entry is identi
cal. |
82 // The bitmap heap should contain the bitmap, but with no references. | 81 // The bitmap heap should contain the bitmap, but with no references. |
83 REPORTER_ASSERT(reporter, 1 == index); | 82 REPORTER_ASSERT(reporter, 1 == index); |
84 REPORTER_ASSERT(reporter, heap.count() == 1); | 83 REPORTER_ASSERT(reporter, heap.count() == 1); |
85 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); | 84 REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0))
== 0); |
86 } | 85 } |
OLD | NEW |