OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 30 matching lines...) Expand all Loading... |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 #define EXPECT_EQ_RECT(a, b) \ | 43 #define EXPECT_EQ_RECT(a, b) \ |
44 EXPECT_EQ(a.x(), b.x()); \ | 44 EXPECT_EQ(a.x(), b.x()); \ |
45 EXPECT_EQ(a.y(), b.y()); \ | 45 EXPECT_EQ(a.y(), b.y()); \ |
46 EXPECT_EQ(a.width(), b.width()); \ | 46 EXPECT_EQ(a.width(), b.width()); \ |
47 EXPECT_EQ(a.height(), b.height()); | 47 EXPECT_EQ(a.height(), b.height()); |
48 | 48 |
49 #define EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, opaqueRect) \ | 49 #define EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, opaqueRect) \ |
50 { \ | 50 { \ |
51 SkAutoLockPixels locker(bitmap); \ | |
52 for (int y = opaqueRect.Y(); y < opaqueRect.MaxY(); ++y) \ | 51 for (int y = opaqueRect.Y(); y < opaqueRect.MaxY(); ++y) \ |
53 for (int x = opaqueRect.X(); x < opaqueRect.MaxX(); ++x) { \ | 52 for (int x = opaqueRect.X(); x < opaqueRect.MaxX(); ++x) { \ |
54 int alpha = *bitmap.getAddr32(x, y) >> 24; \ | 53 int alpha = *bitmap.getAddr32(x, y) >> 24; \ |
55 EXPECT_EQ(255, alpha); \ | 54 EXPECT_EQ(255, alpha); \ |
56 } \ | 55 } \ |
57 } | 56 } |
58 | 57 |
59 #define EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, opaqueRect) \ | 58 #define EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, opaqueRect) \ |
60 { \ | 59 { \ |
61 SkAutoLockPixels locker(bitmap); \ | |
62 for (int y = 0; y < bitmap.height(); ++y) \ | 60 for (int y = 0; y < bitmap.height(); ++y) \ |
63 for (int x = 0; x < bitmap.width(); ++x) { \ | 61 for (int x = 0; x < bitmap.width(); ++x) { \ |
64 int alpha = *bitmap.getAddr32(x, y) >> 24; \ | 62 int alpha = *bitmap.getAddr32(x, y) >> 24; \ |
65 bool opaque = opaqueRect.Contains(x, y); \ | 63 bool opaque = opaqueRect.Contains(x, y); \ |
66 EXPECT_EQ(opaque, alpha == 255); \ | 64 EXPECT_EQ(opaque, alpha == 255); \ |
67 } \ | 65 } \ |
68 } | 66 } |
69 | 67 |
70 TEST(GraphicsContextTest, Recording) { | 68 TEST(GraphicsContextTest, Recording) { |
71 SkBitmap bitmap; | 69 SkBitmap bitmap; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 PaintFlags flags; | 135 PaintFlags flags; |
138 flags.setColor(alpha.Rgb()); | 136 flags.setColor(alpha.Rgb()); |
139 flags.setBlendMode(SkBlendMode::kSrcOut); | 137 flags.setBlendMode(SkBlendMode::kSrcOut); |
140 context.DrawPath(path.GetSkPath(), flags); | 138 context.DrawPath(path.GetSkPath(), flags); |
141 | 139 |
142 canvas.drawPicture(context.EndRecording()); | 140 canvas.drawPicture(context.EndRecording()); |
143 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); | 141 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); |
144 } | 142 } |
145 | 143 |
146 } // namespace blink | 144 } // namespace blink |
OLD | NEW |