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

Side by Side Diff: tests/LayerDrawLooperTest.cpp

Issue 2396953002: Revert[8] "replace SkXfermode obj with SkBlendMode enum in paints" (Closed)
Patch Set: add tmp virtual to unroll legacy arithmodes Created 4 years, 2 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 | « tests/ImageTest.cpp ('k') | tests/PDFOpaqueSrcModeToSrcOverTest.cpp » ('j') | 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 SkLayerDrawLooper::Builder looperBuilder; 46 SkLayerDrawLooper::Builder looperBuilder;
47 SkLayerDrawLooper::LayerInfo layerInfo; 47 SkLayerDrawLooper::LayerInfo layerInfo;
48 48
49 // Add the front layer, with the defaults. 49 // Add the front layer, with the defaults.
50 (void)looperBuilder.addLayer(layerInfo); 50 (void)looperBuilder.addLayer(layerInfo);
51 51
52 // Add the back layer, with some layer info set. 52 // Add the back layer, with some layer info set.
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->setXfermodeMode(SkXfermode::kSrc_Mode); 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 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ()); 63 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ());
64 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); 64 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
65 65
66 // The back layer should come first. 66 // The back layer should come first.
67 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 67 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
68 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode)); 68 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
69 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 69 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
70 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 70 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
71 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 71 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
72 paint.reset(); 72 paint.reset();
73 73
74 // Then the front layer. 74 // Then the front layer.
75 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 75 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
76 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode)); 76 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
77 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 77 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
78 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 78 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
79 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 79 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
80 80
81 // Only two layers were added, so that should be the end. 81 // Only two layers were added, so that should be the end.
82 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); 82 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint));
83 } 83 }
84 84
85 static void test_backToFront(skiatest::Reporter* reporter) { 85 static void test_backToFront(skiatest::Reporter* reporter) {
86 SkLayerDrawLooper::Builder looperBuilder; 86 SkLayerDrawLooper::Builder looperBuilder;
87 SkLayerDrawLooper::LayerInfo layerInfo; 87 SkLayerDrawLooper::LayerInfo layerInfo;
88 88
89 // Add the back layer, with the defaults. 89 // Add the back layer, with the defaults.
90 (void)looperBuilder.addLayerOnTop(layerInfo); 90 (void)looperBuilder.addLayerOnTop(layerInfo);
91 91
92 // Add the front layer, with some layer info set. 92 // Add the front layer, with some layer info set.
93 layerInfo.fOffset.set(10.0f, 20.0f); 93 layerInfo.fOffset.set(10.0f, 20.0f);
94 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 94 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
95 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); 95 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
96 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode); 96 layerPaint->setBlendMode(SkBlendMode::kSrc);
97 97
98 FakeDevice device; 98 FakeDevice device;
99 SkCanvas canvas(&device); 99 SkCanvas canvas(&device);
100 SkPaint paint; 100 SkPaint paint;
101 auto looper(looperBuilder.detach()); 101 auto looper(looperBuilder.detach());
102 SkSmallAllocator<1, 32> allocator; 102 SkSmallAllocator<1, 32> allocator;
103 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ()); 103 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ());
104 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); 104 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
105 105
106 // The back layer should come first. 106 // The back layer should come first.
107 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 107 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
108 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode)); 108 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
109 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 109 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
110 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 110 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
111 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 111 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
112 paint.reset(); 112 paint.reset();
113 113
114 // Then the front layer. 114 // Then the front layer.
115 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 115 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
116 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode)); 116 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
117 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 117 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
118 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 118 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
119 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 119 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
120 120
121 // Only two layers were added, so that should be the end. 121 // Only two layers were added, so that should be the end.
122 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); 122 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint));
123 } 123 }
124 124
125 static void test_mixed(skiatest::Reporter* reporter) { 125 static void test_mixed(skiatest::Reporter* reporter) {
126 SkLayerDrawLooper::Builder looperBuilder; 126 SkLayerDrawLooper::Builder looperBuilder;
127 SkLayerDrawLooper::LayerInfo layerInfo; 127 SkLayerDrawLooper::LayerInfo layerInfo;
128 128
129 // Add the back layer, with the defaults. 129 // Add the back layer, with the defaults.
130 (void)looperBuilder.addLayer(layerInfo); 130 (void)looperBuilder.addLayer(layerInfo);
131 131
132 // Add the front layer, with some layer info set. 132 // Add the front layer, with some layer info set.
133 layerInfo.fOffset.set(10.0f, 20.0f); 133 layerInfo.fOffset.set(10.0f, 20.0f);
134 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 134 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
135 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); 135 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
136 layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode); 136 layerPaint->setBlendMode(SkBlendMode::kSrc);
137 137
138 FakeDevice device; 138 FakeDevice device;
139 SkCanvas canvas(&device); 139 SkCanvas canvas(&device);
140 SkPaint paint; 140 SkPaint paint;
141 sk_sp<SkDrawLooper> looper(looperBuilder.detach()); 141 sk_sp<SkDrawLooper> looper(looperBuilder.detach());
142 SkSmallAllocator<1, 32> allocator; 142 SkSmallAllocator<1, 32> allocator;
143 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ()); 143 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ());
144 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); 144 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
145 145
146 // The back layer should come first. 146 // The back layer should come first.
147 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 147 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
148 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrcOver_Mode)); 148 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
149 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 149 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
150 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 150 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
151 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 151 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
152 paint.reset(); 152 paint.reset();
153 153
154 // Then the front layer. 154 // Then the front layer.
155 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 155 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
156 REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode ::kSrc_Mode)); 156 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
157 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 157 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
158 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 158 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
159 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 159 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
160 160
161 // Only two layers were added, so that should be the end. 161 // Only two layers were added, so that should be the end.
162 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); 162 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint));
163 } 163 }
164 164
165 DEF_TEST(LayerDrawLooper, reporter) { 165 DEF_TEST(LayerDrawLooper, reporter) {
166 test_frontToBack(reporter); 166 test_frontToBack(reporter);
167 test_backToFront(reporter); 167 test_backToFront(reporter);
168 test_mixed(reporter); 168 test_mixed(reporter);
169 } 169 }
OLDNEW
« no previous file with comments | « tests/ImageTest.cpp ('k') | tests/PDFOpaqueSrcModeToSrcOverTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698