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

Side by Side Diff: src/core/SkRecordOpts.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
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 "SkRecordOpts.h" 8 #include "SkRecordOpts.h"
9 9
10 #include "SkRecordPattern.h" 10 #include "SkRecordPattern.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 SkPaint* drawPaint = pattern->second<SkPaint>(); 105 SkPaint* drawPaint = pattern->second<SkPaint>();
106 if (drawPaint == NULL) { 106 if (drawPaint == NULL) {
107 // We can just give the draw the SaveLayer's paint. 107 // We can just give the draw the SaveLayer's paint.
108 // TODO(mtklein): figure out how to do this clearly 108 // TODO(mtklein): figure out how to do this clearly
109 return false; 109 return false;
110 } 110 }
111 111
112 const uint32_t layerColor = layerPaint->getColor(); 112 const uint32_t layerColor = layerPaint->getColor();
113 const uint32_t drawColor = drawPaint->getColor(); 113 const uint32_t drawColor = drawPaint->getColor();
114 if (!IsOnlyAlpha(layerColor) || !IsOpaque(drawColor) || 114 if (!IsOnlyAlpha(layerColor) || HasAnyEffect(*layerPaint) || CantFoldAlp ha(*drawPaint)) {
115 HasAnyEffect(*layerPaint) || CantFoldAlpha(*drawPaint)) { 115 // Too fancy for us.
116 // Too fancy for us. Actually, as long as layerColor is just an alp ha
117 // we can blend it into drawColor's alpha; drawColor doesn't strictl y have to be opaque.
118 return false; 116 return false;
119 } 117 }
120 118
121 drawPaint->setColor(SkColorSetA(drawColor, SkColorGetA(layerColor))); 119 drawPaint->setColor(SkColorSetA(drawColor,
mtklein 2015/01/14 13:28:31 Just FYI, SkPaint has a setAlpha() helper.
120 SkMulDiv255Round(SkColorGetA(drawColor),
121 SkColorGetA(layerColor) )));
122 return KillSaveLayerAndRestore(record, begin); 122 return KillSaveLayerAndRestore(record, begin);
123 } 123 }
124 124
125 static bool KillSaveLayerAndRestore(SkRecord* record, unsigned saveLayerInde x) { 125 static bool KillSaveLayerAndRestore(SkRecord* record, unsigned saveLayerInde x) {
126 record->replace<NoOp>(saveLayerIndex); // SaveLayer 126 record->replace<NoOp>(saveLayerIndex); // SaveLayer
127 record->replace<NoOp>(saveLayerIndex+2); // Restore 127 record->replace<NoOp>(saveLayerIndex+2); // Restore
128 return true; 128 return true;
129 } 129 }
130 130
131 static bool HasAnyEffect(const SkPaint& paint) { 131 static bool HasAnyEffect(const SkPaint& paint) {
(...skipping 11 matching lines...) Expand all
143 // path effect, mask filter and/or rasterizer. 143 // path effect, mask filter and/or rasterizer.
144 // TODO: most likely the looper and only some xfer modes are the hard 144 // TODO: most likely the looper and only some xfer modes are the hard
145 // constraints 145 // constraints
146 static bool CantFoldAlpha(const SkPaint& paint) { 146 static bool CantFoldAlpha(const SkPaint& paint) {
147 return paint.getXfermode() || 147 return paint.getXfermode() ||
148 paint.getColorFilter() || 148 paint.getColorFilter() ||
149 paint.getLooper() || 149 paint.getLooper() ||
150 paint.getImageFilter(); 150 paint.getImageFilter();
151 } 151 }
152 152
153 static bool IsOpaque(SkColor color) {
154 return SkColorGetA(color) == SK_AlphaOPAQUE;
155 }
156 static bool IsOnlyAlpha(SkColor color) { 153 static bool IsOnlyAlpha(SkColor color) {
157 return SK_ColorTRANSPARENT == SkColorSetA(color, SK_AlphaTRANSPARENT); 154 return SK_ColorTRANSPARENT == SkColorSetA(color, SK_AlphaTRANSPARENT);
158 } 155 }
159 }; 156 };
160 void SkRecordNoopSaveLayerDrawRestores(SkRecord* record) { 157 void SkRecordNoopSaveLayerDrawRestores(SkRecord* record) {
161 SaveLayerDrawRestoreNooper pass; 158 SaveLayerDrawRestoreNooper pass;
162 apply(&pass, record); 159 apply(&pass, record);
163 } 160 }
164 161
OLDNEW
« gm/recordopts.cpp ('K') | « gyp/gmslides.gypi ('k') | tests/RecordOptsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698