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

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
« no previous file with comments | « no previous file | tests/RecordOptsTest.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 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 SkPaint* drawPaint = pattern->second<SkPaint>(); 100 SkPaint* drawPaint = pattern->second<SkPaint>();
101 if (drawPaint == NULL) { 101 if (drawPaint == NULL) {
102 // We can just give the draw the SaveLayer's paint. 102 // We can just give the draw the SaveLayer's paint.
103 // TODO(mtklein): figure out how to do this clearly 103 // TODO(mtklein): figure out how to do this clearly
104 return false; 104 return false;
105 } 105 }
106 106
107 const uint32_t layerColor = layerPaint->getColor(); 107 const uint32_t layerColor = layerPaint->getColor();
108 const uint32_t drawColor = drawPaint->getColor(); 108 const uint32_t drawColor = drawPaint->getColor();
109 if (!IsOnlyAlpha(layerColor) || !IsOpaque(drawColor) || 109 if (!IsOnlyAlpha(layerColor) || HasAnyEffect(*layerPaint) || CantFoldAlp ha(*drawPaint)) {
110 HasAnyEffect(*layerPaint) || CantFoldAlpha(*drawPaint)) { 110 // Too fancy for us.
111 // Too fancy for us. Actually, as long as layerColor is just an alp ha
112 // we can blend it into drawColor's alpha; drawColor doesn't strictl y have to be opaque.
113 return false; 111 return false;
114 } 112 }
115 113
116 drawPaint->setColor(SkColorSetA(drawColor, SkColorGetA(layerColor))); 114 drawPaint->setAlpha(SkMulDiv255Round(SkColorGetA(drawColor), SkColorGetA (layerColor)));
117 return KillSaveLayerAndRestore(record, begin); 115 return KillSaveLayerAndRestore(record, begin);
118 } 116 }
119 117
120 static bool KillSaveLayerAndRestore(SkRecord* record, unsigned saveLayerInde x) { 118 static bool KillSaveLayerAndRestore(SkRecord* record, unsigned saveLayerInde x) {
121 record->replace<NoOp>(saveLayerIndex); // SaveLayer 119 record->replace<NoOp>(saveLayerIndex); // SaveLayer
122 record->replace<NoOp>(saveLayerIndex+2); // Restore 120 record->replace<NoOp>(saveLayerIndex+2); // Restore
123 return true; 121 return true;
124 } 122 }
125 123
126 static bool HasAnyEffect(const SkPaint& paint) { 124 static bool HasAnyEffect(const SkPaint& paint) {
(...skipping 11 matching lines...) Expand all
138 // path effect, mask filter and/or rasterizer. 136 // path effect, mask filter and/or rasterizer.
139 // TODO: most likely the looper and only some xfer modes are the hard 137 // TODO: most likely the looper and only some xfer modes are the hard
140 // constraints 138 // constraints
141 static bool CantFoldAlpha(const SkPaint& paint) { 139 static bool CantFoldAlpha(const SkPaint& paint) {
142 return paint.getXfermode() || 140 return paint.getXfermode() ||
143 paint.getColorFilter() || 141 paint.getColorFilter() ||
144 paint.getLooper() || 142 paint.getLooper() ||
145 paint.getImageFilter(); 143 paint.getImageFilter();
146 } 144 }
147 145
148 static bool IsOpaque(SkColor color) {
149 return SkColorGetA(color) == SK_AlphaOPAQUE;
150 }
151 static bool IsOnlyAlpha(SkColor color) { 146 static bool IsOnlyAlpha(SkColor color) {
152 return SK_ColorTRANSPARENT == SkColorSetA(color, SK_AlphaTRANSPARENT); 147 return SK_ColorTRANSPARENT == SkColorSetA(color, SK_AlphaTRANSPARENT);
153 } 148 }
154 }; 149 };
155 void SkRecordNoopSaveLayerDrawRestores(SkRecord* record) { 150 void SkRecordNoopSaveLayerDrawRestores(SkRecord* record) {
156 SaveLayerDrawRestoreNooper pass; 151 SaveLayerDrawRestoreNooper pass;
157 apply(&pass, record); 152 apply(&pass, record);
158 } 153 }
159 154
OLDNEW
« no previous file with comments | « no previous file | tests/RecordOptsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698