Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_icon.cc

Issue 2902153002: arc: Support non-standard display scale factors. (Closed)
Patch Set: rebase + comments fix. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 323
328 return base::MakeUnique<ArcAppIcon::ReadResult>( 324 return base::MakeUnique<ArcAppIcon::ReadResult>(
329 false, request_to_install, scale_factor, unsafe_icon_data); 325 false, request_to_install, scale_factor, unsafe_icon_data);
330 } 326 }
331 327
332 void ArcAppIcon::OnIconRead( 328 void ArcAppIcon::OnIconRead(
333 std::unique_ptr<ArcAppIcon::ReadResult> read_result) { 329 std::unique_ptr<ArcAppIcon::ReadResult> read_result) {
334 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 330 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
335 331
336 if (read_result->request_to_install) 332 if (read_result->request_to_install)
337 MaybeRequestIcon(read_result->scale_factor); 333 MaybeRequestIcon(read_result->scale_factor);
oshima 2017/05/26 16:03:09 How is this scale_factor obtained?
khmel 2017/05/26 16:10:54 There is a long chain of calls and finally this sc
338 334
339 if (!read_result->unsafe_icon_data.empty()) { 335 if (!read_result->unsafe_icon_data.empty()) {
340 decode_requests_.push_back(base::MakeUnique<DecodeRequest>( 336 decode_requests_.push_back(base::MakeUnique<DecodeRequest>(
341 weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip_, 337 weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip_,
342 read_result->scale_factor)); 338 read_result->scale_factor));
343 if (disable_safe_decoding_for_testing) { 339 if (disable_safe_decoding_for_testing) {
344 SkBitmap bitmap; 340 SkBitmap bitmap;
345 if (!read_result->unsafe_icon_data.empty() && 341 if (!read_result->unsafe_icon_data.empty() &&
346 gfx::PNGCodec::Decode( 342 gfx::PNGCodec::Decode(
347 reinterpret_cast<const unsigned char*>( 343 reinterpret_cast<const unsigned char*>(
348 &read_result->unsafe_icon_data.front()), 344 &read_result->unsafe_icon_data.front()),
349 read_result->unsafe_icon_data.length(), 345 read_result->unsafe_icon_data.length(),
350 &bitmap)) { 346 &bitmap)) {
351 decode_requests_.back()->OnImageDecoded(bitmap); 347 decode_requests_.back()->OnImageDecoded(bitmap);
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
oshima 2017/05/26 18:13:23 I looked into a bit more, and the problem seems to
khmel 2017/05/26 19:31:20 Thanks for offline chat! As discussed I moved inva
366 // Regenerate existing non-supported image representations that depend on the
367 // rep of |scale_factor|.
368 std::vector<float> scales_to_regenerate;
369 for (const gfx::ImageSkiaRep& image_rep_to_test : image_skia_.image_reps()) {
370 if (gfx::ImageSkia::MapToSupportedScale(image_rep_to_test.scale()) ==
371 image_rep.scale()) {
372 DCHECK(!ui::IsSupportedScale(image_rep_to_test.scale()));
373 scales_to_regenerate.push_back(image_rep_to_test.scale());
371 } 374 }
372 } 375 }
373 376
377 image_skia_.AddRepresentation(image_rep);
378
379 for (float scale_to_regenerate : scales_to_regenerate) {
380 image_skia_.RemoveRepresentation(scale_to_regenerate);
381 image_skia_.GetRepresentation(scale_to_regenerate);
382 }
383
374 observer_->OnIconUpdated(this); 384 observer_->OnIconUpdated(this);
375 } 385 }
376 386
377 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { 387 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) {
378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 388 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
379 389
380 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), 390 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(),
381 [request](const std::unique_ptr<DecodeRequest>& ptr) { 391 [request](const std::unique_ptr<DecodeRequest>& ptr) {
382 return ptr.get() == request; 392 return ptr.get() == request;
383 }); 393 });
384 CHECK(it != decode_requests_.end()); 394 CHECK(it != decode_requests_.end());
385 decode_requests_.erase(it); 395 decode_requests_.erase(it);
386 } 396 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_icon.h ('k') | chrome/browser/ui/app_list/arc/arc_app_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698