Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "chrome/browser/android/thumbnail/thumbnail.h" | 6 #include "chrome/browser/android/thumbnail/thumbnail.h" |
| 7 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
| 8 #include "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
| 9 #include "ui/android/resources/ui_resource_provider.h" | 9 #include "ui/android/resources/ui_resource_provider.h" |
| 10 #include "ui/gfx/geometry/size_conversions.h" | 10 #include "ui/gfx/geometry/size_conversions.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 thumbnail_delegate_(thumbnail_delegate) { | 48 thumbnail_delegate_(thumbnail_delegate) { |
| 49 } | 49 } |
| 50 | 50 |
| 51 Thumbnail::~Thumbnail() { | 51 Thumbnail::~Thumbnail() { |
| 52 ClearUIResourceId(); | 52 ClearUIResourceId(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void Thumbnail::SetBitmap(const SkBitmap& bitmap) { | 55 void Thumbnail::SetBitmap(const SkBitmap& bitmap) { |
| 56 DCHECK(!bitmap.empty()); | 56 DCHECK(!bitmap.empty()); |
| 57 retrieved_ = false; | 57 retrieved_ = false; |
| 58 // TODO(sievers): We really just need to invalidate it here. | |
| 58 ClearUIResourceId(); | 59 ClearUIResourceId(); |
| 59 scaled_content_size_ = | 60 scaled_content_size_ = |
| 60 gfx::ScaleSize(gfx::Size(bitmap.width(), bitmap.height()), 1.f / scale_); | 61 gfx::ScaleSize(gfx::Size(bitmap.width(), bitmap.height()), 1.f / scale_); |
| 61 scaled_data_size_ = scaled_content_size_; | 62 scaled_data_size_ = scaled_content_size_; |
| 62 bitmap_ = cc::UIResourceBitmap(bitmap); | 63 bitmap_ = cc::UIResourceBitmap(bitmap); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void Thumbnail::SetCompressedBitmap(skia::RefPtr<SkPixelRef> compressed_bitmap, | 66 void Thumbnail::SetCompressedBitmap(skia::RefPtr<SkPixelRef> compressed_bitmap, |
| 66 const gfx::Size& content_size) { | 67 const gfx::Size& content_size) { |
| 67 DCHECK(compressed_bitmap); | 68 DCHECK(compressed_bitmap); |
| 68 DCHECK(!content_size.IsEmpty()); | 69 DCHECK(!content_size.IsEmpty()); |
| 69 retrieved_ = false; | 70 retrieved_ = false; |
| 71 // TODO(sievers): We really just need to invalidate it here. | |
| 70 ClearUIResourceId(); | 72 ClearUIResourceId(); |
| 71 gfx::Size data_size(compressed_bitmap->info().width(), | 73 gfx::Size data_size(compressed_bitmap->info().width(), |
| 72 compressed_bitmap->info().height()); | 74 compressed_bitmap->info().height()); |
| 73 scaled_content_size_ = gfx::ScaleSize(content_size, 1.f / scale_); | 75 scaled_content_size_ = gfx::ScaleSize(content_size, 1.f / scale_); |
| 74 scaled_data_size_ = gfx::ScaleSize(data_size, 1.f / scale_); | 76 scaled_data_size_ = gfx::ScaleSize(data_size, 1.f / scale_); |
| 75 bitmap_ = cc::UIResourceBitmap(compressed_bitmap, data_size); | 77 bitmap_ = cc::UIResourceBitmap(compressed_bitmap, data_size); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void Thumbnail::CreateUIResource() { | 80 void Thumbnail::CreateUIResource() { |
| 79 DCHECK(ui_resource_provider_); | 81 DCHECK(ui_resource_provider_); |
| 80 if (!ui_resource_id_) | 82 if (!ui_resource_id_) |
| 81 ui_resource_id_ = ui_resource_provider_->CreateUIResource(this); | 83 ui_resource_id_ = ui_resource_provider_->CreateUIResource(this); |
| 82 } | 84 } |
| 83 | 85 |
| 84 cc::UIResourceBitmap Thumbnail::GetBitmap(cc::UIResourceId uid, | 86 cc::UIResourceBitmap Thumbnail::GetBitmap(cc::UIResourceId uid, |
| 85 bool resource_lost) { | 87 bool resource_lost) { |
| 86 if (retrieved_) | 88 if (retrieved_) |
| 87 return bitmap_; | 89 return bitmap_; |
| 88 | 90 |
| 89 retrieved_ = true; | 91 retrieved_ = true; |
| 90 | 92 |
| 91 cc::UIResourceBitmap old_bitmap(bitmap_); | 93 cc::UIResourceBitmap old_bitmap(bitmap_); |
| 92 // Return a place holder for all other calls to GetBitmap. | 94 // Return a place holder for all other calls to GetBitmap. |
|
no sievers
2015/09/24 23:27:43
This is basically what is making it hard to simpli
| |
| 93 bitmap_ = cc::UIResourceBitmap(CreateSmallHolderBitmap()); | 95 bitmap_ = cc::UIResourceBitmap(CreateSmallHolderBitmap()); |
| 94 return old_bitmap; | 96 return old_bitmap; |
| 95 } | 97 } |
| 96 | 98 |
| 97 void Thumbnail::UIResourceIsInvalid() { | 99 void Thumbnail::OnWasEvicted() { |
| 98 ui_resource_id_ = 0; | |
| 99 if (thumbnail_delegate_) | 100 if (thumbnail_delegate_) |
| 100 thumbnail_delegate_->InvalidateCachedThumbnail(this); | 101 thumbnail_delegate_->InvalidateCachedThumbnail(this); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void Thumbnail::ClearUIResourceId() { | 104 void Thumbnail::ClearUIResourceId() { |
| 104 if (ui_resource_id_ && ui_resource_provider_) | 105 if (ui_resource_id_ && ui_resource_provider_) |
| 105 ui_resource_provider_->DeleteUIResource(ui_resource_id_); | 106 ui_resource_provider_->DeleteUIResource(ui_resource_id_); |
| 106 ui_resource_id_ = 0; | 107 ui_resource_id_ = 0; |
| 107 } | 108 } |
| OLD | NEW |