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

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

Issue 645693004: Canvas 2D: Remove CompositeOperator and WebBlendMode parameters in drawImageInternal(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Make drawImageInternal() simpler Created 6 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
« no previous file with comments | « Source/core/html/canvas/CanvasRenderingContext2D.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) 247 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black))
248 , m_fillStyle(CanvasStyle::createFromRGBA(Color::black)) 248 , m_fillStyle(CanvasStyle::createFromRGBA(Color::black))
249 , m_lineWidth(1) 249 , m_lineWidth(1)
250 , m_lineCap(ButtCap) 250 , m_lineCap(ButtCap)
251 , m_lineJoin(MiterJoin) 251 , m_lineJoin(MiterJoin)
252 , m_miterLimit(10) 252 , m_miterLimit(10)
253 , m_shadowBlur(0) 253 , m_shadowBlur(0)
254 , m_shadowColor(Color::transparent) 254 , m_shadowColor(Color::transparent)
255 , m_globalAlpha(1) 255 , m_globalAlpha(1)
256 , m_globalComposite(CompositeSourceOver) 256 , m_globalComposite(CompositeSourceOver)
257 , m_globalBlend(blink::WebBlendModeNormal) 257 , m_globalBlend(WebBlendModeNormal)
258 , m_invertibleCTM(true) 258 , m_invertibleCTM(true)
259 , m_lineDashOffset(0) 259 , m_lineDashOffset(0)
260 , m_imageSmoothingEnabled(true) 260 , m_imageSmoothingEnabled(true)
261 , m_textAlign(StartTextAlign) 261 , m_textAlign(StartTextAlign)
262 , m_textBaseline(AlphabeticTextBaseline) 262 , m_textBaseline(AlphabeticTextBaseline)
263 , m_direction(DirectionInherit) 263 , m_direction(DirectionInherit)
264 , m_unparsedFont(defaultFont) 264 , m_unparsedFont(defaultFont)
265 , m_realizedFont(false) 265 , m_realizedFont(false)
266 , m_hasClip(false) 266 , m_hasClip(false)
267 { 267 {
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 691 }
692 692
693 String CanvasRenderingContext2D::globalCompositeOperation() const 693 String CanvasRenderingContext2D::globalCompositeOperation() const
694 { 694 {
695 return compositeOperatorName(state().m_globalComposite, state().m_globalBlen d); 695 return compositeOperatorName(state().m_globalComposite, state().m_globalBlen d);
696 } 696 }
697 697
698 void CanvasRenderingContext2D::setGlobalCompositeOperation(const String& operati on) 698 void CanvasRenderingContext2D::setGlobalCompositeOperation(const String& operati on)
699 { 699 {
700 CompositeOperator op = CompositeSourceOver; 700 CompositeOperator op = CompositeSourceOver;
701 blink::WebBlendMode blendMode = blink::WebBlendModeNormal; 701 WebBlendMode blendMode = WebBlendModeNormal;
702 if (!parseCompositeAndBlendOperator(operation, op, blendMode)) 702 if (!parseCompositeAndBlendOperator(operation, op, blendMode))
703 return; 703 return;
704 if ((state().m_globalComposite == op) && (state().m_globalBlend == blendMode )) 704 if ((state().m_globalComposite == op) && (state().m_globalBlend == blendMode ))
705 return; 705 return;
706 GraphicsContext* c = drawingContext(); 706 GraphicsContext* c = drawingContext();
707 realizeSaves(c); 707 realizeSaves(c);
708 modifiableState().m_globalComposite = op; 708 modifiableState().m_globalComposite = op;
709 modifiableState().m_globalBlend = blendMode; 709 modifiableState().m_globalBlend = blendMode;
710 if (!c) 710 if (!c)
711 return; 711 return;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 // If gradient size is zero, then paint nothing. 1018 // If gradient size is zero, then paint nothing.
1019 Gradient* gradient = c->fillGradient(); 1019 Gradient* gradient = c->fillGradient();
1020 if (gradient && gradient->isZeroSize()) { 1020 if (gradient && gradient->isZeroSize()) {
1021 return; 1021 return;
1022 } 1022 }
1023 1023
1024 WindRule windRule = c->fillRule(); 1024 WindRule windRule = c->fillRule();
1025 c->setFillRule(parseWinding(windingRuleString)); 1025 c->setFillRule(parseWinding(windingRuleString));
1026 1026
1027 if (isFullCanvasCompositeMode(state().m_globalComposite)) { 1027 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1028 fullCanvasCompositedFill(path); 1028 fullCanvasCompositedDraw<Fill>(path);
1029 didDraw(clipBounds); 1029 didDraw(clipBounds);
1030 } else if (state().m_globalComposite == CompositeCopy) { 1030 } else if (state().m_globalComposite == CompositeCopy) {
1031 clearCanvas(); 1031 clearCanvas();
1032 c->fillPath(path); 1032 c->fillPath(path);
1033 didDraw(clipBounds); 1033 didDraw(clipBounds);
1034 } else { 1034 } else {
1035 FloatRect dirtyRect; 1035 FloatRect dirtyRect;
1036 if (computeDirtyRect(path.boundingRect(), clipBounds, &dirtyRect)) { 1036 if (computeDirtyRect(path.boundingRect(), clipBounds, &dirtyRect)) {
1037 c->fillPath(path); 1037 c->fillPath(path);
1038 didDraw(dirtyRect); 1038 didDraw(dirtyRect);
(...skipping 29 matching lines...) Expand all
1068 if (!c->getTransformedClipBounds(&clipBounds)) 1068 if (!c->getTransformedClipBounds(&clipBounds))
1069 return; 1069 return;
1070 1070
1071 // If gradient size is zero, then paint nothing. 1071 // If gradient size is zero, then paint nothing.
1072 Gradient* gradient = c->strokeGradient(); 1072 Gradient* gradient = c->strokeGradient();
1073 if (gradient && gradient->isZeroSize()) { 1073 if (gradient && gradient->isZeroSize()) {
1074 return; 1074 return;
1075 } 1075 }
1076 1076
1077 if (isFullCanvasCompositeMode(state().m_globalComposite)) { 1077 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1078 fullCanvasCompositedStroke(path); 1078 fullCanvasCompositedDraw<Stroke>(path);
1079 didDraw(clipBounds); 1079 didDraw(clipBounds);
1080 } else if (state().m_globalComposite == CompositeCopy) { 1080 } else if (state().m_globalComposite == CompositeCopy) {
1081 clearCanvas(); 1081 clearCanvas();
1082 c->strokePath(path); 1082 c->strokePath(path);
1083 didDraw(clipBounds); 1083 didDraw(clipBounds);
1084 } else { 1084 } else {
1085 FloatRect bounds = path.boundingRect(); 1085 FloatRect bounds = path.boundingRect();
1086 inflateStrokeRect(bounds); 1086 inflateStrokeRect(bounds);
1087 FloatRect dirtyRect; 1087 FloatRect dirtyRect;
1088 if (computeDirtyRect(bounds, clipBounds, &dirtyRect)) { 1088 if (computeDirtyRect(bounds, clipBounds, &dirtyRect)) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 // If x0 = x1 and y0 = y1 and r0 = r1, then the radial gradient must paint n othing 1287 // If x0 = x1 and y0 = y1 and r0 = r1, then the radial gradient must paint n othing
1288 Gradient* gradient = c->fillGradient(); 1288 Gradient* gradient = c->fillGradient();
1289 if (gradient && gradient->isZeroSize()) 1289 if (gradient && gradient->isZeroSize())
1290 return; 1290 return;
1291 1291
1292 FloatRect rect(x, y, width, height); 1292 FloatRect rect(x, y, width, height);
1293 if (rectContainsTransformedRect(rect, clipBounds)) { 1293 if (rectContainsTransformedRect(rect, clipBounds)) {
1294 c->fillRect(rect); 1294 c->fillRect(rect);
1295 didDraw(clipBounds); 1295 didDraw(clipBounds);
1296 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) { 1296 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1297 fullCanvasCompositedFill(rect); 1297 fullCanvasCompositedDraw<Fill>(rect);
1298 didDraw(clipBounds); 1298 didDraw(clipBounds);
1299 } else if (state().m_globalComposite == CompositeCopy) { 1299 } else if (state().m_globalComposite == CompositeCopy) {
1300 clearCanvas(); 1300 clearCanvas();
1301 c->fillRect(rect); 1301 c->fillRect(rect);
1302 didDraw(clipBounds); 1302 didDraw(clipBounds);
1303 } else { 1303 } else {
1304 FloatRect dirtyRect; 1304 FloatRect dirtyRect;
1305 if (computeDirtyRect(rect, clipBounds, &dirtyRect)) { 1305 if (computeDirtyRect(rect, clipBounds, &dirtyRect)) {
1306 c->fillRect(rect); 1306 c->fillRect(rect);
1307 didDraw(dirtyRect); 1307 didDraw(dirtyRect);
(...skipping 17 matching lines...) Expand all
1325 FloatRect clipBounds; 1325 FloatRect clipBounds;
1326 if (!c->getTransformedClipBounds(&clipBounds)) 1326 if (!c->getTransformedClipBounds(&clipBounds))
1327 return; 1327 return;
1328 1328
1329 // If gradient size is zero, then paint nothing. 1329 // If gradient size is zero, then paint nothing.
1330 Gradient* gradient = c->strokeGradient(); 1330 Gradient* gradient = c->strokeGradient();
1331 if (gradient && gradient->isZeroSize()) 1331 if (gradient && gradient->isZeroSize())
1332 return; 1332 return;
1333 1333
1334 FloatRect rect(x, y, width, height); 1334 FloatRect rect(x, y, width, height);
1335
1336 if (isFullCanvasCompositeMode(state().m_globalComposite)) { 1335 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1337 fullCanvasCompositedStroke(rect); 1336 fullCanvasCompositedDraw<Stroke>(rect);
1338 didDraw(clipBounds); 1337 didDraw(clipBounds);
1339 } else if (state().m_globalComposite == CompositeCopy) { 1338 } else if (state().m_globalComposite == CompositeCopy) {
1340 clearCanvas(); 1339 clearCanvas();
1341 c->strokeRect(rect); 1340 c->strokeRect(rect);
1342 didDraw(clipBounds); 1341 didDraw(clipBounds);
1343 } else { 1342 } else {
1344 FloatRect boundingRect = rect; 1343 FloatRect boundingRect = rect;
1345 boundingRect.inflate(state().m_lineWidth / 2); 1344 boundingRect.inflate(state().m_lineWidth / 2);
1346 FloatRect dirtyRect; 1345 FloatRect dirtyRect;
1347 if (computeDirtyRect(boundingRect, clipBounds, &dirtyRect)) { 1346 if (computeDirtyRect(boundingRect, clipBounds, &dirtyRect)) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 srcRect->intersect(imageRect); 1451 srcRect->intersect(imageRect);
1453 1452
1454 // To clip the destination rectangle in the same proportion, transform the c lipped src rect 1453 // To clip the destination rectangle in the same proportion, transform the c lipped src rect
1455 *dstRect = *srcRect; 1454 *dstRect = *srcRect;
1456 dstRect->scale(scale.width(), scale.height()); 1455 dstRect->scale(scale.width(), scale.height());
1457 dstRect->move(offset); 1456 dstRect->move(offset);
1458 } 1457 }
1459 1458
1460 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, float x , float y, ExceptionState& exceptionState) 1459 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, float x , float y, ExceptionState& exceptionState)
1461 { 1460 {
1461 FloatSize sourceRectSize = imageSource->sourceSize();
1462 FloatSize destRectSize = imageSource->defaultDestinationSize(); 1462 FloatSize destRectSize = imageSource->defaultDestinationSize();
1463 drawImage(imageSource, x, y, destRectSize.width(), destRectSize.height(), ex ceptionState); 1463 drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState);
1464 } 1464 }
1465 1465
1466 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, 1466 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
1467 float x, float y, float width, float height, ExceptionState& exceptionState) 1467 float x, float y, float width, float height, ExceptionState& exceptionState)
1468 { 1468 {
1469 FloatSize sourceRectSize = imageSource->sourceSize(); 1469 FloatSize sourceRectSize = imageSource->sourceSize();
1470 drawImage(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height() , x, y, width, height, exceptionState); 1470 drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, width, height, exceptionState);
1471 } 1471 }
1472 1472
1473 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, 1473 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
1474 float sx, float sy, float sw, float sh, 1474 float sx, float sy, float sw, float sh,
1475 float dx, float dy, float dw, float dh, ExceptionState& exceptionState) 1475 float dx, float dy, float dw, float dh, ExceptionState& exceptionState)
1476 { 1476 {
1477 GraphicsContext* c = drawingContext(); // Do not exit yet if !c because we m ay need to throw exceptions first 1477 drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e);
1478 CompositeOperator op = c ? c->compositeOperation() : CompositeSourceOver;
1479 blink::WebBlendMode blendMode = c ? c->blendModeOperation() : blink::WebBlen dModeNormal;
1480 drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e, op, blendMode, c);
1481 } 1478 }
1482 1479
1483 void CanvasRenderingContext2D::drawImageInternal(CanvasImageSource* imageSource, 1480 void CanvasRenderingContext2D::drawImageInternal(CanvasImageSource* imageSource,
1484 float sx, float sy, float sw, float sh, 1481 float sx, float sy, float sw, float sh,
1485 float dx, float dy, float dw, float dh, ExceptionState& exceptionState, 1482 float dx, float dy, float dw, float dh, ExceptionState& exceptionState)
1486 CompositeOperator op, blink::WebBlendMode blendMode, GraphicsContext* c)
1487 { 1483 {
1488 RefPtr<Image> image; 1484 RefPtr<Image> image;
1489 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; 1485 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus;
1490 if (!imageSource->isVideoElement()) { 1486 if (!imageSource->isVideoElement()) {
1491 SourceImageMode mode = canvas() == imageSource ? CopySourceImageIfVolati le : DontCopySourceImage; // Thunking for == 1487 SourceImageMode mode = canvas() == imageSource ? CopySourceImageIfVolati le : DontCopySourceImage; // Thunking for ==
1492 image = imageSource->getSourceImageForCanvas(mode, &sourceImageStatus); 1488 image = imageSource->getSourceImageForCanvas(mode, &sourceImageStatus);
1493 if (sourceImageStatus == UndecodableSourceImageStatus) 1489 if (sourceImageStatus == UndecodableSourceImageStatus)
1494 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state."); 1490 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state.");
1495 if (!image || !image->width() || !image->height()) 1491 if (!image || !image->width() || !image->height())
1496 return; 1492 return;
1497 } 1493 }
1498 1494
1499 if (!c) 1495 GraphicsContext* c = drawingContext();
1500 c = drawingContext();
1501 if (!c) 1496 if (!c)
1502 return; 1497 return;
1503 1498
1504 if (!state().m_invertibleCTM) 1499 if (!state().m_invertibleCTM)
1505 return; 1500 return;
1506 1501
1507 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || !std:: isfinite(dh) 1502 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || !std:: isfinite(dh)
1508 || !std::isfinite(sx) || !std::isfinite(sy) || !std::isfinite(sw) || !st d::isfinite(sh) 1503 || !std::isfinite(sx) || !std::isfinite(sy) || !std::isfinite(sw) || !st d::isfinite(sh)
1509 || !dw || !dh || !sw || !sh) 1504 || !dw || !dh || !sw || !sh)
1510 return; 1505 return;
1511 1506
1512 FloatRect clipBounds; 1507 FloatRect clipBounds;
1513 if (!c->getTransformedClipBounds(&clipBounds)) 1508 if (!c->getTransformedClipBounds(&clipBounds))
1514 return; 1509 return;
1515 1510
1516 FloatRect srcRect = normalizeRect(FloatRect(sx, sy, sw, sh)); 1511 FloatRect srcRect = normalizeRect(FloatRect(sx, sy, sw, sh));
1517 FloatRect dstRect = normalizeRect(FloatRect(dx, dy, dw, dh)); 1512 FloatRect dstRect = normalizeRect(FloatRect(dx, dy, dw, dh));
1518 1513
1519 clipRectsToImageRect(FloatRect(FloatPoint(), imageSource->sourceSize()), &sr cRect, &dstRect); 1514 clipRectsToImageRect(FloatRect(FloatPoint(), imageSource->sourceSize()), &sr cRect, &dstRect);
1520 1515
1521 imageSource->adjustDrawRects(&srcRect, &dstRect); 1516 imageSource->adjustDrawRects(&srcRect, &dstRect);
1522 1517
1523 if (srcRect.isEmpty()) 1518 if (srcRect.isEmpty())
1524 return; 1519 return;
1525 1520
1521 CompositeOperator op = state().m_globalComposite;
1522 WebBlendMode blendMode = state().m_globalBlend;
1526 if (rectContainsTransformedRect(dstRect, clipBounds)) { 1523 if (rectContainsTransformedRect(dstRect, clipBounds)) {
1527 if (!imageSource->isVideoElement()) { 1524 if (!imageSource->isVideoElement()) {
1528 c->drawImage(image.get(), dstRect, srcRect, op, blendMode); 1525 c->drawImage(image.get(), dstRect, srcRect, op, blendMode);
1529 } else { 1526 } else {
1530 drawVideo(static_cast<HTMLVideoElement*>(imageSource), srcRect, dstR ect); 1527 drawVideo(static_cast<HTMLVideoElement*>(imageSource), srcRect, dstR ect);
1531 } 1528 }
1532 didDraw(clipBounds); 1529 didDraw(clipBounds);
1533 } else if (isFullCanvasCompositeMode(op)) { 1530 } else if (isFullCanvasCompositeMode(op)) {
1534 CompositeOperator previousOperator = c->compositeOperation();
1535 WebBlendMode previousBlendMode = c->blendModeOperation();
1536 c->setCompositeOperation(previousOperator, blendMode);
1537 // TODO(dshwang): this code is unnecessarily complicated because beginLa yer() uses current blendMode slightly. 1531 // TODO(dshwang): this code is unnecessarily complicated because beginLa yer() uses current blendMode slightly.
1538 c->beginLayer(1, op); 1532 c->beginLayer(1, op);
1539 if (!imageSource->isVideoElement()) { 1533 if (!imageSource->isVideoElement()) {
1540 c->drawImage(image.get(), dstRect, srcRect, CompositeSourceOver, Web BlendModeNormal); 1534 c->drawImage(image.get(), dstRect, srcRect, CompositeSourceOver, Web BlendModeNormal);
1541 } else { 1535 } else {
1542 c->setCompositeOperation(CompositeSourceOver, WebBlendModeNormal); 1536 c->setCompositeOperation(CompositeSourceOver, WebBlendModeNormal);
1543 drawVideo(static_cast<HTMLVideoElement*>(imageSource), srcRect, dstR ect); 1537 drawVideo(static_cast<HTMLVideoElement*>(imageSource), srcRect, dstR ect);
1544 } 1538 }
1539 c->setCompositeOperation(op, blendMode);
1545 c->endLayer(); 1540 c->endLayer();
1546 c->setCompositeOperation(previousOperator, previousBlendMode);
1547 didDraw(clipBounds); 1541 didDraw(clipBounds);
1548 } else if (op == CompositeCopy) { 1542 } else if (op == CompositeCopy) {
1549 clearCanvas(); 1543 clearCanvas();
1550 if (!imageSource->isVideoElement()) { 1544 if (!imageSource->isVideoElement()) {
1551 c->drawImage(image.get(), dstRect, srcRect, op, blendMode); 1545 c->drawImage(image.get(), dstRect, srcRect, op, blendMode);
1552 } else { 1546 } else {
1553 drawVideo(static_cast<HTMLVideoElement*>(imageSource), srcRect, dstR ect); 1547 drawVideo(static_cast<HTMLVideoElement*>(imageSource), srcRect, dstR ect);
1554 } 1548 }
1555 didDraw(clipBounds); 1549 didDraw(clipBounds);
1556 } else { 1550 } else {
(...skipping 28 matching lines...) Expand all
1585 validateStateStack(); 1579 validateStateStack();
1586 } 1580 }
1587 1581
1588 void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image, 1582 void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
1589 float sx, float sy, float sw, float sh, 1583 float sx, float sy, float sw, float sh,
1590 float dx, float dy, float dw, float dh, 1584 float dx, float dy, float dw, float dh,
1591 const String& compositeOperation) 1585 const String& compositeOperation)
1592 { 1586 {
1593 if (!image) 1587 if (!image)
1594 return; 1588 return;
1595 CompositeOperator op; 1589 save();
1596 blink::WebBlendMode blendOp = blink::WebBlendModeNormal; 1590 setGlobalCompositeOperation(compositeOperation);
1597 if (!parseCompositeAndBlendOperator(compositeOperation, op, blendOp) || blen dOp != blink::WebBlendModeNormal) 1591 drawImageInternal(image, sx, sy, sw, sh, dx, dy, dw, dh, IGNORE_EXCEPTION);
1598 op = CompositeSourceOver; 1592 restore();
1599
1600 drawImageInternal(image, sx, sy, sw, sh, dx, dy, dw, dh, IGNORE_EXCEPTION, o p, blendOp);
1601 } 1593 }
1602 1594
1603 void CanvasRenderingContext2D::setAlpha(float alpha) 1595 void CanvasRenderingContext2D::setAlpha(float alpha)
1604 { 1596 {
1605 setGlobalAlpha(alpha); 1597 setGlobalAlpha(alpha);
1606 } 1598 }
1607 1599
1608 void CanvasRenderingContext2D::setCompositeOperation(const String& operation) 1600 void CanvasRenderingContext2D::setCompositeOperation(const String& operation)
1609 { 1601 {
1610 setGlobalCompositeOperation(operation); 1602 setGlobalCompositeOperation(operation);
(...skipping 22 matching lines...) Expand all
1633 static void fillPrimitive(const FloatRect& rect, GraphicsContext* context) 1625 static void fillPrimitive(const FloatRect& rect, GraphicsContext* context)
1634 { 1626 {
1635 context->fillRect(rect); 1627 context->fillRect(rect);
1636 } 1628 }
1637 1629
1638 static void fillPrimitive(const Path& path, GraphicsContext* context) 1630 static void fillPrimitive(const Path& path, GraphicsContext* context)
1639 { 1631 {
1640 context->fillPath(path); 1632 context->fillPath(path);
1641 } 1633 }
1642 1634
1643 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedFill(const T& area)
1644 {
1645 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite));
1646
1647 GraphicsContext* c = drawingContext();
1648 ASSERT(c);
1649 c->beginLayer(1, state().m_globalComposite);
1650 CompositeOperator previousOperator = c->compositeOperation();
1651 c->setCompositeOperation(CompositeSourceOver);
1652 fillPrimitive(area, c);
1653 c->setCompositeOperation(previousOperator);
1654 c->endLayer();
1655 }
1656
1657 static void strokePrimitive(const FloatRect& rect, GraphicsContext* context) 1635 static void strokePrimitive(const FloatRect& rect, GraphicsContext* context)
1658 { 1636 {
1659 context->strokeRect(rect); 1637 context->strokeRect(rect);
1660 } 1638 }
1661 1639
1662 static void strokePrimitive(const Path& path, GraphicsContext* context) 1640 static void strokePrimitive(const Path& path, GraphicsContext* context)
1663 { 1641 {
1664 context->strokePath(path); 1642 context->strokePath(path);
1665 } 1643 }
1666 1644
1667 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedStroke(cons t T& area) 1645 template<CanvasRenderingContext2D::DrawingType drawingType, class T> void Canvas RenderingContext2D::fullCanvasCompositedDraw(const T& area)
1668 { 1646 {
1669 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); 1647 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite));
1670 1648
1671 GraphicsContext* c = drawingContext(); 1649 GraphicsContext* c = drawingContext();
1672 ASSERT(c); 1650 ASSERT(c);
1673 c->beginLayer(1, state().m_globalComposite); 1651 c->beginLayer(1, state().m_globalComposite);
1674 CompositeOperator previousOperator = c->compositeOperation(); 1652 CompositeOperator previousOperator = c->compositeOperation();
1675 c->setCompositeOperation(CompositeSourceOver); 1653 c->setCompositeOperation(CompositeSourceOver);
1676 strokePrimitive(area, c); 1654 if (drawingType == Fill) {
1655 fillPrimitive(area, c);
1656 } else {
1657 strokePrimitive(area, c);
1658 }
1677 c->setCompositeOperation(previousOperator); 1659 c->setCompositeOperation(previousOperator);
1678 c->endLayer(); 1660 c->endLayer();
1679 } 1661 }
1680 1662
1681 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGra dient(float x0, float y0, float x1, float y1) 1663 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGra dient(float x0, float y0, float x1, float y1)
1682 { 1664 {
1683 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo int(x0, y0), FloatPoint(x1, y1)); 1665 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo int(x0, y0), FloatPoint(x1, y1));
1684 return gradient.release(); 1666 return gradient.release();
1685 } 1667 }
1686 1668
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 return 0; 2283 return 0;
2302 } 2284 }
2303 2285
2304 void CanvasRenderingContext2D::setIsHidden(bool hidden) 2286 void CanvasRenderingContext2D::setIsHidden(bool hidden)
2305 { 2287 {
2306 ImageBuffer* buffer = canvas()->buffer(); 2288 ImageBuffer* buffer = canvas()->buffer();
2307 if (buffer) 2289 if (buffer)
2308 buffer->setIsHidden(hidden); 2290 buffer->setIsHidden(hidden);
2309 } 2291 }
2310 2292
2311 blink::WebLayer* CanvasRenderingContext2D::platformLayer() const 2293 WebLayer* CanvasRenderingContext2D::platformLayer() const
2312 { 2294 {
2313 return canvas()->buffer() ? canvas()->buffer()->platformLayer() : 0; 2295 return canvas()->buffer() ? canvas()->buffer()->platformLayer() : 0;
2314 } 2296 }
2315 2297
2316 bool CanvasRenderingContext2D::imageSmoothingEnabled() const 2298 bool CanvasRenderingContext2D::imageSmoothingEnabled() const
2317 { 2299 {
2318 return state().m_imageSmoothingEnabled; 2300 return state().m_imageSmoothingEnabled;
2319 } 2301 }
2320 2302
2321 void CanvasRenderingContext2D::setImageSmoothingEnabled(bool enabled) 2303 void CanvasRenderingContext2D::setImageSmoothingEnabled(bool enabled)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 StrokeData strokeData; 2369 StrokeData strokeData;
2388 strokeData.setThickness(focusRingWidth); 2370 strokeData.setThickness(focusRingWidth);
2389 2371
2390 FloatRect dirtyRect; 2372 FloatRect dirtyRect;
2391 if (!computeDirtyRect(path.strokeBoundingRect(strokeData), &dirtyRect)) 2373 if (!computeDirtyRect(path.strokeBoundingRect(strokeData), &dirtyRect))
2392 return; 2374 return;
2393 2375
2394 c->save(); 2376 c->save();
2395 c->setAlphaAsFloat(1.0); 2377 c->setAlphaAsFloat(1.0);
2396 c->clearShadow(); 2378 c->clearShadow();
2397 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); 2379 c->setCompositeOperation(CompositeSourceOver, WebBlendModeNormal);
2398 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2380 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2399 c->restore(); 2381 c->restore();
2400 validateStateStack(); 2382 validateStateStack();
2401 didDraw(dirtyRect); 2383 didDraw(dirtyRect);
2402 } 2384 }
2403 2385
2404 void CanvasRenderingContext2D::addHitRegion(const HitRegionOptions& options, Exc eptionState& exceptionState) 2386 void CanvasRenderingContext2D::addHitRegion(const HitRegionOptions& options, Exc eptionState& exceptionState)
2405 { 2387 {
2406 if (options.id().isEmpty() && !options.control()) { 2388 if (options.id().isEmpty() && !options.control()) {
2407 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null."); 2389 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null.");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 2445
2464 unsigned CanvasRenderingContext2D::hitRegionsCount() const 2446 unsigned CanvasRenderingContext2D::hitRegionsCount() const
2465 { 2447 {
2466 if (m_hitRegionManager) 2448 if (m_hitRegionManager)
2467 return m_hitRegionManager->getHitRegionsCount(); 2449 return m_hitRegionManager->getHitRegionsCount();
2468 2450
2469 return 0; 2451 return 0;
2470 } 2452 }
2471 2453
2472 } // namespace blink 2454 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/canvas/CanvasRenderingContext2D.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698