| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/BaseRenderingContext2D.h" | 5 #include "modules/canvas2d/BaseRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 10 #include "core/css/cssom/CSSURLImageValue.h" | 10 #include "core/css/cssom/CSSURLImageValue.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "platform/geometry/FloatQuad.h" | 24 #include "platform/geometry/FloatQuad.h" |
| 25 #include "platform/graphics/Color.h" | 25 #include "platform/graphics/Color.h" |
| 26 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 26 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 27 #include "platform/graphics/Image.h" | 27 #include "platform/graphics/Image.h" |
| 28 #include "platform/graphics/ImageBuffer.h" | 28 #include "platform/graphics/ImageBuffer.h" |
| 29 #include "platform/graphics/StrokeData.h" | 29 #include "platform/graphics/StrokeData.h" |
| 30 #include "platform/graphics/skia/SkiaUtils.h" | 30 #include "platform/graphics/skia/SkiaUtils.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 namespace { |
| 35 |
| 36 bool IsFiniteFloat(float x) { |
| 37 return std::isfinite(x); |
| 38 } |
| 39 |
| 40 bool IsFiniteFloat(double x) { |
| 41 if (!std::isfinite(x)) |
| 42 return false; |
| 43 constexpr double max_float_as_double = |
| 44 static_cast<double>(std::numeric_limits<float>::max()); |
| 45 if (x > max_float_as_double) |
| 46 return false; |
| 47 return true; |
| 48 } |
| 49 } |
| 50 |
| 34 BaseRenderingContext2D::BaseRenderingContext2D() | 51 BaseRenderingContext2D::BaseRenderingContext2D() |
| 35 : m_clipAntialiasing(NotAntiAliased) { | 52 : m_clipAntialiasing(NotAntiAliased) { |
| 36 m_stateStack.append(CanvasRenderingContext2DState::create()); | 53 m_stateStack.append(CanvasRenderingContext2DState::create()); |
| 37 } | 54 } |
| 38 | 55 |
| 39 BaseRenderingContext2D::~BaseRenderingContext2D() {} | 56 BaseRenderingContext2D::~BaseRenderingContext2D() {} |
| 40 | 57 |
| 41 CanvasRenderingContext2DState& BaseRenderingContext2D::modifiableState() { | 58 CanvasRenderingContext2DState& BaseRenderingContext2D::modifiableState() { |
| 42 realizeSaves(); | 59 realizeSaves(); |
| 43 return *m_stateStack.back(); | 60 return *m_stateStack.back(); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 modifiableState().setFillStyle(canvasStyle); | 250 modifiableState().setFillStyle(canvasStyle); |
| 234 modifiableState().setUnparsedFillColor(colorString); | 251 modifiableState().setUnparsedFillColor(colorString); |
| 235 modifiableState().clearResolvedFilter(); | 252 modifiableState().clearResolvedFilter(); |
| 236 } | 253 } |
| 237 | 254 |
| 238 double BaseRenderingContext2D::lineWidth() const { | 255 double BaseRenderingContext2D::lineWidth() const { |
| 239 return state().lineWidth(); | 256 return state().lineWidth(); |
| 240 } | 257 } |
| 241 | 258 |
| 242 void BaseRenderingContext2D::setLineWidth(double width) { | 259 void BaseRenderingContext2D::setLineWidth(double width) { |
| 243 if (!std::isfinite(width) || width <= 0) | 260 if (!IsFiniteFloat(width) || width <= 0) |
| 244 return; | 261 return; |
| 245 if (state().lineWidth() == width) | 262 if (state().lineWidth() == width) |
| 246 return; | 263 return; |
| 247 modifiableState().setLineWidth(width); | 264 modifiableState().setLineWidth(width); |
| 248 } | 265 } |
| 249 | 266 |
| 250 String BaseRenderingContext2D::lineCap() const { | 267 String BaseRenderingContext2D::lineCap() const { |
| 251 return lineCapName(state().getLineCap()); | 268 return lineCapName(state().getLineCap()); |
| 252 } | 269 } |
| 253 | 270 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 271 if (state().getLineJoin() == join) | 288 if (state().getLineJoin() == join) |
| 272 return; | 289 return; |
| 273 modifiableState().setLineJoin(join); | 290 modifiableState().setLineJoin(join); |
| 274 } | 291 } |
| 275 | 292 |
| 276 double BaseRenderingContext2D::miterLimit() const { | 293 double BaseRenderingContext2D::miterLimit() const { |
| 277 return state().miterLimit(); | 294 return state().miterLimit(); |
| 278 } | 295 } |
| 279 | 296 |
| 280 void BaseRenderingContext2D::setMiterLimit(double limit) { | 297 void BaseRenderingContext2D::setMiterLimit(double limit) { |
| 281 if (!std::isfinite(limit) || limit <= 0) | 298 if (!IsFiniteFloat(limit) || limit <= 0) |
| 282 return; | 299 return; |
| 283 if (state().miterLimit() == limit) | 300 if (state().miterLimit() == limit) |
| 284 return; | 301 return; |
| 285 modifiableState().setMiterLimit(limit); | 302 modifiableState().setMiterLimit(limit); |
| 286 } | 303 } |
| 287 | 304 |
| 288 double BaseRenderingContext2D::shadowOffsetX() const { | 305 double BaseRenderingContext2D::shadowOffsetX() const { |
| 289 return state().shadowOffset().width(); | 306 return state().shadowOffset().width(); |
| 290 } | 307 } |
| 291 | 308 |
| 292 void BaseRenderingContext2D::setShadowOffsetX(double x) { | 309 void BaseRenderingContext2D::setShadowOffsetX(double x) { |
| 293 if (!std::isfinite(x)) | 310 if (!IsFiniteFloat(x)) |
| 294 return; | 311 return; |
| 295 if (state().shadowOffset().width() == x) | 312 if (state().shadowOffset().width() == x) |
| 296 return; | 313 return; |
| 297 modifiableState().setShadowOffsetX(x); | 314 modifiableState().setShadowOffsetX(x); |
| 298 } | 315 } |
| 299 | 316 |
| 300 double BaseRenderingContext2D::shadowOffsetY() const { | 317 double BaseRenderingContext2D::shadowOffsetY() const { |
| 301 return state().shadowOffset().height(); | 318 return state().shadowOffset().height(); |
| 302 } | 319 } |
| 303 | 320 |
| 304 void BaseRenderingContext2D::setShadowOffsetY(double y) { | 321 void BaseRenderingContext2D::setShadowOffsetY(double y) { |
| 305 if (!std::isfinite(y)) | 322 if (!IsFiniteFloat(y)) |
| 306 return; | 323 return; |
| 307 if (state().shadowOffset().height() == y) | 324 if (state().shadowOffset().height() == y) |
| 308 return; | 325 return; |
| 309 modifiableState().setShadowOffsetY(y); | 326 modifiableState().setShadowOffsetY(y); |
| 310 } | 327 } |
| 311 | 328 |
| 312 double BaseRenderingContext2D::shadowBlur() const { | 329 double BaseRenderingContext2D::shadowBlur() const { |
| 313 return state().shadowBlur(); | 330 return state().shadowBlur(); |
| 314 } | 331 } |
| 315 | 332 |
| 316 void BaseRenderingContext2D::setShadowBlur(double blur) { | 333 void BaseRenderingContext2D::setShadowBlur(double blur) { |
| 317 if (!std::isfinite(blur) || blur < 0) | 334 if (!IsFiniteFloat(blur) || blur < 0) |
| 318 return; | 335 return; |
| 319 if (state().shadowBlur() == blur) | 336 if (state().shadowBlur() == blur) |
| 320 return; | 337 return; |
| 321 modifiableState().setShadowBlur(blur); | 338 modifiableState().setShadowBlur(blur); |
| 322 } | 339 } |
| 323 | 340 |
| 324 String BaseRenderingContext2D::shadowColor() const { | 341 String BaseRenderingContext2D::shadowColor() const { |
| 325 return Color(state().shadowColor()).serialized(); | 342 return Color(state().shadowColor()).serialized(); |
| 326 } | 343 } |
| 327 | 344 |
| 328 void BaseRenderingContext2D::setShadowColor(const String& colorString) { | 345 void BaseRenderingContext2D::setShadowColor(const String& colorString) { |
| 329 Color color; | 346 Color color; |
| 330 if (!parseColorOrCurrentColor(color, colorString)) | 347 if (!parseColorOrCurrentColor(color, colorString)) |
| 331 return; | 348 return; |
| 332 if (state().shadowColor() == color) | 349 if (state().shadowColor() == color) |
| 333 return; | 350 return; |
| 334 modifiableState().setShadowColor(color.rgb()); | 351 modifiableState().setShadowColor(color.rgb()); |
| 335 } | 352 } |
| 336 | 353 |
| 337 const Vector<double>& BaseRenderingContext2D::getLineDash() const { | 354 const Vector<double>& BaseRenderingContext2D::getLineDash() const { |
| 338 return state().lineDash(); | 355 return state().lineDash(); |
| 339 } | 356 } |
| 340 | 357 |
| 341 static bool lineDashSequenceIsValid(const Vector<double>& dash) { | 358 static bool lineDashSequenceIsValid(const Vector<double>& dash) { |
| 342 for (size_t i = 0; i < dash.size(); i++) { | 359 for (size_t i = 0; i < dash.size(); i++) { |
| 343 if (!std::isfinite(dash[i]) || dash[i] < 0) | 360 if (!IsFiniteFloat(dash[i]) || dash[i] < 0) |
| 344 return false; | 361 return false; |
| 345 } | 362 } |
| 346 return true; | 363 return true; |
| 347 } | 364 } |
| 348 | 365 |
| 349 void BaseRenderingContext2D::setLineDash(const Vector<double>& dash) { | 366 void BaseRenderingContext2D::setLineDash(const Vector<double>& dash) { |
| 350 if (!lineDashSequenceIsValid(dash)) | 367 if (!lineDashSequenceIsValid(dash)) |
| 351 return; | 368 return; |
| 352 modifiableState().setLineDash(dash); | 369 modifiableState().setLineDash(dash); |
| 353 } | 370 } |
| 354 | 371 |
| 355 double BaseRenderingContext2D::lineDashOffset() const { | 372 double BaseRenderingContext2D::lineDashOffset() const { |
| 356 return state().lineDashOffset(); | 373 return state().lineDashOffset(); |
| 357 } | 374 } |
| 358 | 375 |
| 359 void BaseRenderingContext2D::setLineDashOffset(double offset) { | 376 void BaseRenderingContext2D::setLineDashOffset(double offset) { |
| 360 if (!std::isfinite(offset) || state().lineDashOffset() == offset) | 377 if (!IsFiniteFloat(offset) || state().lineDashOffset() == offset) |
| 361 return; | 378 return; |
| 362 modifiableState().setLineDashOffset(offset); | 379 modifiableState().setLineDashOffset(offset); |
| 363 } | 380 } |
| 364 | 381 |
| 365 double BaseRenderingContext2D::globalAlpha() const { | 382 double BaseRenderingContext2D::globalAlpha() const { |
| 366 return state().globalAlpha(); | 383 return state().globalAlpha(); |
| 367 } | 384 } |
| 368 | 385 |
| 369 void BaseRenderingContext2D::setGlobalAlpha(double alpha) { | 386 void BaseRenderingContext2D::setGlobalAlpha(double alpha) { |
| 370 if (!(alpha >= 0 && alpha <= 1)) | 387 if (!(alpha >= 0 && alpha <= 1)) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 const AffineTransform& transform = matrixTearOff->value(); | 439 const AffineTransform& transform = matrixTearOff->value(); |
| 423 setTransform(transform.a(), transform.b(), transform.c(), transform.d(), | 440 setTransform(transform.a(), transform.b(), transform.c(), transform.d(), |
| 424 transform.e(), transform.f()); | 441 transform.e(), transform.f()); |
| 425 } | 442 } |
| 426 | 443 |
| 427 void BaseRenderingContext2D::scale(double sx, double sy) { | 444 void BaseRenderingContext2D::scale(double sx, double sy) { |
| 428 SkCanvas* c = drawingCanvas(); | 445 SkCanvas* c = drawingCanvas(); |
| 429 if (!c) | 446 if (!c) |
| 430 return; | 447 return; |
| 431 | 448 |
| 432 if (!std::isfinite(sx) || !std::isfinite(sy)) | 449 if (!IsFiniteFloat(sx) || !IsFiniteFloat(sy)) |
| 433 return; | 450 return; |
| 434 | 451 |
| 435 AffineTransform newTransform = state().transform(); | 452 AffineTransform newTransform = state().transform(); |
| 436 newTransform.scaleNonUniform(sx, sy); | 453 newTransform.scaleNonUniform(sx, sy); |
| 437 if (state().transform() == newTransform) | 454 if (state().transform() == newTransform) |
| 438 return; | 455 return; |
| 439 | 456 |
| 440 modifiableState().setTransform(newTransform); | 457 modifiableState().setTransform(newTransform); |
| 441 if (!state().isTransformInvertible()) | 458 if (!state().isTransformInvertible()) |
| 442 return; | 459 return; |
| 443 | 460 |
| 444 c->scale(sx, sy); | 461 c->scale(sx, sy); |
| 445 m_path.transform(AffineTransform().scaleNonUniform(1.0 / sx, 1.0 / sy)); | 462 m_path.transform(AffineTransform().scaleNonUniform(1.0 / sx, 1.0 / sy)); |
| 446 } | 463 } |
| 447 | 464 |
| 448 void BaseRenderingContext2D::rotate(double angleInRadians) { | 465 void BaseRenderingContext2D::rotate(double angleInRadians) { |
| 449 SkCanvas* c = drawingCanvas(); | 466 SkCanvas* c = drawingCanvas(); |
| 450 if (!c) | 467 if (!c) |
| 451 return; | 468 return; |
| 452 | 469 |
| 453 if (!std::isfinite(angleInRadians)) | 470 if (!IsFiniteFloat(angleInRadians)) |
| 454 return; | 471 return; |
| 455 | 472 |
| 456 AffineTransform newTransform = state().transform(); | 473 AffineTransform newTransform = state().transform(); |
| 457 newTransform.rotateRadians(angleInRadians); | 474 newTransform.rotateRadians(angleInRadians); |
| 458 if (state().transform() == newTransform) | 475 if (state().transform() == newTransform) |
| 459 return; | 476 return; |
| 460 | 477 |
| 461 modifiableState().setTransform(newTransform); | 478 modifiableState().setTransform(newTransform); |
| 462 if (!state().isTransformInvertible()) | 479 if (!state().isTransformInvertible()) |
| 463 return; | 480 return; |
| 464 c->rotate(angleInRadians * (180.0 / piFloat)); | 481 c->rotate(angleInRadians * (180.0 / piFloat)); |
| 465 m_path.transform(AffineTransform().rotateRadians(-angleInRadians)); | 482 m_path.transform(AffineTransform().rotateRadians(-angleInRadians)); |
| 466 } | 483 } |
| 467 | 484 |
| 468 void BaseRenderingContext2D::translate(double tx, double ty) { | 485 void BaseRenderingContext2D::translate(double tx, double ty) { |
| 469 SkCanvas* c = drawingCanvas(); | 486 SkCanvas* c = drawingCanvas(); |
| 470 if (!c) | 487 if (!c) |
| 471 return; | 488 return; |
| 472 if (!state().isTransformInvertible()) | 489 if (!state().isTransformInvertible()) |
| 473 return; | 490 return; |
| 474 | 491 |
| 475 if (!std::isfinite(tx) || !std::isfinite(ty)) | 492 if (!IsFiniteFloat(tx) || !IsFiniteFloat(ty)) |
| 476 return; | 493 return; |
| 477 | 494 |
| 478 AffineTransform newTransform = state().transform(); | 495 AffineTransform newTransform = state().transform(); |
| 479 newTransform.translate(tx, ty); | 496 newTransform.translate(tx, ty); |
| 480 if (state().transform() == newTransform) | 497 if (state().transform() == newTransform) |
| 481 return; | 498 return; |
| 482 | 499 |
| 483 modifiableState().setTransform(newTransform); | 500 modifiableState().setTransform(newTransform); |
| 484 if (!state().isTransformInvertible()) | 501 if (!state().isTransformInvertible()) |
| 485 return; | 502 return; |
| 486 c->translate(tx, ty); | 503 c->translate(tx, ty); |
| 487 m_path.transform(AffineTransform().translate(-tx, -ty)); | 504 m_path.transform(AffineTransform().translate(-tx, -ty)); |
| 488 } | 505 } |
| 489 | 506 |
| 490 void BaseRenderingContext2D::transform(double m11, | 507 void BaseRenderingContext2D::transform(double m11, |
| 491 double m12, | 508 double m12, |
| 492 double m21, | 509 double m21, |
| 493 double m22, | 510 double m22, |
| 494 double dx, | 511 double dx, |
| 495 double dy) { | 512 double dy) { |
| 496 SkCanvas* c = drawingCanvas(); | 513 SkCanvas* c = drawingCanvas(); |
| 497 if (!c) | 514 if (!c) |
| 498 return; | 515 return; |
| 499 | 516 |
| 500 if (!std::isfinite(m11) || !std::isfinite(m21) || !std::isfinite(dx) || | 517 if (!IsFiniteFloat(m11) || !IsFiniteFloat(m21) || !IsFiniteFloat(dx) || |
| 501 !std::isfinite(m12) || !std::isfinite(m22) || !std::isfinite(dy)) | 518 !IsFiniteFloat(m12) || !IsFiniteFloat(m22) || !IsFiniteFloat(dy)) |
| 502 return; | 519 return; |
| 503 | 520 |
| 504 AffineTransform transform(m11, m12, m21, m22, dx, dy); | 521 AffineTransform transform(m11, m12, m21, m22, dx, dy); |
| 505 AffineTransform newTransform = state().transform() * transform; | 522 AffineTransform newTransform = state().transform() * transform; |
| 506 if (state().transform() == newTransform) | 523 if (state().transform() == newTransform) |
| 507 return; | 524 return; |
| 508 | 525 |
| 509 modifiableState().setTransform(newTransform); | 526 modifiableState().setTransform(newTransform); |
| 510 if (!state().isTransformInvertible()) | 527 if (!state().isTransformInvertible()) |
| 511 return; | 528 return; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 541 void BaseRenderingContext2D::setTransform(double m11, | 558 void BaseRenderingContext2D::setTransform(double m11, |
| 542 double m12, | 559 double m12, |
| 543 double m21, | 560 double m21, |
| 544 double m22, | 561 double m22, |
| 545 double dx, | 562 double dx, |
| 546 double dy) { | 563 double dy) { |
| 547 SkCanvas* c = drawingCanvas(); | 564 SkCanvas* c = drawingCanvas(); |
| 548 if (!c) | 565 if (!c) |
| 549 return; | 566 return; |
| 550 | 567 |
| 551 if (!std::isfinite(m11) || !std::isfinite(m21) || !std::isfinite(dx) || | 568 if (!IsFiniteFloat(m11) || !IsFiniteFloat(m21) || !IsFiniteFloat(dx) || |
| 552 !std::isfinite(m12) || !std::isfinite(m22) || !std::isfinite(dy)) | 569 !IsFiniteFloat(m12) || !IsFiniteFloat(m22) || !IsFiniteFloat(dy)) |
| 553 return; | 570 return; |
| 554 | 571 |
| 555 resetTransform(); | 572 resetTransform(); |
| 556 transform(m11, m12, m21, m22, dx, dy); | 573 transform(m11, m12, m21, m22, dx, dy); |
| 557 } | 574 } |
| 558 | 575 |
| 559 void BaseRenderingContext2D::beginPath() { | 576 void BaseRenderingContext2D::beginPath() { |
| 560 m_path.clear(); | 577 m_path.clear(); |
| 561 } | 578 } |
| 562 | 579 |
| 563 static bool validateRectForCanvas(double& x, | 580 static bool validateRectForCanvas(double& x, |
| 564 double& y, | 581 double& y, |
| 565 double& width, | 582 double& width, |
| 566 double& height) { | 583 double& height) { |
| 567 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || | 584 if (!IsFiniteFloat(x) || !IsFiniteFloat(y) || !IsFiniteFloat(width) || |
| 568 !std::isfinite(height)) | 585 !IsFiniteFloat(height)) |
| 569 return false; | 586 return false; |
| 570 | 587 |
| 571 if (!width && !height) | 588 if (!width && !height) |
| 572 return false; | 589 return false; |
| 573 | 590 |
| 574 if (width < 0) { | 591 if (width < 0) { |
| 575 width = -width; | 592 width = -width; |
| 576 x -= width; | 593 x -= width; |
| 577 } | 594 } |
| 578 | 595 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 const double x, | 790 const double x, |
| 774 const double y, | 791 const double y, |
| 775 const String& windingRuleString) { | 792 const String& windingRuleString) { |
| 776 SkCanvas* c = drawingCanvas(); | 793 SkCanvas* c = drawingCanvas(); |
| 777 if (!c) | 794 if (!c) |
| 778 return false; | 795 return false; |
| 779 if (!state().isTransformInvertible()) | 796 if (!state().isTransformInvertible()) |
| 780 return false; | 797 return false; |
| 781 | 798 |
| 782 FloatPoint point(x, y); | 799 FloatPoint point(x, y); |
| 783 if (!std::isfinite(point.x()) || !std::isfinite(point.y())) | 800 if (!IsFiniteFloat(point.x()) || !IsFiniteFloat(point.y())) |
| 784 return false; | 801 return false; |
| 785 AffineTransform ctm = state().transform(); | 802 AffineTransform ctm = state().transform(); |
| 786 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); | 803 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); |
| 787 | 804 |
| 788 return path.contains(transformedPoint, | 805 return path.contains(transformedPoint, |
| 789 SkFillTypeToWindRule(parseWinding(windingRuleString))); | 806 SkFillTypeToWindRule(parseWinding(windingRuleString))); |
| 790 } | 807 } |
| 791 | 808 |
| 792 bool BaseRenderingContext2D::isPointInStroke(const double x, const double y) { | 809 bool BaseRenderingContext2D::isPointInStroke(const double x, const double y) { |
| 793 return isPointInStrokeInternal(m_path, x, y); | 810 return isPointInStrokeInternal(m_path, x, y); |
| 794 } | 811 } |
| 795 | 812 |
| 796 bool BaseRenderingContext2D::isPointInStroke(Path2D* domPath, | 813 bool BaseRenderingContext2D::isPointInStroke(Path2D* domPath, |
| 797 const double x, | 814 const double x, |
| 798 const double y) { | 815 const double y) { |
| 799 return isPointInStrokeInternal(domPath->path(), x, y); | 816 return isPointInStrokeInternal(domPath->path(), x, y); |
| 800 } | 817 } |
| 801 | 818 |
| 802 bool BaseRenderingContext2D::isPointInStrokeInternal(const Path& path, | 819 bool BaseRenderingContext2D::isPointInStrokeInternal(const Path& path, |
| 803 const double x, | 820 const double x, |
| 804 const double y) { | 821 const double y) { |
| 805 SkCanvas* c = drawingCanvas(); | 822 SkCanvas* c = drawingCanvas(); |
| 806 if (!c) | 823 if (!c) |
| 807 return false; | 824 return false; |
| 808 if (!state().isTransformInvertible()) | 825 if (!state().isTransformInvertible()) |
| 809 return false; | 826 return false; |
| 810 | 827 |
| 811 FloatPoint point(x, y); | 828 FloatPoint point(x, y); |
| 812 if (!std::isfinite(point.x()) || !std::isfinite(point.y())) | 829 if (!IsFiniteFloat(point.x()) || !IsFiniteFloat(point.y())) |
| 813 return false; | 830 return false; |
| 814 AffineTransform ctm = state().transform(); | 831 AffineTransform ctm = state().transform(); |
| 815 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); | 832 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); |
| 816 | 833 |
| 817 StrokeData strokeData; | 834 StrokeData strokeData; |
| 818 strokeData.setThickness(state().lineWidth()); | 835 strokeData.setThickness(state().lineWidth()); |
| 819 strokeData.setLineCap(state().getLineCap()); | 836 strokeData.setLineCap(state().getLineCap()); |
| 820 strokeData.setLineJoin(state().getLineJoin()); | 837 strokeData.setLineJoin(state().getLineJoin()); |
| 821 strokeData.setMiterLimit(state().miterLimit()); | 838 strokeData.setMiterLimit(state().miterLimit()); |
| 822 Vector<float> lineDash(state().lineDash().size()); | 839 Vector<float> lineDash(state().lineDash().size()); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 exceptionState.throwDOMException( | 1160 exceptionState.throwDOMException( |
| 1144 InvalidStateError, | 1161 InvalidStateError, |
| 1145 "The HTMLImageElement provided is in the 'broken' state."); | 1162 "The HTMLImageElement provided is in the 'broken' state."); |
| 1146 if (!image || !image->width() || !image->height()) | 1163 if (!image || !image->width() || !image->height()) |
| 1147 return; | 1164 return; |
| 1148 } else { | 1165 } else { |
| 1149 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame()) | 1166 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame()) |
| 1150 return; | 1167 return; |
| 1151 } | 1168 } |
| 1152 | 1169 |
| 1153 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || | 1170 if (!IsFiniteFloat(dx) || !IsFiniteFloat(dy) || !IsFiniteFloat(dw) || |
| 1154 !std::isfinite(dh) || !std::isfinite(sx) || !std::isfinite(sy) || | 1171 !IsFiniteFloat(dh) || !IsFiniteFloat(sx) || !IsFiniteFloat(sy) || |
| 1155 !std::isfinite(sw) || !std::isfinite(sh) || !dw || !dh || !sw || !sh) | 1172 !IsFiniteFloat(sw) || !IsFiniteFloat(sh) || !dw || !dh || !sw || !sh) |
| 1156 return; | 1173 return; |
| 1157 | 1174 |
| 1158 FloatRect srcRect = normalizeRect(FloatRect(sx, sy, sw, sh)); | 1175 FloatRect srcRect = normalizeRect(FloatRect(sx, sy, sw, sh)); |
| 1159 FloatRect dstRect = normalizeRect(FloatRect(dx, dy, dw, dh)); | 1176 FloatRect dstRect = normalizeRect(FloatRect(dx, dy, dw, dh)); |
| 1160 FloatSize imageSize = imageSource->elementSize(defaultObjectSize); | 1177 FloatSize imageSize = imageSource->elementSize(defaultObjectSize); |
| 1161 | 1178 |
| 1162 clipRectsToImageRect(FloatRect(FloatPoint(), imageSize), &srcRect, &dstRect); | 1179 clipRectsToImageRect(FloatRect(FloatPoint(), imageSize), &srcRect, &dstRect); |
| 1163 | 1180 |
| 1164 imageSource->adjustDrawRects(&srcRect, &dstRect); | 1181 imageSource->adjustDrawRects(&srcRect, &dstRect); |
| 1165 | 1182 |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2013 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * | 2030 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * |
| 2014 m_usageCounters.numBlurredShadows + | 2031 m_usageCounters.numBlurredShadows + |
| 2015 ExpensiveCanvasHeuristicParameters:: | 2032 ExpensiveCanvasHeuristicParameters:: |
| 2016 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * | 2033 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * |
| 2017 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; | 2034 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; |
| 2018 | 2035 |
| 2019 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; | 2036 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; |
| 2020 } | 2037 } |
| 2021 | 2038 |
| 2022 } // namespace blink | 2039 } // namespace blink |
| OLD | NEW |