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

Side by Side Diff: src/core/SkRecordOpts.cpp

Issue 817033002: Allow the alpha folding optimization if the single draw's paint has a shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fearless Created 6 years 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 | « no previous file | 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 "SkRecordOpts.h" 8 #include "SkRecordOpts.h"
9 9
10 #include "SkRecordPattern.h" 10 #include "SkRecordPattern.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) || !IsOpaque(drawColor) ||
115 HasAnyEffect(*layerPaint) || HasAnyEffect(*drawPaint)) { 115 HasAnyEffect(*layerPaint) || CantFoldAlpha(*drawPaint)) {
116 // Too fancy for us. Actually, as long as layerColor is just an alp ha 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. 117 // we can blend it into drawColor's alpha; drawColor doesn't strictl y have to be opaque.
118 return false; 118 return false;
119 } 119 }
120 120
121 drawPaint->setColor(SkColorSetA(drawColor, SkColorGetA(layerColor))); 121 drawPaint->setColor(SkColorSetA(drawColor, 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) {
132 return paint.getPathEffect() || 132 return paint.getPathEffect() ||
133 paint.getShader() || 133 paint.getShader() ||
134 paint.getXfermode() || 134 paint.getXfermode() ||
135 paint.getMaskFilter() || 135 paint.getMaskFilter() ||
136 paint.getColorFilter() || 136 paint.getColorFilter() ||
137 paint.getRasterizer() || 137 paint.getRasterizer() ||
138 paint.getLooper() || 138 paint.getLooper() ||
139 paint.getImageFilter(); 139 paint.getImageFilter();
140 } 140 }
141 141
142 // The alpha folding can proceed if the single draw's paint has a shader,
143 // path effect, mask filter and/or rasterizer.
144 // TODO: most likely the looper and only some xfer modes are the hard
145 // constraints
146 static bool CantFoldAlpha(const SkPaint& paint) {
147 return paint.getXfermode() ||
148 paint.getColorFilter() ||
149 paint.getLooper() ||
150 paint.getImageFilter();
151 }
152
142 static bool IsOpaque(SkColor color) { 153 static bool IsOpaque(SkColor color) {
143 return SkColorGetA(color) == SK_AlphaOPAQUE; 154 return SkColorGetA(color) == SK_AlphaOPAQUE;
144 } 155 }
145 static bool IsOnlyAlpha(SkColor color) { 156 static bool IsOnlyAlpha(SkColor color) {
146 return SK_ColorTRANSPARENT == SkColorSetA(color, SK_AlphaTRANSPARENT); 157 return SK_ColorTRANSPARENT == SkColorSetA(color, SK_AlphaTRANSPARENT);
147 } 158 }
148 }; 159 };
149 void SkRecordNoopSaveLayerDrawRestores(SkRecord* record) { 160 void SkRecordNoopSaveLayerDrawRestores(SkRecord* record) {
150 SaveLayerDrawRestoreNooper pass; 161 SaveLayerDrawRestoreNooper pass;
151 apply(&pass, record); 162 apply(&pass, record);
152 } 163 }
153 164
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698