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

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2DState.cpp

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
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 "core/html/canvas/CanvasRenderingContext2DState.h" 7 #include "core/html/canvas/CanvasRenderingContext2DState.h"
8 8
9 #include "core/css/CSSFontSelector.h" 9 #include "core/css/CSSFontSelector.h"
10 #include "core/html/canvas/CanvasGradient.h" 10 #include "core/html/canvas/CanvasGradient.h"
(...skipping 23 matching lines...) Expand all
34 , m_realizedFont(false) 34 , m_realizedFont(false)
35 , m_isTransformInvertible(true) 35 , m_isTransformInvertible(true)
36 , m_hasClip(false) 36 , m_hasClip(false)
37 , m_hasComplexClip(false) 37 , m_hasComplexClip(false)
38 , m_fillStyleDirty(true) 38 , m_fillStyleDirty(true)
39 , m_strokeStyleDirty(true) 39 , m_strokeStyleDirty(true)
40 , m_lineDashDirty(false) 40 , m_lineDashDirty(false)
41 { 41 {
42 m_fillPaint.setStyle(SkPaint::kFill_Style); 42 m_fillPaint.setStyle(SkPaint::kFill_Style);
43 m_fillPaint.setAntiAlias(true); 43 m_fillPaint.setAntiAlias(true);
44 m_imagePaint.setStyle(SkPaint::kFill_Style);
45 m_imagePaint.setAntiAlias(true);
44 m_strokePaint.setStyle(SkPaint::kStroke_Style); 46 m_strokePaint.setStyle(SkPaint::kStroke_Style);
45 m_strokePaint.setStrokeWidth(1); 47 m_strokePaint.setStrokeWidth(1);
46 m_strokePaint.setStrokeCap(SkPaint::kButt_Cap); 48 m_strokePaint.setStrokeCap(SkPaint::kButt_Cap);
47 m_strokePaint.setStrokeMiter(10); 49 m_strokePaint.setStrokeMiter(10);
48 m_strokePaint.setStrokeJoin(SkPaint::kMiter_Join); 50 m_strokePaint.setStrokeJoin(SkPaint::kMiter_Join);
49 m_strokePaint.setAntiAlias(true); 51 m_strokePaint.setAntiAlias(true);
50 setImageSmoothingEnabled(true); 52 setImageSmoothingEnabled(true);
51 } 53 }
52 54
53 CanvasRenderingContext2DState::CanvasRenderingContext2DState(const CanvasRenderi ngContext2DState& other, ClipListCopyMode mode) 55 CanvasRenderingContext2DState::CanvasRenderingContext2DState(const CanvasRenderi ngContext2DState& other, ClipListCopyMode mode)
54 : CSSFontSelectorClient() 56 : CSSFontSelectorClient()
55 , m_unrealizedSaveCount(other.m_unrealizedSaveCount) 57 , m_unrealizedSaveCount(other.m_unrealizedSaveCount)
56 , m_unparsedStrokeColor(other.m_unparsedStrokeColor) 58 , m_unparsedStrokeColor(other.m_unparsedStrokeColor)
57 , m_unparsedFillColor(other.m_unparsedFillColor) 59 , m_unparsedFillColor(other.m_unparsedFillColor)
58 , m_strokeStyle(other.m_strokeStyle) 60 , m_strokeStyle(other.m_strokeStyle)
59 , m_fillStyle(other.m_fillStyle) 61 , m_fillStyle(other.m_fillStyle)
60 , m_strokePaint(other.m_strokePaint) 62 , m_strokePaint(other.m_strokePaint)
61 , m_fillPaint(other.m_fillPaint) 63 , m_fillPaint(other.m_fillPaint)
64 , m_imagePaint(other.m_imagePaint)
62 , m_shadowOffset(other.m_shadowOffset) 65 , m_shadowOffset(other.m_shadowOffset)
63 , m_shadowBlur(other.m_shadowBlur) 66 , m_shadowBlur(other.m_shadowBlur)
64 , m_shadowColor(other.m_shadowColor) 67 , m_shadowColor(other.m_shadowColor)
65 , m_emptyDrawLooper(other.m_emptyDrawLooper) 68 , m_emptyDrawLooper(other.m_emptyDrawLooper)
66 , m_shadowOnlyDrawLooper(other.m_shadowOnlyDrawLooper) 69 , m_shadowOnlyDrawLooper(other.m_shadowOnlyDrawLooper)
67 , m_shadowAndForegroundDrawLooper(other.m_shadowAndForegroundDrawLooper) 70 , m_shadowAndForegroundDrawLooper(other.m_shadowAndForegroundDrawLooper)
68 , m_shadowOnlyImageFilter(other.m_shadowOnlyImageFilter) 71 , m_shadowOnlyImageFilter(other.m_shadowOnlyImageFilter)
69 , m_shadowAndForegroundImageFilter(other.m_shadowAndForegroundImageFilter) 72 , m_shadowAndForegroundImageFilter(other.m_shadowAndForegroundImageFilter)
70 , m_globalAlpha(other.m_globalAlpha) 73 , m_globalAlpha(other.m_globalAlpha)
71 , m_transform(other.m_transform) 74 , m_transform(other.m_transform)
(...skipping 28 matching lines...) Expand all
100 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval idationCallbacks(this); 103 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval idationCallbacks(this);
101 #endif 104 #endif
102 105
103 m_unrealizedSaveCount = other.m_unrealizedSaveCount; 106 m_unrealizedSaveCount = other.m_unrealizedSaveCount;
104 m_unparsedStrokeColor = other.m_unparsedStrokeColor; 107 m_unparsedStrokeColor = other.m_unparsedStrokeColor;
105 m_unparsedFillColor = other.m_unparsedFillColor; 108 m_unparsedFillColor = other.m_unparsedFillColor;
106 m_strokeStyle = other.m_strokeStyle; 109 m_strokeStyle = other.m_strokeStyle;
107 m_fillStyle = other.m_fillStyle; 110 m_fillStyle = other.m_fillStyle;
108 m_strokePaint = other.m_strokePaint; 111 m_strokePaint = other.m_strokePaint;
109 m_fillPaint = other.m_fillPaint; 112 m_fillPaint = other.m_fillPaint;
113 m_imagePaint = other.m_imagePaint;
110 m_shadowOffset = other.m_shadowOffset; 114 m_shadowOffset = other.m_shadowOffset;
111 m_shadowBlur = other.m_shadowBlur; 115 m_shadowBlur = other.m_shadowBlur;
112 m_shadowColor = other.m_shadowColor; 116 m_shadowColor = other.m_shadowColor;
113 m_emptyDrawLooper = other.m_emptyDrawLooper; 117 m_emptyDrawLooper = other.m_emptyDrawLooper;
114 m_shadowOnlyDrawLooper = other.m_shadowOnlyDrawLooper; 118 m_shadowOnlyDrawLooper = other.m_shadowOnlyDrawLooper;
115 m_shadowAndForegroundDrawLooper = other.m_shadowAndForegroundDrawLooper; 119 m_shadowAndForegroundDrawLooper = other.m_shadowAndForegroundDrawLooper;
116 m_shadowOnlyImageFilter = other.m_shadowOnlyImageFilter; 120 m_shadowOnlyImageFilter = other.m_shadowOnlyImageFilter;
117 m_shadowAndForegroundImageFilter = other.m_shadowAndForegroundImageFilter; 121 m_shadowAndForegroundImageFilter = other.m_shadowAndForegroundImageFilter;
118 m_globalAlpha = other.m_globalAlpha; 122 m_globalAlpha = other.m_globalAlpha;
119 m_transform = other.m_transform; 123 m_transform = other.m_transform;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 m_fillStyleDirty = false; 232 m_fillStyleDirty = false;
229 } 233 }
230 234
231 CanvasStyle* CanvasRenderingContext2DState::style(PaintType paintType) const 235 CanvasStyle* CanvasRenderingContext2DState::style(PaintType paintType) const
232 { 236 {
233 switch (paintType) { 237 switch (paintType) {
234 case FillPaintType: 238 case FillPaintType:
235 return fillStyle(); 239 return fillStyle();
236 case StrokePaintType: 240 case StrokePaintType:
237 return strokeStyle(); 241 return strokeStyle();
242 case ImagePaintType:
243 return nullptr;
238 } 244 }
239 ASSERT_NOT_REACHED(); 245 ASSERT_NOT_REACHED();
240 return nullptr; 246 return nullptr;
241 } 247 }
242 248
243 void CanvasRenderingContext2DState::setGlobalAlpha(float alpha) 249 void CanvasRenderingContext2DState::setGlobalAlpha(float alpha)
244 { 250 {
245 m_globalAlpha = alpha; 251 m_globalAlpha = alpha;
246 m_strokeStyleDirty = true; 252 m_strokeStyleDirty = true;
247 m_fillStyleDirty = true; 253 m_fillStyleDirty = true;
254 m_imagePaint.setColor(scaleAlpha(SK_ColorBLACK, clampedAlphaForBlending(m_gl obalAlpha)));
248 } 255 }
249 256
250 void CanvasRenderingContext2DState::clipPath(const SkPath& path, AntiAliasingMod e antiAliasingMode) 257 void CanvasRenderingContext2DState::clipPath(const SkPath& path, AntiAliasingMod e antiAliasingMode)
251 { 258 {
252 m_clipList.clipPath(path, antiAliasingMode, affineTransformToSkMatrix(m_tran sform)); 259 m_clipList.clipPath(path, antiAliasingMode, affineTransformToSkMatrix(m_tran sform));
253 m_hasClip = true; 260 m_hasClip = true;
254 if (!path.isRect(0)) 261 if (!path.isRect(0))
255 m_hasComplexClip = true; 262 m_hasComplexClip = true;
256 } 263 }
257 264
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 void CanvasRenderingContext2DState::setShadowColor(SkColor shadowColor) 369 void CanvasRenderingContext2DState::setShadowColor(SkColor shadowColor)
363 { 370 {
364 m_shadowColor = shadowColor; 371 m_shadowColor = shadowColor;
365 shadowParameterChanged(); 372 shadowParameterChanged();
366 } 373 }
367 374
368 void CanvasRenderingContext2DState::setGlobalComposite(SkXfermode::Mode mode) 375 void CanvasRenderingContext2DState::setGlobalComposite(SkXfermode::Mode mode)
369 { 376 {
370 m_strokePaint.setXfermodeMode(mode); 377 m_strokePaint.setXfermodeMode(mode);
371 m_fillPaint.setXfermodeMode(mode); 378 m_fillPaint.setXfermodeMode(mode);
379 m_imagePaint.setXfermodeMode(mode);
372 } 380 }
373 381
374 SkXfermode::Mode CanvasRenderingContext2DState::globalComposite() const 382 SkXfermode::Mode CanvasRenderingContext2DState::globalComposite() const
375 { 383 {
376 SkXfermode* xferMode = m_strokePaint.getXfermode(); 384 SkXfermode* xferMode = m_strokePaint.getXfermode();
377 SkXfermode::Mode mode; 385 SkXfermode::Mode mode;
378 if (!xferMode || !xferMode->asMode(&mode)) 386 if (!xferMode || !xferMode->asMode(&mode))
379 return SkXfermode::kSrcOver_Mode; 387 return SkXfermode::kSrcOver_Mode;
380 return mode; 388 return mode;
381 } 389 }
382 390
383 void CanvasRenderingContext2DState::setImageSmoothingEnabled(bool enabled) 391 void CanvasRenderingContext2DState::setImageSmoothingEnabled(bool enabled)
384 { 392 {
385 SkFilterQuality filterQuality = enabled ? kLow_SkFilterQuality : kNone_SkFil terQuality; 393 SkFilterQuality filterQuality = enabled ? kLow_SkFilterQuality : kNone_SkFil terQuality;
386 m_strokePaint.setFilterQuality(filterQuality); 394 m_strokePaint.setFilterQuality(filterQuality);
387 m_fillPaint.setFilterQuality(filterQuality); 395 m_fillPaint.setFilterQuality(filterQuality);
396 m_imagePaint.setFilterQuality(filterQuality);
388 } 397 }
389 398
390 bool CanvasRenderingContext2DState::imageSmoothingEnabled() const 399 bool CanvasRenderingContext2DState::imageSmoothingEnabled() const
391 { 400 {
392 return m_strokePaint.getFilterQuality() == kLow_SkFilterQuality; 401 return m_imagePaint.getFilterQuality() == kLow_SkFilterQuality;
393 } 402 }
394 403
395 bool CanvasRenderingContext2DState::shouldDrawShadows() const 404 bool CanvasRenderingContext2DState::shouldDrawShadows() const
396 { 405 {
397 return alphaChannel(m_shadowColor) && (m_shadowBlur || !m_shadowOffset.isZer o()); 406 return alphaChannel(m_shadowColor) && (m_shadowBlur || !m_shadowOffset.isZer o());
398 } 407 }
399 408
400 const SkPaint* CanvasRenderingContext2DState::getPaint(PaintType paintType, Shad owMode shadowMode, ImageType imageType) const 409 const SkPaint* CanvasRenderingContext2DState::getPaint(PaintType paintType, Shad owMode shadowMode, ImageType imageType) const
401 { 410 {
402 SkPaint* paint; 411 SkPaint* paint;
403 if (paintType == StrokePaintType) { 412 switch (paintType) {
413 case StrokePaintType:
404 updateLineDash(); 414 updateLineDash();
405 updateStrokeStyle(); 415 updateStrokeStyle();
406 paint = &m_strokePaint; 416 paint = &m_strokePaint;
407 } else { 417 break;
418 case FillPaintType:
408 updateFillStyle(); 419 updateFillStyle();
409 paint = &m_fillPaint; 420 paint = &m_fillPaint;
421 break;
422 case ImagePaintType:
423 paint = &m_imagePaint;
424 break;
425 default:
426 ASSERT_NOT_REACHED();
410 } 427 }
411 428
412 if ((!shouldDrawShadows() && shadowMode == DrawShadowAndForeground) || shado wMode == DrawForegroundOnly) { 429 if ((!shouldDrawShadows() && shadowMode == DrawShadowAndForeground) || shado wMode == DrawForegroundOnly) {
413 paint->setLooper(0); 430 paint->setLooper(0);
414 paint->setImageFilter(0); 431 paint->setImageFilter(0);
415 return paint; 432 return paint;
416 } 433 }
417 434
418 if (!shouldDrawShadows() && shadowMode == DrawShadowOnly) { 435 if (!shouldDrawShadows() && shadowMode == DrawShadowOnly) {
419 paint->setLooper(emptyDrawLooper()); // draw nothing 436 paint->setLooper(emptyDrawLooper()); // draw nothing
(...skipping 17 matching lines...) Expand all
437 paint->setLooper(0); 454 paint->setLooper(0);
438 paint->setImageFilter(shadowAndForegroundImageFilter()); 455 paint->setImageFilter(shadowAndForegroundImageFilter());
439 return paint; 456 return paint;
440 } 457 }
441 paint->setLooper(shadowAndForegroundDrawLooper()); 458 paint->setLooper(shadowAndForegroundDrawLooper());
442 paint->setImageFilter(0); 459 paint->setImageFilter(0);
443 return paint; 460 return paint;
444 } 461 }
445 462
446 } // blink 463 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698