OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/canvas2d/CanvasRenderingContext2DState.h" | 5 #include "modules/canvas2d/CanvasRenderingContext2DState.h" |
6 | 6 |
7 #include "core/css/CSSFontSelector.h" | 7 #include "core/css/CSSFontSelector.h" |
8 #include "core/css/resolver/FilterOperationResolver.h" | 8 #include "core/css/resolver/FilterOperationResolver.h" |
9 #include "core/css/resolver/StyleBuilder.h" | 9 #include "core/css/resolver/StyleBuilder.h" |
10 #include "core/css/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
11 #include "core/html/HTMLCanvasElement.h" | 11 #include "core/html/HTMLCanvasElement.h" |
12 #include "core/paint/FilterEffectBuilder.h" | 12 #include "core/paint/FilterEffectBuilder.h" |
13 #include "core/style/ComputedStyle.h" | 13 #include "core/style/ComputedStyle.h" |
14 #include "core/style/FilterOperation.h" | 14 #include "core/style/FilterOperation.h" |
15 #include "core/svg/SVGFilterElement.h" | 15 #include "core/svg/SVGFilterElement.h" |
16 #include "modules/canvas2d/CanvasGradient.h" | 16 #include "modules/canvas2d/CanvasGradient.h" |
17 #include "modules/canvas2d/CanvasPattern.h" | 17 #include "modules/canvas2d/CanvasPattern.h" |
18 #include "modules/canvas2d/CanvasRenderingContext2D.h" | 18 #include "modules/canvas2d/CanvasRenderingContext2D.h" |
19 #include "modules/canvas2d/CanvasStyle.h" | 19 #include "modules/canvas2d/CanvasStyle.h" |
20 #include "platform/graphics/DrawLooperBuilder.h" | 20 #include "platform/graphics/DrawLooperBuilder.h" |
21 #include "platform/graphics/filters/FilterEffect.h" | 21 #include "platform/graphics/filters/FilterEffect.h" |
22 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 22 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| 23 #include "platform/graphics/paint/PaintCanvas.h" |
| 24 #include "platform/graphics/paint/PaintFlags.h" |
23 #include "platform/graphics/skia/SkiaUtils.h" | 25 #include "platform/graphics/skia/SkiaUtils.h" |
24 #include "third_party/skia/include/effects/SkDashPathEffect.h" | 26 #include "third_party/skia/include/effects/SkDashPathEffect.h" |
25 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | 27 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" |
26 #include <memory> | 28 #include <memory> |
27 | 29 |
28 static const char defaultFont[] = "10px sans-serif"; | 30 static const char defaultFont[] = "10px sans-serif"; |
29 static const char defaultFilter[] = "none"; | 31 static const char defaultFilter[] = "none"; |
30 | 32 |
31 namespace blink { | 33 namespace blink { |
32 | 34 |
(...skipping 11 matching lines...) Expand all Loading... |
44 m_textBaseline(AlphabeticTextBaseline), | 46 m_textBaseline(AlphabeticTextBaseline), |
45 m_direction(DirectionInherit), | 47 m_direction(DirectionInherit), |
46 m_realizedFont(false), | 48 m_realizedFont(false), |
47 m_isTransformInvertible(true), | 49 m_isTransformInvertible(true), |
48 m_hasClip(false), | 50 m_hasClip(false), |
49 m_hasComplexClip(false), | 51 m_hasComplexClip(false), |
50 m_fillStyleDirty(true), | 52 m_fillStyleDirty(true), |
51 m_strokeStyleDirty(true), | 53 m_strokeStyleDirty(true), |
52 m_lineDashDirty(false), | 54 m_lineDashDirty(false), |
53 m_imageSmoothingQuality(kLow_SkFilterQuality) { | 55 m_imageSmoothingQuality(kLow_SkFilterQuality) { |
54 m_fillPaint.setStyle(SkPaint::kFill_Style); | 56 m_fillPaint.setStyle(PaintFlags::kFill_Style); |
55 m_fillPaint.setAntiAlias(true); | 57 m_fillPaint.setAntiAlias(true); |
56 m_imagePaint.setStyle(SkPaint::kFill_Style); | 58 m_imagePaint.setStyle(PaintFlags::kFill_Style); |
57 m_imagePaint.setAntiAlias(true); | 59 m_imagePaint.setAntiAlias(true); |
58 m_strokePaint.setStyle(SkPaint::kStroke_Style); | 60 m_strokePaint.setStyle(PaintFlags::kStroke_Style); |
59 m_strokePaint.setStrokeWidth(1); | 61 m_strokePaint.setStrokeWidth(1); |
60 m_strokePaint.setStrokeCap(SkPaint::kButt_Cap); | 62 m_strokePaint.setStrokeCap(PaintFlags::kButt_Cap); |
61 m_strokePaint.setStrokeMiter(10); | 63 m_strokePaint.setStrokeMiter(10); |
62 m_strokePaint.setStrokeJoin(SkPaint::kMiter_Join); | 64 m_strokePaint.setStrokeJoin(PaintFlags::kMiter_Join); |
63 m_strokePaint.setAntiAlias(true); | 65 m_strokePaint.setAntiAlias(true); |
64 setImageSmoothingEnabled(true); | 66 setImageSmoothingEnabled(true); |
65 } | 67 } |
66 | 68 |
67 CanvasRenderingContext2DState::CanvasRenderingContext2DState( | 69 CanvasRenderingContext2DState::CanvasRenderingContext2DState( |
68 const CanvasRenderingContext2DState& other, | 70 const CanvasRenderingContext2DState& other, |
69 ClipListCopyMode mode) | 71 ClipListCopyMode mode) |
70 : CSSFontSelectorClient(), | 72 : CSSFontSelectorClient(), |
71 m_unrealizedSaveCount(other.m_unrealizedSaveCount), | 73 m_unrealizedSaveCount(other.m_unrealizedSaveCount), |
72 m_unparsedStrokeColor(other.m_unparsedStrokeColor), | 74 m_unparsedStrokeColor(other.m_unparsedStrokeColor), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 StyleResolverState resolverState(styleResolutionHost->document(), | 297 StyleResolverState resolverState(styleResolutionHost->document(), |
296 styleResolutionHost, filterStyle.get()); | 298 styleResolutionHost, filterStyle.get()); |
297 resolverState.setStyle(filterStyle); | 299 resolverState.setStyle(filterStyle); |
298 | 300 |
299 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, | 301 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, |
300 *m_filterValue); | 302 *m_filterValue); |
301 resolverState.loadPendingResources(); | 303 resolverState.loadPendingResources(); |
302 | 304 |
303 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these | 305 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these |
304 // incorporate the global alpha, which isn't applicable here. | 306 // incorporate the global alpha, which isn't applicable here. |
305 SkPaint fillPaintForFilter; | 307 PaintFlags fillPaintForFilter; |
306 m_fillStyle->applyToPaint(fillPaintForFilter); | 308 m_fillStyle->applyToPaint(fillPaintForFilter); |
307 fillPaintForFilter.setColor(m_fillStyle->paintColor()); | 309 fillPaintForFilter.setColor(m_fillStyle->paintColor()); |
308 SkPaint strokePaintForFilter; | 310 PaintFlags strokePaintForFilter; |
309 m_strokeStyle->applyToPaint(strokePaintForFilter); | 311 m_strokeStyle->applyToPaint(strokePaintForFilter); |
310 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); | 312 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); |
311 | 313 |
312 FilterEffectBuilder filterEffectBuilder( | 314 FilterEffectBuilder filterEffectBuilder( |
313 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)), | 315 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)), |
314 1.0f, // Deliberately ignore zoom on the canvas element. | 316 1.0f, // Deliberately ignore zoom on the canvas element. |
315 &fillPaintForFilter, &strokePaintForFilter); | 317 &fillPaintForFilter, &strokePaintForFilter); |
316 | 318 |
317 if (FilterEffect* lastEffect = | 319 if (FilterEffect* lastEffect = |
318 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) { | 320 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 m_strokePaint.setFilterQuality(filterQuality); | 491 m_strokePaint.setFilterQuality(filterQuality); |
490 m_fillPaint.setFilterQuality(filterQuality); | 492 m_fillPaint.setFilterQuality(filterQuality); |
491 m_imagePaint.setFilterQuality(filterQuality); | 493 m_imagePaint.setFilterQuality(filterQuality); |
492 } | 494 } |
493 | 495 |
494 bool CanvasRenderingContext2DState::shouldDrawShadows() const { | 496 bool CanvasRenderingContext2DState::shouldDrawShadows() const { |
495 return alphaChannel(m_shadowColor) && | 497 return alphaChannel(m_shadowColor) && |
496 (m_shadowBlur || !m_shadowOffset.isZero()); | 498 (m_shadowBlur || !m_shadowOffset.isZero()); |
497 } | 499 } |
498 | 500 |
499 const SkPaint* CanvasRenderingContext2DState::getPaint( | 501 const PaintFlags* CanvasRenderingContext2DState::getPaint( |
500 PaintType paintType, | 502 PaintType paintType, |
501 ShadowMode shadowMode, | 503 ShadowMode shadowMode, |
502 ImageType imageType) const { | 504 ImageType imageType) const { |
503 SkPaint* paint; | 505 PaintFlags* paint; |
504 switch (paintType) { | 506 switch (paintType) { |
505 case StrokePaintType: | 507 case StrokePaintType: |
506 updateLineDash(); | 508 updateLineDash(); |
507 updateStrokeStyle(); | 509 updateStrokeStyle(); |
508 paint = &m_strokePaint; | 510 paint = &m_strokePaint; |
509 break; | 511 break; |
510 default: | 512 default: |
511 ASSERT_NOT_REACHED(); | 513 ASSERT_NOT_REACHED(); |
512 // no break on purpose: paint needs to be assigned to avoid compiler warning | 514 // no break on purpose: paint needs to be assigned to avoid compiler warning |
513 // about uninitialized variable. | 515 // about uninitialized variable. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 paint->setLooper(0); | 551 paint->setLooper(0); |
550 paint->setImageFilter(shadowAndForegroundImageFilter()); | 552 paint->setImageFilter(shadowAndForegroundImageFilter()); |
551 return paint; | 553 return paint; |
552 } | 554 } |
553 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 555 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
554 paint->setImageFilter(0); | 556 paint->setImageFilter(0); |
555 return paint; | 557 return paint; |
556 } | 558 } |
557 | 559 |
558 } // namespace blink | 560 } // namespace blink |
OLD | NEW |