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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 StyleResolverState resolverState(styleResolutionHost->document(), | 331 StyleResolverState resolverState(styleResolutionHost->document(), |
330 styleResolutionHost, filterStyle.get()); | 332 styleResolutionHost, filterStyle.get()); |
331 resolverState.setStyle(filterStyle); | 333 resolverState.setStyle(filterStyle); |
332 | 334 |
333 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, | 335 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, |
334 *m_filterValue); | 336 *m_filterValue); |
335 resolverState.loadPendingResources(); | 337 resolverState.loadPendingResources(); |
336 | 338 |
337 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these | 339 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these |
338 // incorporate the global alpha, which isn't applicable here. | 340 // incorporate the global alpha, which isn't applicable here. |
339 SkPaint fillPaintForFilter; | 341 PaintFlags fillPaintForFilter; |
340 m_fillStyle->applyToPaint(fillPaintForFilter); | 342 m_fillStyle->applyToPaint(fillPaintForFilter); |
341 fillPaintForFilter.setColor(m_fillStyle->paintColor()); | 343 fillPaintForFilter.setColor(m_fillStyle->paintColor()); |
342 SkPaint strokePaintForFilter; | 344 PaintFlags strokePaintForFilter; |
343 m_strokeStyle->applyToPaint(strokePaintForFilter); | 345 m_strokeStyle->applyToPaint(strokePaintForFilter); |
344 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); | 346 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); |
345 | 347 |
346 FilterEffectBuilder filterEffectBuilder( | 348 FilterEffectBuilder filterEffectBuilder( |
347 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)), | 349 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)), |
348 1.0f, // Deliberately ignore zoom on the canvas element. | 350 1.0f, // Deliberately ignore zoom on the canvas element. |
349 &fillPaintForFilter, &strokePaintForFilter); | 351 &fillPaintForFilter, &strokePaintForFilter); |
350 | 352 |
351 if (FilterEffect* lastEffect = | 353 if (FilterEffect* lastEffect = |
352 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) { | 354 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 m_strokePaint.setFilterQuality(filterQuality); | 532 m_strokePaint.setFilterQuality(filterQuality); |
531 m_fillPaint.setFilterQuality(filterQuality); | 533 m_fillPaint.setFilterQuality(filterQuality); |
532 m_imagePaint.setFilterQuality(filterQuality); | 534 m_imagePaint.setFilterQuality(filterQuality); |
533 } | 535 } |
534 | 536 |
535 bool CanvasRenderingContext2DState::shouldDrawShadows() const { | 537 bool CanvasRenderingContext2DState::shouldDrawShadows() const { |
536 return alphaChannel(m_shadowColor) && | 538 return alphaChannel(m_shadowColor) && |
537 (m_shadowBlur || !m_shadowOffset.isZero()); | 539 (m_shadowBlur || !m_shadowOffset.isZero()); |
538 } | 540 } |
539 | 541 |
540 const SkPaint* CanvasRenderingContext2DState::getPaint( | 542 const PaintFlags* CanvasRenderingContext2DState::getPaint( |
541 PaintType paintType, | 543 PaintType paintType, |
542 ShadowMode shadowMode, | 544 ShadowMode shadowMode, |
543 ImageType imageType) const { | 545 ImageType imageType) const { |
544 SkPaint* paint; | 546 PaintFlags* paint; |
545 switch (paintType) { | 547 switch (paintType) { |
546 case StrokePaintType: | 548 case StrokePaintType: |
547 updateLineDash(); | 549 updateLineDash(); |
548 updateStrokeStyle(); | 550 updateStrokeStyle(); |
549 paint = &m_strokePaint; | 551 paint = &m_strokePaint; |
550 break; | 552 break; |
551 default: | 553 default: |
552 ASSERT_NOT_REACHED(); | 554 ASSERT_NOT_REACHED(); |
553 // no break on purpose: paint needs to be assigned to avoid compiler warning | 555 // no break on purpose: paint needs to be assigned to avoid compiler warning |
554 // about uninitialized variable. | 556 // about uninitialized variable. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 paint->setLooper(0); | 592 paint->setLooper(0); |
591 paint->setImageFilter(shadowAndForegroundImageFilter()); | 593 paint->setImageFilter(shadowAndForegroundImageFilter()); |
592 return paint; | 594 return paint; |
593 } | 595 } |
594 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 596 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
595 paint->setImageFilter(0); | 597 paint->setImageFilter(0); |
596 return paint; | 598 return paint; |
597 } | 599 } |
598 | 600 |
599 } // namespace blink | 601 } // namespace blink |
OLD | NEW |