diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 17:07:29 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 17:07:29 +0000 |
commit | 21697ac3e0beceb79c2db62124ff0b6187b0c132 (patch) | |
tree | 977eed16c67b4e8e2e6faa727ee645d5ad910c74 /skia | |
parent | 67ef2be4c9311dd7acf703effdc214f46a53956a (diff) | |
download | chromium_src-21697ac3e0beceb79c2db62124ff0b6187b0c132.zip chromium_src-21697ac3e0beceb79c2db62124ff0b6187b0c132.tar.gz chromium_src-21697ac3e0beceb79c2db62124ff0b6187b0c132.tar.bz2 |
Reverting 8462,8458 since it broke the linux builder.
Review URL: http://codereview.chromium.org/18668
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8463 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/image_operations_unittest.cc | 5 | ||||
-rw-r--r-- | skia/ext/platform_canvas_unittest.cc | 34 | ||||
-rw-r--r-- | skia/ext/vector_canvas_unittest.cc | 147 |
3 files changed, 111 insertions, 75 deletions
diff --git a/skia/ext/image_operations_unittest.cc b/skia/ext/image_operations_unittest.cc index 27e3fcc..1a32bfd 100644 --- a/skia/ext/image_operations_unittest.cc +++ b/skia/ext/image_operations_unittest.cc @@ -132,8 +132,8 @@ TEST(ImageOperations, ResampleToSame) { // Do a resize of the full bitmap to the same size. The lanczos filter is good // enough that we should get exactly the same image for output. - SkBitmap results = skia::ImageOperations::Resize( - src, skia::ImageOperations::RESIZE_LANCZOS3, src_w, src_h); + SkBitmap results = gfx::ImageOperations::Resize( + src, gfx::ImageOperations::RESIZE_LANCZOS3, gfx::Size(src_w, src_h)); ASSERT_EQ(src_w, results.width()); ASSERT_EQ(src_h, results.height()); @@ -145,3 +145,4 @@ TEST(ImageOperations, ResampleToSame) { } } } + diff --git a/skia/ext/platform_canvas_unittest.cc b/skia/ext/platform_canvas_unittest.cc index ea6d5b3..d382477 100644 --- a/skia/ext/platform_canvas_unittest.cc +++ b/skia/ext/platform_canvas_unittest.cc @@ -6,7 +6,9 @@ #include "build/build_config.h" -#if !defined(OS_WIN) +#if defined(OS_WIN) +#include <windows.h> +#else #include <unistd.h> #endif @@ -48,7 +50,8 @@ bool VerifyRect(const PlatformCanvas& canvas, // Checks whether there is a white canvas with a black square at the given // location in pixels (not in the canvas coordinate system). -bool VerifyBlackRect(const PlatformCanvas& canvas, int x, int y, int w, int h) { +// TODO(ericroman): rename Square to Rect +bool VerifyBlackSquare(const PlatformCanvas& canvas, int x, int y, int w, int h) { return VerifyRect(canvas, SK_ColorWHITE, SK_ColorBLACK, x, y, w, h); } @@ -158,7 +161,7 @@ TEST(PlatformCanvas, SkLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); canvas.drawColor(SK_ColorBLACK); } - EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); } // Test native clipping. @@ -199,7 +202,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, 0, 0, 100, 100); } - EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); // Make a layer and fill it partially to make sure the translation is correct. canvas.drawColor(SK_ColorWHITE); @@ -207,7 +210,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); } - EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); // Add a clip on the layer and fill to make sure clip is correct. canvas.drawColor(SK_ColorWHITE); @@ -218,7 +221,7 @@ TEST(PlatformCanvas, FillLayer) { DrawNativeRect(canvas, 0, 0, 100, 100); canvas.restore(); } - EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); // Add a clip and then make the layer to make sure the clip is correct. canvas.drawColor(SK_ColorWHITE); @@ -229,7 +232,7 @@ TEST(PlatformCanvas, FillLayer) { DrawNativeRect(canvas, 0, 0, 100, 100); } canvas.restore(); - EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); } // Test that translation + make layer works properly. @@ -247,8 +250,8 @@ TEST(PlatformCanvas, TranslateLayer) { DrawNativeRect(canvas, 0, 0, 100, 100); } canvas.restore(); - EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX + 1, kLayerY + 1, - kLayerW, kLayerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX + 1, kLayerY + 1, + kLayerW, kLayerH)); // Translate then make the layer. canvas.drawColor(SK_ColorWHITE); @@ -259,8 +262,8 @@ TEST(PlatformCanvas, TranslateLayer) { DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); } canvas.restore(); - EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 1, kInnerY + 1, - kInnerW, kInnerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1, + kInnerW, kInnerH)); // Make the layer then translate. canvas.drawColor(SK_ColorWHITE); @@ -271,8 +274,8 @@ TEST(PlatformCanvas, TranslateLayer) { DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); } canvas.restore(); - EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 1, kInnerY + 1, - kInnerW, kInnerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1, + kInnerW, kInnerH)); // Translate both before and after, and have a clip. canvas.drawColor(SK_ColorWHITE); @@ -285,8 +288,9 @@ TEST(PlatformCanvas, TranslateLayer) { DrawNativeRect(canvas, 0, 0, 100, 100); } canvas.restore(); - EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 2, kInnerY + 2, - kInnerW, kInnerH)); + EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 2, kInnerY + 2, + kInnerW, kInnerH)); } } // namespace skia + diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc index 9b2ff85..7f8a309 100644 --- a/skia/ext/vector_canvas_unittest.cc +++ b/skia/ext/vector_canvas_unittest.cc @@ -2,25 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "build/build_config.h" - -#include "webkit/tools/test_shell/image_decoder_unittest.h" - -#if !defined(OS_WIN) -#include <unistd.h> -#endif - #include "skia/ext/vector_canvas.h" -#include "PNGImageDecoder.h" +#include <vector> #include "base/command_line.h" #include "base/file_util.h" #include "base/gfx/gdi_util.h" +#include "base/gfx/png_decoder.h" #include "base/gfx/png_encoder.h" +#include "base/gfx/size.h" #include "base/path_service.h" #include "base/string_util.h" - +#include "base/win_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "SkDashPathEffect.h" @@ -79,12 +73,17 @@ class Image { public: // Creates the image from the given filename on disk. Image(const std::wstring& filename) : ignore_alpha_(true) { - Vector<char> compressed; - ReadFileToVector(filename, &compressed); + std::string compressed; + file_util::ReadFileToString(filename, &compressed); EXPECT_TRUE(compressed.size()); - WebCore::PNGImageDecoder decoder; - decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); - SetSkBitmap(decoder.frameBufferAtIndex(0)->bitmap()); + + int w; + int h; + EXPECT_TRUE(PNGDecoder::Decode( + reinterpret_cast<const unsigned char*>(compressed.c_str()), + compressed.size(), PNGDecoder::FORMAT_BGRA, &data_, &w, &h)); + size_.SetSize(w, h); + row_length_ = w * sizeof(uint32); } // Loads the image from a canvas. @@ -96,31 +95,40 @@ class Image { EXPECT_TRUE(bitmap != NULL); // Initialize the clip region to the entire bitmap. BITMAP bitmap_data; - EXPECT_EQ(GetObject(bitmap, sizeof(BITMAP), &bitmap_data), sizeof(BITMAP)); - width_ = bitmap_data.bmWidth; - height_ = bitmap_data.bmHeight; + EXPECT_EQ(GetObject(bitmap, sizeof(BITMAP), &bitmap_data), + sizeof(BITMAP)); + size_.SetSize(bitmap_data.bmWidth, bitmap_data.bmHeight); row_length_ = bitmap_data.bmWidthBytes; - size_t size = row_length_ * height_; + size_t size = row_length_ * size_.height(); data_.resize(size); memcpy(&*data_.begin(), bitmap_data.bmBits, size); } // Loads the image from a canvas. Image(const SkBitmap& bitmap) : ignore_alpha_(true) { - SetSkBitmap(bitmap); + SkAutoLockPixels lock(bitmap); + size_.SetSize(bitmap.width(), bitmap.height()); + row_length_ = static_cast<int>(bitmap.rowBytes()); + size_t size = row_length_ * size_.height(); + data_.resize(size); + memcpy(&*data_.begin(), bitmap.getAddr(0, 0), size); } - int width() const { return width_; } - int height() const { return height_; } - int row_length() const { return row_length_; } + const gfx::Size& size() const { + return size_; + } + + int row_length() const { + return row_length_; + } // Save the image to a png file. Used to create the initial test files. void SaveToFile(const std::wstring& filename) { std::vector<unsigned char> compressed; ASSERT_TRUE(PNGEncoder::Encode(&*data_.begin(), PNGEncoder::FORMAT_BGRA, - width_, - height_, + size_.width(), + size_.height(), row_length_, true, &compressed)); @@ -135,17 +143,14 @@ class Image { // Returns the percentage of the image that is different from the other, // between 0 and 100. double PercentageDifferent(const Image& rhs) const { - if (width_ != rhs.width_ || - height_ != rhs.height_ || - row_length_ != rhs.row_length_ || - width_ == 0 || - height_ == 0) { + if (size_ != rhs.size_ || row_length_ != rhs.row_length_ || + size_.width() == 0 || size_.height() == 0) return 100.; // When of different size or empty, they are 100% different. - } + // Compute pixels different in the overlap int pixels_different = 0; - for (int y = 0; y < height_; ++y) { - for (int x = 0; x < width_; ++x) { + for (int y = 0; y < size_.height(); ++y) { + for (int x = 0; x < size_.width(); ++x) { uint32_t lhs_pixel = pixel_at(x, y); uint32_t rhs_pixel = rhs.pixel_at(x, y); if (lhs_pixel != rhs_pixel) @@ -155,16 +160,16 @@ class Image { // Like the WebKit ImageDiff tool, we define percentage different in terms // of the size of the 'actual' bitmap. - double total_pixels = static_cast<double>(width_) * - static_cast<double>(height_); + double total_pixels = static_cast<double>(size_.width()) * + static_cast<double>(size_.height()); return static_cast<double>(pixels_different) / total_pixels * 100.; } // Returns the 0x0RGB or 0xARGB value of the pixel at the given location, // depending on ignore_alpha_. uint32 pixel_at(int x, int y) const { - EXPECT_TRUE(x >= 0 && x < width_); - EXPECT_TRUE(y >= 0 && y < height_); + EXPECT_TRUE(x >= 0 && x < size_.width()); + EXPECT_TRUE(y >= 0 && y < size_.height()); const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin()); const uint32* data_row = data + y * row_length_ / sizeof(uint32); if (ignore_alpha_) @@ -173,21 +178,9 @@ class Image { return data_row[x]; } - protected: - void SetSkBitmap(const SkBitmap& bitmap) { - SkAutoLockPixels lock(bitmap); - width_ = bitmap.width(); - height_ = bitmap.height(); - row_length_ = static_cast<int>(bitmap.rowBytes()); - size_t size = row_length_ * height_; - data_.resize(size); - memcpy(&*data_.begin(), bitmap.getAddr(0, 0), size); - } - private: // Pixel dimensions of the image. - int width_; - int height_; + gfx::Size size_; // Length of a line in bytes. int row_length_; @@ -320,13 +313,16 @@ void Premultiply(SkBitmap bitmap) { } } -void LoadPngFileToSkBitmap(const std::wstring& filename, SkBitmap* bitmap) { - Vector<char> compressed; - ReadFileToVector(filename, &compressed); +void LoadPngFileToSkBitmap(const std::wstring& file, SkBitmap* bitmap) { + std::string compressed; + file_util::ReadFileToString(file, &compressed); EXPECT_TRUE(compressed.size()); - WebCore::PNGImageDecoder decoder; - decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); - *bitmap = decoder.frameBufferAtIndex(0)->bitmap(); + // Extra-lame. If you care, fix it. + std::vector<unsigned char> data; + data.assign(reinterpret_cast<const unsigned char*>(compressed.c_str()), + reinterpret_cast<const unsigned char*>(compressed.c_str() + + compressed.size())); + EXPECT_TRUE(PNGDecoder::Decode(&data, bitmap)); EXPECT_FALSE(bitmap->isOpaque()); Premultiply(*bitmap); } @@ -335,8 +331,8 @@ void LoadPngFileToSkBitmap(const std::wstring& filename, SkBitmap* bitmap) { // Streams an image. inline std::ostream& operator<<(std::ostream& out, const Image& image) { - return out << "Image(" << image.width() << ", " - << image.height() << ", " << image.row_length() << ")"; + return out << "Image(" << image.size().width() << ", " + << image.size().height() << ", " << image.row_length() << ")"; } // Runs simultaneously the same drawing commands on VectorCanvas and @@ -794,6 +790,11 @@ TEST_F(VectorCanvasTest, PathEffects) { } TEST_F(VectorCanvasTest, Bitmaps) { + // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests + // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't + // really care about Windows 2000 pixel colors. + if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) + return; { SkBitmap bitmap; LoadPngFileToSkBitmap(test_file(L"bitmap_opaque.png"), &bitmap); @@ -812,6 +813,11 @@ TEST_F(VectorCanvasTest, Bitmaps) { } TEST_F(VectorCanvasTest, ClippingRect) { + // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests + // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't + // really care about Windows 2000 pixel colors. + if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) + return; SkBitmap bitmap; LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); SkRect rect; @@ -828,6 +834,11 @@ TEST_F(VectorCanvasTest, ClippingRect) { } TEST_F(VectorCanvasTest, ClippingPath) { + // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests + // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't + // really care about Windows 2000 pixel colors. + if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) + return; SkBitmap bitmap; LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); SkPath path; @@ -841,6 +852,11 @@ TEST_F(VectorCanvasTest, ClippingPath) { } TEST_F(VectorCanvasTest, ClippingCombined) { + // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests + // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't + // really care about Windows 2000 pixel colors. + if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) + return; SkBitmap bitmap; LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); @@ -862,6 +878,11 @@ TEST_F(VectorCanvasTest, ClippingCombined) { } TEST_F(VectorCanvasTest, ClippingIntersect) { + // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests + // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't + // really care about Windows 2000 pixel colors. + if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) + return; SkBitmap bitmap; LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); @@ -883,6 +904,11 @@ TEST_F(VectorCanvasTest, ClippingIntersect) { } TEST_F(VectorCanvasTest, ClippingClean) { + // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests + // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't + // really care about Windows 2000 pixel colors. + if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) + return; SkBitmap bitmap; LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); { @@ -910,6 +936,11 @@ TEST_F(VectorCanvasTest, ClippingClean) { } TEST_F(VectorCanvasTest, Matrix) { + // ICM is enabled on VectorCanvas only on Windows 2000 so bitmap-based tests + // can't compare the pixels between PlatformCanvas and VectorCanvas. We don't + // really care about Windows 2000 pixel colors. + if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) + return; SkBitmap bitmap; LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap); { |