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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 context.beginRecording(bounds); | 79 context.beginRecording(bounds); |
80 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkXfermode::kSrcOver_Mode); | 80 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkXfermode::kSrcOver_Mode); |
81 sk_sp<const SkPicture> picture = context.endRecording(); | 81 sk_sp<const SkPicture> picture = context.endRecording(); |
82 canvas.drawPicture(picture.get()); | 82 canvas.drawPicture(picture.get()); |
83 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) | 83 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) |
84 | 84 |
85 context.beginRecording(bounds); | 85 context.beginRecording(bounds); |
86 context.fillRect(FloatRect(0, 0, 100, 100), opaque, | 86 context.fillRect(FloatRect(0, 0, 100, 100), opaque, |
87 SkXfermode::kSrcOver_Mode); | 87 SkXfermode::kSrcOver_Mode); |
88 picture = context.endRecording(); | 88 picture = context.endRecording(); |
89 // Make sure the opaque region was unaffected by the rect drawn during Picture
recording. | 89 // Make sure the opaque region was unaffected by the rect drawn during Picture |
| 90 // recording. |
90 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) | 91 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) |
91 | 92 |
92 canvas.drawPicture(picture.get()); | 93 canvas.drawPicture(picture.get()); |
93 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 100, 100)) | 94 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 100, 100)) |
94 } | 95 } |
95 | 96 |
96 TEST(GraphicsContextTest, UnboundedDrawsAreClipped) { | 97 TEST(GraphicsContextTest, UnboundedDrawsAreClipped) { |
97 SkBitmap bitmap; | 98 SkBitmap bitmap; |
98 bitmap.allocN32Pixels(400, 400); | 99 bitmap.allocN32Pixels(400, 400); |
99 bitmap.eraseColor(0); | 100 bitmap.eraseColor(0); |
(...skipping 23 matching lines...) Expand all Loading... |
123 context.fillRect(FloatRect(10, 10, 40, 40), opaque, | 124 context.fillRect(FloatRect(10, 10, 40, 40), opaque, |
124 SkXfermode::kSrcOver_Mode); | 125 SkXfermode::kSrcOver_Mode); |
125 sk_sp<const SkPicture> picture = context.endRecording(); | 126 sk_sp<const SkPicture> picture = context.endRecording(); |
126 canvas.drawPicture(picture.get()); | 127 canvas.drawPicture(picture.get()); |
127 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(10, 10, 40, 40)); | 128 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(10, 10, 40, 40)); |
128 | 129 |
129 context.beginRecording(bounds); | 130 context.beginRecording(bounds); |
130 // Clip to the left edge of the opaque area. | 131 // Clip to the left edge of the opaque area. |
131 context.clip(IntRect(10, 10, 10, 40)); | 132 context.clip(IntRect(10, 10, 10, 40)); |
132 | 133 |
133 // Draw a path that gets clipped. This should destroy the opaque area but only
inside the clip. | 134 // Draw a path that gets clipped. This should destroy the opaque area, but |
| 135 // only inside the clip. |
134 Path path; | 136 Path path; |
135 path.moveTo(FloatPoint(10, 10)); | 137 path.moveTo(FloatPoint(10, 10)); |
136 path.addLineTo(FloatPoint(40, 40)); | 138 path.addLineTo(FloatPoint(40, 40)); |
137 SkPaint paint; | 139 SkPaint paint; |
138 paint.setColor(alpha.rgb()); | 140 paint.setColor(alpha.rgb()); |
139 paint.setXfermodeMode(SkXfermode::kSrcOut_Mode); | 141 paint.setXfermodeMode(SkXfermode::kSrcOut_Mode); |
140 context.drawPath(path.getSkPath(), paint); | 142 context.drawPath(path.getSkPath(), paint); |
141 | 143 |
142 picture = context.endRecording(); | 144 picture = context.endRecording(); |
143 canvas.drawPicture(picture.get()); | 145 canvas.drawPicture(picture.get()); |
144 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); | 146 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); |
145 } | 147 } |
146 | 148 |
147 } // namespace blink | 149 } // namespace blink |
OLD | NEW |