| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/mac/GraphicsContextCanvas.h" |
| 6 #include "skia/ext/skia_utils_mac.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 enum TestType { |
| 12 TestIdentity = 0, |
| 13 TestTranslate = 1, |
| 14 TestClip = 2, |
| 15 TestXClip = TestTranslate | TestClip, |
| 16 }; |
| 17 |
| 18 void RunTest(TestType test) { |
| 19 const unsigned width = 2; |
| 20 const unsigned height = 2; |
| 21 const unsigned storageSize = width * height; |
| 22 const unsigned original[] = {0xFF333333, 0xFF666666, 0xFF999999, 0xFFCCCCCC}; |
| 23 EXPECT_EQ(storageSize, sizeof(original) / sizeof(original[0])); |
| 24 unsigned bits[storageSize]; |
| 25 memcpy(bits, original, sizeof(original)); |
| 26 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 27 SkBitmap bitmap; |
| 28 bitmap.installPixels(info, bits, info.minRowBytes()); |
| 29 |
| 30 PaintCanvas canvas(bitmap); |
| 31 if (test & TestTranslate) |
| 32 canvas.translate(width / 2, 0); |
| 33 if (test & TestClip) { |
| 34 SkRect clipRect = {0, height / 2, width, height}; |
| 35 canvas.clipRect(clipRect); |
| 36 } |
| 37 { |
| 38 SkIRect clip = |
| 39 SkIRect::MakeSize(canvas.getBaseLayerSize()) |
| 40 .makeOffset( |
| 41 (test & TestTranslate) ? -(static_cast<int>(width)) / 2 : 0, 0); |
| 42 GraphicsContextCanvas bitLocker(&canvas, clip); |
| 43 CGContextRef cgContext = bitLocker.cgContext(); |
| 44 CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); |
| 45 CGContextSetFillColorWithColor(cgContext, testColor); |
| 46 CGRect cgRect = {{0, 0}, {width, height}}; |
| 47 CGContextFillRect(cgContext, cgRect); |
| 48 } |
| 49 const unsigned results[][storageSize] = { |
| 50 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}, // identity |
| 51 {0xFF333333, 0xFFFFFFFF, 0xFF999999, 0xFFFFFFFF}, // translate |
| 52 {0xFF333333, 0xFF666666, 0xFFFFFFFF, 0xFFFFFFFF}, // clip |
| 53 {0xFF333333, 0xFF666666, 0xFF999999, 0xFFFFFFFF} // translate | clip |
| 54 }; |
| 55 for (unsigned index = 0; index < storageSize; index++) |
| 56 EXPECT_EQ(results[test][index], bits[index]); |
| 57 } |
| 58 |
| 59 TEST(GraphicsContextCanvasTest, Identity) { |
| 60 RunTest(TestIdentity); |
| 61 } |
| 62 |
| 63 TEST(GraphicsContextCanvasTest, Translate) { |
| 64 RunTest(TestTranslate); |
| 65 } |
| 66 |
| 67 TEST(GraphicsContextCanvasTest, Clip) { |
| 68 RunTest(TestClip); |
| 69 } |
| 70 |
| 71 TEST(GraphicsContextCanvasTest, XClip) { |
| 72 RunTest(TestXClip); |
| 73 } |
| 74 |
| 75 } // namespace |
| OLD | NEW |