| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" |
| 6 |
| 7 #include "webkit/tools/test_shell/image_decoder_unittest.h" |
| 8 |
| 9 #if !defined(OS_WIN) |
| 10 #include <unistd.h> |
| 11 #endif |
| 12 |
| 5 #include "skia/ext/vector_canvas.h" | 13 #include "skia/ext/vector_canvas.h" |
| 6 | 14 |
| 7 #include <vector> | 15 #include "PNGImageDecoder.h" |
| 8 | 16 |
| 9 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 11 #include "base/gfx/gdi_util.h" | 19 #include "base/gfx/gdi_util.h" |
| 12 #include "base/gfx/png_decoder.h" | |
| 13 #include "base/gfx/png_encoder.h" | 20 #include "base/gfx/png_encoder.h" |
| 14 #include "base/gfx/size.h" | |
| 15 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 16 #include "base/string_util.h" | 22 #include "base/string_util.h" |
| 17 #include "base/win_util.h" | 23 |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 25 |
| 20 #include "SkDashPathEffect.h" | 26 #include "SkDashPathEffect.h" |
| 21 | 27 |
| 22 namespace skia { | 28 namespace skia { |
| 23 | 29 |
| 24 namespace { | 30 namespace { |
| 25 | 31 |
| 26 const wchar_t* const kGenerateSwitch = L"vector-canvas-generate"; | 32 const wchar_t* const kGenerateSwitch = L"vector-canvas-generate"; |
| 27 | 33 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 72 |
| 67 DISALLOW_EVIL_CONSTRUCTORS(Bitmap); | 73 DISALLOW_EVIL_CONSTRUCTORS(Bitmap); |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 // Lightweight raw-bitmap management. The image, once initialized, is immuable. | 76 // Lightweight raw-bitmap management. The image, once initialized, is immuable. |
| 71 // It is mainly used for comparison. | 77 // It is mainly used for comparison. |
| 72 class Image { | 78 class Image { |
| 73 public: | 79 public: |
| 74 // Creates the image from the given filename on disk. | 80 // Creates the image from the given filename on disk. |
| 75 Image(const std::wstring& filename) : ignore_alpha_(true) { | 81 Image(const std::wstring& filename) : ignore_alpha_(true) { |
| 76 std::string compressed; | 82 Vector<char> compressed; |
| 77 file_util::ReadFileToString(filename, &compressed); | 83 ReadFileToVector(filename, &compressed); |
| 78 EXPECT_TRUE(compressed.size()); | 84 EXPECT_TRUE(compressed.size()); |
| 79 | 85 WebCore::PNGImageDecoder decoder; |
| 80 int w; | 86 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); |
| 81 int h; | 87 SetSkBitmap(decoder.frameBufferAtIndex(0)->bitmap()); |
| 82 EXPECT_TRUE(PNGDecoder::Decode( | |
| 83 reinterpret_cast<const unsigned char*>(compressed.c_str()), | |
| 84 compressed.size(), PNGDecoder::FORMAT_BGRA, &data_, &w, &h)); | |
| 85 size_.SetSize(w, h); | |
| 86 row_length_ = w * sizeof(uint32); | |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Loads the image from a canvas. | 90 // Loads the image from a canvas. |
| 90 Image(const skia::PlatformCanvasWin& canvas) : ignore_alpha_(true) { | 91 Image(const skia::PlatformCanvasWin& canvas) : ignore_alpha_(true) { |
| 91 // Use a different way to access the bitmap. The normal way would be to | 92 // Use a different way to access the bitmap. The normal way would be to |
| 92 // query the SkBitmap. | 93 // query the SkBitmap. |
| 93 HDC context = canvas.getTopPlatformDevice().getBitmapDC(); | 94 HDC context = canvas.getTopPlatformDevice().getBitmapDC(); |
| 94 HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP); | 95 HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP); |
| 95 EXPECT_TRUE(bitmap != NULL); | 96 EXPECT_TRUE(bitmap != NULL); |
| 96 // Initialize the clip region to the entire bitmap. | 97 // Initialize the clip region to the entire bitmap. |
| 97 BITMAP bitmap_data; | 98 BITMAP bitmap_data; |
| 98 EXPECT_EQ(GetObject(bitmap, sizeof(BITMAP), &bitmap_data), | 99 EXPECT_EQ(GetObject(bitmap, sizeof(BITMAP), &bitmap_data), sizeof(BITMAP)); |
| 99 sizeof(BITMAP)); | 100 width_ = bitmap_data.bmWidth; |
| 100 size_.SetSize(bitmap_data.bmWidth, bitmap_data.bmHeight); | 101 height_ = bitmap_data.bmHeight; |
| 101 row_length_ = bitmap_data.bmWidthBytes; | 102 row_length_ = bitmap_data.bmWidthBytes; |
| 102 size_t size = row_length_ * size_.height(); | 103 size_t size = row_length_ * height_; |
| 103 data_.resize(size); | 104 data_.resize(size); |
| 104 memcpy(&*data_.begin(), bitmap_data.bmBits, size); | 105 memcpy(&*data_.begin(), bitmap_data.bmBits, size); |
| 105 } | 106 } |
| 106 | 107 |
| 107 // Loads the image from a canvas. | 108 // Loads the image from a canvas. |
| 108 Image(const SkBitmap& bitmap) : ignore_alpha_(true) { | 109 Image(const SkBitmap& bitmap) : ignore_alpha_(true) { |
| 109 SkAutoLockPixels lock(bitmap); | 110 SetSkBitmap(bitmap); |
| 110 size_.SetSize(bitmap.width(), bitmap.height()); | |
| 111 row_length_ = static_cast<int>(bitmap.rowBytes()); | |
| 112 size_t size = row_length_ * size_.height(); | |
| 113 data_.resize(size); | |
| 114 memcpy(&*data_.begin(), bitmap.getAddr(0, 0), size); | |
| 115 } | 111 } |
| 116 | 112 |
| 117 const gfx::Size& size() const { | 113 int width() const { return width_; } |
| 118 return size_; | 114 int height() const { return height_; } |
| 119 } | 115 int row_length() const { return row_length_; } |
| 120 | |
| 121 int row_length() const { | |
| 122 return row_length_; | |
| 123 } | |
| 124 | 116 |
| 125 // Save the image to a png file. Used to create the initial test files. | 117 // Save the image to a png file. Used to create the initial test files. |
| 126 void SaveToFile(const std::wstring& filename) { | 118 void SaveToFile(const std::wstring& filename) { |
| 127 std::vector<unsigned char> compressed; | 119 std::vector<unsigned char> compressed; |
| 128 ASSERT_TRUE(PNGEncoder::Encode(&*data_.begin(), | 120 ASSERT_TRUE(PNGEncoder::Encode(&*data_.begin(), |
| 129 PNGEncoder::FORMAT_BGRA, | 121 PNGEncoder::FORMAT_BGRA, |
| 130 size_.width(), | 122 width_, |
| 131 size_.height(), | 123 height_, |
| 132 row_length_, | 124 row_length_, |
| 133 true, | 125 true, |
| 134 &compressed)); | 126 &compressed)); |
| 135 ASSERT_TRUE(compressed.size()); | 127 ASSERT_TRUE(compressed.size()); |
| 136 FILE* f = file_util::OpenFile(filename, "wb"); | 128 FILE* f = file_util::OpenFile(filename, "wb"); |
| 137 ASSERT_TRUE(f); | 129 ASSERT_TRUE(f); |
| 138 ASSERT_EQ(fwrite(&*compressed.begin(), 1, compressed.size(), f), | 130 ASSERT_EQ(fwrite(&*compressed.begin(), 1, compressed.size(), f), |
| 139 compressed.size()); | 131 compressed.size()); |
| 140 file_util::CloseFile(f); | 132 file_util::CloseFile(f); |
| 141 } | 133 } |
| 142 | 134 |
| 143 // Returns the percentage of the image that is different from the other, | 135 // Returns the percentage of the image that is different from the other, |
| 144 // between 0 and 100. | 136 // between 0 and 100. |
| 145 double PercentageDifferent(const Image& rhs) const { | 137 double PercentageDifferent(const Image& rhs) const { |
| 146 if (size_ != rhs.size_ || row_length_ != rhs.row_length_ || | 138 if (width_ != rhs.width_ || |
| 147 size_.width() == 0 || size_.height() == 0) | 139 height_ != rhs.height_ || |
| 140 row_length_ != rhs.row_length_ || |
| 141 width_ == 0 || |
| 142 height_ == 0) { |
| 148 return 100.; // When of different size or empty, they are 100% different. | 143 return 100.; // When of different size or empty, they are 100% different. |
| 149 | 144 } |
| 150 // Compute pixels different in the overlap | 145 // Compute pixels different in the overlap |
| 151 int pixels_different = 0; | 146 int pixels_different = 0; |
| 152 for (int y = 0; y < size_.height(); ++y) { | 147 for (int y = 0; y < height_; ++y) { |
| 153 for (int x = 0; x < size_.width(); ++x) { | 148 for (int x = 0; x < width_; ++x) { |
| 154 uint32_t lhs_pixel = pixel_at(x, y); | 149 uint32_t lhs_pixel = pixel_at(x, y); |
| 155 uint32_t rhs_pixel = rhs.pixel_at(x, y); | 150 uint32_t rhs_pixel = rhs.pixel_at(x, y); |
| 156 if (lhs_pixel != rhs_pixel) | 151 if (lhs_pixel != rhs_pixel) |
| 157 ++pixels_different; | 152 ++pixels_different; |
| 158 } | 153 } |
| 159 } | 154 } |
| 160 | 155 |
| 161 // Like the WebKit ImageDiff tool, we define percentage different in terms | 156 // Like the WebKit ImageDiff tool, we define percentage different in terms |
| 162 // of the size of the 'actual' bitmap. | 157 // of the size of the 'actual' bitmap. |
| 163 double total_pixels = static_cast<double>(size_.width()) * | 158 double total_pixels = static_cast<double>(width_) * |
| 164 static_cast<double>(size_.height()); | 159 static_cast<double>(height_); |
| 165 return static_cast<double>(pixels_different) / total_pixels * 100.; | 160 return static_cast<double>(pixels_different) / total_pixels * 100.; |
| 166 } | 161 } |
| 167 | 162 |
| 168 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location, | 163 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location, |
| 169 // depending on ignore_alpha_. | 164 // depending on ignore_alpha_. |
| 170 uint32 pixel_at(int x, int y) const { | 165 uint32 pixel_at(int x, int y) const { |
| 171 EXPECT_TRUE(x >= 0 && x < size_.width()); | 166 EXPECT_TRUE(x >= 0 && x < width_); |
| 172 EXPECT_TRUE(y >= 0 && y < size_.height()); | 167 EXPECT_TRUE(y >= 0 && y < height_); |
| 173 const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin()); | 168 const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin()); |
| 174 const uint32* data_row = data + y * row_length_ / sizeof(uint32); | 169 const uint32* data_row = data + y * row_length_ / sizeof(uint32); |
| 175 if (ignore_alpha_) | 170 if (ignore_alpha_) |
| 176 return data_row[x] & 0xFFFFFF; // Strip out A. | 171 return data_row[x] & 0xFFFFFF; // Strip out A. |
| 177 else | 172 else |
| 178 return data_row[x]; | 173 return data_row[x]; |
| 179 } | 174 } |
| 180 | 175 |
| 176 protected: |
| 177 void SetSkBitmap(const SkBitmap& bitmap) { |
| 178 SkAutoLockPixels lock(bitmap); |
| 179 width_ = bitmap.width(); |
| 180 height_ = bitmap.height(); |
| 181 row_length_ = static_cast<int>(bitmap.rowBytes()); |
| 182 size_t size = row_length_ * height_; |
| 183 data_.resize(size); |
| 184 memcpy(&*data_.begin(), bitmap.getAddr(0, 0), size); |
| 185 } |
| 186 |
| 181 private: | 187 private: |
| 182 // Pixel dimensions of the image. | 188 // Pixel dimensions of the image. |
| 183 gfx::Size size_; | 189 int width_; |
| 190 int height_; |
| 184 | 191 |
| 185 // Length of a line in bytes. | 192 // Length of a line in bytes. |
| 186 int row_length_; | 193 int row_length_; |
| 187 | 194 |
| 188 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's | 195 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's |
| 189 // 0xABGR). | 196 // 0xABGR). |
| 190 std::vector<unsigned char> data_; | 197 std::vector<unsigned char> data_; |
| 191 | 198 |
| 192 // Flag to signal if the comparison functions should ignore the alpha channel. | 199 // Flag to signal if the comparison functions should ignore the alpha channel. |
| 193 const bool ignore_alpha_; | 200 const bool ignore_alpha_; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 *pixel_addr = SkColorSetARGB( | 313 *pixel_addr = SkColorSetARGB( |
| 307 SkColorGetA(color), | 314 SkColorGetA(color), |
| 308 (SkColorGetR(color) * 255 + alpha_offset) / alpha, | 315 (SkColorGetR(color) * 255 + alpha_offset) / alpha, |
| 309 (SkColorGetG(color) * 255 + alpha_offset) / alpha, | 316 (SkColorGetG(color) * 255 + alpha_offset) / alpha, |
| 310 (SkColorGetB(color) * 255 + alpha_offset) / alpha); | 317 (SkColorGetB(color) * 255 + alpha_offset) / alpha); |
| 311 } | 318 } |
| 312 } | 319 } |
| 313 } | 320 } |
| 314 } | 321 } |
| 315 | 322 |
| 316 void LoadPngFileToSkBitmap(const std::wstring& file, SkBitmap* bitmap) { | 323 void LoadPngFileToSkBitmap(const std::wstring& filename, SkBitmap* bitmap) { |
| 317 std::string compressed; | 324 Vector<char> compressed; |
| 318 file_util::ReadFileToString(file, &compressed); | 325 ReadFileToVector(filename, &compressed); |
| 319 EXPECT_TRUE(compressed.size()); | 326 EXPECT_TRUE(compressed.size()); |
| 320 // Extra-lame. If you care, fix it. | 327 WebCore::PNGImageDecoder decoder; |
| 321 std::vector<unsigned char> data; | 328 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); |
| 322 data.assign(reinterpret_cast<const unsigned char*>(compressed.c_str()), | 329 *bitmap = decoder.frameBufferAtIndex(0)->bitmap(); |
| 323 reinterpret_cast<const unsigned char*>(compressed.c_str() + | |
| 324 compressed.size())); | |
| 325 EXPECT_TRUE(PNGDecoder::Decode(&data, bitmap)); | |
| 326 EXPECT_FALSE(bitmap->isOpaque()); | 330 EXPECT_FALSE(bitmap->isOpaque()); |
| 327 Premultiply(*bitmap); | 331 Premultiply(*bitmap); |
| 328 } | 332 } |
| 329 | 333 |
| 330 } // namespace | 334 } // namespace |
| 331 | 335 |
| 332 // Streams an image. | 336 // Streams an image. |
| 333 inline std::ostream& operator<<(std::ostream& out, const Image& image) { | 337 inline std::ostream& operator<<(std::ostream& out, const Image& image) { |
| 334 return out << "Image(" << image.size().width() << ", " | 338 return out << "Image(" << image.width() << ", " |
| 335 << image.size().height() << ", " << image.row_length() << ")"; | 339 << image.height() << ", " << image.row_length() << ")"; |
| 336 } | 340 } |
| 337 | 341 |
| 338 // Runs simultaneously the same drawing commands on VectorCanvas and | 342 // Runs simultaneously the same drawing commands on VectorCanvas and |
| 339 // PlatformCanvas and compare the results. | 343 // PlatformCanvas and compare the results. |
| 340 class VectorCanvasTest : public ImageTest { | 344 class VectorCanvasTest : public ImageTest { |
| 341 public: | 345 public: |
| 342 typedef ImageTest parent; | 346 typedef ImageTest parent; |
| 343 | 347 |
| 344 VectorCanvasTest() : parent(CurrentMode()), compare_canvas_(true) { | 348 VectorCanvasTest() : parent(CurrentMode()), compare_canvas_(true) { |
| 345 } | 349 } |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 | 787 |
| 784 SkPath path; | 788 SkPath path; |
| 785 path.addCircle(50, 75, 10); | 789 path.addCircle(50, 75, 10); |
| 786 vcanvas_->drawPath(path, paint); | 790 vcanvas_->drawPath(path, paint); |
| 787 pcanvas_->drawPath(path, paint); | 791 pcanvas_->drawPath(path, paint); |
| 788 EXPECT_EQ(0., ProcessImage(L"circle")); | 792 EXPECT_EQ(0., ProcessImage(L"circle")); |
| 789 } | 793 } |
| 790 } | 794 } |
| 791 | 795 |
| 792 TEST_F(VectorCanvasTest, Bitmaps) { | 796 TEST_F(VectorCanvasTest, Bitmaps) { |
| 793 // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests | |
| 794 // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't | |
| 795 // really care about Windows 2000 pixel colors. | |
| 796 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 797 return; | |
| 798 { | 797 { |
| 799 SkBitmap bitmap; | 798 SkBitmap bitmap; |
| 800 LoadPngFileToSkBitmap(test_file(L"bitmap_opaque.png"), &bitmap); | 799 LoadPngFileToSkBitmap(test_file(L"bitmap_opaque.png"), &bitmap); |
| 801 vcanvas_->drawBitmap(bitmap, 13, 3, NULL); | 800 vcanvas_->drawBitmap(bitmap, 13, 3, NULL); |
| 802 pcanvas_->drawBitmap(bitmap, 13, 3, NULL); | 801 pcanvas_->drawBitmap(bitmap, 13, 3, NULL); |
| 803 EXPECT_EQ(0., ProcessImage(L"opaque")); | 802 EXPECT_EQ(0., ProcessImage(L"opaque")); |
| 804 } | 803 } |
| 805 | 804 |
| 806 { | 805 { |
| 807 SkBitmap bitmap; | 806 SkBitmap bitmap; |
| 808 LoadPngFileToSkBitmap(test_file(L"bitmap_alpha.png"), &bitmap); | 807 LoadPngFileToSkBitmap(test_file(L"bitmap_alpha.png"), &bitmap); |
| 809 vcanvas_->drawBitmap(bitmap, 5, 15, NULL); | 808 vcanvas_->drawBitmap(bitmap, 5, 15, NULL); |
| 810 pcanvas_->drawBitmap(bitmap, 5, 15, NULL); | 809 pcanvas_->drawBitmap(bitmap, 5, 15, NULL); |
| 811 EXPECT_EQ(0., ProcessImage(L"alpha")); | 810 EXPECT_EQ(0., ProcessImage(L"alpha")); |
| 812 } | 811 } |
| 813 } | 812 } |
| 814 | 813 |
| 815 TEST_F(VectorCanvasTest, ClippingRect) { | 814 TEST_F(VectorCanvasTest, ClippingRect) { |
| 816 // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests | |
| 817 // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't | |
| 818 // really care about Windows 2000 pixel colors. | |
| 819 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 820 return; | |
| 821 SkBitmap bitmap; | 815 SkBitmap bitmap; |
| 822 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); | 816 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); |
| 823 SkRect rect; | 817 SkRect rect; |
| 824 rect.fLeft = 2; | 818 rect.fLeft = 2; |
| 825 rect.fTop = 2; | 819 rect.fTop = 2; |
| 826 rect.fRight = 30.5f; | 820 rect.fRight = 30.5f; |
| 827 rect.fBottom = 30.5f; | 821 rect.fBottom = 30.5f; |
| 828 vcanvas_->clipRect(rect); | 822 vcanvas_->clipRect(rect); |
| 829 pcanvas_->clipRect(rect); | 823 pcanvas_->clipRect(rect); |
| 830 | 824 |
| 831 vcanvas_->drawBitmap(bitmap, 13, 3, NULL); | 825 vcanvas_->drawBitmap(bitmap, 13, 3, NULL); |
| 832 pcanvas_->drawBitmap(bitmap, 13, 3, NULL); | 826 pcanvas_->drawBitmap(bitmap, 13, 3, NULL); |
| 833 EXPECT_EQ(0., ProcessImage(L"rect")); | 827 EXPECT_EQ(0., ProcessImage(L"rect")); |
| 834 } | 828 } |
| 835 | 829 |
| 836 TEST_F(VectorCanvasTest, ClippingPath) { | 830 TEST_F(VectorCanvasTest, ClippingPath) { |
| 837 // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests | |
| 838 // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't | |
| 839 // really care about Windows 2000 pixel colors. | |
| 840 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 841 return; | |
| 842 SkBitmap bitmap; | 831 SkBitmap bitmap; |
| 843 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); | 832 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); |
| 844 SkPath path; | 833 SkPath path; |
| 845 path.addCircle(20, 20, 10); | 834 path.addCircle(20, 20, 10); |
| 846 vcanvas_->clipPath(path); | 835 vcanvas_->clipPath(path); |
| 847 pcanvas_->clipPath(path); | 836 pcanvas_->clipPath(path); |
| 848 | 837 |
| 849 vcanvas_->drawBitmap(bitmap, 14, 3, NULL); | 838 vcanvas_->drawBitmap(bitmap, 14, 3, NULL); |
| 850 pcanvas_->drawBitmap(bitmap, 14, 3, NULL); | 839 pcanvas_->drawBitmap(bitmap, 14, 3, NULL); |
| 851 EXPECT_EQ(0., ProcessImage(L"path")); | 840 EXPECT_EQ(0., ProcessImage(L"path")); |
| 852 } | 841 } |
| 853 | 842 |
| 854 TEST_F(VectorCanvasTest, ClippingCombined) { | 843 TEST_F(VectorCanvasTest, ClippingCombined) { |
| 855 // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests | |
| 856 // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't | |
| 857 // really care about Windows 2000 pixel colors. | |
| 858 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 859 return; | |
| 860 SkBitmap bitmap; | 844 SkBitmap bitmap; |
| 861 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); | 845 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); |
| 862 | 846 |
| 863 SkRect rect; | 847 SkRect rect; |
| 864 rect.fLeft = 2; | 848 rect.fLeft = 2; |
| 865 rect.fTop = 2; | 849 rect.fTop = 2; |
| 866 rect.fRight = 30.5f; | 850 rect.fRight = 30.5f; |
| 867 rect.fBottom = 30.5f; | 851 rect.fBottom = 30.5f; |
| 868 vcanvas_->clipRect(rect); | 852 vcanvas_->clipRect(rect); |
| 869 pcanvas_->clipRect(rect); | 853 pcanvas_->clipRect(rect); |
| 870 SkPath path; | 854 SkPath path; |
| 871 path.addCircle(20, 20, 10); | 855 path.addCircle(20, 20, 10); |
| 872 vcanvas_->clipPath(path, SkRegion::kUnion_Op); | 856 vcanvas_->clipPath(path, SkRegion::kUnion_Op); |
| 873 pcanvas_->clipPath(path, SkRegion::kUnion_Op); | 857 pcanvas_->clipPath(path, SkRegion::kUnion_Op); |
| 874 | 858 |
| 875 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); | 859 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); |
| 876 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); | 860 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); |
| 877 EXPECT_EQ(0., ProcessImage(L"combined")); | 861 EXPECT_EQ(0., ProcessImage(L"combined")); |
| 878 } | 862 } |
| 879 | 863 |
| 880 TEST_F(VectorCanvasTest, ClippingIntersect) { | 864 TEST_F(VectorCanvasTest, ClippingIntersect) { |
| 881 // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests | |
| 882 // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't | |
| 883 // really care about Windows 2000 pixel colors. | |
| 884 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 885 return; | |
| 886 SkBitmap bitmap; | 865 SkBitmap bitmap; |
| 887 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); | 866 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); |
| 888 | 867 |
| 889 SkRect rect; | 868 SkRect rect; |
| 890 rect.fLeft = 2; | 869 rect.fLeft = 2; |
| 891 rect.fTop = 2; | 870 rect.fTop = 2; |
| 892 rect.fRight = 30.5f; | 871 rect.fRight = 30.5f; |
| 893 rect.fBottom = 30.5f; | 872 rect.fBottom = 30.5f; |
| 894 vcanvas_->clipRect(rect); | 873 vcanvas_->clipRect(rect); |
| 895 pcanvas_->clipRect(rect); | 874 pcanvas_->clipRect(rect); |
| 896 SkPath path; | 875 SkPath path; |
| 897 path.addCircle(23, 23, 15); | 876 path.addCircle(23, 23, 15); |
| 898 vcanvas_->clipPath(path); | 877 vcanvas_->clipPath(path); |
| 899 pcanvas_->clipPath(path); | 878 pcanvas_->clipPath(path); |
| 900 | 879 |
| 901 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); | 880 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); |
| 902 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); | 881 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); |
| 903 EXPECT_EQ(0., ProcessImage(L"intersect")); | 882 EXPECT_EQ(0., ProcessImage(L"intersect")); |
| 904 } | 883 } |
| 905 | 884 |
| 906 TEST_F(VectorCanvasTest, ClippingClean) { | 885 TEST_F(VectorCanvasTest, ClippingClean) { |
| 907 // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests | |
| 908 // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't | |
| 909 // really care about Windows 2000 pixel colors. | |
| 910 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 911 return; | |
| 912 SkBitmap bitmap; | 886 SkBitmap bitmap; |
| 913 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); | 887 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); |
| 914 { | 888 { |
| 915 SkRegion old_region(pcanvas_->getTotalClip()); | 889 SkRegion old_region(pcanvas_->getTotalClip()); |
| 916 SkRect rect; | 890 SkRect rect; |
| 917 rect.fLeft = 2; | 891 rect.fLeft = 2; |
| 918 rect.fTop = 2; | 892 rect.fTop = 2; |
| 919 rect.fRight = 30.5f; | 893 rect.fRight = 30.5f; |
| 920 rect.fBottom = 30.5f; | 894 rect.fBottom = 30.5f; |
| 921 vcanvas_->clipRect(rect); | 895 vcanvas_->clipRect(rect); |
| 922 pcanvas_->clipRect(rect); | 896 pcanvas_->clipRect(rect); |
| 923 | 897 |
| 924 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); | 898 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); |
| 925 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); | 899 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); |
| 926 EXPECT_EQ(0., ProcessImage(L"clipped")); | 900 EXPECT_EQ(0., ProcessImage(L"clipped")); |
| 927 vcanvas_->clipRegion(old_region, SkRegion::kReplace_Op); | 901 vcanvas_->clipRegion(old_region, SkRegion::kReplace_Op); |
| 928 pcanvas_->clipRegion(old_region, SkRegion::kReplace_Op); | 902 pcanvas_->clipRegion(old_region, SkRegion::kReplace_Op); |
| 929 } | 903 } |
| 930 { | 904 { |
| 931 // Verify that the clipping region has been fixed back. | 905 // Verify that the clipping region has been fixed back. |
| 932 vcanvas_->drawBitmap(bitmap, 55, 3, NULL); | 906 vcanvas_->drawBitmap(bitmap, 55, 3, NULL); |
| 933 pcanvas_->drawBitmap(bitmap, 55, 3, NULL); | 907 pcanvas_->drawBitmap(bitmap, 55, 3, NULL); |
| 934 EXPECT_EQ(0., ProcessImage(L"unclipped")); | 908 EXPECT_EQ(0., ProcessImage(L"unclipped")); |
| 935 } | 909 } |
| 936 } | 910 } |
| 937 | 911 |
| 938 TEST_F(VectorCanvasTest, Matrix) { | 912 TEST_F(VectorCanvasTest, Matrix) { |
| 939 // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests | |
| 940 // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't | |
| 941 // really care about Windows 2000 pixel colors. | |
| 942 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 943 return; | |
| 944 SkBitmap bitmap; | 913 SkBitmap bitmap; |
| 945 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); | 914 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); |
| 946 { | 915 { |
| 947 vcanvas_->translate(15, 3); | 916 vcanvas_->translate(15, 3); |
| 948 pcanvas_->translate(15, 3); | 917 pcanvas_->translate(15, 3); |
| 949 vcanvas_->drawBitmap(bitmap, 0, 0, NULL); | 918 vcanvas_->drawBitmap(bitmap, 0, 0, NULL); |
| 950 pcanvas_->drawBitmap(bitmap, 0, 0, NULL); | 919 pcanvas_->drawBitmap(bitmap, 0, 0, NULL); |
| 951 EXPECT_EQ(0., ProcessImage(L"translate1")); | 920 EXPECT_EQ(0., ProcessImage(L"translate1")); |
| 952 } | 921 } |
| 953 { | 922 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 978 { | 947 { |
| 979 vcanvas_->rotate(67); | 948 vcanvas_->rotate(67); |
| 980 pcanvas_->rotate(67); | 949 pcanvas_->rotate(67); |
| 981 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); | 950 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); |
| 982 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); | 951 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); |
| 983 EXPECT_EQ(0., ProcessImage(L"rotate")); | 952 EXPECT_EQ(0., ProcessImage(L"rotate")); |
| 984 } | 953 } |
| 985 } | 954 } |
| 986 | 955 |
| 987 } // namespace skia | 956 } // namespace skia |
| OLD | NEW |