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 14 matching lines...) Expand all Loading... |
25 #include "platform/graphics/GraphicsContext.h" | 25 #include "platform/graphics/GraphicsContext.h" |
26 | 26 |
27 #include "platform/graphics/BitmapImage.h" | 27 #include "platform/graphics/BitmapImage.h" |
28 #include "platform/graphics/Path.h" | 28 #include "platform/graphics/Path.h" |
29 #include "platform/graphics/paint/PaintController.h" | 29 #include "platform/graphics/paint/PaintController.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "third_party/skia/include/core/SkCanvas.h" | 32 #include "third_party/skia/include/core/SkCanvas.h" |
33 #include "third_party/skia/include/core/SkPicture.h" | 33 #include "third_party/skia/include/core/SkPicture.h" |
34 #include "third_party/skia/include/core/SkShader.h" | 34 #include "third_party/skia/include/core/SkShader.h" |
| 35 #include <memory> |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 #define EXPECT_EQ_RECT(a, b) \ | 39 #define EXPECT_EQ_RECT(a, b) \ |
39 EXPECT_EQ(a.x(), b.x()); \ | 40 EXPECT_EQ(a.x(), b.x()); \ |
40 EXPECT_EQ(a.y(), b.y()); \ | 41 EXPECT_EQ(a.y(), b.y()); \ |
41 EXPECT_EQ(a.width(), b.width()); \ | 42 EXPECT_EQ(a.width(), b.width()); \ |
42 EXPECT_EQ(a.height(), b.height()); | 43 EXPECT_EQ(a.height(), b.height()); |
43 | 44 |
44 #define EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, opaqueRect) \ | 45 #define EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, opaqueRect) \ |
(...skipping 17 matching lines...) Expand all Loading... |
62 } \ | 63 } \ |
63 } | 64 } |
64 | 65 |
65 TEST(GraphicsContextTest, pictureRecording) | 66 TEST(GraphicsContextTest, pictureRecording) |
66 { | 67 { |
67 SkBitmap bitmap; | 68 SkBitmap bitmap; |
68 bitmap.allocN32Pixels(100, 100); | 69 bitmap.allocN32Pixels(100, 100); |
69 bitmap.eraseColor(0); | 70 bitmap.eraseColor(0); |
70 SkCanvas canvas(bitmap); | 71 SkCanvas canvas(bitmap); |
71 | 72 |
72 OwnPtr<PaintController> paintController = PaintController::create(); | 73 std::unique_ptr<PaintController> paintController = PaintController::create()
; |
73 GraphicsContext context(*paintController); | 74 GraphicsContext context(*paintController); |
74 | 75 |
75 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); | 76 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); |
76 FloatRect bounds(0, 0, 100, 100); | 77 FloatRect bounds(0, 0, 100, 100); |
77 | 78 |
78 context.beginRecording(bounds); | 79 context.beginRecording(bounds); |
79 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkXfermode::kSrcOver_Mode)
; | 80 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkXfermode::kSrcOver_Mode)
; |
80 RefPtr<const SkPicture> picture = context.endRecording(); | 81 RefPtr<const SkPicture> picture = context.endRecording(); |
81 canvas.drawPicture(picture.get()); | 82 canvas.drawPicture(picture.get()); |
82 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)) |
(...skipping 12 matching lines...) Expand all Loading... |
95 { | 96 { |
96 SkBitmap bitmap; | 97 SkBitmap bitmap; |
97 bitmap.allocN32Pixels(400, 400); | 98 bitmap.allocN32Pixels(400, 400); |
98 bitmap.eraseColor(0); | 99 bitmap.eraseColor(0); |
99 SkCanvas canvas(bitmap); | 100 SkCanvas canvas(bitmap); |
100 | 101 |
101 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); | 102 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); |
102 Color alpha(0.0f, 0.0f, 0.0f, 0.0f); | 103 Color alpha(0.0f, 0.0f, 0.0f, 0.0f); |
103 FloatRect bounds(0, 0, 100, 100); | 104 FloatRect bounds(0, 0, 100, 100); |
104 | 105 |
105 OwnPtr<PaintController> paintController = PaintController::create(); | 106 std::unique_ptr<PaintController> paintController = PaintController::create()
; |
106 GraphicsContext context(*paintController); | 107 GraphicsContext context(*paintController); |
107 context.beginRecording(bounds); | 108 context.beginRecording(bounds); |
108 | 109 |
109 context.setShouldAntialias(false); | 110 context.setShouldAntialias(false); |
110 context.setMiterLimit(1); | 111 context.setMiterLimit(1); |
111 context.setStrokeThickness(5); | 112 context.setStrokeThickness(5); |
112 context.setLineCap(SquareCap); | 113 context.setLineCap(SquareCap); |
113 context.setStrokeStyle(SolidStroke); | 114 context.setStrokeStyle(SolidStroke); |
114 | 115 |
115 // Make skia unable to compute fast bounds for our paths. | 116 // Make skia unable to compute fast bounds for our paths. |
(...skipping 20 matching lines...) Expand all Loading... |
136 paint.setColor(alpha.rgb()); | 137 paint.setColor(alpha.rgb()); |
137 paint.setXfermodeMode(SkXfermode::kSrcOut_Mode); | 138 paint.setXfermodeMode(SkXfermode::kSrcOut_Mode); |
138 context.drawPath(path.getSkPath(), paint); | 139 context.drawPath(path.getSkPath(), paint); |
139 | 140 |
140 picture = context.endRecording(); | 141 picture = context.endRecording(); |
141 canvas.drawPicture(picture.get()); | 142 canvas.drawPicture(picture.get()); |
142 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); | 143 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); |
143 } | 144 } |
144 | 145 |
145 } // namespace blink | 146 } // namespace blink |
OLD | NEW |