Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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, |
| 120 SkFloatToIntRound(SkColorGetA(drawColor) * | |
|
mtklein
2015/01/13 18:48:20
Let's use SkMulDiv255Round?
Kimmo Kinnunen
2015/01/14 13:07:51
Done.
| |
| 121 SkColorGetA(layerColor ) / 255.0f))); | |
| 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 Loading... | |
| 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 |
| OLD | NEW |