| 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 "chrome/browser/android/thumbnail/thumbnail_cache.h" | 5 #include "chrome/browser/android/thumbnail/thumbnail_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 count++; | 302 count++; |
| 303 } | 303 } |
| 304 | 304 |
| 305 ReadNextThumbnail(); | 305 ReadNextThumbnail(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void ThumbnailCache::DecompressThumbnailFromFile( | 308 void ThumbnailCache::DecompressThumbnailFromFile( |
| 309 TabId tab_id, | 309 TabId tab_id, |
| 310 const base::Callback<void(bool, SkBitmap)>& | 310 const base::Callback<void(bool, SkBitmap)>& |
| 311 post_decompress_callback) { | 311 post_decompress_callback) { |
| 312 base::Callback<void(skia::RefPtr<SkPixelRef>, float, const gfx::Size&)> | 312 base::Callback<void(sk_sp<SkPixelRef>, float, const gfx::Size&)> |
| 313 decompress_task = base::Bind( | 313 decompress_task = base::Bind( |
| 314 &ThumbnailCache::DecompressionTask, post_decompress_callback); | 314 &ThumbnailCache::DecompressionTask, post_decompress_callback); |
| 315 | 315 |
| 316 content::BrowserThread::PostTask( | 316 content::BrowserThread::PostTask( |
| 317 content::BrowserThread::FILE, | 317 content::BrowserThread::FILE, |
| 318 FROM_HERE, | 318 FROM_HERE, |
| 319 base::Bind(&ThumbnailCache::ReadTask, true, tab_id, decompress_task)); | 319 base::Bind(&ThumbnailCache::ReadTask, true, tab_id, decompress_task)); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void ThumbnailCache::RemoveFromDisk(TabId tab_id) { | 322 void ThumbnailCache::RemoveFromDisk(TabId tab_id) { |
| 323 base::Closure task = | 323 base::Closure task = |
| 324 base::Bind(&ThumbnailCache::RemoveFromDiskTask, tab_id); | 324 base::Bind(&ThumbnailCache::RemoveFromDiskTask, tab_id); |
| 325 content::BrowserThread::PostTask( | 325 content::BrowserThread::PostTask( |
| 326 content::BrowserThread::FILE, FROM_HERE, task); | 326 content::BrowserThread::FILE, FROM_HERE, task); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void ThumbnailCache::RemoveFromDiskTask(TabId tab_id) { | 329 void ThumbnailCache::RemoveFromDiskTask(TabId tab_id) { |
| 330 base::FilePath file_path = GetFilePath(tab_id); | 330 base::FilePath file_path = GetFilePath(tab_id); |
| 331 if (base::PathExists(file_path)) | 331 if (base::PathExists(file_path)) |
| 332 base::DeleteFile(file_path, false); | 332 base::DeleteFile(file_path, false); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void ThumbnailCache::WriteThumbnailIfNecessary( | 335 void ThumbnailCache::WriteThumbnailIfNecessary( |
| 336 TabId tab_id, | 336 TabId tab_id, |
| 337 skia::RefPtr<SkPixelRef> compressed_data, | 337 sk_sp<SkPixelRef> compressed_data, |
| 338 float scale, | 338 float scale, |
| 339 const gfx::Size& content_size) { | 339 const gfx::Size& content_size) { |
| 340 if (write_tasks_count_ >= write_queue_max_size_) | 340 if (write_tasks_count_ >= write_queue_max_size_) |
| 341 return; | 341 return; |
| 342 | 342 |
| 343 write_tasks_count_++; | 343 write_tasks_count_++; |
| 344 | 344 |
| 345 base::Callback<void()> post_write_task = | 345 base::Callback<void()> post_write_task = |
| 346 base::Bind(&ThumbnailCache::PostWriteTask, weak_factory_.GetWeakPtr()); | 346 base::Bind(&ThumbnailCache::PostWriteTask, weak_factory_.GetWeakPtr()); |
| 347 content::BrowserThread::PostTask(content::BrowserThread::FILE, | 347 content::BrowserThread::PostTask(content::BrowserThread::FILE, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 359 const base::Time& time_stamp, | 359 const base::Time& time_stamp, |
| 360 const SkBitmap& bitmap, | 360 const SkBitmap& bitmap, |
| 361 float scale) { | 361 float scale) { |
| 362 if (compression_tasks_count_ >= compression_queue_max_size_) { | 362 if (compression_tasks_count_ >= compression_queue_max_size_) { |
| 363 RemoveOnMatchedTimeStamp(tab_id, time_stamp); | 363 RemoveOnMatchedTimeStamp(tab_id, time_stamp); |
| 364 return; | 364 return; |
| 365 } | 365 } |
| 366 | 366 |
| 367 compression_tasks_count_++; | 367 compression_tasks_count_++; |
| 368 | 368 |
| 369 base::Callback<void(skia::RefPtr<SkPixelRef>, const gfx::Size&)> | 369 base::Callback<void(sk_sp<SkPixelRef>, const gfx::Size&)> |
| 370 post_compression_task = base::Bind(&ThumbnailCache::PostCompressionTask, | 370 post_compression_task = base::Bind(&ThumbnailCache::PostCompressionTask, |
| 371 weak_factory_.GetWeakPtr(), | 371 weak_factory_.GetWeakPtr(), |
| 372 tab_id, | 372 tab_id, |
| 373 time_stamp, | 373 time_stamp, |
| 374 scale); | 374 scale); |
| 375 | 375 |
| 376 gfx::Size raw_data_size(bitmap.width(), bitmap.height()); | 376 gfx::Size raw_data_size(bitmap.width(), bitmap.height()); |
| 377 gfx::Size encoded_size = GetEncodedSize( | 377 gfx::Size encoded_size = GetEncodedSize( |
| 378 raw_data_size, ui_resource_provider_->SupportsETC1NonPowerOfTwo()); | 378 raw_data_size, ui_resource_provider_->SupportsETC1NonPowerOfTwo()); |
| 379 | 379 |
| 380 base::WorkerPool::PostTask(FROM_HERE, | 380 base::WorkerPool::PostTask(FROM_HERE, |
| 381 base::Bind(&ThumbnailCache::CompressionTask, | 381 base::Bind(&ThumbnailCache::CompressionTask, |
| 382 bitmap, | 382 bitmap, |
| 383 encoded_size, | 383 encoded_size, |
| 384 post_compression_task), | 384 post_compression_task), |
| 385 true); | 385 true); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void ThumbnailCache::ReadNextThumbnail() { | 388 void ThumbnailCache::ReadNextThumbnail() { |
| 389 if (read_queue_.empty() || read_in_progress_) | 389 if (read_queue_.empty() || read_in_progress_) |
| 390 return; | 390 return; |
| 391 | 391 |
| 392 TabId tab_id = read_queue_.front(); | 392 TabId tab_id = read_queue_.front(); |
| 393 read_in_progress_ = true; | 393 read_in_progress_ = true; |
| 394 | 394 |
| 395 base::Callback<void(skia::RefPtr<SkPixelRef>, float, const gfx::Size&)> | 395 base::Callback<void(sk_sp<SkPixelRef>, float, const gfx::Size&)> |
| 396 post_read_task = base::Bind( | 396 post_read_task = base::Bind( |
| 397 &ThumbnailCache::PostReadTask, weak_factory_.GetWeakPtr(), tab_id); | 397 &ThumbnailCache::PostReadTask, weak_factory_.GetWeakPtr(), tab_id); |
| 398 | 398 |
| 399 content::BrowserThread::PostTask( | 399 content::BrowserThread::PostTask( |
| 400 content::BrowserThread::FILE, | 400 content::BrowserThread::FILE, |
| 401 FROM_HERE, | 401 FROM_HERE, |
| 402 base::Bind(&ThumbnailCache::ReadTask, false, tab_id, post_read_task)); | 402 base::Bind(&ThumbnailCache::ReadTask, false, tab_id, post_read_task)); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void ThumbnailCache::MakeSpaceForNewItemIfNecessary(TabId tab_id) { | 405 void ThumbnailCache::MakeSpaceForNewItemIfNecessary(TabId tab_id) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 cached_thumbnail = approximation_cache_.Get(tab_id); | 464 cached_thumbnail = approximation_cache_.Get(tab_id); |
| 465 if (cached_thumbnail && cached_thumbnail->ui_resource_id() == uid) | 465 if (cached_thumbnail && cached_thumbnail->ui_resource_id() == uid) |
| 466 approximation_cache_.Remove(tab_id); | 466 approximation_cache_.Remove(tab_id); |
| 467 } | 467 } |
| 468 | 468 |
| 469 namespace { | 469 namespace { |
| 470 | 470 |
| 471 bool WriteToFile(base::File& file, | 471 bool WriteToFile(base::File& file, |
| 472 const gfx::Size& content_size, | 472 const gfx::Size& content_size, |
| 473 const float scale, | 473 const float scale, |
| 474 skia::RefPtr<SkPixelRef> compressed_data) { | 474 sk_sp<SkPixelRef> compressed_data) { |
| 475 if (!file.IsValid()) | 475 if (!file.IsValid()) |
| 476 return false; | 476 return false; |
| 477 | 477 |
| 478 if (!WriteBigEndianToFile(file, kCompressedKey)) | 478 if (!WriteBigEndianToFile(file, kCompressedKey)) |
| 479 return false; | 479 return false; |
| 480 | 480 |
| 481 if (!WriteBigEndianToFile(file, content_size.width())) | 481 if (!WriteBigEndianToFile(file, content_size.width())) |
| 482 return false; | 482 return false; |
| 483 | 483 |
| 484 if (!WriteBigEndianToFile(file, content_size.height())) | 484 if (!WriteBigEndianToFile(file, content_size.height())) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 513 | 513 |
| 514 if (!WriteBigEndianFloatToFile(file, 1.f / scale)) | 514 if (!WriteBigEndianFloatToFile(file, 1.f / scale)) |
| 515 return false; | 515 return false; |
| 516 | 516 |
| 517 return true; | 517 return true; |
| 518 } | 518 } |
| 519 | 519 |
| 520 } // anonymous namespace | 520 } // anonymous namespace |
| 521 | 521 |
| 522 void ThumbnailCache::WriteTask(TabId tab_id, | 522 void ThumbnailCache::WriteTask(TabId tab_id, |
| 523 skia::RefPtr<SkPixelRef> compressed_data, | 523 sk_sp<SkPixelRef> compressed_data, |
| 524 float scale, | 524 float scale, |
| 525 const gfx::Size& content_size, | 525 const gfx::Size& content_size, |
| 526 const base::Callback<void()>& post_write_task) { | 526 const base::Callback<void()>& post_write_task) { |
| 527 DCHECK(compressed_data); | 527 DCHECK(compressed_data); |
| 528 | 528 |
| 529 base::FilePath file_path = GetFilePath(tab_id); | 529 base::FilePath file_path = GetFilePath(tab_id); |
| 530 | 530 |
| 531 base::File file(file_path, | 531 base::File file(file_path, |
| 532 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); | 532 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); |
| 533 | 533 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 545 content::BrowserThread::UI, FROM_HERE, post_write_task); | 545 content::BrowserThread::UI, FROM_HERE, post_write_task); |
| 546 } | 546 } |
| 547 | 547 |
| 548 void ThumbnailCache::PostWriteTask() { | 548 void ThumbnailCache::PostWriteTask() { |
| 549 write_tasks_count_--; | 549 write_tasks_count_--; |
| 550 } | 550 } |
| 551 | 551 |
| 552 void ThumbnailCache::CompressionTask( | 552 void ThumbnailCache::CompressionTask( |
| 553 SkBitmap raw_data, | 553 SkBitmap raw_data, |
| 554 gfx::Size encoded_size, | 554 gfx::Size encoded_size, |
| 555 const base::Callback<void(skia::RefPtr<SkPixelRef>, const gfx::Size&)>& | 555 const base::Callback<void(sk_sp<SkPixelRef>, const gfx::Size&)>& |
| 556 post_compression_task) { | 556 post_compression_task) { |
| 557 skia::RefPtr<SkPixelRef> compressed_data; | 557 sk_sp<SkPixelRef> compressed_data; |
| 558 gfx::Size content_size; | 558 gfx::Size content_size; |
| 559 | 559 |
| 560 if (!raw_data.empty()) { | 560 if (!raw_data.empty()) { |
| 561 SkAutoLockPixels raw_data_lock(raw_data); | 561 SkAutoLockPixels raw_data_lock(raw_data); |
| 562 gfx::Size raw_data_size(raw_data.width(), raw_data.height()); | 562 gfx::Size raw_data_size(raw_data.width(), raw_data.height()); |
| 563 size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config. | 563 size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config. |
| 564 size_t stride = pixel_size * raw_data_size.width(); | 564 size_t stride = pixel_size * raw_data_size.width(); |
| 565 | 565 |
| 566 size_t encoded_bytes = | 566 size_t encoded_bytes = |
| 567 etc1_get_encoded_data_size(encoded_size.width(), encoded_size.height()); | 567 etc1_get_encoded_data_size(encoded_size.width(), encoded_size.height()); |
| 568 SkImageInfo info = SkImageInfo::Make(encoded_size.width(), | 568 SkImageInfo info = SkImageInfo::Make(encoded_size.width(), |
| 569 encoded_size.height(), | 569 encoded_size.height(), |
| 570 kUnknown_SkColorType, | 570 kUnknown_SkColorType, |
| 571 kUnpremul_SkAlphaType); | 571 kUnpremul_SkAlphaType); |
| 572 skia::RefPtr<SkData> etc1_pixel_data = skia::AdoptRef( | 572 sk_sp<SkData> etc1_pixel_data(SkData::NewUninitialized(encoded_bytes)); |
| 573 SkData::NewUninitialized(encoded_bytes)); | 573 sk_sp<SkMallocPixelRef> etc1_pixel_ref( |
| 574 skia::RefPtr<SkMallocPixelRef> etc1_pixel_ref = skia::AdoptRef( | |
| 575 SkMallocPixelRef::NewWithData(info, 0, NULL, etc1_pixel_data.get())); | 574 SkMallocPixelRef::NewWithData(info, 0, NULL, etc1_pixel_data.get())); |
| 576 | 575 |
| 577 etc1_pixel_ref->lockPixels(); | 576 etc1_pixel_ref->lockPixels(); |
| 578 bool success = etc1_encode_image( | 577 bool success = etc1_encode_image( |
| 579 reinterpret_cast<unsigned char*>(raw_data.getPixels()), | 578 reinterpret_cast<unsigned char*>(raw_data.getPixels()), |
| 580 raw_data_size.width(), | 579 raw_data_size.width(), |
| 581 raw_data_size.height(), | 580 raw_data_size.height(), |
| 582 pixel_size, | 581 pixel_size, |
| 583 stride, | 582 stride, |
| 584 reinterpret_cast<unsigned char*>(etc1_pixel_ref->pixels()), | 583 reinterpret_cast<unsigned char*>(etc1_pixel_ref->pixels()), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 596 content::BrowserThread::PostTask( | 595 content::BrowserThread::PostTask( |
| 597 content::BrowserThread::UI, | 596 content::BrowserThread::UI, |
| 598 FROM_HERE, | 597 FROM_HERE, |
| 599 base::Bind(post_compression_task, compressed_data, content_size)); | 598 base::Bind(post_compression_task, compressed_data, content_size)); |
| 600 } | 599 } |
| 601 | 600 |
| 602 void ThumbnailCache::PostCompressionTask( | 601 void ThumbnailCache::PostCompressionTask( |
| 603 TabId tab_id, | 602 TabId tab_id, |
| 604 const base::Time& time_stamp, | 603 const base::Time& time_stamp, |
| 605 float scale, | 604 float scale, |
| 606 skia::RefPtr<SkPixelRef> compressed_data, | 605 sk_sp<SkPixelRef> compressed_data, |
| 607 const gfx::Size& content_size) { | 606 const gfx::Size& content_size) { |
| 608 compression_tasks_count_--; | 607 compression_tasks_count_--; |
| 609 if (!compressed_data) { | 608 if (!compressed_data) { |
| 610 RemoveOnMatchedTimeStamp(tab_id, time_stamp); | 609 RemoveOnMatchedTimeStamp(tab_id, time_stamp); |
| 611 return; | 610 return; |
| 612 } | 611 } |
| 613 | 612 |
| 614 Thumbnail* thumbnail = cache_.Get(tab_id); | 613 Thumbnail* thumbnail = cache_.Get(tab_id); |
| 615 if (thumbnail) { | 614 if (thumbnail) { |
| 616 if (thumbnail->time_stamp() != time_stamp) | 615 if (thumbnail->time_stamp() != time_stamp) |
| 617 return; | 616 return; |
| 618 thumbnail->SetCompressedBitmap(compressed_data, content_size); | 617 thumbnail->SetCompressedBitmap(compressed_data, content_size); |
| 619 thumbnail->CreateUIResource(); | 618 thumbnail->CreateUIResource(); |
| 620 } | 619 } |
| 621 WriteThumbnailIfNecessary(tab_id, compressed_data, scale, content_size); | 620 WriteThumbnailIfNecessary(tab_id, compressed_data, scale, content_size); |
| 622 } | 621 } |
| 623 | 622 |
| 624 namespace { | 623 namespace { |
| 625 | 624 |
| 626 bool ReadFromFile(base::File& file, | 625 bool ReadFromFile(base::File& file, |
| 627 gfx::Size* out_content_size, | 626 gfx::Size* out_content_size, |
| 628 float* out_scale, | 627 float* out_scale, |
| 629 skia::RefPtr<SkPixelRef>* out_pixels) { | 628 sk_sp<SkPixelRef>* out_pixels) { |
| 630 if (!file.IsValid()) | 629 if (!file.IsValid()) |
| 631 return false; | 630 return false; |
| 632 | 631 |
| 633 int key = 0; | 632 int key = 0; |
| 634 if (!ReadBigEndianFromFile(file, &key)) | 633 if (!ReadBigEndianFromFile(file, &key)) |
| 635 return false; | 634 return false; |
| 636 | 635 |
| 637 if (key != kCompressedKey) | 636 if (key != kCompressedKey) |
| 638 return false; | 637 return false; |
| 639 | 638 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 display_info.GetDisplayHeight()); | 676 display_info.GetDisplayHeight()); |
| 678 | 677 |
| 679 if (content_width > max_dimension | 678 if (content_width > max_dimension |
| 680 || content_height > max_dimension | 679 || content_height > max_dimension |
| 681 || static_cast<size_t>(raw_width) > NextPowerOfTwo(max_dimension) | 680 || static_cast<size_t>(raw_width) > NextPowerOfTwo(max_dimension) |
| 682 || static_cast<size_t>(raw_height) > NextPowerOfTwo(max_dimension)) { | 681 || static_cast<size_t>(raw_height) > NextPowerOfTwo(max_dimension)) { |
| 683 return false; | 682 return false; |
| 684 } | 683 } |
| 685 | 684 |
| 686 int data_size = etc1_get_encoded_data_size(raw_width, raw_height); | 685 int data_size = etc1_get_encoded_data_size(raw_width, raw_height); |
| 687 skia::RefPtr<SkData> etc1_pixel_data = | 686 sk_sp<SkData> etc1_pixel_data(SkData::NewUninitialized(data_size)); |
| 688 skia::AdoptRef(SkData::NewUninitialized(data_size)); | |
| 689 | 687 |
| 690 int pixel_bytes_read = file.ReadAtCurrentPos( | 688 int pixel_bytes_read = file.ReadAtCurrentPos( |
| 691 reinterpret_cast<char*>(etc1_pixel_data->writable_data()), | 689 reinterpret_cast<char*>(etc1_pixel_data->writable_data()), |
| 692 data_size); | 690 data_size); |
| 693 | 691 |
| 694 if (pixel_bytes_read != data_size) | 692 if (pixel_bytes_read != data_size) |
| 695 return false; | 693 return false; |
| 696 | 694 |
| 697 SkImageInfo info = SkImageInfo::Make(raw_width, | 695 SkImageInfo info = SkImageInfo::Make(raw_width, |
| 698 raw_height, | 696 raw_height, |
| 699 kUnknown_SkColorType, | 697 kUnknown_SkColorType, |
| 700 kUnpremul_SkAlphaType); | 698 kUnpremul_SkAlphaType); |
| 701 | 699 |
| 702 *out_pixels = skia::AdoptRef( | 700 *out_pixels = sk_sp<SkPixelRef>( |
| 703 SkMallocPixelRef::NewWithData(info, | 701 SkMallocPixelRef::NewWithData(info, |
| 704 0, | 702 0, |
| 705 NULL, | 703 NULL, |
| 706 etc1_pixel_data.get())); | 704 etc1_pixel_data.get())); |
| 707 | 705 |
| 708 int extra_data_version = 0; | 706 int extra_data_version = 0; |
| 709 if (!ReadBigEndianFromFile(file, &extra_data_version)) | 707 if (!ReadBigEndianFromFile(file, &extra_data_version)) |
| 710 return false; | 708 return false; |
| 711 | 709 |
| 712 *out_scale = 1.f; | 710 *out_scale = 1.f; |
| 713 if (extra_data_version == 1) { | 711 if (extra_data_version == 1) { |
| 714 if (!ReadBigEndianFloatFromFile(file, out_scale)) | 712 if (!ReadBigEndianFloatFromFile(file, out_scale)) |
| 715 return false; | 713 return false; |
| 716 | 714 |
| 717 if (*out_scale == 0.f) | 715 if (*out_scale == 0.f) |
| 718 return false; | 716 return false; |
| 719 | 717 |
| 720 *out_scale = 1.f / *out_scale; | 718 *out_scale = 1.f / *out_scale; |
| 721 } | 719 } |
| 722 | 720 |
| 723 return true; | 721 return true; |
| 724 } | 722 } |
| 725 | 723 |
| 726 }// anonymous namespace | 724 }// anonymous namespace |
| 727 | 725 |
| 728 void ThumbnailCache::ReadTask( | 726 void ThumbnailCache::ReadTask( |
| 729 bool decompress, | 727 bool decompress, |
| 730 TabId tab_id, | 728 TabId tab_id, |
| 731 const base::Callback< | 729 const base::Callback< |
| 732 void(skia::RefPtr<SkPixelRef>, float, const gfx::Size&)>& | 730 void(sk_sp<SkPixelRef>, float, const gfx::Size&)>& |
| 733 post_read_task) { | 731 post_read_task) { |
| 734 gfx::Size content_size; | 732 gfx::Size content_size; |
| 735 float scale = 0.f; | 733 float scale = 0.f; |
| 736 skia::RefPtr<SkPixelRef> compressed_data; | 734 sk_sp<SkPixelRef> compressed_data; |
| 737 base::FilePath file_path = GetFilePath(tab_id); | 735 base::FilePath file_path = GetFilePath(tab_id); |
| 738 | 736 |
| 739 if (base::PathExists(file_path)) { | 737 if (base::PathExists(file_path)) { |
| 740 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 738 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 741 | 739 |
| 742 | 740 |
| 743 bool valid_contents = ReadFromFile(file, | 741 bool valid_contents = ReadFromFile(file, |
| 744 &content_size, | 742 &content_size, |
| 745 &scale, | 743 &scale, |
| 746 &compressed_data); | 744 &compressed_data); |
| 747 file.Close(); | 745 file.Close(); |
| 748 | 746 |
| 749 if (!valid_contents) { | 747 if (!valid_contents) { |
| 750 content_size.SetSize(0, 0); | 748 content_size.SetSize(0, 0); |
| 751 scale = 0.f; | 749 scale = 0.f; |
| 752 compressed_data.clear(); | 750 compressed_data.reset(); |
| 753 base::DeleteFile(file_path, false); | 751 base::DeleteFile(file_path, false); |
| 754 } | 752 } |
| 755 } | 753 } |
| 756 | 754 |
| 757 if (decompress) { | 755 if (decompress) { |
| 758 base::WorkerPool::PostTask( | 756 base::WorkerPool::PostTask( |
| 759 FROM_HERE, | 757 FROM_HERE, |
| 760 base::Bind(post_read_task, compressed_data, scale, content_size), | 758 base::Bind(post_read_task, compressed_data, scale, content_size), |
| 761 true); | 759 true); |
| 762 } else { | 760 } else { |
| 763 content::BrowserThread::PostTask( | 761 content::BrowserThread::PostTask( |
| 764 content::BrowserThread::UI, | 762 content::BrowserThread::UI, |
| 765 FROM_HERE, | 763 FROM_HERE, |
| 766 base::Bind(post_read_task, compressed_data, scale, content_size)); | 764 base::Bind(post_read_task, compressed_data, scale, content_size)); |
| 767 } | 765 } |
| 768 } | 766 } |
| 769 | 767 |
| 770 void ThumbnailCache::PostReadTask(TabId tab_id, | 768 void ThumbnailCache::PostReadTask(TabId tab_id, |
| 771 skia::RefPtr<SkPixelRef> compressed_data, | 769 sk_sp<SkPixelRef> compressed_data, |
| 772 float scale, | 770 float scale, |
| 773 const gfx::Size& content_size) { | 771 const gfx::Size& content_size) { |
| 774 read_in_progress_ = false; | 772 read_in_progress_ = false; |
| 775 | 773 |
| 776 TabIdList::iterator iter = | 774 TabIdList::iterator iter = |
| 777 std::find(read_queue_.begin(), read_queue_.end(), tab_id); | 775 std::find(read_queue_.begin(), read_queue_.end(), tab_id); |
| 778 if (iter == read_queue_.end()) { | 776 if (iter == read_queue_.end()) { |
| 779 ReadNextThumbnail(); | 777 ReadNextThumbnail(); |
| 780 return; | 778 return; |
| 781 } | 779 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 if ((thumbnail && thumbnail->time_stamp() == time_stamp) || | 815 if ((thumbnail && thumbnail->time_stamp() == time_stamp) || |
| 818 (approx_thumbnail && approx_thumbnail->time_stamp() == time_stamp)) { | 816 (approx_thumbnail && approx_thumbnail->time_stamp() == time_stamp)) { |
| 819 Remove(tab_id); | 817 Remove(tab_id); |
| 820 } | 818 } |
| 821 return; | 819 return; |
| 822 } | 820 } |
| 823 | 821 |
| 824 void ThumbnailCache::DecompressionTask( | 822 void ThumbnailCache::DecompressionTask( |
| 825 const base::Callback<void(bool, SkBitmap)>& | 823 const base::Callback<void(bool, SkBitmap)>& |
| 826 post_decompression_callback, | 824 post_decompression_callback, |
| 827 skia::RefPtr<SkPixelRef> compressed_data, | 825 sk_sp<SkPixelRef> compressed_data, |
| 828 float scale, | 826 float scale, |
| 829 const gfx::Size& content_size) { | 827 const gfx::Size& content_size) { |
| 830 SkBitmap raw_data_small; | 828 SkBitmap raw_data_small; |
| 831 bool success = false; | 829 bool success = false; |
| 832 | 830 |
| 833 if (compressed_data.get()) { | 831 if (compressed_data.get()) { |
| 834 gfx::Size buffer_size = gfx::Size(compressed_data->info().width(), | 832 gfx::Size buffer_size = gfx::Size(compressed_data->info().width(), |
| 835 compressed_data->info().height()); | 833 compressed_data->info().height()); |
| 836 | 834 |
| 837 SkBitmap raw_data; | 835 SkBitmap raw_data; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 dst_bitmap.eraseColor(0); | 901 dst_bitmap.eraseColor(0); |
| 904 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); | 902 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); |
| 905 | 903 |
| 906 SkCanvas canvas(dst_bitmap); | 904 SkCanvas canvas(dst_bitmap); |
| 907 canvas.scale(new_scale, new_scale); | 905 canvas.scale(new_scale, new_scale); |
| 908 canvas.drawBitmap(bitmap, 0, 0, NULL); | 906 canvas.drawBitmap(bitmap, 0, 0, NULL); |
| 909 dst_bitmap.setImmutable(); | 907 dst_bitmap.setImmutable(); |
| 910 | 908 |
| 911 return std::make_pair(dst_bitmap, new_scale * scale); | 909 return std::make_pair(dst_bitmap, new_scale * scale); |
| 912 } | 910 } |
| OLD | NEW |