| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 int alpha = *bitmap.getAddr32(x, y) >> 24; \ | 64 int alpha = *bitmap.getAddr32(x, y) >> 24; \ |
| 65 bool opaque = opaqueRect.contains(x, y); \ | 65 bool opaque = opaqueRect.contains(x, y); \ |
| 66 EXPECT_EQ(opaque, alpha == 255); \ | 66 EXPECT_EQ(opaque, alpha == 255); \ |
| 67 } \ | 67 } \ |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST(GraphicsContextTest, Recording) { | 70 TEST(GraphicsContextTest, Recording) { |
| 71 SkBitmap bitmap; | 71 SkBitmap bitmap; |
| 72 bitmap.allocN32Pixels(100, 100); | 72 bitmap.allocN32Pixels(100, 100); |
| 73 bitmap.eraseColor(0); | 73 bitmap.eraseColor(0); |
| 74 PaintCanvas canvas(bitmap); | 74 SkiaPaintCanvas canvas(bitmap); |
| 75 | 75 |
| 76 std::unique_ptr<PaintController> paintController = PaintController::create(); | 76 std::unique_ptr<PaintController> paintController = PaintController::create(); |
| 77 GraphicsContext context(*paintController); | 77 GraphicsContext context(*paintController); |
| 78 | 78 |
| 79 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); | 79 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); |
| 80 FloatRect bounds(0, 0, 100, 100); | 80 FloatRect bounds(0, 0, 100, 100); |
| 81 | 81 |
| 82 context.beginRecording(bounds); | 82 context.beginRecording(bounds); |
| 83 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkBlendMode::kSrcOver); | 83 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkBlendMode::kSrcOver); |
| 84 sk_sp<const PaintRecord> record = context.endRecording(); | 84 sk_sp<const PaintRecord> record = context.endRecording(); |
| 85 canvas.drawPicture(record.get()); | 85 canvas.drawPicture(record.get()); |
| 86 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) | 86 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) |
| 87 | 87 |
| 88 context.beginRecording(bounds); | 88 context.beginRecording(bounds); |
| 89 context.fillRect(FloatRect(0, 0, 100, 100), opaque, SkBlendMode::kSrcOver); | 89 context.fillRect(FloatRect(0, 0, 100, 100), opaque, SkBlendMode::kSrcOver); |
| 90 record = context.endRecording(); | 90 record = context.endRecording(); |
| 91 // Make sure the opaque region was unaffected by the rect drawn during | 91 // Make sure the opaque region was unaffected by the rect drawn during |
| 92 // recording. | 92 // recording. |
| 93 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) | 93 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) |
| 94 | 94 |
| 95 canvas.drawPicture(record.get()); | 95 canvas.drawPicture(record.get()); |
| 96 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 100, 100)) | 96 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 100, 100)) |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST(GraphicsContextTest, UnboundedDrawsAreClipped) { | 99 TEST(GraphicsContextTest, UnboundedDrawsAreClipped) { |
| 100 SkBitmap bitmap; | 100 SkBitmap bitmap; |
| 101 bitmap.allocN32Pixels(400, 400); | 101 bitmap.allocN32Pixels(400, 400); |
| 102 bitmap.eraseColor(0); | 102 bitmap.eraseColor(0); |
| 103 PaintCanvas canvas(bitmap); | 103 SkiaPaintCanvas canvas(bitmap); |
| 104 | 104 |
| 105 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); | 105 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); |
| 106 Color alpha(0.0f, 0.0f, 0.0f, 0.0f); | 106 Color alpha(0.0f, 0.0f, 0.0f, 0.0f); |
| 107 FloatRect bounds(0, 0, 100, 100); | 107 FloatRect bounds(0, 0, 100, 100); |
| 108 | 108 |
| 109 std::unique_ptr<PaintController> paintController = PaintController::create(); | 109 std::unique_ptr<PaintController> paintController = PaintController::create(); |
| 110 GraphicsContext context(*paintController); | 110 GraphicsContext context(*paintController); |
| 111 context.beginRecording(bounds); | 111 context.beginRecording(bounds); |
| 112 | 112 |
| 113 context.setShouldAntialias(false); | 113 context.setShouldAntialias(false); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 141 flags.setColor(alpha.rgb()); | 141 flags.setColor(alpha.rgb()); |
| 142 flags.setBlendMode(SkBlendMode::kSrcOut); | 142 flags.setBlendMode(SkBlendMode::kSrcOut); |
| 143 context.drawPath(path.getSkPath(), flags); | 143 context.drawPath(path.getSkPath(), flags); |
| 144 | 144 |
| 145 record = context.endRecording(); | 145 record = context.endRecording(); |
| 146 canvas.drawPicture(record.get()); | 146 canvas.drawPicture(record.get()); |
| 147 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); | 147 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |