Chromium Code Reviews| 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_store.h" | 5 #include "chrome/browser/android/thumbnail/thumbnail_store.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config. | 562 size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config. |
| 563 size_t stride = pixel_size * raw_data_size.width(); | 563 size_t stride = pixel_size * raw_data_size.width(); |
| 564 | 564 |
| 565 size_t encoded_bytes = | 565 size_t encoded_bytes = |
| 566 etc1_get_encoded_data_size(encoded_size.width(), encoded_size.height()); | 566 etc1_get_encoded_data_size(encoded_size.width(), encoded_size.height()); |
| 567 SkImageInfo info = SkImageInfo::Make(encoded_size.width(), | 567 SkImageInfo info = SkImageInfo::Make(encoded_size.width(), |
| 568 encoded_size.height(), | 568 encoded_size.height(), |
| 569 kUnknown_SkColorType, | 569 kUnknown_SkColorType, |
| 570 kUnpremul_SkAlphaType); | 570 kUnpremul_SkAlphaType); |
| 571 skia::RefPtr<SkData> etc1_pixel_data = skia::AdoptRef( | 571 skia::RefPtr<SkData> etc1_pixel_data = skia::AdoptRef( |
| 572 SkData::NewFromMalloc(new uint8_t[encoded_bytes], encoded_bytes)); | 572 SkData::NewUninitialized(encoded_bytes)); |
| 573 skia::RefPtr<SkMallocPixelRef> etc1_pixel_ref = skia::AdoptRef( | 573 skia::RefPtr<SkMallocPixelRef> etc1_pixel_ref = skia::AdoptRef( |
| 574 SkMallocPixelRef::NewWithData(info, 0, NULL, etc1_pixel_data.get())); | 574 SkMallocPixelRef::NewWithData(info, 0, NULL, etc1_pixel_data.get())); |
|
f(malita)
2014/09/12 11:49:59
Is this safe? Looks like SkMallocPixelRef is ref-i
f(malita)
2014/09/12 11:54:34
I see it's just writable_data() asserting it gets
reed1
2014/09/12 18:00:08
Yes, the existing code is tricky that way, but sin
| |
| 575 | 575 |
| 576 etc1_pixel_ref->lockPixels(); | 576 etc1_pixel_ref->lockPixels(); |
| 577 bool success = etc1_encode_image( | 577 bool success = etc1_encode_image( |
| 578 reinterpret_cast<unsigned char*>(raw_data.getPixels()), | 578 reinterpret_cast<unsigned char*>(raw_data.getPixels()), |
| 579 raw_data_size.width(), | 579 raw_data_size.width(), |
| 580 raw_data_size.height(), | 580 raw_data_size.height(), |
| 581 pixel_size, | 581 pixel_size, |
| 582 stride, | 582 stride, |
| 583 reinterpret_cast<unsigned char*>(etc1_pixel_ref->pixels()), | 583 reinterpret_cast<unsigned char*>(etc1_pixel_ref->pixels()), |
| 584 encoded_size.width(), | 584 encoded_size.width(), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 int max_dimension = std::max(display_info.GetDisplayWidth(), | 675 int max_dimension = std::max(display_info.GetDisplayWidth(), |
| 676 display_info.GetDisplayHeight()); | 676 display_info.GetDisplayHeight()); |
| 677 | 677 |
| 678 if (content_width > max_dimension | 678 if (content_width > max_dimension |
| 679 || content_height > max_dimension | 679 || content_height > max_dimension |
| 680 || static_cast<size_t>(raw_width) > NextPowerOfTwo(max_dimension) | 680 || static_cast<size_t>(raw_width) > NextPowerOfTwo(max_dimension) |
| 681 || static_cast<size_t>(raw_height) > NextPowerOfTwo(max_dimension)) { | 681 || static_cast<size_t>(raw_height) > NextPowerOfTwo(max_dimension)) { |
| 682 return false; | 682 return false; |
| 683 } | 683 } |
| 684 | 684 |
| 685 skia::RefPtr<SkData> etc1_pixel_data; | |
| 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 scoped_ptr<uint8_t[]> raw_data = | 686 skia::RefPtr<SkData> etc1_pixel_data = |
| 688 scoped_ptr<uint8_t[]>(new uint8_t[data_size]); | 687 skia::AdoptRef(SkData::NewUninitialized(data_size)); |
| 689 | 688 |
| 690 int pixel_bytes_read = file.ReadAtCurrentPos( | 689 int pixel_bytes_read = file.ReadAtCurrentPos( |
| 691 reinterpret_cast<char*>(raw_data.get()), | 690 reinterpret_cast<char*>(etc1_pixel_data->writable_data()), |
| 692 data_size); | 691 data_size); |
| 693 | 692 |
| 694 if (pixel_bytes_read != data_size) | 693 if (pixel_bytes_read != data_size) |
| 695 return false; | 694 return false; |
| 696 | 695 |
| 697 SkImageInfo info = SkImageInfo::Make(raw_width, | 696 SkImageInfo info = SkImageInfo::Make(raw_width, |
| 698 raw_height, | 697 raw_height, |
| 699 kUnknown_SkColorType, | 698 kUnknown_SkColorType, |
| 700 kUnpremul_SkAlphaType); | 699 kUnpremul_SkAlphaType); |
| 701 | 700 |
| 702 etc1_pixel_data = skia::AdoptRef( | |
| 703 SkData::NewFromMalloc(raw_data.release(), data_size)); | |
| 704 | |
| 705 *out_pixels = skia::AdoptRef( | 701 *out_pixels = skia::AdoptRef( |
| 706 SkMallocPixelRef::NewWithData(info, | 702 SkMallocPixelRef::NewWithData(info, |
| 707 0, | 703 0, |
| 708 NULL, | 704 NULL, |
| 709 etc1_pixel_data.get())); | 705 etc1_pixel_data.get())); |
| 710 | 706 |
| 711 int extra_data_version = 0; | 707 int extra_data_version = 0; |
| 712 if (!ReadBigEndianFromFile(file, &extra_data_version)) | 708 if (!ReadBigEndianFromFile(file, &extra_data_version)) |
| 713 return false; | 709 return false; |
| 714 | 710 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 dst_bitmap.eraseColor(0); | 837 dst_bitmap.eraseColor(0); |
| 842 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); | 838 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); |
| 843 | 839 |
| 844 SkCanvas canvas(dst_bitmap); | 840 SkCanvas canvas(dst_bitmap); |
| 845 canvas.scale(new_scale, new_scale); | 841 canvas.scale(new_scale, new_scale); |
| 846 canvas.drawBitmap(bitmap, 0, 0, NULL); | 842 canvas.drawBitmap(bitmap, 0, 0, NULL); |
| 847 dst_bitmap.setImmutable(); | 843 dst_bitmap.setImmutable(); |
| 848 | 844 |
| 849 return std::make_pair(dst_bitmap, new_scale * scale); | 845 return std::make_pair(dst_bitmap, new_scale * scale); |
| 850 } | 846 } |
| OLD | NEW |