| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } else { | 348 } else { |
| 353 decode_requests_.back()->OnDecodeImageFailed(); | 349 decode_requests_.back()->OnDecodeImageFailed(); |
| 354 } | 350 } |
| 355 } else { | 351 } else { |
| 356 ImageDecoder::Start(decode_requests_.back().get(), | 352 ImageDecoder::Start(decode_requests_.back().get(), |
| 357 read_result->unsafe_icon_data); | 353 read_result->unsafe_icon_data); |
| 358 } | 354 } |
| 359 } | 355 } |
| 360 } | 356 } |
| 361 | 357 |
| 362 void ArcAppIcon::Update(const gfx::ImageSkia* image) { | 358 void ArcAppIcon::Update(ui::ScaleFactor scale_factor, const SkBitmap& bitmap) { |
| 363 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 359 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 364 CHECK(image && !image->isNull()); | |
| 365 | 360 |
| 366 std::vector<gfx::ImageSkiaRep> reps = image->image_reps(); | 361 gfx::ImageSkiaRep image_rep(bitmap, ui::GetScaleForScaleFactor(scale_factor)); |
| 367 for (const auto& image_rep : reps) { | 362 DCHECK(ui::IsSupportedScale(image_rep.scale())); |
| 368 if (ui::IsSupportedScale(image_rep.scale())) { | 363 |
| 369 image_skia_.RemoveRepresentation(image_rep.scale()); | 364 image_skia_.RemoveRepresentation(image_rep.scale()); |
| 370 image_skia_.AddRepresentation(image_rep); | 365 image_skia_.AddRepresentation(image_rep); |
| 371 } | 366 image_skia_.RemoveUnsupportedRepresentationsForScale(image_rep.scale()); |
| 372 } | |
| 373 | 367 |
| 374 observer_->OnIconUpdated(this); | 368 observer_->OnIconUpdated(this); |
| 375 } | 369 } |
| 376 | 370 |
| 377 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { | 371 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { |
| 378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 372 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 379 | 373 |
| 380 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), | 374 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), |
| 381 [request](const std::unique_ptr<DecodeRequest>& ptr) { | 375 [request](const std::unique_ptr<DecodeRequest>& ptr) { |
| 382 return ptr.get() == request; | 376 return ptr.get() == request; |
| 383 }); | 377 }); |
| 384 CHECK(it != decode_requests_.end()); | 378 CHECK(it != decode_requests_.end()); |
| 385 decode_requests_.erase(it); | 379 decode_requests_.erase(it); |
| 386 } | 380 } |
| OLD | NEW |