| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 IntSize toImageSize = m_toImage->size(); | 52 IntSize toImageSize = m_toImage->size(); |
| 53 | 53 |
| 54 // Draw nothing if either of the images hasn't loaded yet. | 54 // Draw nothing if either of the images hasn't loaded yet. |
| 55 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) | 55 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 GraphicsContextStateSaver stateSaver(*context); | 58 GraphicsContextStateSaver stateSaver(*context); |
| 59 | 59 |
| 60 context->clip(IntRect(IntPoint(), m_crossfadeSize)); | 60 context->clip(IntRect(IntPoint(), m_crossfadeSize)); |
| 61 context->beginTransparencyLayer(1); | 61 context->beginTransparencyLayer(1); |
| 62 | 62 |
| 63 // Draw the image we're fading away from. | 63 // Draw the image we're fading away from. |
| 64 context->save(); | 64 context->save(); |
| 65 if (m_crossfadeSize != fromImageSize) | 65 if (m_crossfadeSize != fromImageSize) |
| 66 context->scale(FloatSize(static_cast<float>(m_crossfadeSize.width()) / f
romImageSize.width(), | 66 context->scale(FloatSize(static_cast<float>(m_crossfadeSize.width()) / f
romImageSize.width(), |
| 67 static_cast<float>(m_crossfadeSize.height()) /
fromImageSize.height())); | 67 static_cast<float>(m_crossfadeSize.height()) /
fromImageSize.height())); |
| 68 context->setAlpha(inversePercentage); | 68 context->setAlpha(inversePercentage); |
| 69 context->drawImage(m_fromImage, ColorSpaceDeviceRGB, IntPoint()); | 69 context->drawImage(m_fromImage, IntPoint()); |
| 70 context->restore(); | 70 context->restore(); |
| 71 | 71 |
| 72 // Draw the image we're fading towards. | 72 // Draw the image we're fading towards. |
| 73 context->save(); | 73 context->save(); |
| 74 if (m_crossfadeSize != toImageSize) | 74 if (m_crossfadeSize != toImageSize) |
| 75 context->scale(FloatSize(static_cast<float>(m_crossfadeSize.width()) / t
oImageSize.width(), | 75 context->scale(FloatSize(static_cast<float>(m_crossfadeSize.width()) / t
oImageSize.width(), |
| 76 static_cast<float>(m_crossfadeSize.height()) /
toImageSize.height())); | 76 static_cast<float>(m_crossfadeSize.height()) /
toImageSize.height())); |
| 77 context->setAlpha(m_percentage); | 77 context->setAlpha(m_percentage); |
| 78 context->drawImage(m_toImage, ColorSpaceDeviceRGB, IntPoint(), CompositePlus
Lighter); | 78 context->drawImage(m_toImage, IntPoint(), CompositePlusLighter); |
| 79 context->restore(); | 79 context->restore(); |
| 80 | 80 |
| 81 context->endTransparencyLayer(); | 81 context->endTransparencyLayer(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void CrossfadeGeneratedImage::draw(GraphicsContext* context, const FloatRect& ds
tRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp, Blen
dMode) | 84 void CrossfadeGeneratedImage::draw(GraphicsContext* context, const FloatRect& ds
tRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode) |
| 85 { | 85 { |
| 86 GraphicsContextStateSaver stateSaver(*context); | 86 GraphicsContextStateSaver stateSaver(*context); |
| 87 context->setCompositeOperation(compositeOp); | 87 context->setCompositeOperation(compositeOp); |
| 88 context->clip(dstRect); | 88 context->clip(dstRect); |
| 89 context->translate(dstRect.x(), dstRect.y()); | 89 context->translate(dstRect.x(), dstRect.y()); |
| 90 if (dstRect.size() != srcRect.size()) | 90 if (dstRect.size() != srcRect.size()) |
| 91 context->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.heig
ht() / srcRect.height())); | 91 context->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.heig
ht() / srcRect.height())); |
| 92 context->translate(-srcRect.x(), -srcRect.y()); | 92 context->translate(-srcRect.x(), -srcRect.y()); |
| 93 | 93 |
| 94 drawCrossfade(context); | 94 drawCrossfade(context); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void CrossfadeGeneratedImage::drawPattern(GraphicsContext* context, const FloatR
ect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase,
ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& dstR
ect, BlendMode) | 97 void CrossfadeGeneratedImage::drawPattern(GraphicsContext* context, const FloatR
ect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase,
CompositeOperator compositeOp, const FloatRect& dstRect, BlendMode) |
| 98 { | 98 { |
| 99 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(m_size, 1, ColorSpaceD
eviceRGB, context->isAccelerated() ? Accelerated : Unaccelerated); | 99 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(m_size, 1, context->is
Accelerated() ? Accelerated : Unaccelerated); |
| 100 if (!imageBuffer) | 100 if (!imageBuffer) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 // Fill with the cross-faded image. | 103 // Fill with the cross-faded image. |
| 104 GraphicsContext* graphicsContext = imageBuffer->context(); | 104 GraphicsContext* graphicsContext = imageBuffer->context(); |
| 105 drawCrossfade(graphicsContext); | 105 drawCrossfade(graphicsContext); |
| 106 | 106 |
| 107 // Tile the image buffer into the context. | 107 // Tile the image buffer into the context. |
| 108 imageBuffer->drawPattern(context, srcRect, patternTransform, phase, styleCol
orSpace, compositeOp, dstRect); | 108 imageBuffer->drawPattern(context, srcRect, patternTransform, phase, composit
eOp, dstRect); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void CrossfadeGeneratedImage::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn
fo) const | 111 void CrossfadeGeneratedImage::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn
fo) const |
| 112 { | 112 { |
| 113 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); | 113 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); |
| 114 GeneratedImage::reportMemoryUsage(memoryObjectInfo); | 114 GeneratedImage::reportMemoryUsage(memoryObjectInfo); |
| 115 info.addMember(m_fromImage, "fromImage"); | 115 info.addMember(m_fromImage, "fromImage"); |
| 116 info.addMember(m_toImage, "toImage"); | 116 info.addMember(m_toImage, "toImage"); |
| 117 } | 117 } |
| 118 | 118 |
| 119 } | 119 } |
| OLD | NEW |