Chromium Code Reviews| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 } else { | 343 } else { |
| 348 decode_requests_.back()->OnDecodeImageFailed(); | 344 decode_requests_.back()->OnDecodeImageFailed(); |
| 349 } | 345 } |
| 350 } else { | 346 } else { |
| 351 ImageDecoder::Start(decode_requests_.back().get(), | 347 ImageDecoder::Start(decode_requests_.back().get(), |
| 352 read_result->unsafe_icon_data); | 348 read_result->unsafe_icon_data); |
| 353 } | 349 } |
| 354 } | 350 } |
| 355 } | 351 } |
| 356 | 352 |
| 357 void ArcAppIcon::Update(const gfx::ImageSkia* image) { | 353 void ArcAppIcon::Update(ui::ScaleFactor scale_factor, const SkBitmap& bitmap) { |
| 358 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 354 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 359 CHECK(image && !image->isNull()); | |
| 360 | 355 |
| 361 std::vector<gfx::ImageSkiaRep> reps = image->image_reps(); | 356 gfx::ImageSkiaRep image_rep(bitmap, ui::GetScaleForScaleFactor(scale_factor)); |
| 362 for (const auto& image_rep : reps) { | 357 DCHECK(ui::IsSupportedScale(image_rep.scale())); |
| 363 if (ui::IsSupportedScale(image_rep.scale())) { | 358 |
| 364 image_skia_.RemoveRepresentation(image_rep.scale()); | 359 image_skia_.RemoveRepresentation(image_rep.scale()); |
| 365 image_skia_.AddRepresentation(image_rep); | 360 |
| 361 // Regenerate all non-supported image representations if they exist. Handle | |
| 362 // scales that are mapped to updated scale. | |
|
xiyuan
2017/05/24 16:37:09
nit: Emphasize on removing dependent reps of the n
khmel
2017/05/24 20:20:58
Nice...
| |
| 363 std::vector<float> scales_to_regenerate; | |
| 364 for (const gfx::ImageSkiaRep& image_rep_to_test : image_skia_.image_reps()) { | |
| 365 if (gfx::ImageSkia::MapToSupportedScale(image_rep_to_test.scale()) == | |
| 366 image_rep.scale()) { | |
| 367 DCHECK(!ui::IsSupportedScale(image_rep_to_test.scale())); | |
| 368 scales_to_regenerate.push_back(image_rep_to_test.scale()); | |
| 366 } | 369 } |
| 367 } | 370 } |
| 368 | 371 |
| 372 image_skia_.AddRepresentation(image_rep); | |
| 373 | |
| 374 for (float scale_to_regenerate : scales_to_regenerate) { | |
| 375 image_skia_.RemoveRepresentation(scale_to_regenerate); | |
| 376 image_skia_.GetRepresentation(scale_to_regenerate); | |
| 377 } | |
| 378 | |
| 369 observer_->OnIconUpdated(this); | 379 observer_->OnIconUpdated(this); |
| 370 } | 380 } |
| 371 | 381 |
| 372 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { | 382 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { |
| 373 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 383 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 374 | 384 |
| 375 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), | 385 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), |
| 376 [request](const std::unique_ptr<DecodeRequest>& ptr) { | 386 [request](const std::unique_ptr<DecodeRequest>& ptr) { |
| 377 return ptr.get() == request; | 387 return ptr.get() == request; |
| 378 }); | 388 }); |
| 379 CHECK(it != decode_requests_.end()); | 389 CHECK(it != decode_requests_.end()); |
| 380 decode_requests_.erase(it); | 390 decode_requests_.erase(it); |
| 381 } | 391 } |
| OLD | NEW |