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

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

Issue 1402963003: ** DO NO COMMIT ** for jake Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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 "config.h" 5 #include "config.h"
6 6
7 #include "modules/canvas2d/CanvasRenderingContext2DState.h" 7 #include "modules/canvas2d/CanvasRenderingContext2DState.h"
8 8
9 #include "core/css/CSSFontSelector.h" 9 #include "core/css/CSSFontSelector.h"
10 #include "core/css/resolver/FilterOperationResolver.h" 10 #include "core/css/resolver/FilterOperationResolver.h"
11 #include "core/css/resolver/StyleBuilder.h" 11 #include "core/css/resolver/StyleBuilder.h"
12 #include "core/css/resolver/StyleResolverState.h" 12 #include "core/css/resolver/StyleResolverState.h"
13 #include "core/paint/FilterEffectBuilder.h" 13 #include "core/paint/FilterEffectBuilder.h"
14 #include "core/style/ComputedStyle.h" 14 #include "core/style/ComputedStyle.h"
15 #include "modules/canvas2d/CanvasGradient.h" 15 #include "modules/canvas2d/CanvasGradient.h"
16 #include "modules/canvas2d/CanvasPattern.h" 16 #include "modules/canvas2d/CanvasPattern.h"
17 #include "modules/canvas2d/CanvasStyle.h" 17 #include "modules/canvas2d/CanvasStyle.h"
18 #include "platform/graphics/DrawLooperBuilder.h" 18 #include "platform/graphics/DrawLooperBuilder.h"
19 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" 19 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
20 #include "platform/graphics/skia/SkiaUtils.h" 20 #include "platform/graphics/skia/SkiaUtils.h"
21 #include "third_party/skia/include/effects/SkDashPathEffect.h" 21 #include "third_party/skia/include/effects/SkDashPathEffect.h"
22 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" 22 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
23 23
24 static const char defaultFont[] = "10px sans-serif"; 24 static const char defaultFont[] = "10px sans-serif";
25 static const char defaultFilter[] = "none"; 25 static const char defaultFilter[] = "none";
26 static const char defaultImageSmoothingQuality[] = "low";
26 27
27 namespace blink { 28 namespace blink {
28 29
29 CanvasRenderingContext2DState::CanvasRenderingContext2DState() 30 CanvasRenderingContext2DState::CanvasRenderingContext2DState()
30 : m_unrealizedSaveCount(0) 31 : m_unrealizedSaveCount(0)
31 , m_strokeStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)) 32 , m_strokeStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK))
32 , m_fillStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)) 33 , m_fillStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK))
33 , m_shadowBlur(0) 34 , m_shadowBlur(0)
34 , m_shadowColor(Color::transparent) 35 , m_shadowColor(Color::transparent)
35 , m_globalAlpha(1) 36 , m_globalAlpha(1)
(...skipping 15 matching lines...) Expand all
51 m_fillPaint.setAntiAlias(true); 52 m_fillPaint.setAntiAlias(true);
52 m_imagePaint.setStyle(SkPaint::kFill_Style); 53 m_imagePaint.setStyle(SkPaint::kFill_Style);
53 m_imagePaint.setAntiAlias(true); 54 m_imagePaint.setAntiAlias(true);
54 m_strokePaint.setStyle(SkPaint::kStroke_Style); 55 m_strokePaint.setStyle(SkPaint::kStroke_Style);
55 m_strokePaint.setStrokeWidth(1); 56 m_strokePaint.setStrokeWidth(1);
56 m_strokePaint.setStrokeCap(SkPaint::kButt_Cap); 57 m_strokePaint.setStrokeCap(SkPaint::kButt_Cap);
57 m_strokePaint.setStrokeMiter(10); 58 m_strokePaint.setStrokeMiter(10);
58 m_strokePaint.setStrokeJoin(SkPaint::kMiter_Join); 59 m_strokePaint.setStrokeJoin(SkPaint::kMiter_Join);
59 m_strokePaint.setAntiAlias(true); 60 m_strokePaint.setAntiAlias(true);
60 setImageSmoothingEnabled(true); 61 setImageSmoothingEnabled(true);
62 setImageSmoothingQuality(defaultImageSmoothingQuality);
61 } 63 }
62 64
63 CanvasRenderingContext2DState::CanvasRenderingContext2DState(const CanvasRenderi ngContext2DState& other, ClipListCopyMode mode) 65 CanvasRenderingContext2DState::CanvasRenderingContext2DState(const CanvasRenderi ngContext2DState& other, ClipListCopyMode mode)
64 : CSSFontSelectorClient() 66 : CSSFontSelectorClient()
65 , m_unrealizedSaveCount(other.m_unrealizedSaveCount) 67 , m_unrealizedSaveCount(other.m_unrealizedSaveCount)
66 , m_unparsedStrokeColor(other.m_unparsedStrokeColor) 68 , m_unparsedStrokeColor(other.m_unparsedStrokeColor)
67 , m_unparsedFillColor(other.m_unparsedFillColor) 69 , m_unparsedFillColor(other.m_unparsedFillColor)
68 , m_strokeStyle(other.m_strokeStyle) 70 , m_strokeStyle(other.m_strokeStyle)
69 , m_fillStyle(other.m_fillStyle) 71 , m_fillStyle(other.m_fillStyle)
70 , m_strokePaint(other.m_strokePaint) 72 , m_strokePaint(other.m_strokePaint)
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 void CanvasRenderingContext2DState::setImageSmoothingEnabled(bool enabled) 471 void CanvasRenderingContext2DState::setImageSmoothingEnabled(bool enabled)
470 { 472 {
471 SkFilterQuality filterQuality = enabled ? kLow_SkFilterQuality : kNone_SkFil terQuality; 473 SkFilterQuality filterQuality = enabled ? kLow_SkFilterQuality : kNone_SkFil terQuality;
472 m_strokePaint.setFilterQuality(filterQuality); 474 m_strokePaint.setFilterQuality(filterQuality);
473 m_fillPaint.setFilterQuality(filterQuality); 475 m_fillPaint.setFilterQuality(filterQuality);
474 m_imagePaint.setFilterQuality(filterQuality); 476 m_imagePaint.setFilterQuality(filterQuality);
475 } 477 }
476 478
477 bool CanvasRenderingContext2DState::imageSmoothingEnabled() const 479 bool CanvasRenderingContext2DState::imageSmoothingEnabled() const
478 { 480 {
479 return m_imagePaint.getFilterQuality() == kLow_SkFilterQuality; 481 return m_imagePaint.getFilterQuality() == kLow_SkFilterQuality;
zino 2015/10/14 07:51:36 I think you will have to modify the imageSmoothing
480 } 482 }
481 483
484 void CanvasRenderingContext2DState::setImageSmoothingQuality(String quality)
485 {
486 SkFilterQuality filterQuality = imageSmoothingQuality2SkFilterQuality(qualit y);
487 m_strokePaint.setFilterQuality(filterQuality);
488 m_fillPaint.setFilterQuality(filterQuality);
489 m_imagePaint.setFilterQuality(filterQuality);
490 }
491
492 String CanvasRenderingContext2DState::imageSmoothingQuality() const
493 {
494 return SkFilterQuality2imageSmoothingQuality(m_imagePaint.getFilterQuality() );
495 }
496
497 String CanvasRenderingContext2DState::SkFilterQuality2imageSmoothingQuality(SkFi lterQuality quality) const
zino 2015/10/14 07:51:36 I think it is better to avoid unnecessary addition
498 {
499 if (quality == kLow_SkFilterQuality)
zino 2015/10/14 07:51:36 Please see: http://www.chromium.org/blink/coding-s
500 return "low";
501 else if (quality == kMedium_SkFilterQuality)
502 return "medium";
503 else if (quality == kHigh_SkFilterQuality)
504 return "high";
505 else
506 return "none";
507 }
508
509 SkFilterQuality CanvasRenderingContext2DState::imageSmoothingQuality2SkFilterQua lity(String quality) const
510 {
511 if (quality == "low")
zino 2015/10/14 07:51:36 ditto ('ditto' means that this is the same as abov
512 return kLow_SkFilterQuality;
513 else if (quality == "medium")
514 return kMedium_SkFilterQuality;
515 else if (quality == "high")
516 return kHigh_SkFilterQuality;
517 else
518 return kNone_SkFilterQuality;
519 }
520
482 bool CanvasRenderingContext2DState::shouldDrawShadows() const 521 bool CanvasRenderingContext2DState::shouldDrawShadows() const
483 { 522 {
484 return alphaChannel(m_shadowColor) && (m_shadowBlur || !m_shadowOffset.isZer o()); 523 return alphaChannel(m_shadowColor) && (m_shadowBlur || !m_shadowOffset.isZer o());
485 } 524 }
486 525
487 const SkPaint* CanvasRenderingContext2DState::getPaint(PaintType paintType, Shad owMode shadowMode, ImageType imageType) const 526 const SkPaint* CanvasRenderingContext2DState::getPaint(PaintType paintType, Shad owMode shadowMode, ImageType imageType) const
488 { 527 {
489 SkPaint* paint; 528 SkPaint* paint;
490 switch (paintType) { 529 switch (paintType) {
491 case StrokePaintType: 530 case StrokePaintType:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 paint->setLooper(0); 572 paint->setLooper(0);
534 paint->setImageFilter(shadowAndForegroundImageFilter()); 573 paint->setImageFilter(shadowAndForegroundImageFilter());
535 return paint; 574 return paint;
536 } 575 }
537 paint->setLooper(shadowAndForegroundDrawLooper()); 576 paint->setLooper(shadowAndForegroundDrawLooper());
538 paint->setImageFilter(0); 577 paint->setImageFilter(0);
539 return paint; 578 return paint;
540 } 579 }
541 580
542 } // blink 581 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698