| 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 "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" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 | 181 |
| 182 DEFINE_TRACE(CanvasRenderingContext2DState) | 182 DEFINE_TRACE(CanvasRenderingContext2DState) |
| 183 { | 183 { |
| 184 visitor->trace(m_strokeStyle); | 184 visitor->trace(m_strokeStyle); |
| 185 visitor->trace(m_fillStyle); | 185 visitor->trace(m_fillStyle); |
| 186 visitor->trace(m_filterValue); | 186 visitor->trace(m_filterValue); |
| 187 CSSFontSelectorClient::trace(visitor); | 187 CSSFontSelectorClient::trace(visitor); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void CanvasRenderingContext2DState::setLineDashOffset(float offset) | 190 void CanvasRenderingContext2DState::setLineDashOffset(double offset) |
| 191 { | 191 { |
| 192 m_lineDashOffset = offset; | 192 m_lineDashOffset = offset; |
| 193 m_lineDashDirty = true; | 193 m_lineDashDirty = true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void CanvasRenderingContext2DState::setLineDash(const Vector<float>& dash) | 196 void CanvasRenderingContext2DState::setLineDash(const Vector<double>& dash) |
| 197 { | 197 { |
| 198 m_lineDash = dash; | 198 m_lineDash = dash; |
| 199 // Spec requires the concatenation of two copies the dash list when the | 199 // Spec requires the concatenation of two copies the dash list when the |
| 200 // number of elements is odd | 200 // number of elements is odd |
| 201 if (dash.size() % 2) | 201 if (dash.size() % 2) |
| 202 m_lineDash.appendVector(dash); | 202 m_lineDash.appendVector(dash); |
| 203 | 203 |
| 204 m_lineDashDirty = true; | 204 m_lineDashDirty = true; |
| 205 } | 205 } |
| 206 | 206 |
| 207 static bool hasANonZeroElement(const Vector<float>& lineDash) | 207 static bool hasANonZeroElement(const Vector<double>& lineDash) |
| 208 { | 208 { |
| 209 for (size_t i = 0; i < lineDash.size(); i++) { | 209 for (size_t i = 0; i < lineDash.size(); i++) { |
| 210 if (lineDash[i] != 0.0f) | 210 if (lineDash[i] != 0.0) |
| 211 return true; | 211 return true; |
| 212 } | 212 } |
| 213 return false; | 213 return false; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void CanvasRenderingContext2DState::updateLineDash() const | 216 void CanvasRenderingContext2DState::updateLineDash() const |
| 217 { | 217 { |
| 218 if (!m_lineDashDirty) | 218 if (!m_lineDashDirty) |
| 219 return; | 219 return; |
| 220 | 220 |
| 221 if (!hasANonZeroElement(m_lineDash)) { | 221 if (!hasANonZeroElement(m_lineDash)) { |
| 222 m_strokePaint.setPathEffect(0); | 222 m_strokePaint.setPathEffect(0); |
| 223 } else { | 223 } else { |
| 224 RefPtr<SkPathEffect> dashPathEffect = adoptRef(SkDashPathEffect::Create(
m_lineDash.data(), m_lineDash.size(), m_lineDashOffset)); | 224 Vector<float> lineDash(m_lineDash.size()); |
| 225 std::copy(m_lineDash.begin(), m_lineDash.end(), lineDash.begin()); |
| 226 RefPtr<SkPathEffect> dashPathEffect = adoptRef(SkDashPathEffect::Create(
lineDash.data(), lineDash.size(), m_lineDashOffset)); |
| 225 m_strokePaint.setPathEffect(dashPathEffect.get()); | 227 m_strokePaint.setPathEffect(dashPathEffect.get()); |
| 226 } | 228 } |
| 227 | 229 |
| 228 m_lineDashDirty = false; | 230 m_lineDashDirty = false; |
| 229 } | 231 } |
| 230 | 232 |
| 231 void CanvasRenderingContext2DState::setStrokeStyle(CanvasStyle* style) | 233 void CanvasRenderingContext2DState::setStrokeStyle(CanvasStyle* style) |
| 232 { | 234 { |
| 233 m_strokeStyle = style; | 235 m_strokeStyle = style; |
| 234 m_strokeStyleDirty = true; | 236 m_strokeStyleDirty = true; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 m_strokePaint.setAntiAlias(shouldAntialias); | 296 m_strokePaint.setAntiAlias(shouldAntialias); |
| 295 m_imagePaint.setAntiAlias(shouldAntialias); | 297 m_imagePaint.setAntiAlias(shouldAntialias); |
| 296 } | 298 } |
| 297 | 299 |
| 298 bool CanvasRenderingContext2DState::shouldAntialias() const | 300 bool CanvasRenderingContext2DState::shouldAntialias() const |
| 299 { | 301 { |
| 300 ASSERT(m_fillPaint.isAntiAlias() == m_strokePaint.isAntiAlias() && m_fillPai
nt.isAntiAlias() == m_imagePaint.isAntiAlias()); | 302 ASSERT(m_fillPaint.isAntiAlias() == m_strokePaint.isAntiAlias() && m_fillPai
nt.isAntiAlias() == m_imagePaint.isAntiAlias()); |
| 301 return m_fillPaint.isAntiAlias(); | 303 return m_fillPaint.isAntiAlias(); |
| 302 } | 304 } |
| 303 | 305 |
| 304 void CanvasRenderingContext2DState::setGlobalAlpha(float alpha) | 306 void CanvasRenderingContext2DState::setGlobalAlpha(double alpha) |
| 305 { | 307 { |
| 306 m_globalAlpha = alpha; | 308 m_globalAlpha = alpha; |
| 307 m_strokeStyleDirty = true; | 309 m_strokeStyleDirty = true; |
| 308 m_fillStyleDirty = true; | 310 m_fillStyleDirty = true; |
| 309 int imageAlpha = clampedAlphaForBlending(alpha); | 311 int imageAlpha = clampedAlphaForBlending(alpha); |
| 310 m_imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); | 312 m_imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); |
| 311 } | 313 } |
| 312 | 314 |
| 313 void CanvasRenderingContext2DState::clipPath(const SkPath& path, AntiAliasingMod
e antiAliasingMode) | 315 void CanvasRenderingContext2DState::clipPath(const SkPath& path, AntiAliasingMod
e antiAliasingMode) |
| 314 { | 316 { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // Must set font in case the filter uses any font-relative units (em, ex
) | 363 // Must set font in case the filter uses any font-relative units (em, ex
) |
| 362 filterStyle->setFont(font); | 364 filterStyle->setFont(font); |
| 363 | 365 |
| 364 StyleResolverState resolverState(styleResolutionHost->document(), styleR
esolutionHost, filterStyle.get()); | 366 StyleResolverState resolverState(styleResolutionHost->document(), styleR
esolutionHost, filterStyle.get()); |
| 365 resolverState.setStyle(filterStyle); | 367 resolverState.setStyle(filterStyle); |
| 366 | 368 |
| 367 // TODO(junov): crbug.com/502877 Feed m_fillStyle and m_strokeStyle into
FillPaint and | 369 // TODO(junov): crbug.com/502877 Feed m_fillStyle and m_strokeStyle into
FillPaint and |
| 368 // StrokePaint respectively for filters that reference SVG. | 370 // StrokePaint respectively for filters that reference SVG. |
| 369 StyleBuilder::applyProperty(CSSPropertyWebkitFilter, resolverState, m_fi
lterValue.get()); | 371 StyleBuilder::applyProperty(CSSPropertyWebkitFilter, resolverState, m_fi
lterValue.get()); |
| 370 RefPtrWillBeRawPtr<FilterEffectBuilder> filterEffectBuilder = FilterEffe
ctBuilder::create(); | 372 RefPtrWillBeRawPtr<FilterEffectBuilder> filterEffectBuilder = FilterEffe
ctBuilder::create(); |
| 371 const float effectiveZoom = 1.0f; // Deliberately ignore zoom on the can
vas element | 373 const double effectiveZoom = 1.0; // Deliberately ignore zoom on the can
vas element |
| 372 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e
ffectiveZoom); | 374 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e
ffectiveZoom); |
| 373 | 375 |
| 374 SkiaImageFilterBuilder imageFilterBuilder; | 376 SkiaImageFilterBuilder imageFilterBuilder; |
| 375 RefPtrWillBeRawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastE
ffect(); | 377 RefPtrWillBeRawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastE
ffect(); |
| 376 m_resolvedFilter = imageFilterBuilder.build(lastEffect.get(), ColorSpace
DeviceRGB); | 378 m_resolvedFilter = imageFilterBuilder.build(lastEffect.get(), ColorSpace
DeviceRGB); |
| 377 } | 379 } |
| 378 | 380 |
| 379 return m_resolvedFilter.get(); | 381 return m_resolvedFilter.get(); |
| 380 } | 382 } |
| 381 | 383 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 405 drawLooperBuilder->addShadow(m_shadowOffset, m_shadowBlur, m_shadowColor
, DrawLooperBuilder::ShadowIgnoresTransforms, DrawLooperBuilder::ShadowRespectsA
lpha); | 407 drawLooperBuilder->addShadow(m_shadowOffset, m_shadowBlur, m_shadowColor
, DrawLooperBuilder::ShadowIgnoresTransforms, DrawLooperBuilder::ShadowRespectsA
lpha); |
| 406 drawLooperBuilder->addUnmodifiedContent(); | 408 drawLooperBuilder->addUnmodifiedContent(); |
| 407 m_shadowAndForegroundDrawLooper = drawLooperBuilder->detachDrawLooper(); | 409 m_shadowAndForegroundDrawLooper = drawLooperBuilder->detachDrawLooper(); |
| 408 } | 410 } |
| 409 return m_shadowAndForegroundDrawLooper.get(); | 411 return m_shadowAndForegroundDrawLooper.get(); |
| 410 } | 412 } |
| 411 | 413 |
| 412 SkImageFilter* CanvasRenderingContext2DState::shadowOnlyImageFilter() const | 414 SkImageFilter* CanvasRenderingContext2DState::shadowOnlyImageFilter() const |
| 413 { | 415 { |
| 414 if (!m_shadowOnlyImageFilter) { | 416 if (!m_shadowOnlyImageFilter) { |
| 415 float sigma = skBlurRadiusToSigma(m_shadowBlur); | 417 double sigma = skBlurRadiusToSigma(m_shadowBlur); |
| 416 m_shadowOnlyImageFilter = adoptRef(SkDropShadowImageFilter::Create(m_sha
dowOffset.width(), m_shadowOffset.height(), sigma, sigma, m_shadowColor, SkDropS
hadowImageFilter::kDrawShadowOnly_ShadowMode)); | 418 m_shadowOnlyImageFilter = adoptRef(SkDropShadowImageFilter::Create(m_sha
dowOffset.width(), m_shadowOffset.height(), sigma, sigma, m_shadowColor, SkDropS
hadowImageFilter::kDrawShadowOnly_ShadowMode)); |
| 417 } | 419 } |
| 418 return m_shadowOnlyImageFilter.get(); | 420 return m_shadowOnlyImageFilter.get(); |
| 419 } | 421 } |
| 420 | 422 |
| 421 SkImageFilter* CanvasRenderingContext2DState::shadowAndForegroundImageFilter() c
onst | 423 SkImageFilter* CanvasRenderingContext2DState::shadowAndForegroundImageFilter() c
onst |
| 422 { | 424 { |
| 423 if (!m_shadowAndForegroundImageFilter) { | 425 if (!m_shadowAndForegroundImageFilter) { |
| 424 float sigma = skBlurRadiusToSigma(m_shadowBlur); | 426 double sigma = skBlurRadiusToSigma(m_shadowBlur); |
| 425 m_shadowAndForegroundImageFilter = adoptRef(SkDropShadowImageFilter::Cre
ate(m_shadowOffset.width(), m_shadowOffset.height(), sigma, sigma, m_shadowColor
, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); | 427 m_shadowAndForegroundImageFilter = adoptRef(SkDropShadowImageFilter::Cre
ate(m_shadowOffset.width(), m_shadowOffset.height(), sigma, sigma, m_shadowColor
, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); |
| 426 } | 428 } |
| 427 return m_shadowAndForegroundImageFilter.get(); | 429 return m_shadowAndForegroundImageFilter.get(); |
| 428 } | 430 } |
| 429 | 431 |
| 430 void CanvasRenderingContext2DState::shadowParameterChanged() | 432 void CanvasRenderingContext2DState::shadowParameterChanged() |
| 431 { | 433 { |
| 432 m_shadowOnlyDrawLooper.clear(); | 434 m_shadowOnlyDrawLooper.clear(); |
| 433 m_shadowAndForegroundDrawLooper.clear(); | 435 m_shadowAndForegroundDrawLooper.clear(); |
| 434 m_shadowOnlyImageFilter.clear(); | 436 m_shadowOnlyImageFilter.clear(); |
| 435 m_shadowAndForegroundImageFilter.clear(); | 437 m_shadowAndForegroundImageFilter.clear(); |
| 436 } | 438 } |
| 437 | 439 |
| 438 void CanvasRenderingContext2DState::setShadowOffsetX(float x) | 440 void CanvasRenderingContext2DState::setShadowOffsetX(double x) |
| 439 { | 441 { |
| 440 m_shadowOffset.setWidth(x); | 442 m_shadowOffset.setWidth(x); |
| 441 shadowParameterChanged(); | 443 shadowParameterChanged(); |
| 442 } | 444 } |
| 443 | 445 |
| 444 void CanvasRenderingContext2DState::setShadowOffsetY(float y) | 446 void CanvasRenderingContext2DState::setShadowOffsetY(double y) |
| 445 { | 447 { |
| 446 m_shadowOffset.setHeight(y); | 448 m_shadowOffset.setHeight(y); |
| 447 shadowParameterChanged(); | 449 shadowParameterChanged(); |
| 448 } | 450 } |
| 449 | 451 |
| 450 void CanvasRenderingContext2DState::setShadowBlur(float shadowBlur) | 452 void CanvasRenderingContext2DState::setShadowBlur(double shadowBlur) |
| 451 { | 453 { |
| 452 m_shadowBlur = shadowBlur; | 454 m_shadowBlur = shadowBlur; |
| 453 shadowParameterChanged(); | 455 shadowParameterChanged(); |
| 454 } | 456 } |
| 455 | 457 |
| 456 void CanvasRenderingContext2DState::setShadowColor(SkColor shadowColor) | 458 void CanvasRenderingContext2DState::setShadowColor(SkColor shadowColor) |
| 457 { | 459 { |
| 458 m_shadowColor = shadowColor; | 460 m_shadowColor = shadowColor; |
| 459 shadowParameterChanged(); | 461 shadowParameterChanged(); |
| 460 } | 462 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 paint->setLooper(0); | 594 paint->setLooper(0); |
| 593 paint->setImageFilter(shadowAndForegroundImageFilter()); | 595 paint->setImageFilter(shadowAndForegroundImageFilter()); |
| 594 return paint; | 596 return paint; |
| 595 } | 597 } |
| 596 paint->setLooper(shadowAndForegroundDrawLooper()); | 598 paint->setLooper(shadowAndForegroundDrawLooper()); |
| 597 paint->setImageFilter(0); | 599 paint->setImageFilter(0); |
| 598 return paint; | 600 return paint; |
| 599 } | 601 } |
| 600 | 602 |
| 601 } // blink | 603 } // blink |
| OLD | NEW |