Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: tests/LayerDrawLooperTest.cpp

Issue 133813005: Builder class for SkLayerDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@draw_looper_context
Patch Set: Implement own CreateProc & remove SkLayerDrawLooper(SkReadBuffer&). Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkLayerDrawLooper.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 INHERITED::drawRect(draw, r, paint); 28 INHERITED::drawRect(draw, r, paint);
29 } 29 }
30 30
31 SkMatrix fLastMatrix; 31 SkMatrix fLastMatrix;
32 32
33 private: 33 private:
34 typedef SkBitmapDevice INHERITED; 34 typedef SkBitmapDevice INHERITED;
35 }; 35 };
36 36
37 static void test_frontToBack(skiatest::Reporter* reporter) { 37 static void test_frontToBack(skiatest::Reporter* reporter) {
38 SkAutoTUnref<SkLayerDrawLooper> looper(SkNEW(SkLayerDrawLooper)); 38 SkLayerDrawLooper::Builder looperBuilder;
39 SkLayerDrawLooper::LayerInfo layerInfo; 39 SkLayerDrawLooper::LayerInfo layerInfo;
40 40
41 // Add the front layer, with the defaults. 41 // Add the front layer, with the defaults.
42 (void)looper->addLayer(layerInfo); 42 (void)looperBuilder.addLayer(layerInfo);
43 43
44 // Add the back layer, with some layer info set. 44 // Add the back layer, with some layer info set.
45 layerInfo.fOffset.set(10.0f, 20.0f); 45 layerInfo.fOffset.set(10.0f, 20.0f);
46 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 46 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
47 SkPaint* layerPaint = looper->addLayer(layerInfo); 47 SkPaint* layerPaint = looperBuilder.addLayer(layerInfo);
48 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode); 48 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode);
49 49
50 FakeDevice device; 50 FakeDevice device;
51 SkCanvas canvas(&device); 51 SkCanvas canvas(&device);
52 SkPaint paint; 52 SkPaint paint;
53 SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
53 looper->init(&canvas); 54 looper->init(&canvas);
54 55
55 // The back layer should come first. 56 // The back layer should come first.
56 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); 57 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
57 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode)); 58 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode));
58 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 59 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
59 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 60 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
60 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 61 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
61 paint.reset(); 62 paint.reset();
62 63
63 // Then the front layer. 64 // Then the front layer.
64 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); 65 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
65 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode)); 66 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode));
66 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 67 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
67 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 68 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
68 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 69 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
69 70
70 // Only two layers were added, so that should be the end. 71 // Only two layers were added, so that should be the end.
71 REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint)); 72 REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint));
72 } 73 }
73 74
74 static void test_backToFront(skiatest::Reporter* reporter) { 75 static void test_backToFront(skiatest::Reporter* reporter) {
75 SkAutoTUnref<SkLayerDrawLooper> looper(SkNEW(SkLayerDrawLooper)); 76 SkLayerDrawLooper::Builder looperBuilder;
76 SkLayerDrawLooper::LayerInfo layerInfo; 77 SkLayerDrawLooper::LayerInfo layerInfo;
77 78
78 // Add the back layer, with the defaults. 79 // Add the back layer, with the defaults.
79 (void)looper->addLayerOnTop(layerInfo); 80 (void)looperBuilder.addLayerOnTop(layerInfo);
80 81
81 // Add the front layer, with some layer info set. 82 // Add the front layer, with some layer info set.
82 layerInfo.fOffset.set(10.0f, 20.0f); 83 layerInfo.fOffset.set(10.0f, 20.0f);
83 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 84 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
84 SkPaint* layerPaint = looper->addLayerOnTop(layerInfo); 85 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
85 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode); 86 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode);
86 87
87 FakeDevice device; 88 FakeDevice device;
88 SkCanvas canvas(&device); 89 SkCanvas canvas(&device);
89 SkPaint paint; 90 SkPaint paint;
91 SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
90 looper->init(&canvas); 92 looper->init(&canvas);
91 93
92 // The back layer should come first. 94 // The back layer should come first.
93 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); 95 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
94 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode)); 96 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode));
95 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 97 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
96 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 98 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
97 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 99 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
98 paint.reset(); 100 paint.reset();
99 101
100 // Then the front layer. 102 // Then the front layer.
101 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); 103 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
102 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode)); 104 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode));
103 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 105 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
104 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 106 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
105 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 107 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
106 108
107 // Only two layers were added, so that should be the end. 109 // Only two layers were added, so that should be the end.
108 REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint)); 110 REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint));
109 } 111 }
110 112
111 static void test_mixed(skiatest::Reporter* reporter) { 113 static void test_mixed(skiatest::Reporter* reporter) {
112 SkAutoTUnref<SkLayerDrawLooper> looper(SkNEW(SkLayerDrawLooper)); 114 SkLayerDrawLooper::Builder looperBuilder;
113 SkLayerDrawLooper::LayerInfo layerInfo; 115 SkLayerDrawLooper::LayerInfo layerInfo;
114 116
115 // Add the back layer, with the defaults. 117 // Add the back layer, with the defaults.
116 (void)looper->addLayer(layerInfo); 118 (void)looperBuilder.addLayer(layerInfo);
117 119
118 // Add the front layer, with some layer info set. 120 // Add the front layer, with some layer info set.
119 layerInfo.fOffset.set(10.0f, 20.0f); 121 layerInfo.fOffset.set(10.0f, 20.0f);
120 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 122 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
121 SkPaint* layerPaint = looper->addLayerOnTop(layerInfo); 123 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
122 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode); 124 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode);
123 125
124 FakeDevice device; 126 FakeDevice device;
125 SkCanvas canvas(&device); 127 SkCanvas canvas(&device);
126 SkPaint paint; 128 SkPaint paint;
129 SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
127 looper->init(&canvas); 130 looper->init(&canvas);
128 131
129 // The back layer should come first. 132 // The back layer should come first.
130 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); 133 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
131 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode)); 134 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode));
132 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 135 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
133 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 136 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
134 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 137 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
135 paint.reset(); 138 paint.reset();
136 139
137 // Then the front layer. 140 // Then the front layer.
138 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); 141 REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
139 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode)); 142 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode));
140 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 143 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
141 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 144 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
142 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 145 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
143 146
144 // Only two layers were added, so that should be the end. 147 // Only two layers were added, so that should be the end.
145 REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint)); 148 REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint));
146 } 149 }
147 150
148 DEF_TEST(LayerDrawLooper, reporter) { 151 DEF_TEST(LayerDrawLooper, reporter) {
149 test_frontToBack(reporter); 152 test_frontToBack(reporter);
150 test_backToFront(reporter); 153 test_backToFront(reporter);
151 test_mixed(reporter); 154 test_mixed(reporter);
152 } 155 }
OLDNEW
« no previous file with comments | « src/effects/SkLayerDrawLooper.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698