OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "cc/test/pixel_test_utils.h" | 5 #include "cc/test/pixel_test_utils.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "ui/gfx/codec/png_codec.h" | 10 #include "ui/gfx/codec/png_codec.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { | 14 bool WritePNGFile(const SkBitmap& bitmap, const base::FilePath& file_path) { |
15 std::vector<unsigned char> png_data; | 15 std::vector<unsigned char> png_data; |
16 const bool discard_transparency = true; | 16 const bool discard_transparency = true; |
17 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, | 17 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, |
18 discard_transparency, | 18 discard_transparency, |
19 &png_data) && | 19 &png_data) && |
20 file_util::CreateDirectory(file_path.DirName())) { | 20 file_util::CreateDirectory(file_path.DirName())) { |
21 char* data = reinterpret_cast<char*>(&png_data[0]); | 21 char* data = reinterpret_cast<char*>(&png_data[0]); |
22 int size = static_cast<int>(png_data.size()); | 22 int size = static_cast<int>(png_data.size()); |
23 return file_util::WriteFile(file_path, data, size) == size; | 23 return file_util::WriteFile(file_path, data, size) == size; |
24 } | 24 } |
25 return false; | 25 return false; |
26 } | 26 } |
27 | 27 |
28 bool ReadPNGFile(const FilePath& file_path, SkBitmap* bitmap) { | 28 bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) { |
29 DCHECK(bitmap); | 29 DCHECK(bitmap); |
30 std::string png_data; | 30 std::string png_data; |
31 return file_util::ReadFileToString(file_path, &png_data) && | 31 return file_util::ReadFileToString(file_path, &png_data) && |
32 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), | 32 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), |
33 png_data.length(), | 33 png_data.length(), |
34 bitmap); | 34 bitmap); |
35 } | 35 } |
36 | 36 |
37 bool IsSameAsPNGFile(const SkBitmap& gen_bmp, FilePath ref_img_path) { | 37 bool IsSameAsPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path) { |
38 SkBitmap ref_bmp; | 38 SkBitmap ref_bmp; |
39 if (!ReadPNGFile(ref_img_path, &ref_bmp)) { | 39 if (!ReadPNGFile(ref_img_path, &ref_bmp)) { |
40 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); | 40 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 if (ref_bmp.width() != gen_bmp.width() || | 44 if (ref_bmp.width() != gen_bmp.width() || |
45 ref_bmp.height() != gen_bmp.height()) { | 45 ref_bmp.height() != gen_bmp.height()) { |
46 LOG(ERROR) | 46 LOG(ERROR) |
47 << "Dimensions do not match (Expected) vs (Actual):" | 47 << "Dimensions do not match (Expected) vs (Actual):" |
(...skipping 21 matching lines...) Expand all Loading... |
69 | 69 |
70 if (diff_pixels_count != 0) { | 70 if (diff_pixels_count != 0) { |
71 LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count; | 71 LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count; |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 return true; | 75 return true; |
76 } | 76 } |
77 | 77 |
78 } // namespace cc | 78 } // namespace cc |
OLD | NEW |