| OLD | NEW |
| 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 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012 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 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 | 1293 |
| 1294 Image* imageForRendering = cachedImage->imageForRenderer(image->renderer()); | 1294 Image* imageForRendering = cachedImage->imageForRenderer(image->renderer()); |
| 1295 | 1295 |
| 1296 // For images that depend on an unavailable container size, we need to fall
back to the intrinsic | 1296 // For images that depend on an unavailable container size, we need to fall
back to the intrinsic |
| 1297 // object size. http://www.w3.org/TR/2dcontext2/#dom-context-2d-drawimage | 1297 // object size. http://www.w3.org/TR/2dcontext2/#dom-context-2d-drawimage |
| 1298 // FIXME: Without a specified image size this should resolve against the can
vas element's size, see: crbug.com/230163. | 1298 // FIXME: Without a specified image size this should resolve against the can
vas element's size, see: crbug.com/230163. |
| 1299 if (!image->renderer() && imageForRendering->usesContainerSize()) | 1299 if (!image->renderer() && imageForRendering->usesContainerSize()) |
| 1300 imageForRendering->setContainerSize(imageForRendering->size()); | 1300 imageForRendering->setContainerSize(imageForRendering->size()); |
| 1301 | 1301 |
| 1302 if (rectContainsCanvas(normalizedDstRect)) { | 1302 if (rectContainsCanvas(normalizedDstRect)) { |
| 1303 c->drawImage(imageForRendering, ColorSpaceDeviceRGB, normalizedDstRect,
normalizedSrcRect, op, blendMode); | 1303 c->drawImage(imageForRendering, normalizedDstRect, normalizedSrcRect, op
, blendMode); |
| 1304 didDrawEntireCanvas(); | 1304 didDrawEntireCanvas(); |
| 1305 } else if (isFullCanvasCompositeMode(op)) { | 1305 } else if (isFullCanvasCompositeMode(op)) { |
| 1306 fullCanvasCompositedDrawImage(imageForRendering, ColorSpaceDeviceRGB, no
rmalizedDstRect, normalizedSrcRect, op); | 1306 fullCanvasCompositedDrawImage(imageForRendering, normalizedDstRect, norm
alizedSrcRect, op); |
| 1307 didDrawEntireCanvas(); | 1307 didDrawEntireCanvas(); |
| 1308 } else if (op == CompositeCopy) { | 1308 } else if (op == CompositeCopy) { |
| 1309 clearCanvas(); | 1309 clearCanvas(); |
| 1310 c->drawImage(imageForRendering, ColorSpaceDeviceRGB, normalizedDstRect,
normalizedSrcRect, op, blendMode); | 1310 c->drawImage(imageForRendering, normalizedDstRect, normalizedSrcRect, op
, blendMode); |
| 1311 didDrawEntireCanvas(); | 1311 didDrawEntireCanvas(); |
| 1312 } else { | 1312 } else { |
| 1313 c->drawImage(imageForRendering, ColorSpaceDeviceRGB, normalizedDstRect,
normalizedSrcRect, op, blendMode); | 1313 c->drawImage(imageForRendering, normalizedDstRect, normalizedSrcRect, op
, blendMode); |
| 1314 didDraw(normalizedDstRect); | 1314 didDraw(normalizedDstRect); |
| 1315 } | 1315 } |
| 1316 } | 1316 } |
| 1317 | 1317 |
| 1318 void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, float
x, float y, ExceptionCode& ec) | 1318 void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, float
x, float y, ExceptionCode& ec) |
| 1319 { | 1319 { |
| 1320 drawImage(sourceCanvas, 0, 0, sourceCanvas->width(), sourceCanvas->height(),
x, y, sourceCanvas->width(), sourceCanvas->height(), ec); | 1320 drawImage(sourceCanvas, 0, 0, sourceCanvas->width(), sourceCanvas->height(),
x, y, sourceCanvas->width(), sourceCanvas->height(), ec); |
| 1321 } | 1321 } |
| 1322 | 1322 |
| 1323 void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, | 1323 void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 checkOrigin(sourceCanvas); | 1372 checkOrigin(sourceCanvas); |
| 1373 | 1373 |
| 1374 // If we're drawing from one accelerated canvas 2d to another, avoid calling
sourceCanvas->makeRenderingResultsAvailable() | 1374 // If we're drawing from one accelerated canvas 2d to another, avoid calling
sourceCanvas->makeRenderingResultsAvailable() |
| 1375 // as that will do a readback to software. | 1375 // as that will do a readback to software. |
| 1376 CanvasRenderingContext* sourceContext = sourceCanvas->renderingContext(); | 1376 CanvasRenderingContext* sourceContext = sourceCanvas->renderingContext(); |
| 1377 // FIXME: Implement an accelerated path for drawing from a WebGL canvas to a
2d canvas when possible. | 1377 // FIXME: Implement an accelerated path for drawing from a WebGL canvas to a
2d canvas when possible. |
| 1378 if (!isAccelerated() || !sourceContext || !sourceContext->isAccelerated() ||
!sourceContext->is2d()) | 1378 if (!isAccelerated() || !sourceContext || !sourceContext->isAccelerated() ||
!sourceContext->is2d()) |
| 1379 sourceCanvas->makeRenderingResultsAvailable(); | 1379 sourceCanvas->makeRenderingResultsAvailable(); |
| 1380 | 1380 |
| 1381 if (rectContainsCanvas(dstRect)) { | 1381 if (rectContainsCanvas(dstRect)) { |
| 1382 c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state(
).m_globalComposite, state().m_globalBlend); | 1382 c->drawImageBuffer(buffer, dstRect, srcRect, state().m_globalComposite,
state().m_globalBlend); |
| 1383 didDrawEntireCanvas(); | 1383 didDrawEntireCanvas(); |
| 1384 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) { | 1384 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) { |
| 1385 fullCanvasCompositedDrawImage(buffer, ColorSpaceDeviceRGB, dstRect, srcR
ect, state().m_globalComposite); | 1385 fullCanvasCompositedDrawImage(buffer, dstRect, srcRect, state().m_global
Composite); |
| 1386 didDrawEntireCanvas(); | 1386 didDrawEntireCanvas(); |
| 1387 } else if (state().m_globalComposite == CompositeCopy) { | 1387 } else if (state().m_globalComposite == CompositeCopy) { |
| 1388 clearCanvas(); | 1388 clearCanvas(); |
| 1389 c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state(
).m_globalComposite, state().m_globalBlend); | 1389 c->drawImageBuffer(buffer, dstRect, srcRect, state().m_globalComposite,
state().m_globalBlend); |
| 1390 didDrawEntireCanvas(); | 1390 didDrawEntireCanvas(); |
| 1391 } else { | 1391 } else { |
| 1392 c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state(
).m_globalComposite, state().m_globalBlend); | 1392 c->drawImageBuffer(buffer, dstRect, srcRect, state().m_globalComposite,
state().m_globalBlend); |
| 1393 didDraw(dstRect); | 1393 didDraw(dstRect); |
| 1394 } | 1394 } |
| 1395 } | 1395 } |
| 1396 | 1396 |
| 1397 void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, float x, float
y, ExceptionCode& ec) | 1397 void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, float x, float
y, ExceptionCode& ec) |
| 1398 { | 1398 { |
| 1399 if (!video) { | 1399 if (!video) { |
| 1400 ec = TYPE_MISMATCH_ERR; | 1400 ec = TYPE_MISMATCH_ERR; |
| 1401 return; | 1401 return; |
| 1402 } | 1402 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 IntPoint originalLocation = bufferRect.location(); | 1529 IntPoint originalLocation = bufferRect.location(); |
| 1530 bufferRect.intersect(canvasRect); | 1530 bufferRect.intersect(canvasRect); |
| 1531 if (croppedOffset) | 1531 if (croppedOffset) |
| 1532 *croppedOffset = originalLocation - bufferRect.location(); | 1532 *croppedOffset = originalLocation - bufferRect.location(); |
| 1533 return bufferRect; | 1533 return bufferRect; |
| 1534 } | 1534 } |
| 1535 | 1535 |
| 1536 PassOwnPtr<ImageBuffer> CanvasRenderingContext2D::createCompositingBuffer(const
IntRect& bufferRect) | 1536 PassOwnPtr<ImageBuffer> CanvasRenderingContext2D::createCompositingBuffer(const
IntRect& bufferRect) |
| 1537 { | 1537 { |
| 1538 RenderingMode renderMode = isAccelerated() ? Accelerated : Unaccelerated; | 1538 RenderingMode renderMode = isAccelerated() ? Accelerated : Unaccelerated; |
| 1539 return ImageBuffer::create(bufferRect.size(), 1, ColorSpaceDeviceRGB, render
Mode); | 1539 return ImageBuffer::create(bufferRect.size(), 1, renderMode); |
| 1540 } | 1540 } |
| 1541 | 1541 |
| 1542 void CanvasRenderingContext2D::compositeBuffer(ImageBuffer* buffer, const IntRec
t& bufferRect, CompositeOperator op) | 1542 void CanvasRenderingContext2D::compositeBuffer(ImageBuffer* buffer, const IntRec
t& bufferRect, CompositeOperator op) |
| 1543 { | 1543 { |
| 1544 IntRect canvasRect(0, 0, canvas()->width(), canvas()->height()); | 1544 IntRect canvasRect(0, 0, canvas()->width(), canvas()->height()); |
| 1545 canvasRect = canvas()->baseTransform().mapRect(canvasRect); | 1545 canvasRect = canvas()->baseTransform().mapRect(canvasRect); |
| 1546 | 1546 |
| 1547 GraphicsContext* c = drawingContext(); | 1547 GraphicsContext* c = drawingContext(); |
| 1548 if (!c) | 1548 if (!c) |
| 1549 return; | 1549 return; |
| 1550 | 1550 |
| 1551 c->save(); | 1551 c->save(); |
| 1552 c->setCTM(AffineTransform()); | 1552 c->setCTM(AffineTransform()); |
| 1553 c->setCompositeOperation(op); | 1553 c->setCompositeOperation(op); |
| 1554 | 1554 |
| 1555 c->save(); | 1555 c->save(); |
| 1556 c->clipOut(bufferRect); | 1556 c->clipOut(bufferRect); |
| 1557 c->clearRect(canvasRect); | 1557 c->clearRect(canvasRect); |
| 1558 c->restore(); | 1558 c->restore(); |
| 1559 | 1559 |
| 1560 c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, bufferRect.location(), state
().m_globalComposite); | 1560 c->drawImageBuffer(buffer, bufferRect.location(), state().m_globalComposite)
; |
| 1561 c->restore(); | 1561 c->restore(); |
| 1562 } | 1562 } |
| 1563 | 1563 |
| 1564 static void drawImageToContext(Image* image, GraphicsContext* context, ColorSpac
e styleColorSpace, const FloatRect& dest, const FloatRect& src, CompositeOperato
r op) | 1564 static void drawImageToContext(Image* image, GraphicsContext* context, FloatRect
& dest, const FloatRect& src, CompositeOperator op) |
| 1565 { | 1565 { |
| 1566 context->drawImage(image, styleColorSpace, dest, src, op); | 1566 context->drawImage(image, dest, src, op); |
| 1567 } | 1567 } |
| 1568 | 1568 |
| 1569 static void drawImageToContext(ImageBuffer* imageBuffer, GraphicsContext* contex
t, ColorSpace styleColorSpace, const FloatRect& dest, const FloatRect& src, Comp
ositeOperator op) | 1569 static void drawImageToContext(ImageBuffer* imageBuffer, GraphicsContext* contex
t, const FloatRect& dest, const FloatRect& src, CompositeOperator op) |
| 1570 { | 1570 { |
| 1571 context->drawImageBuffer(imageBuffer, styleColorSpace, dest, src, op); | 1571 context->drawImageBuffer(imageBuffer, dest, src, op); |
| 1572 } | 1572 } |
| 1573 | 1573 |
| 1574 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage(
T* image, ColorSpace styleColorSpace, const FloatRect& dest, const FloatRect& sr
c, CompositeOperator op) | 1574 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage(
T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) |
| 1575 { | 1575 { |
| 1576 ASSERT(isFullCanvasCompositeMode(op)); | 1576 ASSERT(isFullCanvasCompositeMode(op)); |
| 1577 | 1577 |
| 1578 IntSize croppedOffset; | 1578 IntSize croppedOffset; |
| 1579 IntRect bufferRect = calculateCompositingBufferRect(dest, &croppedOffset); | 1579 IntRect bufferRect = calculateCompositingBufferRect(dest, &croppedOffset); |
| 1580 if (bufferRect.isEmpty()) { | 1580 if (bufferRect.isEmpty()) { |
| 1581 clearCanvas(); | 1581 clearCanvas(); |
| 1582 return; | 1582 return; |
| 1583 } | 1583 } |
| 1584 | 1584 |
| 1585 OwnPtr<ImageBuffer> buffer = createCompositingBuffer(bufferRect); | 1585 OwnPtr<ImageBuffer> buffer = createCompositingBuffer(bufferRect); |
| 1586 if (!buffer) | 1586 if (!buffer) |
| 1587 return; | 1587 return; |
| 1588 | 1588 |
| 1589 GraphicsContext* c = drawingContext(); | 1589 GraphicsContext* c = drawingContext(); |
| 1590 if (!c) | 1590 if (!c) |
| 1591 return; | 1591 return; |
| 1592 | 1592 |
| 1593 FloatRect adjustedDest = dest; | 1593 FloatRect adjustedDest = dest; |
| 1594 adjustedDest.setLocation(FloatPoint(0, 0)); | 1594 adjustedDest.setLocation(FloatPoint(0, 0)); |
| 1595 AffineTransform effectiveTransform = c->getCTM(); | 1595 AffineTransform effectiveTransform = c->getCTM(); |
| 1596 IntRect transformedAdjustedRect = enclosingIntRect(effectiveTransform.mapRec
t(adjustedDest)); | 1596 IntRect transformedAdjustedRect = enclosingIntRect(effectiveTransform.mapRec
t(adjustedDest)); |
| 1597 buffer->context()->translate(-transformedAdjustedRect.location().x(), -trans
formedAdjustedRect.location().y()); | 1597 buffer->context()->translate(-transformedAdjustedRect.location().x(), -trans
formedAdjustedRect.location().y()); |
| 1598 buffer->context()->translate(croppedOffset.width(), croppedOffset.height()); | 1598 buffer->context()->translate(croppedOffset.width(), croppedOffset.height()); |
| 1599 buffer->context()->concatCTM(effectiveTransform); | 1599 buffer->context()->concatCTM(effectiveTransform); |
| 1600 drawImageToContext(image, buffer->context(), styleColorSpace, adjustedDest,
src, CompositeSourceOver); | 1600 drawImageToContext(image, buffer->context(), adjustedDest, src, CompositeSou
rceOver); |
| 1601 | 1601 |
| 1602 compositeBuffer(buffer.get(), bufferRect, op); | 1602 compositeBuffer(buffer.get(), bufferRect, op); |
| 1603 } | 1603 } |
| 1604 | 1604 |
| 1605 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedFill(const
T& area) | 1605 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedFill(const
T& area) |
| 1606 { | 1606 { |
| 1607 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); | 1607 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); |
| 1608 | 1608 |
| 1609 IntRect bufferRect = calculateCompositingBufferRect(area, 0); | 1609 IntRect bufferRect = calculateCompositingBufferRect(area, 0); |
| 1610 if (bufferRect.isEmpty()) { | 1610 if (bufferRect.isEmpty()) { |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 } | 2250 } |
| 2251 | 2251 |
| 2252 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib
utes() const | 2252 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib
utes() const |
| 2253 { | 2253 { |
| 2254 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr
eate(); | 2254 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr
eate(); |
| 2255 attributes->setAlpha(m_hasAlpha); | 2255 attributes->setAlpha(m_hasAlpha); |
| 2256 return attributes.release(); | 2256 return attributes.release(); |
| 2257 } | 2257 } |
| 2258 | 2258 |
| 2259 } // namespace WebCore | 2259 } // namespace WebCore |
| OLD | NEW |