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