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 22 matching lines...) Expand all Loading... |
33 #include "core/platform/graphics/ImageBuffer.h" | 33 #include "core/platform/graphics/ImageBuffer.h" |
34 #include "core/platform/graphics/IntRect.h" | 34 #include "core/platform/graphics/IntRect.h" |
35 #include "core/platform/graphics/RoundedRect.h" | 35 #include "core/platform/graphics/RoundedRect.h" |
36 #include "core/platform/graphics/TextRunIterator.h" | 36 #include "core/platform/graphics/TextRunIterator.h" |
37 #include "core/platform/graphics/skia/SkiaUtils.h" | 37 #include "core/platform/graphics/skia/SkiaUtils.h" |
38 #include "core/platform/text/BidiResolver.h" | 38 #include "core/platform/text/BidiResolver.h" |
39 | 39 |
40 #include "third_party/skia/include/core/SkAnnotation.h" | 40 #include "third_party/skia/include/core/SkAnnotation.h" |
41 #include "third_party/skia/include/core/SkColorFilter.h" | 41 #include "third_party/skia/include/core/SkColorFilter.h" |
42 #include "third_party/skia/include/core/SkData.h" | 42 #include "third_party/skia/include/core/SkData.h" |
| 43 #include "third_party/skia/include/core/SkRefCnt.h" |
43 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 44 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
44 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" | |
45 | 45 |
46 #include <wtf/Assertions.h> | 46 #include <wtf/Assertions.h> |
47 #include <wtf/MathExtras.h> | 47 #include <wtf/MathExtras.h> |
48 | 48 |
49 #if OS(DARWIN) | 49 #if OS(DARWIN) |
50 #include <ApplicationServices/ApplicationServices.h> | 50 #include <ApplicationServices/ApplicationServices.h> |
51 #endif | 51 #endif |
52 | 52 |
53 using namespace std; | 53 using namespace std; |
54 | 54 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (paintingDisabled()) | 174 if (paintingDisabled()) |
175 return; | 175 return; |
176 | 176 |
177 m_state->m_strokeColor = color; | 177 m_state->m_strokeColor = color; |
178 m_state->m_strokeColorPacked = color.rgb(); | 178 m_state->m_strokeColorPacked = color.rgb(); |
179 m_state->m_strokeColorSpace = colorSpace; | 179 m_state->m_strokeColorSpace = colorSpace; |
180 m_state->m_strokeGradient.clear(); | 180 m_state->m_strokeGradient.clear(); |
181 m_state->m_strokePattern.clear(); | 181 m_state->m_strokePattern.clear(); |
182 } | 182 } |
183 | 183 |
184 void GraphicsContext::setShadow(const FloatSize& size, float blur, const Color&
color, ColorSpace colorSpace) | 184 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color
& color, DrawLooper::ShadowAlphaMode shadowAlphaMode) |
185 { | 185 { |
186 if (paintingDisabled()) | 186 if (paintingDisabled()) |
187 return; | 187 return; |
188 | 188 |
189 m_state->m_shadowOffset = size; | 189 if (!color.isValid() || !color.alpha() || (!offset.width() && !offset.height
() && !blur)) { |
190 m_state->m_shadowBlur = blur; | 190 clearShadow(); |
191 m_state->m_shadowColor = color; | |
192 m_state->m_shadowColorSpace = colorSpace; | |
193 | |
194 // Detect when there's no effective shadow and clear the looper. | |
195 if (!size.width() && !size.height() && !blur) { | |
196 setDrawLooper(0); | |
197 return; | 191 return; |
198 } | 192 } |
199 | 193 |
200 double width = size.width(); | 194 DrawLooper::ShadowTransformMode shadowTransformMode; |
201 double height = size.height(); | 195 if (m_state->m_shadowsIgnoreTransforms) |
| 196 shadowTransformMode = DrawLooper::ShadowIgnoresTransforms; |
| 197 else |
| 198 shadowTransformMode = DrawLooper::ShadowRespectsTransforms; |
202 | 199 |
203 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag; | 200 DrawLooper drawLooper; |
204 | 201 drawLooper.addUnmodifiedContent(); |
205 if (m_state->m_shadowsIgnoreTransforms) | 202 drawLooper.addShadow(offset, blur, color, shadowTransformMode, shadowAlphaMo
de); |
206 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag; | 203 setDrawLooper(drawLooper); |
207 | |
208 SkColor c; | |
209 if (color.isValid()) | |
210 c = color.rgb(); | |
211 else | |
212 c = SkColorSetARGB(0xFF/3, 0, 0, 0); // "std" apple shadow color. | |
213 | |
214 // TODO(tc): Should we have a max value for the blur? CG clamps at 1000.0 | |
215 // for perf reasons. | |
216 | |
217 SkLayerDrawLooper* dl = new SkLayerDrawLooper; | |
218 SkAutoUnref aur(dl); | |
219 | |
220 // top layer, we just draw unchanged | |
221 dl->addLayer(); | |
222 | |
223 // lower layer contains our offset, blur, and colorfilter | |
224 SkLayerDrawLooper::LayerInfo info; | |
225 | |
226 // Since CSS box-shadow ignores the original alpha, we used to default to kS
rc_Mode here and | |
227 // only switch to kDst_Mode for Canvas. But that precaution is not really ne
cessary because | |
228 // RenderBoxModelObject performs a dedicated shadow fill with opaque black t
o ensure | |
229 // cross-platform consistent results. | |
230 info.fColorMode = SkXfermode::kDst_Mode; | |
231 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur | |
232 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; | |
233 info.fOffset.set(width, height); | |
234 info.fPostTranslate = m_state->m_shadowsIgnoreTransforms; | |
235 | |
236 SkMaskFilter* mf = SkBlurMaskFilter::Create((double)blur / 2.0, SkBlurMaskFi
lter::kNormal_BlurStyle, mfFlags); | |
237 | |
238 SkColorFilter* cf = SkColorFilter::CreateModeFilter(c, SkXfermode::kSrcIn_Mo
de); | |
239 | |
240 SkPaint* paint = dl->addLayer(info); | |
241 SkSafeUnref(paint->setMaskFilter(mf)); | |
242 SkSafeUnref(paint->setColorFilter(cf)); | |
243 | |
244 // dl is now built, just install it | |
245 setDrawLooper(dl); | |
246 } | 204 } |
247 | 205 |
248 void GraphicsContext::clearShadow() | 206 void GraphicsContext::setDrawLooper(DrawLooper& drawLooper) |
249 { | 207 { |
250 if (paintingDisabled()) | 208 if (paintingDisabled()) |
251 return; | 209 return; |
252 | 210 |
253 m_state->m_shadowOffset = FloatSize(); | 211 setDrawLooper(drawLooper.skDrawLooper()); |
254 m_state->m_shadowBlur = 0; | 212 } |
255 m_state->m_shadowColor = Color(); | 213 |
256 m_state->m_shadowColorSpace = ColorSpaceDeviceRGB; | 214 void GraphicsContext::clearDrawLooper() |
| 215 { |
| 216 if (paintingDisabled()) |
| 217 return; |
257 | 218 |
258 setDrawLooper(0); | 219 setDrawLooper(0); |
259 } | 220 } |
260 | 221 |
261 bool GraphicsContext::hasShadow() const | 222 bool GraphicsContext::hasShadow() const |
262 { | 223 { |
263 return m_state->m_shadowColor.isValid() && m_state->m_shadowColor.alpha() | 224 return !!m_state->m_looper; |
264 && (m_state->m_shadowBlur || m_state->m_shadowOffset.width() || m_state-
>m_shadowOffset.height()); | |
265 } | |
266 | |
267 bool GraphicsContext::getShadow(FloatSize& offset, float& blur, Color& color, Co
lorSpace& colorSpace) const | |
268 { | |
269 offset = m_state->m_shadowOffset; | |
270 blur = m_state->m_shadowBlur; | |
271 color = m_state->m_shadowColor; | |
272 colorSpace = m_state->m_shadowColorSpace; | |
273 | |
274 return hasShadow(); | |
275 } | 225 } |
276 | 226 |
277 float GraphicsContext::strokeThickness() const | 227 float GraphicsContext::strokeThickness() const |
278 { | 228 { |
279 return m_state->m_strokeThickness; | 229 return m_state->m_strokeThickness; |
280 } | 230 } |
281 | 231 |
282 StrokeStyle GraphicsContext::strokeStyle() const | 232 StrokeStyle GraphicsContext::strokeStyle() const |
283 { | 233 { |
284 return m_state->m_strokeStyle; | 234 return m_state->m_strokeStyle; |
(...skipping 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 | 2103 |
2154 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) | 2104 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
2155 { | 2105 { |
2156 if (m_trackTextRegion) { | 2106 if (m_trackTextRegion) { |
2157 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 2107 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
2158 m_textRegion.join(textRect); | 2108 m_textRegion.join(textRect); |
2159 } | 2109 } |
2160 } | 2110 } |
2161 | 2111 |
2162 } | 2112 } |
OLD | NEW |