OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 layerInfo.fOffset.set(10.0f, 20.0f); | 53 layerInfo.fOffset.set(10.0f, 20.0f); |
54 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; | 54 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; |
55 SkPaint* layerPaint = looperBuilder.addLayer(layerInfo); | 55 SkPaint* layerPaint = looperBuilder.addLayer(layerInfo); |
56 layerPaint->setBlendMode(SkBlendMode::kSrc); | 56 layerPaint->setBlendMode(SkBlendMode::kSrc); |
57 | 57 |
58 FakeDevice device; | 58 FakeDevice device; |
59 SkCanvas canvas(&device); | 59 SkCanvas canvas(&device); |
60 SkPaint paint; | 60 SkPaint paint; |
61 auto looper(looperBuilder.detach()); | 61 auto looper(looperBuilder.detach()); |
62 SkSmallAllocator<1, 32> allocator; | 62 SkSmallAllocator<1, 32> allocator; |
63 SkDrawLooper::Context* context = allocator.createWithIniterT<SkDrawLooper::C
ontext>( | 63 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize
()); |
64 looper->contextSize(), | 64 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); |
65 [&](void* buffer) { | |
66 return looper->createContext(&canvas, buffer); | |
67 }); | |
68 | 65 |
69 // The back layer should come first. | 66 // The back layer should come first. |
70 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); | 67 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); |
71 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc); | 68 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc); |
72 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); | 69 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); |
73 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); | 70 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); |
74 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); | 71 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); |
75 paint.reset(); | 72 paint.reset(); |
76 | 73 |
77 // Then the front layer. | 74 // Then the front layer. |
(...skipping 18 matching lines...) Expand all Loading... |
96 layerInfo.fOffset.set(10.0f, 20.0f); | 93 layerInfo.fOffset.set(10.0f, 20.0f); |
97 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; | 94 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; |
98 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); | 95 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); |
99 layerPaint->setBlendMode(SkBlendMode::kSrc); | 96 layerPaint->setBlendMode(SkBlendMode::kSrc); |
100 | 97 |
101 FakeDevice device; | 98 FakeDevice device; |
102 SkCanvas canvas(&device); | 99 SkCanvas canvas(&device); |
103 SkPaint paint; | 100 SkPaint paint; |
104 auto looper(looperBuilder.detach()); | 101 auto looper(looperBuilder.detach()); |
105 SkSmallAllocator<1, 32> allocator; | 102 SkSmallAllocator<1, 32> allocator; |
106 SkDrawLooper::Context* context = allocator.createWithIniterT<SkDrawLooper::C
ontext>( | 103 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize
()); |
107 looper->contextSize(), | 104 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); |
108 [&](void* buffer) { | |
109 return looper->createContext(&canvas, buffer); | |
110 }); | |
111 | 105 |
112 // The back layer should come first. | 106 // The back layer should come first. |
113 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); | 107 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); |
114 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver); | 108 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver); |
115 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); | 109 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); |
116 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); | 110 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); |
117 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); | 111 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); |
118 paint.reset(); | 112 paint.reset(); |
119 | 113 |
120 // Then the front layer. | 114 // Then the front layer. |
(...skipping 18 matching lines...) Expand all Loading... |
139 layerInfo.fOffset.set(10.0f, 20.0f); | 133 layerInfo.fOffset.set(10.0f, 20.0f); |
140 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; | 134 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; |
141 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); | 135 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); |
142 layerPaint->setBlendMode(SkBlendMode::kSrc); | 136 layerPaint->setBlendMode(SkBlendMode::kSrc); |
143 | 137 |
144 FakeDevice device; | 138 FakeDevice device; |
145 SkCanvas canvas(&device); | 139 SkCanvas canvas(&device); |
146 SkPaint paint; | 140 SkPaint paint; |
147 sk_sp<SkDrawLooper> looper(looperBuilder.detach()); | 141 sk_sp<SkDrawLooper> looper(looperBuilder.detach()); |
148 SkSmallAllocator<1, 32> allocator; | 142 SkSmallAllocator<1, 32> allocator; |
149 SkDrawLooper::Context* context = allocator.createWithIniterT<SkDrawLooper::C
ontext>( | 143 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize
()); |
150 looper->contextSize(), | 144 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); |
151 [&](void* buffer) { | |
152 return looper->createContext(&canvas, buffer); | |
153 }); | |
154 | 145 |
155 // The back layer should come first. | 146 // The back layer should come first. |
156 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); | 147 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); |
157 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver); | 148 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver); |
158 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); | 149 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); |
159 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); | 150 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); |
160 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); | 151 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); |
161 paint.reset(); | 152 paint.reset(); |
162 | 153 |
163 // Then the front layer. | 154 // Then the front layer. |
164 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); | 155 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); |
165 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc); | 156 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc); |
166 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); | 157 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); |
167 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); | 158 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); |
168 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); | 159 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); |
169 | 160 |
170 // Only two layers were added, so that should be the end. | 161 // Only two layers were added, so that should be the end. |
171 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); | 162 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); |
172 } | 163 } |
173 | 164 |
174 DEF_TEST(LayerDrawLooper, reporter) { | 165 DEF_TEST(LayerDrawLooper, reporter) { |
175 test_frontToBack(reporter); | 166 test_frontToBack(reporter); |
176 test_backToFront(reporter); | 167 test_backToFront(reporter); |
177 test_mixed(reporter); | 168 test_mixed(reporter); |
178 } | 169 } |
OLD | NEW |