| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 // Corner shadow size. | 56 // Corner shadow size. |
| 57 const int kCornerDecorationSize = 15; | 57 const int kCornerDecorationSize = 15; |
| 58 // Side shadow size. | 58 // Side shadow size. |
| 59 const int kSideDecorationSize = 2; | 59 const int kSideDecorationSize = 2; |
| 60 | 60 |
| 61 // Reads and decodes a PNG image to a bitmap. Returns true on success. The PNG | 61 // Reads and decodes a PNG image to a bitmap. Returns true on success. The PNG |
| 62 // should have been encoded using |gfx::PNGCodec::Encode|. | 62 // should have been encoded using |gfx::PNGCodec::Encode|. |
| 63 bool ReadPNGFile(const FilePath& file_path, SkBitmap* bitmap) { | 63 bool ReadPNGFile(const FilePath& file_path, SkBitmap* bitmap) { |
| 64 DCHECK(bitmap); | 64 DCHECK(bitmap); |
| 65 FilePath abs_path(file_path); |
| 66 if (!file_util::AbsolutePath(&abs_path)) |
| 67 return false; |
| 68 |
| 65 std::string png_data; | 69 std::string png_data; |
| 66 return file_util::ReadFileToString(file_path, &png_data) && | 70 return file_util::ReadFileToString(abs_path, &png_data) && |
| 67 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), | 71 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), |
| 68 png_data.length(), | 72 png_data.length(), |
| 69 bitmap); | 73 bitmap); |
| 70 } | 74 } |
| 71 | 75 |
| 72 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The | 76 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The |
| 73 // parent directory does not have to exist. | 77 // parent directory does not have to exist. |
| 74 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { | 78 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { |
| 75 std::vector<unsigned char> png_data; | 79 std::vector<unsigned char> png_data; |
| 76 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) && | 80 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) && |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 {160, 100, 0, 0, 0} | 594 {160, 100, 0, 0, 0} |
| 591 }; | 595 }; |
| 592 const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel); | 596 const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel); |
| 593 | 597 |
| 594 gfx::Size container_size(400, 300); | 598 gfx::Size container_size(400, 300); |
| 595 FilePath url = | 599 FilePath url = |
| 596 test_data_dir().AppendASCII("pixel_canvas2d.html"); | 600 test_data_dir().AppendASCII("pixel_canvas2d.html"); |
| 597 RunPixelTest(container_size, url, ref_img_revision_update, | 601 RunPixelTest(container_size, url, ref_img_revision_update, |
| 598 ref_pixels, ref_pixel_count); | 602 ref_pixels, ref_pixel_count); |
| 599 } | 603 } |
| OLD | NEW |