| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/table_row_nsimage_cache.h" | 5 #include "chrome/browser/ui/cocoa/table_row_nsimage_cache.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "skia/ext/skia_utils_mac.h" | 8 #include "skia/ext/skia_utils_mac.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "ui/gfx/image/image_skia.h" |
| 10 | 10 |
| 11 TableRowNSImageCache::TableRowNSImageCache(Table* model) | 11 TableRowNSImageCache::TableRowNSImageCache(Table* model) |
| 12 : model_(model), | 12 : model_(model), |
| 13 icon_images_([[NSPointerArray alloc] initWithOptions: | 13 icon_images_([[NSPointerArray alloc] initWithOptions: |
| 14 NSPointerFunctionsStrongMemory | | 14 NSPointerFunctionsStrongMemory | |
| 15 NSPointerFunctionsObjectPersonality]) { | 15 NSPointerFunctionsObjectPersonality]) { |
| 16 int count = model_->RowCount(); | 16 int count = model_->RowCount(); |
| 17 [icon_images_ setCount:count]; | 17 [icon_images_ setCount:count]; |
| 18 } | 18 } |
| 19 | 19 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 static_cast<int>([icon_images_ count])); | 59 static_cast<int>([icon_images_ count])); |
| 60 } | 60 } |
| 61 | 61 |
| 62 NSImage* TableRowNSImageCache::GetImageForRow(int row) { | 62 NSImage* TableRowNSImageCache::GetImageForRow(int row) { |
| 63 DCHECK_EQ(model_->RowCount(), | 63 DCHECK_EQ(model_->RowCount(), |
| 64 static_cast<int>([icon_images_ count])); | 64 static_cast<int>([icon_images_ count])); |
| 65 DCHECK_GE(row, 0); | 65 DCHECK_GE(row, 0); |
| 66 DCHECK_LT(row, static_cast<int>([icon_images_ count])); | 66 DCHECK_LT(row, static_cast<int>([icon_images_ count])); |
| 67 NSImage* image = static_cast<NSImage*>([icon_images_ pointerAtIndex:row]); | 67 NSImage* image = static_cast<NSImage*>([icon_images_ pointerAtIndex:row]); |
| 68 if (!image) { | 68 if (!image) { |
| 69 const SkBitmap bitmap_icon = | 69 const gfx::ImageSkia bitmap_icon = |
| 70 model_->GetIcon(row); | 70 model_->GetIcon(row); |
| 71 // This means GetIcon() will get called until it returns a non-empty bitmap. | 71 // This means GetIcon() will get called until it returns a non-empty bitmap. |
| 72 // Empty bitmaps are intentionally not cached. | 72 // Empty bitmaps are intentionally not cached. |
| 73 if (!bitmap_icon.isNull()) { | 73 if (!bitmap_icon.isNull()) { |
| 74 image = gfx::SkBitmapToNSImage(bitmap_icon); | 74 image = gfx::SkBitmapToNSImage(bitmap_icon); |
| 75 DCHECK(image); | 75 DCHECK(image); |
| 76 [icon_images_ replacePointerAtIndex:row withPointer:image]; | 76 [icon_images_ replacePointerAtIndex:row withPointer:image]; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 return image; | 79 return image; |
| 80 } | 80 } |
| 81 | 81 |
| OLD | NEW |