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

Side by Side Diff: tests/RecordOptsTest.cpp

Issue 840483005: Fold alpha to the draw in savelayer-draw-restore patterns with non-opaque draw (Closed) Base URL: https://skia.googlesource.com/skia.git@unique-id-unflatten
Patch Set: Created 5 years, 11 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
« src/core/SkRecordOpts.cpp ('K') | « src/core/SkRecordOpts.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 2014 Google Inc. 2 * Copyright 2014 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 "Test.h" 8 #include "Test.h"
9 #include "RecordTestUtils.h" 9 #include "RecordTestUtils.h"
10 10
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 SkRect bounds = SkRect::MakeWH(100, 200); 118 SkRect bounds = SkRect::MakeWH(100, 200);
119 SkRect draw = SkRect::MakeWH(50, 60); 119 SkRect draw = SkRect::MakeWH(50, 60);
120 120
121 SkPaint goodLayerPaint, badLayerPaint, worseLayerPaint; 121 SkPaint goodLayerPaint, badLayerPaint, worseLayerPaint;
122 goodLayerPaint.setColor(0x03000000); // Only alpha. 122 goodLayerPaint.setColor(0x03000000); // Only alpha.
123 badLayerPaint.setColor( 0x03040506); // Not only alpha. 123 badLayerPaint.setColor( 0x03040506); // Not only alpha.
124 worseLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect wil l do. 124 worseLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect wil l do.
125 125
126 SkPaint goodDrawPaint, badDrawPaint; 126 SkPaint goodDrawPaint, badDrawPaint;
127 goodDrawPaint.setColor(0xFF020202); // Opaque. 127 goodDrawPaint.setColor(0xFF020202); // Opaque.
128 badDrawPaint.setColor( 0x0F020202); // Not opaque. 128 badDrawPaint.setColor( 0x0F020202); // Not opaque.
mtklein 2015/01/13 18:48:20 Let's rename goodDrawPaint -> opaqueDrawPaint, bad
Kimmo Kinnunen 2015/01/14 13:07:51 Done.
129 129
130 // No change: optimization can't handle bounds. 130 // No change: optimization can't handle bounds.
131 recorder.saveLayer(&bounds, NULL); 131 recorder.saveLayer(&bounds, NULL);
132 recorder.drawRect(draw, goodDrawPaint); 132 recorder.drawRect(draw, goodDrawPaint);
133 recorder.restore(); 133 recorder.restore();
134 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { 134 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) {
135 assert_savelayer_restore(r, &record, 0, false); 135 assert_savelayer_restore(r, &record, 0, false);
136 } 136 }
137 137
138 // SaveLayer/Restore removed: no bounds + no paint = no point. 138 // SaveLayer/Restore removed: no bounds + no paint = no point.
139 recorder.saveLayer(NULL, NULL); 139 recorder.saveLayer(NULL, NULL);
140 recorder.drawRect(draw, goodDrawPaint); 140 recorder.drawRect(draw, goodDrawPaint);
141 recorder.restore(); 141 recorder.restore();
142 assert_savelayer_restore(r, &record, 3, true); 142 assert_savelayer_restore(r, &record, 3, true);
143 143
144 // TODO(mtklein): test case with null draw paint 144 // TODO(mtklein): test case with null draw paint
145 145
146 // No change: layer paint isn't alpha-only. 146 // No change: layer paint isn't alpha-only.
147 recorder.saveLayer(NULL, &badLayerPaint); 147 recorder.saveLayer(NULL, &badLayerPaint);
148 recorder.drawRect(draw, goodDrawPaint); 148 recorder.drawRect(draw, goodDrawPaint);
149 recorder.restore(); 149 recorder.restore();
150 assert_savelayer_restore(r, &record, 6, false); 150 assert_savelayer_restore(r, &record, 6, false);
151 151
152 // No change: layer paint has an effect. 152 // No change: layer paint has an effect.
153 recorder.saveLayer(NULL, &worseLayerPaint); 153 recorder.saveLayer(NULL, &worseLayerPaint);
154 recorder.drawRect(draw, goodDrawPaint); 154 recorder.drawRect(draw, goodDrawPaint);
155 recorder.restore(); 155 recorder.restore();
156 assert_savelayer_restore(r, &record, 9, false); 156 assert_savelayer_restore(r, &record, 9, false);
157 157
158 // No change: draw paint isn't opaque. 158 // SaveLayer/Restore removed: we can fold in the alpha!
159 recorder.saveLayer(NULL, &goodLayerPaint); 159 recorder.saveLayer(NULL, &goodLayerPaint);
160 recorder.drawRect(draw, badDrawPaint); 160 recorder.drawRect(draw, badDrawPaint);
161 recorder.restore(); 161 recorder.restore();
162 assert_savelayer_restore(r, &record, 12, false); 162 assert_savelayer_restore(r, &record, 12, true);
163 163
164 // SaveLayer/Restore removed: we can fold in the alpha! 164 // SaveLayer/Restore removed: we can fold in the alpha!
165 recorder.saveLayer(NULL, &goodLayerPaint); 165 recorder.saveLayer(NULL, &goodLayerPaint);
166 recorder.drawRect(draw, goodDrawPaint); 166 recorder.drawRect(draw, goodDrawPaint);
167 recorder.restore(); 167 recorder.restore();
168 assert_savelayer_restore(r, &record, 15, true); 168 assert_savelayer_restore(r, &record, 15, true);
169 169
170 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16); 170 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16);
171 REPORTER_ASSERT(r, drawRect != NULL); 171 REPORTER_ASSERT(r, drawRect != NULL);
172 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); 172 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
173 } 173 }
OLDNEW
« src/core/SkRecordOpts.cpp ('K') | « src/core/SkRecordOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698