Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/skia/SkiaUtils.h" 23 #include "platform/graphics/skia/SkiaUtils.h"
24 #include "third_party/skia/include/effects/SkDashPathEffect.h" 24 #include "third_party/skia/include/effects/SkDashPathEffect.h"
25 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" 25 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
26 #include "skia/ext/cdl_canvas.h"
27 #include "skia/ext/cdl_paint.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
33 CanvasRenderingContext2DState::CanvasRenderingContext2DState() 35 CanvasRenderingContext2DState::CanvasRenderingContext2DState()
34 : m_unrealizedSaveCount(0), 36 : m_unrealizedSaveCount(0),
35 m_strokeStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)), 37 m_strokeStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)),
36 m_fillStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)), 38 m_fillStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)),
37 m_shadowBlur(0), 39 m_shadowBlur(0),
38 m_shadowColor(Color::transparent), 40 m_shadowColor(Color::transparent),
39 m_globalAlpha(1), 41 m_globalAlpha(1),
40 m_lineDashOffset(0), 42 m_lineDashOffset(0),
41 m_unparsedFont(defaultFont), 43 m_unparsedFont(defaultFont),
42 m_unparsedFilter(defaultFilter), 44 m_unparsedFilter(defaultFilter),
43 m_textAlign(StartTextAlign), 45 m_textAlign(StartTextAlign),
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(CdlPaint::kFill_Style);
55 m_fillPaint.setAntiAlias(true); 57 m_fillPaint.setAntiAlias(true);
56 m_imagePaint.setStyle(SkPaint::kFill_Style); 58 m_imagePaint.setStyle(CdlPaint::kFill_Style);
57 m_imagePaint.setAntiAlias(true); 59 m_imagePaint.setAntiAlias(true);
58 m_strokePaint.setStyle(SkPaint::kStroke_Style); 60 m_strokePaint.setStyle(CdlPaint::kStroke_Style);
59 m_strokePaint.setStrokeWidth(1); 61 m_strokePaint.setStrokeWidth(1);
60 m_strokePaint.setStrokeCap(SkPaint::kButt_Cap); 62 m_strokePaint.setStrokeCap(CdlPaint::kButt_Cap);
61 m_strokePaint.setStrokeMiter(10); 63 m_strokePaint.setStrokeMiter(10);
62 m_strokePaint.setStrokeJoin(SkPaint::kMiter_Join); 64 m_strokePaint.setStrokeJoin(CdlPaint::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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 StyleResolverState resolverState(styleResolutionHost->document(), 293 StyleResolverState resolverState(styleResolutionHost->document(),
292 styleResolutionHost, filterStyle.get()); 294 styleResolutionHost, filterStyle.get());
293 resolverState.setStyle(filterStyle); 295 resolverState.setStyle(filterStyle);
294 296
295 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, 297 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState,
296 *m_filterValue); 298 *m_filterValue);
297 resolverState.loadPendingResources(); 299 resolverState.loadPendingResources();
298 300
299 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these 301 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these
300 // incorporate the global alpha, which isn't applicable here. 302 // incorporate the global alpha, which isn't applicable here.
301 SkPaint fillPaintForFilter; 303 CdlPaint fillPaintForFilter;
302 m_fillStyle->applyToPaint(fillPaintForFilter); 304 m_fillStyle->applyToPaint(fillPaintForFilter);
303 fillPaintForFilter.setColor(m_fillStyle->paintColor()); 305 fillPaintForFilter.setColor(m_fillStyle->paintColor());
304 SkPaint strokePaintForFilter; 306 CdlPaint strokePaintForFilter;
305 m_strokeStyle->applyToPaint(strokePaintForFilter); 307 m_strokeStyle->applyToPaint(strokePaintForFilter);
306 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); 308 strokePaintForFilter.setColor(m_strokeStyle->paintColor());
307 309
308 FilterEffectBuilder filterEffectBuilder( 310 FilterEffectBuilder filterEffectBuilder(
309 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)), 311 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)),
310 1.0f, // Deliberately ignore zoom on the canvas element. 312 1.0f, // Deliberately ignore zoom on the canvas element.
311 &fillPaintForFilter, &strokePaintForFilter); 313 &fillPaintForFilter, &strokePaintForFilter);
312 314
313 if (FilterEffect* lastEffect = 315 if (FilterEffect* lastEffect =
314 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) { 316 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 m_strokePaint.setFilterQuality(filterQuality); 487 m_strokePaint.setFilterQuality(filterQuality);
486 m_fillPaint.setFilterQuality(filterQuality); 488 m_fillPaint.setFilterQuality(filterQuality);
487 m_imagePaint.setFilterQuality(filterQuality); 489 m_imagePaint.setFilterQuality(filterQuality);
488 } 490 }
489 491
490 bool CanvasRenderingContext2DState::shouldDrawShadows() const { 492 bool CanvasRenderingContext2DState::shouldDrawShadows() const {
491 return alphaChannel(m_shadowColor) && 493 return alphaChannel(m_shadowColor) &&
492 (m_shadowBlur || !m_shadowOffset.isZero()); 494 (m_shadowBlur || !m_shadowOffset.isZero());
493 } 495 }
494 496
495 const SkPaint* CanvasRenderingContext2DState::getPaint( 497 const CdlPaint* CanvasRenderingContext2DState::getPaint(
496 PaintType paintType, 498 PaintType paintType,
497 ShadowMode shadowMode, 499 ShadowMode shadowMode,
498 ImageType imageType) const { 500 ImageType imageType) const {
499 SkPaint* paint; 501 CdlPaint* paint;
500 switch (paintType) { 502 switch (paintType) {
501 case StrokePaintType: 503 case StrokePaintType:
502 updateLineDash(); 504 updateLineDash();
503 updateStrokeStyle(); 505 updateStrokeStyle();
504 paint = &m_strokePaint; 506 paint = &m_strokePaint;
505 break; 507 break;
506 default: 508 default:
507 ASSERT_NOT_REACHED(); 509 ASSERT_NOT_REACHED();
508 // no break on purpose: paint needs to be assigned to avoid compiler warning 510 // no break on purpose: paint needs to be assigned to avoid compiler warning
509 // about uninitialized variable. 511 // about uninitialized variable.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 paint->setLooper(0); 547 paint->setLooper(0);
546 paint->setImageFilter(shadowAndForegroundImageFilter()); 548 paint->setImageFilter(shadowAndForegroundImageFilter());
547 return paint; 549 return paint;
548 } 550 }
549 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); 551 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper()));
550 paint->setImageFilter(0); 552 paint->setImageFilter(0);
551 return paint; 553 return paint;
552 } 554 }
553 555
554 } // namespace blink 556 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698