OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2006, Google Inc. All rights reserved. | 2 * Copyright (c) 2006, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 if (!size.width() && !size.height() && !blurFloat) { | 1040 if (!size.width() && !size.height() && !blurFloat) { |
1041 platformContext()->setDrawLooper(0); | 1041 platformContext()->setDrawLooper(0); |
1042 return; | 1042 return; |
1043 } | 1043 } |
1044 | 1044 |
1045 double width = size.width(); | 1045 double width = size.width(); |
1046 double height = size.height(); | 1046 double height = size.height(); |
1047 double blur = blurFloat; | 1047 double blur = blurFloat; |
1048 | 1048 |
1049 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag; | 1049 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
| 1050 SkXfermode::Mode colorMode = SkXfermode::kSrc_Mode; |
1050 | 1051 |
1051 if (m_state.shadowsIgnoreTransforms) { | 1052 if (m_state.shadowsIgnoreTransforms) { |
1052 // Currently only the GraphicsContext associated with the | 1053 // Currently only the GraphicsContext associated with the |
1053 // CanvasRenderingContext for HTMLCanvasElement have shadows ignore | 1054 // CanvasRenderingContext for HTMLCanvasElement have shadows ignore |
1054 // Transforms. So with this flag set, we know this state is associated | 1055 // Transforms. So with this flag set, we know this state is associated |
1055 // with a CanvasRenderingContext. | 1056 // with a CanvasRenderingContext. |
1056 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag; | 1057 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag; |
1057 | 1058 |
| 1059 // CSS wants us to ignore the original's alpha, but Canvas wants us to |
| 1060 // modulate with it. Using shadowsIgnoreTransforms to tell us that we're |
| 1061 // in a Canvas, we change the colormode to kDst_Mode, so we don't overwr
ite |
| 1062 // it with our layer's (default opaque-black) color. |
| 1063 colorMode = SkXfermode::kDst_Mode; |
| 1064 |
1058 // CG uses natural orientation for Y axis, but the HTML5 canvas spec | 1065 // CG uses natural orientation for Y axis, but the HTML5 canvas spec |
1059 // does not. | 1066 // does not. |
1060 // So we now flip the height since it was flipped in | 1067 // So we now flip the height since it was flipped in |
1061 // CanvasRenderingContext in order to work with CG. | 1068 // CanvasRenderingContext in order to work with CG. |
1062 height = -height; | 1069 height = -height; |
1063 } | 1070 } |
1064 | 1071 |
1065 SkColor c; | 1072 SkColor c; |
1066 if (color.isValid()) | 1073 if (color.isValid()) |
1067 c = color.rgb(); | 1074 c = color.rgb(); |
1068 else | 1075 else |
1069 c = SkColorSetARGB(0xFF/3, 0, 0, 0); // "std" apple shadow color. | 1076 c = SkColorSetARGB(0xFF/3, 0, 0, 0); // "std" apple shadow color. |
1070 | 1077 |
1071 // TODO(tc): Should we have a max value for the blur? CG clamps at 1000.0 | 1078 // TODO(tc): Should we have a max value for the blur? CG clamps at 1000.0 |
1072 // for perf reasons. | 1079 // for perf reasons. |
1073 | 1080 |
1074 SkLayerDrawLooper* dl = new SkLayerDrawLooper; | 1081 SkLayerDrawLooper* dl = new SkLayerDrawLooper; |
1075 SkAutoUnref aur(dl); | 1082 SkAutoUnref aur(dl); |
1076 | 1083 |
1077 // top layer, we just draw unchanged | 1084 // top layer, we just draw unchanged |
1078 dl->addLayer(); | 1085 dl->addLayer(); |
1079 | 1086 |
1080 // lower layer contains our offset, blur, and colorfilter | 1087 // lower layer contains our offset, blur, and colorfilter |
1081 SkLayerDrawLooper::LayerInfo info; | 1088 SkLayerDrawLooper::LayerInfo info; |
1082 | 1089 |
1083 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur | 1090 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur |
1084 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; | 1091 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; |
1085 info.fColorMode = SkXfermode::kDst_Mode; | 1092 info.fColorMode = colorMode; |
1086 info.fOffset.set(width, height); | 1093 info.fOffset.set(width, height); |
1087 info.fPostTranslate = m_state.shadowsIgnoreTransforms; | 1094 info.fPostTranslate = m_state.shadowsIgnoreTransforms; |
1088 | 1095 |
1089 SkMaskFilter* mf = SkBlurMaskFilter::Create(blur / 2, SkBlurMaskFilter::kNor
mal_BlurStyle, mfFlags); | 1096 SkMaskFilter* mf = SkBlurMaskFilter::Create(blur / 2, SkBlurMaskFilter::kNor
mal_BlurStyle, mfFlags); |
1090 | 1097 |
1091 SkColorFilter* cf = SkColorFilter::CreateModeFilter(c, SkXfermode::kSrcIn_Mo
de); | 1098 SkColorFilter* cf = SkColorFilter::CreateModeFilter(c, SkXfermode::kSrcIn_Mo
de); |
1092 | 1099 |
1093 SkPaint* paint = dl->addLayer(info); | 1100 SkPaint* paint = dl->addLayer(info); |
1094 SkSafeUnref(paint->setMaskFilter(mf)); | 1101 SkSafeUnref(paint->setMaskFilter(mf)); |
1095 SkSafeUnref(paint->setColorFilter(cf)); | 1102 SkSafeUnref(paint->setColorFilter(cf)); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 { | 1259 { |
1253 platformContext()->setSharedGraphicsContext3D(context, framebuffer, size); | 1260 platformContext()->setSharedGraphicsContext3D(context, framebuffer, size); |
1254 } | 1261 } |
1255 | 1262 |
1256 void GraphicsContext::markDirtyRect(const IntRect& rect) | 1263 void GraphicsContext::markDirtyRect(const IntRect& rect) |
1257 { | 1264 { |
1258 platformContext()->markDirtyRect(rect); | 1265 platformContext()->markDirtyRect(rect); |
1259 } | 1266 } |
1260 | 1267 |
1261 } // namespace WebCore | 1268 } // namespace WebCore |
OLD | NEW |