| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/app_list/arc/arc_app_icon.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (bitmap.width() != expected_dim || bitmap.height() != expected_dim) { | 206 if (bitmap.width() != expected_dim || bitmap.height() != expected_dim) { |
| 207 VLOG(2) << "Decoded ARC icon has unexpected dimension " | 207 VLOG(2) << "Decoded ARC icon has unexpected dimension " |
| 208 << bitmap.width() << "x" << bitmap.height() << ". Expected " | 208 << bitmap.width() << "x" << bitmap.height() << ". Expected " |
| 209 << expected_dim << "x" << "."; | 209 << expected_dim << "x" << "."; |
| 210 | 210 |
| 211 host_->MaybeRequestIcon(scale_factor_); | 211 host_->MaybeRequestIcon(scale_factor_); |
| 212 host_->DiscardDecodeRequest(this); | 212 host_->DiscardDecodeRequest(this); |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 gfx::ImageSkia image_skia; | 216 host_->Update(scale_factor_, bitmap); |
| 217 image_skia.AddRepresentation(gfx::ImageSkiaRep( | |
| 218 bitmap, | |
| 219 ui::GetScaleForScaleFactor(scale_factor_))); | |
| 220 host_->Update(&image_skia); | |
| 221 host_->DiscardDecodeRequest(this); | 217 host_->DiscardDecodeRequest(this); |
| 222 } | 218 } |
| 223 | 219 |
| 224 void ArcAppIcon::DecodeRequest::OnDecodeImageFailed() { | 220 void ArcAppIcon::DecodeRequest::OnDecodeImageFailed() { |
| 225 VLOG(2) << "Failed to decode ARC icon."; | 221 VLOG(2) << "Failed to decode ARC icon."; |
| 226 | 222 |
| 227 if (!host_) | 223 if (!host_) |
| 228 return; | 224 return; |
| 229 | 225 |
| 230 host_->MaybeRequestIcon(scale_factor_); | 226 host_->MaybeRequestIcon(scale_factor_); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 } else { | 350 } else { |
| 355 decode_requests_.back()->OnDecodeImageFailed(); | 351 decode_requests_.back()->OnDecodeImageFailed(); |
| 356 } | 352 } |
| 357 } else { | 353 } else { |
| 358 ImageDecoder::Start(decode_requests_.back().get(), | 354 ImageDecoder::Start(decode_requests_.back().get(), |
| 359 read_result->unsafe_icon_data); | 355 read_result->unsafe_icon_data); |
| 360 } | 356 } |
| 361 } | 357 } |
| 362 } | 358 } |
| 363 | 359 |
| 364 void ArcAppIcon::Update(const gfx::ImageSkia* image) { | 360 void ArcAppIcon::Update(ui::ScaleFactor scale_factor, const SkBitmap& bitmap) { |
| 365 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 361 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 366 CHECK(image && !image->isNull()); | |
| 367 | 362 |
| 368 std::vector<gfx::ImageSkiaRep> reps = image->image_reps(); | 363 gfx::ImageSkiaRep image_rep(bitmap, ui::GetScaleForScaleFactor(scale_factor)); |
| 369 for (const auto& image_rep : reps) { | 364 DCHECK(ui::IsSupportedScale(image_rep.scale())); |
| 370 if (ui::IsSupportedScale(image_rep.scale())) { | 365 |
| 371 image_skia_.RemoveRepresentation(image_rep.scale()); | 366 image_skia_.RemoveRepresentation(image_rep.scale()); |
| 372 image_skia_.AddRepresentation(image_rep); | 367 image_skia_.AddRepresentation(image_rep); |
| 373 } | 368 image_skia_.RemoveUnsupportedRepresentationsForScale(image_rep.scale()); |
| 374 } | |
| 375 | 369 |
| 376 observer_->OnIconUpdated(this); | 370 observer_->OnIconUpdated(this); |
| 377 } | 371 } |
| 378 | 372 |
| 379 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { | 373 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { |
| 380 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 374 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 381 | 375 |
| 382 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), | 376 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), |
| 383 [request](const std::unique_ptr<DecodeRequest>& ptr) { | 377 [request](const std::unique_ptr<DecodeRequest>& ptr) { |
| 384 return ptr.get() == request; | 378 return ptr.get() == request; |
| 385 }); | 379 }); |
| 386 CHECK(it != decode_requests_.end()); | 380 CHECK(it != decode_requests_.end()); |
| 387 decode_requests_.erase(it); | 381 decode_requests_.erase(it); |
| 388 } | 382 } |
| OLD | NEW |