Changeset 39079 in webkit
- Timestamp:
- Dec 6, 2008 11:48:53 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r39078 r39079 1 2008-12-06 Dirk Schulze <krit@webkit.org> 2 3 Reviewed by Oliver Hunt. 4 5 Added tests for canvas's setTransform() and updated an existing one. 6 7 * fast/canvas/canvas-setTransform-expected.txt: Added. 8 * fast/canvas/canvas-setTransform.html: Added. 9 * fast/canvas/resources/canvas-setTransform.js: Added. 10 * fast/dom/Window/window-properties-expected.txt: 11 1 12 2008-12-06 Antti Koivisto <antti@apple.com> 2 13 -
trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt
r38583 r39079 316 316 window.CanvasRenderingContext2D.prototype.setShadow [function] 317 317 window.CanvasRenderingContext2D.prototype.setStrokeColor [function] 318 window.CanvasRenderingContext2D.prototype.setTransform [function] 318 319 window.CanvasRenderingContext2D.prototype.stroke [function] 319 320 window.CanvasRenderingContext2D.prototype.strokeRect [function] -
trunk/WebCore/ChangeLog
r39078 r39079 1 2008-12-06 Dirk Schulze <krit@webkit.org> 2 3 Reviewed by Oliver Hunt. 4 5 Add support for setTransform() in canvas. 6 7 <canvas> lacks transform() and setTransform() 8 https://bugs.webkit.org/show_bug.cgi?id=16604 9 10 Test: fast/canvas/canvas-setTransform.html 11 12 * html/CanvasRenderingContext2D.cpp: 13 (WebCore::CanvasRenderingContext2D::State::State): 14 (WebCore::CanvasRenderingContext2D::setStrokeStyle): 15 (WebCore::CanvasRenderingContext2D::setFillStyle): 16 (WebCore::CanvasRenderingContext2D::scale): 17 (WebCore::CanvasRenderingContext2D::rotate): 18 (WebCore::CanvasRenderingContext2D::translate): 19 (WebCore::CanvasRenderingContext2D::transform): 20 (WebCore::CanvasRenderingContext2D::setTransform): 21 (WebCore::CanvasRenderingContext2D::beginPath): 22 (WebCore::CanvasRenderingContext2D::closePath): 23 (WebCore::CanvasRenderingContext2D::moveTo): 24 (WebCore::CanvasRenderingContext2D::lineTo): 25 (WebCore::CanvasRenderingContext2D::quadraticCurveTo): 26 (WebCore::CanvasRenderingContext2D::bezierCurveTo): 27 (WebCore::CanvasRenderingContext2D::arcTo): 28 (WebCore::CanvasRenderingContext2D::arc): 29 (WebCore::CanvasRenderingContext2D::rect): 30 (WebCore::CanvasRenderingContext2D::fill): 31 (WebCore::CanvasRenderingContext2D::stroke): 32 (WebCore::CanvasRenderingContext2D::clip): 33 (WebCore::CanvasRenderingContext2D::isPointInPath): 34 (WebCore::CanvasRenderingContext2D::clearRect): 35 (WebCore::CanvasRenderingContext2D::fillRect): 36 (WebCore::CanvasRenderingContext2D::strokeRect): 37 (WebCore::CanvasRenderingContext2D::drawImage): 38 (WebCore::CanvasRenderingContext2D::drawImageFromRect): 39 (WebCore::CanvasRenderingContext2D::willDraw): 40 (WebCore::CanvasRenderingContext2D::drawTextInternal): 41 * html/CanvasRenderingContext2D.h: 42 * html/CanvasRenderingContext2D.idl: 43 * html/HTMLCanvasElement.cpp: 44 (WebCore::HTMLCanvasElement::baseTransform): 45 * html/HTMLCanvasElement.h: 46 * platform/graphics/ImageBuffer.h: 47 (WebCore::ImageBuffer::baseTransform): 48 1 49 2008-12-06 Antti Koivisto <antti@apple.com> 2 50 -
trunk/WebCore/html/CanvasRenderingContext2D.cpp
r39000 r39079 4 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 5 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 7 * 7 8 * Redistribution and use in source and binary forms, with or without … … 100 101 , m_globalAlpha(1) 101 102 , m_globalComposite(CompositeSourceOver) 103 , m_invertibleCTM(true) 102 104 , m_textAlign(StartTextAlign) 103 105 , m_textBaseline(AlphabeticTextBaseline) … … 151 153 GraphicsContext* c = drawingContext(); 152 154 if (!c) 155 return; 156 if (!state().m_invertibleCTM) 153 157 return; 154 158 state().m_strokeStyle->applyStrokeColor(c); … … 176 180 if (!c) 177 181 return; 182 if (!state().m_invertibleCTM) 183 return; 178 184 state().m_fillStyle->applyFillColor(c); 179 185 } … … 328 334 if (!c) 329 335 return; 336 if (!state().m_invertibleCTM) 337 return; 338 339 AffineTransform newTransform = state().m_transform; 340 newTransform.scale(sx, sy); 341 if (!newTransform.isInvertible()) { 342 state().m_invertibleCTM = false; 343 return; 344 } 345 346 state().m_transform = newTransform; 330 347 c->scale(FloatSize(sx, sy)); 331 state().m_transform.scale(sx, sy);332 348 m_path.transform(AffineTransform().scale(1.0/sx, 1.0/sy)); 333 349 } … … 338 354 if (!c) 339 355 return; 356 if (!state().m_invertibleCTM) 357 return; 358 359 AffineTransform newTransform = state().m_transform; 360 newTransform.rotate(angleInRadians / piDouble * 180.0); 361 if (!newTransform.isInvertible()) { 362 state().m_invertibleCTM = false; 363 return; 364 } 365 366 state().m_transform = newTransform; 340 367 c->rotate(angleInRadians); 341 state().m_transform.rotate(angleInRadians / piDouble * 180.0);342 368 m_path.transform(AffineTransform().rotate(-angleInRadians / piDouble * 180.0)); 343 369 } … … 348 374 if (!c) 349 375 return; 376 if (!state().m_invertibleCTM) 377 return; 378 379 AffineTransform newTransform = state().m_transform; 380 newTransform.translate(tx, ty); 381 if (!newTransform.isInvertible()) { 382 state().m_invertibleCTM = false; 383 return; 384 } 385 386 state().m_transform = newTransform; 350 387 c->translate(tx, ty); 351 state().m_transform.translate(tx, ty);352 388 m_path.transform(AffineTransform().translate(-tx, -ty)); 353 389 } … … 357 393 GraphicsContext* c = drawingContext(); 358 394 if (!c) 395 return; 396 if (!state().m_invertibleCTM) 359 397 return; 360 398 … … 363 401 !isfinite(m12) | !isfinite(m22) | !isfinite(dy)) 364 402 return; 403 365 404 AffineTransform transform(m11, m12, m21, m22, dx, dy); 405 406 AffineTransform newTransform = state().m_transform; 407 newTransform.multiply(transform); 408 if (!newTransform.isInvertible()) { 409 state().m_invertibleCTM = false; 410 return; 411 } 412 413 state().m_transform = newTransform; 366 414 c->concatCTM(transform); 367 state().m_transform.multiply(transform);368 415 m_path.transform(transform.inverse()); 369 416 } 370 417 418 void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, float m22, float dx, float dy) 419 { 420 GraphicsContext* c = drawingContext(); 421 if (!c) 422 return; 423 if (!state().m_invertibleCTM) 424 return; 425 426 // HTML5 3.14.11.1 -- ignore any calls that pass non-finite numbers 427 if (!isfinite(m11) | !isfinite(m21) | !isfinite(dx) | 428 !isfinite(m12) | !isfinite(m22) | !isfinite(dy)) 429 return; 430 431 AffineTransform ctm = state().m_transform; 432 if (!ctm.isInvertible()) 433 return; 434 c->concatCTM(c->getCTM().inverse()); 435 c->concatCTM(m_canvas->baseTransform()); 436 state().m_transform.multiply(ctm.inverse()); 437 m_path.transform(ctm); 438 439 transform(m11, m12, m21, m22, dx, dy); 440 } 441 371 442 void CanvasRenderingContext2D::setStrokeColor(const String& color) 372 443 { … … 431 502 void CanvasRenderingContext2D::beginPath() 432 503 { 504 if (!state().m_invertibleCTM) 505 return; 433 506 m_path.clear(); 434 507 } … … 436 509 void CanvasRenderingContext2D::closePath() 437 510 { 511 if (!state().m_invertibleCTM) 512 return; 438 513 m_path.closeSubpath(); 439 514 } … … 443 518 if (!isfinite(x) | !isfinite(y)) 444 519 return; 520 if (!state().m_invertibleCTM) 521 return; 445 522 m_path.moveTo(FloatPoint(x, y)); 446 523 } … … 450 527 if (!isfinite(x) | !isfinite(y)) 451 528 return; 529 if (!state().m_invertibleCTM) 530 return; 452 531 m_path.addLineTo(FloatPoint(x, y)); 453 532 } … … 457 536 if (!isfinite(cpx) | !isfinite(cpy) | !isfinite(x) | !isfinite(y)) 458 537 return; 538 if (!state().m_invertibleCTM) 539 return; 459 540 m_path.addQuadCurveTo(FloatPoint(cpx, cpy), FloatPoint(x, y)); 460 541 } … … 463 544 { 464 545 if (!isfinite(cp1x) | !isfinite(cp1y) | !isfinite(cp2x) | !isfinite(cp2y) | !isfinite(x) | !isfinite(y)) 546 return; 547 if (!state().m_invertibleCTM) 465 548 return; 466 549 m_path.addBezierCurveTo(FloatPoint(cp1x, cp1y), FloatPoint(cp2x, cp2y), FloatPoint(x, y)); … … 477 560 return; 478 561 } 479 562 if (!state().m_invertibleCTM) 563 return; 480 564 m_path.addArcTo(FloatPoint(x0, y0), FloatPoint(x1, y1), r); 481 565 } … … 491 575 return; 492 576 } 493 577 if (!state().m_invertibleCTM) 578 return; 494 579 m_path.addArc(FloatPoint(x, y), r, sa, ea, anticlockwise); 495 580 } … … 517 602 if (!validateRectForCanvas(x, y, width, height)) 518 603 return; 519 604 if (!state().m_invertibleCTM) 605 return; 520 606 m_path.addRect(FloatRect(x, y, width, height)); 521 607 } … … 534 620 GraphicsContext* c = drawingContext(); 535 621 if (!c) 622 return; 623 if (!state().m_invertibleCTM) 536 624 return; 537 625 … … 552 640 GraphicsContext* c = drawingContext(); 553 641 if (!c) 642 return; 643 if (!state().m_invertibleCTM) 554 644 return; 555 645 c->beginPath(); … … 577 667 if (!c) 578 668 return; 669 if (!state().m_invertibleCTM) 670 return; 579 671 c->clip(m_path); 580 672 #if ENABLE(DASHBOARD_SUPPORT) … … 588 680 if (!c) 589 681 return false; 682 if (!state().m_invertibleCTM) 683 return false; 684 590 685 FloatPoint point(x, y); 591 // We have to invert the current transform to ensure we correctly handle the592 // transforms applied to the current path.593 686 AffineTransform ctm = state().m_transform; 594 if (!ctm.isInvertible())595 return false;596 687 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); 597 688 return m_path.contains(transformedPoint); … … 604 695 GraphicsContext* c = drawingContext(); 605 696 if (!c) 697 return; 698 if (!state().m_invertibleCTM) 606 699 return; 607 700 FloatRect rect(x, y, width, height); … … 618 711 if (!c) 619 712 return; 713 if (!state().m_invertibleCTM) 714 return; 620 715 621 716 FloatRect rect(x, y, width, height); … … 644 739 GraphicsContext* c = drawingContext(); 645 740 if (!c) 741 return; 742 if (!state().m_invertibleCTM) 646 743 return; 647 744 … … 888 985 if (!c) 889 986 return; 987 if (!state().m_invertibleCTM) 988 return; 890 989 891 990 CachedImage* cachedImage = image->cachedImage(); … … 937 1036 GraphicsContext* c = drawingContext(); 938 1037 if (!c) 1038 return; 1039 if (!state().m_invertibleCTM) 939 1040 return; 940 1041 … … 977 1078 if (!c) 978 1079 return; 1080 if (!state().m_invertibleCTM) 1081 return; 979 1082 980 1083 CompositeOperator op; … … 1061 1164 GraphicsContext* c = drawingContext(); 1062 1165 if (!c) 1166 return; 1167 if (!state().m_invertibleCTM) 1063 1168 return; 1064 1169 … … 1257 1362 GraphicsContext* c = drawingContext(); 1258 1363 if (!c) 1364 return; 1365 if (!state().m_invertibleCTM) 1259 1366 return; 1260 1367 -
trunk/WebCore/html/CanvasRenderingContext2D.h
r37538 r39079 106 106 void translate(float tx, float ty); 107 107 void transform(float m11, float m12, float m21, float m22, float dx, float dy); 108 void setTransform(float m11, float m12, float m21, float m22, float dx, float dy); 108 109 109 110 void setStrokeColor(const String& color); … … 210 211 CompositeOperator m_globalComposite; 211 212 AffineTransform m_transform; 213 bool m_invertibleCTM; 212 214 213 215 // Text state. -
trunk/WebCore/html/CanvasRenderingContext2D.idl
r37538 r39079 43 43 void translate(in float tx, in float ty); 44 44 void transform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy); 45 void setTransform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy); 45 46 46 47 attribute float globalAlpha; -
trunk/WebCore/html/HTMLCanvasElement.cpp
r39007 r39079 268 268 return m_imageBuffer.get(); 269 269 } 270 271 } 270 271 AffineTransform HTMLCanvasElement::baseTransform() const 272 { 273 ASSERT(m_createdImageBuffer); 274 return m_imageBuffer->baseTransform(); 275 } 276 277 } -
trunk/WebCore/html/HTMLCanvasElement.h
r39007 r39079 28 28 #define HTMLCanvasElement_h 29 29 30 #include "AffineTransform.h" 30 31 #include "HTMLElement.h" 31 32 #include "IntSize.h" … … 106 107 void setObserver(CanvasObserver* o) { m_observer = o; } 107 108 109 AffineTransform baseTransform() const; 108 110 private: 109 111 void createImageBuffer() const; -
trunk/WebCore/platform/graphics/ImageBuffer.h
r37953 r39079 28 28 #define ImageBuffer_h 29 29 30 #include "AffineTransform.h" 30 31 #include "Image.h" 31 32 #include "IntSize.h" … … 68 69 69 70 String toDataURL(const String& mimeType) const; 70 71 #if !PLATFORM(CG) 72 AffineTransform baseTransform() const { return AffineTransform(); } 73 #else 74 AffineTransform baseTransform() const { return AffineTransform(1, 0, 0, -1, 0, m_size.height()); } 75 #endif 71 76 private: 72 77 ImageBufferData m_data;
Note: See TracChangeset
for help on using the changeset viewer.