| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 | 1106 |
| 1107 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) | 1107 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) |
| 1108 { | 1108 { |
| 1109 if (contextDisabled()) | 1109 if (contextDisabled()) |
| 1110 return; | 1110 return; |
| 1111 ASSERT(m_canvas); | 1111 ASSERT(m_canvas); |
| 1112 | 1112 |
| 1113 m_canvas->drawRRect(rrect, paint); | 1113 m_canvas->drawRRect(rrect, paint); |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 void GraphicsContext::fillPath(const Path& pathToFill) | 1116 void GraphicsContext::fillPath(const Path& pathToFill, const SkPaint* fillPaint) |
| 1117 { | 1117 { |
| 1118 if (contextDisabled() || pathToFill.isEmpty()) | 1118 if (contextDisabled() || pathToFill.isEmpty()) |
| 1119 return; | 1119 return; |
| 1120 | 1120 |
| 1121 // Use const_cast and temporarily modify the fill type instead of copying th
e path. | 1121 // Use const_cast and temporarily modify the fill type instead of copying th
e path. |
| 1122 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); | 1122 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); |
| 1123 SkPath::FillType previousFillType = path.getFillType(); | 1123 SkPath::FillType previousFillType = path.getFillType(); |
| 1124 | 1124 |
| 1125 SkPath::FillType temporaryFillType = WebCoreWindRuleToSkFillType(immutableSt
ate()->fillRule()); | 1125 SkPath::FillType temporaryFillType = WebCoreWindRuleToSkFillType(immutableSt
ate()->fillRule()); |
| 1126 path.setFillType(temporaryFillType); | 1126 path.setFillType(temporaryFillType); |
| 1127 | 1127 |
| 1128 drawPath(path, immutableState()->fillPaint()); | 1128 drawPath(path, fillPaint ? *fillPaint : immutableState()->fillPaint()); |
| 1129 | 1129 |
| 1130 path.setFillType(previousFillType); | 1130 path.setFillType(previousFillType); |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 void GraphicsContext::fillRect(const FloatRect& rect) | 1133 void GraphicsContext::fillRect(const FloatRect& rect, const SkPaint* fillPaint) |
| 1134 { | 1134 { |
| 1135 if (contextDisabled()) | 1135 if (contextDisabled()) |
| 1136 return; | 1136 return; |
| 1137 | 1137 |
| 1138 drawRect(rect, immutableState()->fillPaint()); | 1138 drawRect(rect, fillPaint ? *fillPaint : immutableState()->fillPaint()); |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer
mode::Mode xferMode) | 1141 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer
mode::Mode xferMode) |
| 1142 { | 1142 { |
| 1143 if (contextDisabled()) | 1143 if (contextDisabled()) |
| 1144 return; | 1144 return; |
| 1145 | 1145 |
| 1146 if (color == fillColor() && xferMode == compositeOperation()) { | 1146 if (color == fillColor() && xferMode == compositeOperation()) { |
| 1147 drawRect(rect, immutableState()->fillPaint()); | 1147 drawRect(rect, immutableState()->fillPaint()); |
| 1148 return; | 1148 return; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 | 1208 |
| 1209 SkRRect rr; | 1209 SkRRect rr; |
| 1210 rr.setRectRadii(rect, radii); | 1210 rr.setRectRadii(rect, radii); |
| 1211 | 1211 |
| 1212 SkPaint paint(immutableState()->fillPaint()); | 1212 SkPaint paint(immutableState()->fillPaint()); |
| 1213 paint.setColor(color.rgb()); | 1213 paint.setColor(color.rgb()); |
| 1214 | 1214 |
| 1215 m_canvas->drawRRect(rr, paint); | 1215 m_canvas->drawRRect(rr, paint); |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 void GraphicsContext::fillEllipse(const FloatRect& ellipse) | 1218 void GraphicsContext::fillEllipse(const FloatRect& ellipse, const SkPaint* fillP
aint) |
| 1219 { | 1219 { |
| 1220 if (contextDisabled()) | 1220 if (contextDisabled()) |
| 1221 return; | 1221 return; |
| 1222 | 1222 |
| 1223 SkRect rect = ellipse; | 1223 SkRect rect = ellipse; |
| 1224 drawOval(rect, immutableState()->fillPaint()); | 1224 drawOval(rect, fillPaint ? *fillPaint : immutableState()->fillPaint()); |
| 1225 } | 1225 } |
| 1226 | 1226 |
| 1227 void GraphicsContext::strokePath(const Path& pathToStroke) | 1227 void GraphicsContext::strokePath(const Path& pathToStroke, const SkPaint* stroke
Paint) |
| 1228 { | 1228 { |
| 1229 if (contextDisabled() || pathToStroke.isEmpty()) | 1229 if (contextDisabled() || pathToStroke.isEmpty()) |
| 1230 return; | 1230 return; |
| 1231 | 1231 |
| 1232 const SkPath& path = pathToStroke.skPath(); | 1232 const SkPath& path = pathToStroke.skPath(); |
| 1233 drawPath(path, immutableState()->strokePaint()); | 1233 drawPath(path, strokePaint ? *strokePaint : immutableState()->strokePaint())
; |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 void GraphicsContext::strokeRect(const FloatRect& rect) | 1236 void GraphicsContext::strokeRect(const FloatRect& rect) |
| 1237 { | 1237 { |
| 1238 strokeRect(rect, strokeThickness()); | 1238 strokeRect(rect, strokeThickness()); |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) | 1241 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) |
| 1242 { | 1242 { |
| 1243 if (contextDisabled()) | 1243 if (contextDisabled()) |
| 1244 return; | 1244 return; |
| 1245 | 1245 |
| 1246 SkPaint paint(immutableState()->strokePaint()); | 1246 SkPaint paint(immutableState()->strokePaint()); |
| 1247 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); | 1247 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); |
| 1248 // Reset the dash effect to account for the width | 1248 // Reset the dash effect to account for the width |
| 1249 immutableState()->strokeData().setupPaintDashPathEffect(&paint, 0); | 1249 immutableState()->strokeData().setupPaintDashPathEffect(&paint, 0); |
| 1250 |
| 1251 strokeRect(rect, paint); |
| 1252 } |
| 1253 |
| 1254 void GraphicsContext::strokeRect(const FloatRect& rect, const SkPaint& strokePai
nt) |
| 1255 { |
| 1256 if (contextDisabled()) |
| 1257 return; |
| 1258 |
| 1259 ASSERT(strokePaint.getStyle() == SkPaint::kStroke_Style); |
| 1260 |
| 1250 // strokerect has special rules for CSS when the rect is degenerate: | 1261 // strokerect has special rules for CSS when the rect is degenerate: |
| 1251 // if width==0 && height==0, do nothing | 1262 // if width==0 && height==0, do nothing |
| 1252 // if width==0 || height==0, then just draw line for the other dimension | 1263 // if width==0 || height==0, then just draw line for the other dimension |
| 1253 SkRect r(rect); | 1264 SkRect r(rect); |
| 1254 bool validW = r.width() > 0; | 1265 bool validW = r.width() > 0; |
| 1255 bool validH = r.height() > 0; | 1266 bool validH = r.height() > 0; |
| 1256 if (validW && validH) { | 1267 if (validW && validH) { |
| 1257 drawRect(r, paint); | 1268 drawRect(r, strokePaint); |
| 1258 } else if (validW || validH) { | 1269 } else if (validW || validH) { |
| 1259 // we are expected to respect the lineJoin, so we can't just call | 1270 // we are expected to respect the lineJoin, so we can't just call |
| 1260 // drawLine -- we have to create a path that doubles back on itself. | 1271 // drawLine -- we have to create a path that doubles back on itself. |
| 1261 SkPath path; | 1272 SkPath path; |
| 1262 path.moveTo(r.fLeft, r.fTop); | 1273 path.moveTo(r.fLeft, r.fTop); |
| 1263 path.lineTo(r.fRight, r.fBottom); | 1274 path.lineTo(r.fRight, r.fBottom); |
| 1264 path.close(); | 1275 path.close(); |
| 1265 drawPath(path, paint); | 1276 drawPath(path, strokePaint); |
| 1266 } | 1277 } |
| 1267 } | 1278 } |
| 1268 | 1279 |
| 1269 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) | 1280 void GraphicsContext::strokeEllipse(const FloatRect& ellipse, const SkPaint* str
okePaint) |
| 1270 { | 1281 { |
| 1271 if (contextDisabled()) | 1282 if (contextDisabled()) |
| 1272 return; | 1283 return; |
| 1273 | 1284 |
| 1274 drawOval(ellipse, immutableState()->strokePaint()); | 1285 drawOval(ellipse, strokePaint ? *strokePaint : immutableState()->strokePaint
()); |
| 1275 } | 1286 } |
| 1276 | 1287 |
| 1277 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect, SkRegion::Op
regionOp) | 1288 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect, SkRegion::Op
regionOp) |
| 1278 { | 1289 { |
| 1279 if (contextDisabled()) | 1290 if (contextDisabled()) |
| 1280 return; | 1291 return; |
| 1281 | 1292 |
| 1282 if (!rect.isRounded()) { | 1293 if (!rect.isRounded()) { |
| 1283 clipRect(rect.rect(), NotAntiAliased, regionOp); | 1294 clipRect(rect.rect(), NotAntiAliased, regionOp); |
| 1284 return; | 1295 return; |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 // being returned from computeInterpolationQuality. | 1748 // being returned from computeInterpolationQuality. |
| 1738 resampling = InterpolationLow; | 1749 resampling = InterpolationLow; |
| 1739 } | 1750 } |
| 1740 resampling = limitInterpolationQuality(this, resampling); | 1751 resampling = limitInterpolationQuality(this, resampling); |
| 1741 paint->setFilterQuality(static_cast<SkFilterQuality>(resampling)); | 1752 paint->setFilterQuality(static_cast<SkFilterQuality>(resampling)); |
| 1742 | 1753 |
| 1743 return initialSaveCount; | 1754 return initialSaveCount; |
| 1744 } | 1755 } |
| 1745 | 1756 |
| 1746 } // namespace blink | 1757 } // namespace blink |
| OLD | NEW |